init
This commit is contained in:
		
							
								
								
									
										60
									
								
								plugins/auth.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								plugins/auth.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
import store from '@/store'
 | 
			
		||||
 | 
			
		||||
function authPermission(permission) {
 | 
			
		||||
  const all_permission = "*:*:*"
 | 
			
		||||
  const permissions = store.getters && store.getters.permissions
 | 
			
		||||
  if (permission && permission.length > 0) {
 | 
			
		||||
    return permissions.some(v => {
 | 
			
		||||
      return all_permission === v || v === permission
 | 
			
		||||
    })
 | 
			
		||||
  } else {
 | 
			
		||||
    return false
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function authRole(role) {
 | 
			
		||||
  const super_admin = "admin"
 | 
			
		||||
  const roles = store.getters && store.getters.roles
 | 
			
		||||
  if (role && role.length > 0) {
 | 
			
		||||
    return roles.some(v => {
 | 
			
		||||
      return super_admin === v || v === role
 | 
			
		||||
    })
 | 
			
		||||
  } else {
 | 
			
		||||
    return false
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  // 验证用户是否具备某权限
 | 
			
		||||
  hasPermi(permission) {
 | 
			
		||||
    return authPermission(permission)
 | 
			
		||||
  },
 | 
			
		||||
  // 验证用户是否含有指定权限,只需包含其中一个
 | 
			
		||||
  hasPermiOr(permissions) {
 | 
			
		||||
    return permissions.some(item => {
 | 
			
		||||
      return authPermission(item)
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 验证用户是否含有指定权限,必须全部拥有
 | 
			
		||||
  hasPermiAnd(permissions) {
 | 
			
		||||
    return permissions.every(item => {
 | 
			
		||||
      return authPermission(item)
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 验证用户是否具备某角色
 | 
			
		||||
  hasRole(role) {
 | 
			
		||||
    return authRole(role)
 | 
			
		||||
  },
 | 
			
		||||
  // 验证用户是否含有指定角色,只需包含其中一个
 | 
			
		||||
  hasRoleOr(roles) {
 | 
			
		||||
    return roles.some(item => {
 | 
			
		||||
      return authRole(item)
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 验证用户是否含有指定角色,必须全部拥有
 | 
			
		||||
  hasRoleAnd(roles) {
 | 
			
		||||
    return roles.every(item => {
 | 
			
		||||
      return authRole(item)
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								plugins/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								plugins/index.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
import tab from './tab'
 | 
			
		||||
import auth from './auth'
 | 
			
		||||
import modal from './modal'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  install(Vue) {
 | 
			
		||||
    // 页签操作
 | 
			
		||||
    Vue.prototype.$tab = tab
 | 
			
		||||
    // 认证对象
 | 
			
		||||
    Vue.prototype.$auth = auth
 | 
			
		||||
    // 模态框对象
 | 
			
		||||
    Vue.prototype.$modal = modal
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										74
									
								
								plugins/modal.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								plugins/modal.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
export default {
 | 
			
		||||
  // 消息提示
 | 
			
		||||
  msg(content) {
 | 
			
		||||
    uni.showToast({
 | 
			
		||||
      title: content,
 | 
			
		||||
      icon: 'none'
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 错误消息
 | 
			
		||||
  msgError(content) {
 | 
			
		||||
    uni.showToast({
 | 
			
		||||
      title: content,
 | 
			
		||||
      icon: 'error'
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 成功消息
 | 
			
		||||
  msgSuccess(content) {
 | 
			
		||||
    uni.showToast({
 | 
			
		||||
      title: content,
 | 
			
		||||
      icon: 'success'
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 隐藏消息
 | 
			
		||||
  hideMsg(content) {
 | 
			
		||||
    uni.hideToast()
 | 
			
		||||
  },
 | 
			
		||||
  // 弹出提示
 | 
			
		||||
  alert(content, title) {
 | 
			
		||||
    uni.showModal({
 | 
			
		||||
      title: title || '系统提示',
 | 
			
		||||
      content: content,
 | 
			
		||||
      showCancel: false
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 确认窗体
 | 
			
		||||
  confirm(content, title) {
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      uni.showModal({
 | 
			
		||||
        title: title || '系统提示',
 | 
			
		||||
        content: content,
 | 
			
		||||
        cancelText: '取消',
 | 
			
		||||
        confirmText: '确定',
 | 
			
		||||
        success: function(res) {
 | 
			
		||||
          if (res.confirm) {
 | 
			
		||||
            resolve(res.confirm)
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 提示信息
 | 
			
		||||
  showToast(option) {
 | 
			
		||||
    if (typeof option === "object") {
 | 
			
		||||
      uni.showToast(option)
 | 
			
		||||
    } else {
 | 
			
		||||
      uni.showToast({
 | 
			
		||||
        title: option,
 | 
			
		||||
        icon: "none",
 | 
			
		||||
        duration: 2500
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  // 打开遮罩层
 | 
			
		||||
  loading(content) {
 | 
			
		||||
    uni.showLoading({
 | 
			
		||||
      title: content,
 | 
			
		||||
      icon: 'none'
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 关闭遮罩层
 | 
			
		||||
  closeLoading() {
 | 
			
		||||
    uni.hideLoading()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								plugins/tab.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								plugins/tab.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
export default {
 | 
			
		||||
  // 关闭所有页面,打开到应用内的某个页面
 | 
			
		||||
  reLaunch(url) {
 | 
			
		||||
    return uni.reLaunch({
 | 
			
		||||
      url: url
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 跳转到tabBar页面,并关闭其他所有非tabBar页面
 | 
			
		||||
  switchTab(url) {
 | 
			
		||||
    return uni.switchTab({
 | 
			
		||||
      url: url
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 关闭当前页面,跳转到应用内的某个页面
 | 
			
		||||
  redirectTo(url) {
 | 
			
		||||
    return uni.redirectTo({
 | 
			
		||||
      url: url
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 保留当前页面,跳转到应用内的某个页面
 | 
			
		||||
  navigateTo(url) {
 | 
			
		||||
    return uni.navigateTo({
 | 
			
		||||
      url: url
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  // 关闭当前页面,返回上一页面或多级页面
 | 
			
		||||
  navigateBack() {
 | 
			
		||||
    return uni.navigateBack()
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user