diff --git a/src/plugins/auth.js b/src/plugins/auth.js deleted file mode 100644 index 3b91c14..0000000 --- a/src/plugins/auth.js +++ /dev/null @@ -1,60 +0,0 @@ -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/src/plugins/auth.ts b/src/plugins/auth.ts new file mode 100644 index 0000000..48b9de7 --- /dev/null +++ b/src/plugins/auth.ts @@ -0,0 +1,84 @@ +import store from '@/store' + +function authPermission(permission: string): boolean { + const all_permission = "*:*:*" + const permissions: Array = 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: string): boolean { + const super_admin = "admin" + const roles: Array = 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 { + /** + * 验证用户是否具备某权限 + * @param permission 权限符 + * @returns + */ + hasPermi(permission: string): boolean { + return authPermission(permission) + }, + /** + * 验证用户是否含有指定权限,只需包含其中一个 + * @param permissions 权限符数组 + * @returns + */ + hasPermiOr(permissions: Array): boolean { + return permissions.some(item => { + return authPermission(item) + }) + }, + /** + * 验证用户是否含有指定权限,必须全部拥有 + * @param permissions 权限符数组 + * @returns + */ + hasPermiAnd(permissions: Array): boolean { + return permissions.every(item => { + return authPermission(item) + }) + }, + /** + * 验证用户是否具备某角色 + * @param role 角色 + * @returns + */ + hasRole(role: string): boolean { + return authRole(role) + }, + /** + * 验证用户是否含有指定角色,只需包含其中一个 + * @param roles 角色数组 + * @returns + */ + hasRoleOr(roles: Array): boolean { + return roles.some(item => { + return authRole(item) + }) + }, + /** + * 验证用户是否含有指定角色,必须全部拥有 + * @param roles 角色数组 + * @returns + */ + hasRoleAnd(roles: Array) { + return roles.every(item => { + return authRole(item) + }) + } +} diff --git a/src/plugins/index.js b/src/plugins/index.js deleted file mode 100644 index e7f0d3d..0000000 --- a/src/plugins/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import tab from './tab' -import auth from './auth' -import modal from './modal' - -export default { - install(app) { - app.config.globalProperties.$tab = tab - app.config.globalProperties.$auth = auth - app.config.globalProperties.$modal = modal - } -} diff --git a/src/plugins/index.ts b/src/plugins/index.ts new file mode 100644 index 0000000..6546c1c --- /dev/null +++ b/src/plugins/index.ts @@ -0,0 +1,16 @@ +import Tab from './tab' +import Auth from './auth' +import Modal from './modal' +import { App } from 'vue'; + +export const tab = Tab; +export const auth = Auth; +export const modal = Modal; + +export default { + install(app:App):void { + app.config.globalProperties.$tab = tab + app.config.globalProperties.$auth = auth + app.config.globalProperties.$modal = modal + } +} diff --git a/src/plugins/modal.ts b/src/plugins/modal.ts index ea6e14e..4a97dd3 100644 --- a/src/plugins/modal.ts +++ b/src/plugins/modal.ts @@ -1,46 +1,64 @@ export default { - // 消息提示 - msg(content:string) { + /** + * 消息提示 + * @param content 消息内容 + */ + msg(content: string): void { uni.showToast({ title: content, icon: 'none' }) }, - // 错误消息 - msgError(content:string) { + /** + * 错误消息 + * @param content 消息内容 + */ + msgError(content: string): void { uni.showToast({ title: content, icon: 'error' }) }, - // 成功消息 - msgSuccess(content:string) { + /** + * 成功消息 + * @param content 消息内容 + */ + msgSuccess(content: string): void { uni.showToast({ title: content, icon: 'success' }) }, - // 隐藏消息 - hideMsg(content:string) { + /** + * 隐藏消息 + */ + hideMsg(): void { uni.hideToast() }, - // 弹出提示 - alert(content:string) { + /** + * 弹出提示 + * @param content 提示内容 + */ + alert(content: string): void { uni.showModal({ title: '提示', content: content, showCancel: false }) }, - // 确认窗体 - confirm(content:string) { - return new Promise((resolve:Function, reject:Function) => { + /** + * 确认窗体 + * @param content 提示内容 + * @returns + */ + confirm(content: string): Promise { + return new Promise((resolve: Function, reject: Function) => { uni.showModal({ title: '系统提示', content: content, cancelText: '取消', confirmText: '确定', - success: function(res) { + success: function (res) { if (res.confirm) { resolve(res.confirm) } @@ -48,8 +66,11 @@ export default { }) }) }, - // 提示信息 - showToast(option: string | object) { + /** + * 提示信息 + * @param option 提示内容或者提示框配置 + */ + showToast(option: string | object): void { if (typeof option === "object") { uni.showToast(option) } else { @@ -60,14 +81,19 @@ export default { }) } }, - // 打开遮罩层 - loading(content:string) { + /** + * 打开遮罩层,需要手动关闭遮罩层 + * @param content 遮罩层内容 + */ + loading(content: string): void { uni.showLoading({ title: content }) }, - // 关闭遮罩层 - closeLoading() { + /** + * 关闭遮罩层 + */ + closeLoading(): void { uni.hideLoading() } } diff --git a/src/plugins/tab.ts b/src/plugins/tab.ts index 9139c47..a0819a9 100644 --- a/src/plugins/tab.ts +++ b/src/plugins/tab.ts @@ -1,6 +1,10 @@ export default { - // 关闭所有页面,打开到应用内的某个页面 - reLaunch(url:string) { + /** + * 关闭所有页面,打开到应用内的某个页面 + * @param url 页面路径 + * @returns + */ + reLaunch(url: string): Promise { return new Promise((resolve, reject) => { uni.reLaunch({ url: url, @@ -10,8 +14,12 @@ export default { }); }, - // 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 - switchTab(url:string) { + /** + * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 + * @param url 页面路径 + * @returns + */ + switchTab(url: string): Promise { return new Promise((resolve, reject) => { uni.switchTab({ url: url, @@ -21,8 +29,12 @@ export default { }); } , - // 关闭当前页面,跳转到应用内的某个页面 - redirectTo(url:string) { + /** + * 关闭当前页面,跳转到应用内的某个页面 + * @param url 页面路径 + * @returns + */ + redirectTo(url: string): Promise { return new Promise((resolve, reject) => { uni.redirectTo({ url: url, @@ -31,8 +43,12 @@ export default { }); }); }, - // 保留当前页面,跳转到应用内的某个页面 - navigateTo(url:string) { + /** + * 保留当前页面,跳转到应用内的某个页面 + * @param url 页面路径 + * @returns + */ + navigateTo(url: string): Promise { return new Promise((resolve, reject) => { uni.navigateTo({ url: url, @@ -42,8 +58,11 @@ export default { }); }, - // 关闭当前页面,返回上一页面或多级页面 - navigateBack() { + /** + * 关闭当前页面,返回上一页面或多级页面 + * @returns + */ + navigateBack(): Promise { return new Promise((resolve, reject) => { uni.navigateBack({ success: resolve,