1. 修复:移动端头像剪切功能 2. 修复:系统展示头像展示时从固定静态文件改为接口数据 3. 更新:升级PC端vue-element-plus-admin版本到1.9.2 4. 更新:文件上传接口 5. 更新:依赖库更新,使用python10版本 6. 新增:kinit-api 命令创建app目录
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { App, Directive, DirectiveBinding } from 'vue'
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
import { useCache } from '@/hooks/web/useCache'
|
|
import { intersection } from 'lodash-es'
|
|
import { isArray } from '@/utils/is'
|
|
import { useAuthStoreWithOut } from '@/store/modules/auth'
|
|
|
|
const { t } = useI18n()
|
|
const { wsCache } = useCache()
|
|
const authStore = useAuthStoreWithOut()
|
|
|
|
// 全部权限
|
|
const all_permission = ['*.*.*']
|
|
const hasPermission = (value: string | string[]): boolean => {
|
|
const permissions = wsCache.get(authStore.getUserInfo).permissions as string[]
|
|
if (!value) {
|
|
throw new Error(t('permission.hasPermission'))
|
|
}
|
|
if (!isArray(value)) {
|
|
return permissions?.includes(value as string)
|
|
}
|
|
if (all_permission[0] === permissions[0]) {
|
|
return true
|
|
}
|
|
return (intersection(value, permissions) as string[]).length > 0
|
|
}
|
|
function hasPermi(el: Element, binding: DirectiveBinding) {
|
|
const value = binding.value
|
|
|
|
const flag = hasPermission(value)
|
|
if (!flag) {
|
|
el.parentNode?.removeChild(el)
|
|
}
|
|
}
|
|
const mounted = (el: Element, binding: DirectiveBinding<any>) => {
|
|
hasPermi(el, binding)
|
|
}
|
|
|
|
const permiDirective: Directive = {
|
|
mounted
|
|
}
|
|
|
|
export const setupPermissionDirective = (app: App<Element>) => {
|
|
app.directive('hasPermi', permiDirective)
|
|
}
|
|
|
|
export default permiDirective
|