规范类型

This commit is contained in:
D 2023-08-28 22:43:06 +08:00
parent 3cb86f446b
commit 3acfa75037
6 changed files with 175 additions and 101 deletions

View File

@ -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)
})
}
}

84
src/plugins/auth.ts Normal file
View File

@ -0,0 +1,84 @@
import store from '@/store'
function authPermission(permission: string): boolean {
const all_permission = "*:*:*"
const permissions: Array<string> = 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<string> = 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<string>): boolean {
return permissions.some(item => {
return authPermission(item)
})
},
/**
*
* @param permissions
* @returns
*/
hasPermiAnd(permissions: Array<string>): boolean {
return permissions.every(item => {
return authPermission(item)
})
},
/**
*
* @param role
* @returns
*/
hasRole(role: string): boolean {
return authRole(role)
},
/**
*
* @param roles
* @returns
*/
hasRoleOr(roles: Array<string>): boolean {
return roles.some(item => {
return authRole(item)
})
},
/**
*
* @param roles
* @returns
*/
hasRoleAnd(roles: Array<string>) {
return roles.every(item => {
return authRole(item)
})
}
}

View File

@ -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
}
}

16
src/plugins/index.ts Normal file
View File

@ -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
}
}

View File

@ -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<unknown> {
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()
}
}

View File

@ -1,6 +1,10 @@
export default {
// 关闭所有页面,打开到应用内的某个页面
reLaunch(url:string) {
/**
*
* @param url
* @returns
*/
reLaunch(url: string): Promise<unknown> {
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<unknown> {
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<unknown> {
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<unknown> {
return new Promise((resolve, reject) => {
uni.navigateTo({
url: url,
@ -42,8 +58,11 @@ export default {
});
},
// 关闭当前页面,返回上一页面或多级页面
navigateBack() {
/**
*
* @returns
*/
navigateBack(): Promise<unknown> {
return new Promise((resolve, reject) => {
uni.navigateBack({
success: resolve,