20260715221223
This commit is contained in:
1 parent
7049584d1e
commit
704dda07b5
21 files changed
+2649
-427
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export const useAppStore = defineStore("app", {
|
||||
state: () => ({
|
||||
locale: "zh-CN",
|
||||
sidebarCollapsed: false,
|
||||
visitedTabs: [{ key: "/dashboard", label: "工作台", closable: false }],
|
||||
}),
|
||||
actions: {
|
||||
toggleSidebar() {
|
||||
this.sidebarCollapsed = !this.sidebarCollapsed;
|
||||
},
|
||||
setLocale(locale) {
|
||||
this.locale = locale;
|
||||
},
|
||||
addVisitedTab(tab) {
|
||||
if (!this.visitedTabs.some((item) => item.key === tab.key)) {
|
||||
this.visitedTabs.push(tab);
|
||||
}
|
||||
},
|
||||
removeVisitedTab(key) {
|
||||
this.visitedTabs = this.visitedTabs.filter((item) => item.key !== key);
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
key: "fms-app",
|
||||
pick: ["locale", "sidebarCollapsed", "visitedTabs"],
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { computed, ref } from "vue";
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export const useAuthStore = defineStore(
|
||||
"auth",
|
||||
() => {
|
||||
const token = ref("");
|
||||
const orgid = ref("");
|
||||
const user = ref(null);
|
||||
const isAuthenticated = computed(() => Boolean(token.value));
|
||||
|
||||
function setSession(payload, organization) {
|
||||
token.value = payload.token ?? payload.access_token ?? "";
|
||||
orgid.value = payload.orgid ?? organization;
|
||||
user.value = payload.user ?? payload.user_info ?? null;
|
||||
}
|
||||
|
||||
function clearSession() {
|
||||
token.value = "";
|
||||
orgid.value = "";
|
||||
user.value = null;
|
||||
}
|
||||
|
||||
return {
|
||||
token,
|
||||
orgid,
|
||||
user,
|
||||
isAuthenticated,
|
||||
setSession,
|
||||
clearSession,
|
||||
};
|
||||
},
|
||||
{
|
||||
persist: {
|
||||
key: "fms-auth",
|
||||
pick: ["token", "orgid", "user"],
|
||||
},
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user