From 671e99bfc3c67fbe285cf21593e9790edfbd1d1c Mon Sep 17 00:00:00 2001 From: Iruka <1017819588@qq.com> Date: Wed, 18 Sep 2024 12:50:53 +0800 Subject: [PATCH] . --- plugins/auth.js | 60 ++++++++++++++++++++++++++++++++++++ plugins/index.js | 10 ++++++ plugins/modal.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ plugins/tab.js | 30 ++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 plugins/auth.js create mode 100644 plugins/index.js create mode 100644 plugins/modal.js create mode 100644 plugins/tab.js diff --git a/plugins/auth.js b/plugins/auth.js new file mode 100644 index 0000000..3b91c14 --- /dev/null +++ b/plugins/auth.js @@ -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) + }) + } +} diff --git a/plugins/index.js b/plugins/index.js new file mode 100644 index 0000000..bbac158 --- /dev/null +++ b/plugins/index.js @@ -0,0 +1,10 @@ +import tab from './tab' +import auth from './auth' +import modal from './modal' + +const plugins = { + tab, + auth, + modal +} +export default plugins diff --git a/plugins/modal.js b/plugins/modal.js new file mode 100644 index 0000000..e4ea871 --- /dev/null +++ b/plugins/modal.js @@ -0,0 +1,80 @@ +export default { + // 消息提示 + msg(text) { + uni.showToast({ + title: text, + icon: 'none', + duration: 3000 + }) + }, + // 错误消息 + msgError(text) { + uni.showToast({ + title: text, + icon: 'none', + duration: 3000 + }) + }, + // 成功消息 + msgSuccess(text) { + uni.showToast({ + title: text, + icon: 'none', + duration: 3000 + }) + }, + // 隐藏消息 + hideMsg(text) { + uni.hideToast() + }, + // 弹出提示 + alert(text) { + uni.showModal({ + title: '提示', + content: text, + showCancel: false + }) + }, + // 确认窗体 + confirm(text) { + return new Promise((resolve, reject) => { + uni.showModal({ + title: '系统提示', + content: text, + cancelText: '取消', + confirmText: '确定', + success: function(res) { + if (res.confirm) { + resolve(res.confirm) + } + if(res.cancel){ + reject(res.cancel); + } + } + }) + }) + }, + // 提示信息 + showToast(option) { + if (typeof option === "object") { + uni.showToast(option) + } else { + uni.showToast({ + title: option, + icon: "none", + duration: 2500 + }) + } + }, + // 打开遮罩层 + loading(text) { + uni.showLoading({ + title: text, + icon: 'none' + }) + }, + // 关闭遮罩层 + closeLoading() { + uni.hideLoading() + } +} \ No newline at end of file diff --git a/plugins/tab.js b/plugins/tab.js new file mode 100644 index 0000000..5d1b305 --- /dev/null +++ b/plugins/tab.js @@ -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() + } +}