2025-03-26
This commit is contained in:
8
src/stores/index.ts
Normal file
8
src/stores/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createPinia } from "pinia";
|
||||
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
|
||||
|
||||
// pinia persist
|
||||
const pinia = createPinia();
|
||||
pinia.use(piniaPluginPersistedstate);
|
||||
|
||||
export default pinia;
|
||||
23
src/stores/interface/global.ts
Normal file
23
src/stores/interface/global.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/* GlobalState */
|
||||
export type LayoutType = "vertical" | "classic" | "transverse" | "columns";
|
||||
|
||||
export type AssemblySizeType = "large" | "default" | "small";
|
||||
|
||||
export type LanguageType = "zh" | "en" | null;
|
||||
export interface GlobalState {
|
||||
layout: LayoutType;
|
||||
assemblySize: AssemblySizeType;
|
||||
language: LanguageType;
|
||||
maximize: boolean;
|
||||
primary: string;
|
||||
isDark: boolean;
|
||||
isGrey: boolean;
|
||||
isWeak: boolean;
|
||||
asideInverted: boolean;
|
||||
isCollapse: boolean;
|
||||
breadcrumb: boolean;
|
||||
breadcrumbIcon: boolean;
|
||||
tabs: boolean;
|
||||
tabsIcon: boolean;
|
||||
footer: boolean;
|
||||
}
|
||||
5
src/stores/interface/index.ts
Normal file
5
src/stores/interface/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { GlobalState } from "./global";
|
||||
import { TabsState } from "./tabs";
|
||||
import { KeepAliveState } from "./keepAlive";
|
||||
|
||||
export type { GlobalState, KeepAliveState, TabsState };
|
||||
4
src/stores/interface/keepAlive.ts
Normal file
4
src/stores/interface/keepAlive.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/* KeepAliveState */
|
||||
export interface KeepAliveState {
|
||||
keepAliveName: string[];
|
||||
}
|
||||
13
src/stores/interface/tabs.ts
Normal file
13
src/stores/interface/tabs.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/* tabsMenuProps */
|
||||
export interface TabsMenuProps {
|
||||
icon: string;
|
||||
title: string;
|
||||
path: string;
|
||||
name: string;
|
||||
close: boolean;
|
||||
}
|
||||
|
||||
/* TabsState */
|
||||
export interface TabsState {
|
||||
tabsMenuList: TabsMenuProps[];
|
||||
}
|
||||
61
src/stores/modules/auth.ts
Normal file
61
src/stores/modules/auth.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { defineStore } from "pinia";
|
||||
// import router from "@/routers";
|
||||
//setKeeAliveRoute
|
||||
import { getAuthMenuListApi } from "@/api/modules/login";
|
||||
import { getFlatMenuList, getShowMenuList, getAllBreadcrumbList, getBtnsAuthList } from "@/utils";
|
||||
//setKeeAliveRoute
|
||||
export const useAuthStore = defineStore({
|
||||
id: "gw-auth",
|
||||
state: (): Record<string, any> => ({
|
||||
// 菜单权限列表
|
||||
authMenuList: [],
|
||||
// 当前页面的 router name,用来做按钮权限筛选
|
||||
routeName: ""
|
||||
}),
|
||||
getters: {
|
||||
// 按钮权限列表
|
||||
authButtonListGet: state => state.authButtonList,
|
||||
// 菜单权限列表 ==> 这里的菜单没有经过任何处理
|
||||
authMenuListGet: state => state.authMenuList,
|
||||
// 菜单权限列表 ==> 这里的菜单没有经过任何处理(如果没有设置isKeepAlive的地方所有自己动手)
|
||||
|
||||
// authMenuListGet: state => setKeeAliveRoute(state.authMenuList),
|
||||
// 菜单权限列表 ==> 左侧菜单栏渲染,需要剔除 isHide == true
|
||||
showMenuListGet: state => getShowMenuList(state.authMenuList),
|
||||
// 菜单权限列表 ==> 扁平化之后的一维数组菜单,主要用来添加动态路由
|
||||
flatMenuListGet: state => getFlatMenuList(state.authMenuList),
|
||||
// 递归处理后的所有面包屑导航列表
|
||||
breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList),
|
||||
//设置按钮权限
|
||||
btnsAuthList: state => getBtnsAuthList(state.authMenuList)
|
||||
},
|
||||
actions: {
|
||||
// Get AuthMenuList
|
||||
async getAuthMenuList() {
|
||||
let userInfo: any = localStorage.getItem("gw-user");
|
||||
let userInfoClone: any = JSON.parse(userInfo);
|
||||
|
||||
const { data } = await getAuthMenuListApi(userInfoClone.uid);
|
||||
// {
|
||||
// id: 1,
|
||||
// path: "/index",
|
||||
// name: "home",
|
||||
// component: "/home/index",
|
||||
// hidden: true,
|
||||
// children: [],
|
||||
// meta: {
|
||||
// icon: "",
|
||||
// title: "首页",
|
||||
// isKeepAlive: true
|
||||
// }
|
||||
// }
|
||||
//如果有路由就使用路由,如果沒有就添加一個首頁,讓用戶條到首頁去
|
||||
this.authMenuList = data;
|
||||
},
|
||||
|
||||
// Set RouteName
|
||||
async setRouteName(name: string) {
|
||||
this.routeName = name;
|
||||
}
|
||||
}
|
||||
});
|
||||
49
src/stores/modules/global.ts
Normal file
49
src/stores/modules/global.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { GlobalState } from "@/stores/interface";
|
||||
import { DEFAULT_PRIMARY } from "@/config";
|
||||
import piniaPersistConfig from "@/config/piniaPersist";
|
||||
|
||||
export const useGlobalStore = defineStore({
|
||||
id: "gw-global",
|
||||
// 修改默认值之后,需清除 localStorage 数据
|
||||
state: (): GlobalState => ({
|
||||
// 布局模式 (纵向:vertical | 经典:classic | 横向:transverse | 分栏:columns)
|
||||
layout: "vertical",
|
||||
// element 组件大小
|
||||
assemblySize: "default",
|
||||
// 当前系统语言
|
||||
language: null,
|
||||
// 当前页面是否全屏
|
||||
maximize: false,
|
||||
// 主题颜色
|
||||
primary: DEFAULT_PRIMARY,
|
||||
// 深色模式
|
||||
isDark: false,
|
||||
// 灰色模式
|
||||
isGrey: false,
|
||||
// 色弱模式
|
||||
isWeak: false,
|
||||
// 侧边栏反转 (目前仅支持 'vertical' 模式)
|
||||
asideInverted: false,
|
||||
// 折叠菜单
|
||||
isCollapse: true,
|
||||
// 面包屑导航
|
||||
breadcrumb: true,
|
||||
// 面包屑导航图标
|
||||
breadcrumbIcon: true,
|
||||
// 标签页
|
||||
tabs: true,
|
||||
// 标签页图标
|
||||
tabsIcon: true,
|
||||
// 页脚
|
||||
footer: true
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
// Set GlobalState
|
||||
setGlobalState(...args: ObjToKeyValArray<GlobalState>) {
|
||||
this.$patch({ [args[0]]: args[1] });
|
||||
}
|
||||
},
|
||||
persist: piniaPersistConfig("gw-global")
|
||||
});
|
||||
23
src/stores/modules/keepAlive.ts
Normal file
23
src/stores/modules/keepAlive.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { KeepAliveState } from "@/stores/interface";
|
||||
|
||||
export const useKeepAliveStore = defineStore({
|
||||
id: "gw-keepAlive",
|
||||
state: (): KeepAliveState => ({
|
||||
keepAliveName: []
|
||||
}),
|
||||
actions: {
|
||||
// Add KeepAliveName
|
||||
async addKeepAliveName(name: string) {
|
||||
!this.keepAliveName.includes(name) && this.keepAliveName.push(name);
|
||||
},
|
||||
// Remove KeepAliveName
|
||||
async removeKeepAliveName(name: string) {
|
||||
this.keepAliveName = this.keepAliveName.filter(item => item !== name);
|
||||
},
|
||||
// Set KeepAliveName
|
||||
async setKeepAliveName(keepAliveName: string[] = []) {
|
||||
this.keepAliveName = keepAliveName;
|
||||
}
|
||||
}
|
||||
});
|
||||
20
src/stores/modules/status.ts
Normal file
20
src/stores/modules/status.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { defineStore } from "pinia";
|
||||
import piniaPersistConfig from "@/config/piniaPersist";
|
||||
|
||||
export const useStatusStore = defineStore({
|
||||
id: "gw-status",
|
||||
// 修改默认值之后,需清除 localStorage 数据
|
||||
state: (): any => ({
|
||||
status: {
|
||||
setSupplier: [] //供应商
|
||||
}
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
// Set setSupplier
|
||||
setSupplier(data: any) {
|
||||
this.status.setSupplier = data;
|
||||
}
|
||||
},
|
||||
persist: piniaPersistConfig("gw-status")
|
||||
});
|
||||
50
src/stores/modules/tabs.ts
Normal file
50
src/stores/modules/tabs.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import router from "@/routers";
|
||||
import { defineStore } from "pinia";
|
||||
import { TabsState } from "@/stores/interface";
|
||||
import piniaPersistConfig from "@/config/piniaPersist";
|
||||
|
||||
export const useTabsStore = defineStore({
|
||||
id: "gw-tabs",
|
||||
state: (): TabsState => ({
|
||||
tabsMenuList: []
|
||||
}),
|
||||
actions: {
|
||||
// Add Tabs
|
||||
async addTabs(tabItem: any) {
|
||||
if (this.tabsMenuList.every(item => item.path !== tabItem.path)) {
|
||||
this.tabsMenuList.push(tabItem);
|
||||
}
|
||||
},
|
||||
// Remove Tabs
|
||||
async removeTabs(tabPath: string, isCurrent: boolean = true) {
|
||||
const tabsMenuList = this.tabsMenuList;
|
||||
if (isCurrent) {
|
||||
tabsMenuList.forEach((item, index) => {
|
||||
if (item.path !== tabPath) return;
|
||||
const nextTab = tabsMenuList[index + 1] || tabsMenuList[index - 1];
|
||||
if (!nextTab) return;
|
||||
router.push(nextTab.path);
|
||||
});
|
||||
}
|
||||
this.tabsMenuList = tabsMenuList.filter(item => item.path !== tabPath);
|
||||
},
|
||||
// Close MultipleTab
|
||||
async closeMultipleTab(tabsMenuValue?: string) {
|
||||
this.tabsMenuList = this.tabsMenuList.filter(item => {
|
||||
return item.path === tabsMenuValue || !item.close;
|
||||
});
|
||||
},
|
||||
// Set Tabs
|
||||
async setTabs(tabsMenuList: any[]) {
|
||||
this.tabsMenuList = tabsMenuList;
|
||||
},
|
||||
// Set Tabs Title
|
||||
async setTabsTitle(title: string) {
|
||||
const nowFullPath = location.hash.substring(1);
|
||||
this.tabsMenuList.forEach(item => {
|
||||
if (item.path == nowFullPath) item.title = title;
|
||||
});
|
||||
}
|
||||
},
|
||||
persist: piniaPersistConfig("gw-tabs")
|
||||
});
|
||||
34
src/stores/modules/user.ts
Normal file
34
src/stores/modules/user.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
import piniaPersistConfig from "@/config/piniaPersist";
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
id: "gw-user",
|
||||
state: () => ({
|
||||
uid: "",
|
||||
token: "",
|
||||
avatar: "",
|
||||
username: "",
|
||||
languageType: null
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
// Set Token
|
||||
setToken(token: string) {
|
||||
this.token = token;
|
||||
},
|
||||
setNickname(userName: string) {
|
||||
this.username = userName;
|
||||
},
|
||||
setUid(uid: string) {
|
||||
this.uid = uid;
|
||||
},
|
||||
setAvatar(avatar: string) {
|
||||
this.avatar = avatar;
|
||||
},
|
||||
setLanguageType(type: any) {
|
||||
this.languageType = type;
|
||||
}
|
||||
},
|
||||
persist: piniaPersistConfig("gw-user")
|
||||
});
|
||||
Reference in New Issue
Block a user