21 lines
621 B
TypeScript
21 lines
621 B
TypeScript
// /stores/permissionStore.ts
|
|
import { defineStore } from "pinia";
|
|
|
|
export const usePermissionStore = defineStore("permission", {
|
|
state: () => ({
|
|
data: null as any,
|
|
}),
|
|
actions: {
|
|
async load(path: string) {
|
|
const parts = path.split("/").filter(Boolean);
|
|
const group = parts[1] || "";
|
|
const role = parts.at(-1)?.toLowerCase() || "";
|
|
const url = `http://10.10.150.131:8080/api/permission?roles=${role}&groups=${group}`;
|
|
const { data } = await useFetch(url);
|
|
this.data = data.value;
|
|
},
|
|
can(action: string) {
|
|
return this.data?.[action] === true;
|
|
},
|
|
},
|
|
}); |