This commit is contained in:
oneao committed 2026-03-31 17:19:34 +08:00
1 parent 422d206bd6
commit a4bd92264d
108 files changed
+16862 -35

No files matched your search

@@ -0,0 +1,95 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { getModuleQxApi } from '@/request/api'
import { useUserStore } from './user'
const PERMISSION_PATH_MAP = [
// {
// moduleId: 'xc_consite_checkcon',
// path: '/pages-sub/jiaoyan',
// },
// {
// moduleId: 'xc_consite_clearcon',
// path: '/pages-sub/qingxi',
// },
// {
// moduleId: 'xc_consite_jiarecon',
// path: '/pages-sub/jiare',
// },
// {
// moduleId: 'xc_consite_wxcon',
// path: '/pages-sub/weixiu',
// },
// {
// moduleId: 'xc_conyard_in',
// path: '/pages-sub/jinchang',
// },
// {
// moduleId: 'xc_conyard_out',
// path: '/pages-sub/chuchang',
// },
]
export const usePermissionStore = defineStore(
'permission',
() => {
const userStore = useUserStore()
const modulePermissions = ref({})
async function init() {
if (!userStore.isLogined) {
return
}
if (Object.keys(modulePermissions.value).length > 0) {
return
}
const moduleQxRes = await getModuleQxApi()
if (moduleQxRes && moduleQxRes.data) {
console.log(moduleQxRes)
modulePermissions.value = moduleQxRes.data
}
}
function reset() {
modulePermissions.value = {}
}
function hasPermission(moduleid: string): boolean {
const val = modulePermissions.value?.[moduleid]
return val === '完全'
}
function checkPermissionByUrl(url?: string): boolean {
// 1、获取当前页面路径
if (!url) {
const pages = getCurrentPages()
const current = pages[pages.length - 1]
url = `/${current.route}`
}
// 2、匹配路径规则
const match = PERMISSION_PATH_MAP.find(item =>
url === item.path || url.startsWith(`${item.path}/`),
)
// 3、不在权限表 → 放行
if (!match)
return true
// 4、在权限表 → 必须满足“moduleId存在 + 值为完全”
return hasPermission(match.moduleId)
}
return {
modulePermissions,
init,
reset,
hasPermission,
checkPermissionByUrl,
}
},
)