20260804173126
This commit is contained in:
1 parent
e17bbe9db3
commit
75b1ccaa6d
36 files changed
+3521
-718
No files matched your search
@@ -7,6 +7,7 @@ import { useAuthStore } from "./auth";
|
||||
export const usePermissionStore = defineStore("permissions", () => {
|
||||
const authStore = useAuthStore();
|
||||
const loadedPrincipalKey = ref("");
|
||||
const modules = ref([]);
|
||||
const functionNodes = ref([]);
|
||||
const pageNodes = ref([]);
|
||||
const actions = ref([]);
|
||||
@@ -23,6 +24,9 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
const grantedFunctionSet = computed(() => new Set(grantedFunctionNodeIds.value));
|
||||
const grantedPageSet = computed(() => new Set(grantedPageNodeIds.value));
|
||||
const grantedActionSet = computed(() => new Set(grantedActionIds.value));
|
||||
const isSystemUser = computed(
|
||||
() => String(authStore.user?.account || "").toLowerCase() === "g3soft",
|
||||
);
|
||||
|
||||
async function load() {
|
||||
const userId = String(authStore.user?.id || "");
|
||||
@@ -34,6 +38,7 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
const requestVersion = ++loadVersion;
|
||||
loadingPrincipalKey = principalKey;
|
||||
const request = Promise.all([
|
||||
loadDataApi("v_s_module_runtime", "b_canuse = 1", "b_module_id ASC, b_profile_id ASC"),
|
||||
loadDataApi("v_s_function_node", "b_canuse = 1", "b_xh ASC, b_id ASC"),
|
||||
loadDataApi("v_s_page_node", "b_canuse = 1", "b_xh ASC, b_id ASC"),
|
||||
loadDataApi("v_s_module_action", "b_canuse = 1", "b_xh ASC, b_id ASC"),
|
||||
@@ -47,6 +52,7 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
])
|
||||
.then(
|
||||
([
|
||||
moduleResponse,
|
||||
functionResponse,
|
||||
pageResponse,
|
||||
actionResponse,
|
||||
@@ -55,6 +61,7 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
actionGrants,
|
||||
]) => {
|
||||
if (requestVersion !== loadVersion) return;
|
||||
modules.value = moduleResponse.data || [];
|
||||
functionNodes.value = functionResponse.data || [];
|
||||
pageNodes.value = pageResponse.data || [];
|
||||
actions.value = actionResponse.data || [];
|
||||
@@ -97,6 +104,11 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
if (!id) return false;
|
||||
const node = functionNodeById.value.get(id);
|
||||
if (!node) return false;
|
||||
if (isSystemUser.value) {
|
||||
if (node.b_node_type === "directory") return true;
|
||||
if (node.b_page_mode === "custom" && !hasPageComponent(node.b_component_key)) return false;
|
||||
return true;
|
||||
}
|
||||
if (node.b_node_type === "directory") return hasGrantedDescendant(id);
|
||||
if (node.b_page_mode === "custom" && !hasPageComponent(node.b_component_key)) return false;
|
||||
return grantedFunctionSet.value.has(id);
|
||||
@@ -104,6 +116,7 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
|
||||
function canAccessRoute(path) {
|
||||
if (path === "/dashboard") return true;
|
||||
if (isSystemUser.value) return true;
|
||||
const node = functionNodes.value.find(
|
||||
(item) => item.b_node_type === "entry" && String(item.b_route || "") === String(path || ""),
|
||||
);
|
||||
@@ -112,10 +125,12 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
|
||||
function canViewPageNode(nodeId, permissionRequired = true) {
|
||||
if (!permissionRequired) return true;
|
||||
if (isSystemUser.value) return true;
|
||||
return grantedPageSet.value.has(String(nodeId || ""));
|
||||
}
|
||||
|
||||
function canAction(moduleIdOrCode, actionCode) {
|
||||
if (isSystemUser.value) return true;
|
||||
const action = actions.value.find(
|
||||
(item) =>
|
||||
(String(item.b_module_id) === String(moduleIdOrCode) ||
|
||||
@@ -130,6 +145,7 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
loadingPromise = null;
|
||||
loadingPrincipalKey = "";
|
||||
loadedPrincipalKey.value = "";
|
||||
modules.value = [];
|
||||
functionNodes.value = [];
|
||||
pageNodes.value = [];
|
||||
actions.value = [];
|
||||
@@ -149,6 +165,8 @@ export const usePermissionStore = defineStore("permissions", () => {
|
||||
canAction,
|
||||
canAccess: canAccessRoute,
|
||||
canPower: canAction,
|
||||
isSystemUser,
|
||||
modules,
|
||||
functionNodes,
|
||||
pageNodes,
|
||||
actions,
|
||||
|
||||
Reference in new issue
Block a user