【新增】前端代码第一次提交

This commit is contained in:
YOHO\20373
2025-04-17 16:42:02 +08:00
parent e0f13c705b
commit 865ebd0a4d
1635 changed files with 237638 additions and 23 deletions

View File

@@ -0,0 +1,31 @@
import type { App } from 'vue'
import { useUserStore } from '@/store/modules/user'
const { t } = useI18n() // 国际化
/** 判断权限的指令 directive */
export function hasPermi(app: App<Element>) {
app.directive('hasPermi', (el, binding) => {
const { value } = binding
if (value && value instanceof Array && value.length > 0) {
const hasPermissions = hasPermission(value)
if (!hasPermissions) {
el.parentNode && el.parentNode.removeChild(el)
}
} else {
throw new Error(t('permission.hasPermission'))
}
})
}
/** 判断权限的方法 function */
const userStore = useUserStore()
const all_permission = '*:*:*'
export const hasPermission = (permission: string[]) => {
return (
userStore.permissions.has(all_permission) ||
permission.some((permission) => userStore.permissions.has(permission))
)
}

View File

@@ -0,0 +1,28 @@
import type { App } from 'vue'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
const { t } = useI18n() // 国际化
export function hasRole(app: App<Element>) {
app.directive('hasRole', (el, binding) => {
const { wsCache } = useCache()
const { value } = binding
const super_admin = 'super_admin'
const userInfo = wsCache.get(CACHE_KEY.USER)
const roles = userInfo?.roles || []
if (value && value instanceof Array && value.length > 0) {
const roleFlag = value
const hasRole = roles.some((role: string) => {
return super_admin === role || roleFlag.includes(role)
})
if (!hasRole) {
el.parentNode && el.parentNode.removeChild(el)
}
} else {
throw new Error(t('permission.hasRole'))
}
})
}