20260905172534
This commit is contained in:
1 parent
1b01a31252
commit
7b00eeb88c
711 files changed
+2849
-959
No files matched your search
@@ -21,8 +21,9 @@ export const usePermissionStore = defineStore('permissions', () => {
|
||||
let loadingPrincipalKey = ''
|
||||
let loadVersion = 0
|
||||
|
||||
// 字符串业务键:模块编码即主键 b_id
|
||||
const moduleByCode = computed(
|
||||
() => new Map(modules.value.map((m) => [String(m.b_code || ''), m])),
|
||||
() => new Map(modules.value.map((m) => [String(m.b_id || ''), m])),
|
||||
)
|
||||
const moduleById = computed(() => new Map(modules.value.map((m) => [String(m.b_id || ''), m])))
|
||||
const grantedPageSet = computed(() => new Set(grantedPageIds.value))
|
||||
@@ -68,17 +69,20 @@ export const usePermissionStore = defineStore('permissions', () => {
|
||||
return request
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(userId)) throw new Error('登录用户 ID 无效,请重新登录')
|
||||
if (loadedPrincipalKey.value === principalKey) return
|
||||
if (loadingPromise && loadingPrincipalKey === principalKey) return loadingPromise
|
||||
|
||||
const requestVersion = ++loadVersion
|
||||
loadingPrincipalKey = principalKey
|
||||
// 授权表(b_user_module/b_user_power/s_module_power)在部分机构库不存在,
|
||||
// 失败时按无授权处理,不阻塞登录主流程。
|
||||
const failSafe = () => ({ data: [] })
|
||||
const quotedUserId = `N'${String(userId).replaceAll("'", "''")}'`
|
||||
const request = Promise.all([
|
||||
loadDataApi('s_module', 'b_canuse = 1', 'b_id ASC'),
|
||||
loadDataApi('b_user_module', `b_user_id = ${userId}`, 'b_id ASC'),
|
||||
loadDataApi('b_user_power', `b_user_id = ${userId}`, 'b_id ASC'),
|
||||
loadDataApi('s_module_power', 'b_canuse = 1', 'b_id ASC'),
|
||||
loadDataApi('b_user_module', `b_user_id = ${quotedUserId}`, 'b_id ASC').catch(failSafe),
|
||||
loadDataApi('b_user_power', `b_user_id = ${quotedUserId}`, 'b_id ASC').catch(failSafe),
|
||||
loadDataApi('s_module_power', 'b_canuse = 1', 'b_id ASC').catch(failSafe),
|
||||
])
|
||||
.then(([moduleResponse, userModules, userPowers, powers]) => {
|
||||
if (requestVersion !== loadVersion) return
|
||||
@@ -90,13 +94,14 @@ export const usePermissionStore = defineStore('permissions', () => {
|
||||
.filter(Boolean)
|
||||
modules.value = activeModules
|
||||
grantedPageIds.value = pageIds
|
||||
// 模块编码即主键 b_id
|
||||
moduleCodes.value = userModules.data
|
||||
.map((item) => mById.get(String(item.b_module_id))?.b_code)
|
||||
.map((item) => mById.get(String(item.b_module_id))?.b_id)
|
||||
.filter(Boolean)
|
||||
powerCodes.value = userPowers.data
|
||||
.map((item) => pById.get(String(item.b_power_id)))
|
||||
.filter((p) => Boolean(p))
|
||||
.map((power) => `${String(power.b_module_id)}.${power.b_code}`)
|
||||
.map((power) => `${String(power.b_module_id)}.${power.b_id}`)
|
||||
loadedPrincipalKey.value = principalKey
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
Reference in new issue
Block a user