u
This commit is contained in:
1 parent
4aaa93df7d
commit
c330e52fd3
66 files changed
+7386
-4
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,74 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
|
||||
export const useTabStore = defineStore("tabs", () => {
|
||||
const tabs = ref([{ title: "首页", path: "/", fullPath: "/" }]);
|
||||
const activeTab = ref("/");
|
||||
const cachedKeys = ref(["/"]);
|
||||
|
||||
const tabMap = computed(() => {
|
||||
const map = new Map();
|
||||
tabs.value.forEach((t) => map.set(t.fullPath, t));
|
||||
return map;
|
||||
});
|
||||
|
||||
const addTab = (tab) => {
|
||||
const existing = tabMap.value.get(tab.fullPath);
|
||||
if (existing) {
|
||||
existing.title = tab.title;
|
||||
} else {
|
||||
tabs.value.push(tab);
|
||||
if (tab.meta?.keepAlive && !cachedKeys.value.includes(tab.fullPath)) {
|
||||
cachedKeys.value.push(tab.fullPath);
|
||||
}
|
||||
}
|
||||
activeTab.value = tab.fullPath;
|
||||
};
|
||||
|
||||
const setActiveTab = (fullPath) => {
|
||||
if (tabMap.value.has(fullPath)) activeTab.value = fullPath;
|
||||
};
|
||||
|
||||
const closeTab = (fullPath) => {
|
||||
if (fullPath === "/") return activeTab.value;
|
||||
|
||||
const index = tabs.value.findIndex((t) => t.fullPath === fullPath);
|
||||
if (index === -1) return activeTab.value;
|
||||
|
||||
tabs.value.splice(index, 1);
|
||||
const cacheIndex = cachedKeys.value.indexOf(fullPath);
|
||||
if (cacheIndex !== -1) cachedKeys.value.splice(cacheIndex, 1);
|
||||
|
||||
if (activeTab.value === fullPath) {
|
||||
const newIndex = Math.max(index - 1, 0);
|
||||
activeTab.value = tabs.value[newIndex].fullPath;
|
||||
}
|
||||
|
||||
return activeTab.value;
|
||||
};
|
||||
|
||||
const resetTabs = () => {
|
||||
const homeTab = { title: "首页", path: "/", fullPath: "/" };
|
||||
tabs.value = [homeTab];
|
||||
activeTab.value = "/";
|
||||
cachedKeys.value = ["/"];
|
||||
};
|
||||
|
||||
const currentActiveTab = computed(() => tabMap.value.get(activeTab.value));
|
||||
|
||||
const findTabIndex = (fullPath) => {
|
||||
return tabs.value.findIndex((t) => t.fullPath === fullPath);
|
||||
};
|
||||
|
||||
return {
|
||||
tabs,
|
||||
activeTab,
|
||||
cachedKeys,
|
||||
addTab,
|
||||
setActiveTab,
|
||||
closeTab,
|
||||
resetTabs,
|
||||
currentActiveTab,
|
||||
findTabIndex,
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
export const useUserStore = defineStore(
|
||||
"userInfo",
|
||||
() => {
|
||||
const userInfo = ref({
|
||||
orgid: "",
|
||||
userid: "",
|
||||
username: "",
|
||||
token: "",
|
||||
});
|
||||
|
||||
function setUserInfo(orgid, userid, username, token) {
|
||||
userInfo.value.orgid = orgid;
|
||||
userInfo.value.userid = userid;
|
||||
userInfo.value.token = token;
|
||||
userInfo.value.username = username;
|
||||
}
|
||||
|
||||
function resetUserInfo() {
|
||||
userInfo.value.token = "";
|
||||
}
|
||||
|
||||
function isLogined() {
|
||||
return !!userInfo.value.orgid && !!userInfo.value.userid && !!userInfo.value.token;
|
||||
}
|
||||
|
||||
return {
|
||||
userInfo,
|
||||
setUserInfo,
|
||||
resetUserInfo,
|
||||
isLogined,
|
||||
};
|
||||
},
|
||||
{
|
||||
persist: {
|
||||
paths: ["userInfo"],
|
||||
},
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user