From abccb799755474551f084defdd09ee052ae49c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=AE=8F=E6=9D=B0?= <1943105267@qq.com> Date: Fri, 8 Nov 2024 17:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E8=B8=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.vue | 15 +++++++ pages/mine/index.vue | 1 - plugins/auth.js | 103 ++++++++++++++++++++++--------------------- 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index c18ab56..1e3802e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -53,6 +53,8 @@ onLoad: function() { + + const systemData = this.$u.sys() this.boxTop = (systemData.statusBarHeight + 44) * 2 + 80 this.queryParams.xiaoquId = this.dept.xiaoquId @@ -60,6 +62,19 @@ }, onShow() { + if (!this.$auth.hasRole("network")) { + uni.showToast({ + title: '该角色暂无权限访问App', + icon: 'error' + }) + setTimeout(() => { + this.$store.dispatch('LogOut').then(() => { + this.$tab.reLaunch('/pages/index') + }) + }, 1000) + + return + } this.queryParams.pageNum = 1 this.total = 0 this.buildingList = [] diff --git a/pages/mine/index.vue b/pages/mine/index.vue index 2f85d1e..6289b89 100644 --- a/pages/mine/index.vue +++ b/pages/mine/index.vue @@ -132,7 +132,6 @@ display: flex; align-items: center; - height: 300rpx; background-color: #3c96f3; color: white; diff --git a/plugins/auth.js b/plugins/auth.js index 3b91c14..0d5930b 100644 --- a/plugins/auth.js +++ b/plugins/auth.js @@ -1,60 +1,61 @@ 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 - } + 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 - } + // const super_admin = "admin" + const roles = store.getters && store.getters.roles + if (role && role.length > 0) { + return roles.some(v => { + return v.includes(role) + // 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) - }) - } -} + // 验证用户是否具备某权限 + 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) + }) + } +} \ No newline at end of file