feat: add pure-admin-thin
This commit is contained in:
9
src/store/index.ts
Normal file
9
src/store/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { App } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
const store = createPinia();
|
||||
|
||||
export function setupStore(app: App<Element>) {
|
||||
app.use(store);
|
||||
}
|
||||
|
||||
export { store };
|
72
src/store/modules/app.ts
Normal file
72
src/store/modules/app.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { storageLocal } from "/@/utils/storage";
|
||||
import { deviceDetection } from "/@/utils/deviceDetection";
|
||||
import { defineStore } from "pinia";
|
||||
import { store } from "/@/store";
|
||||
|
||||
interface AppState {
|
||||
sidebar: {
|
||||
opened: boolean;
|
||||
withoutAnimation: boolean;
|
||||
};
|
||||
layout: string;
|
||||
device: string;
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore({
|
||||
id: "pure-app",
|
||||
state: (): AppState => ({
|
||||
sidebar: {
|
||||
opened: storageLocal.getItem("sidebarStatus")
|
||||
? !!+storageLocal.getItem("sidebarStatus")
|
||||
: true,
|
||||
withoutAnimation: false
|
||||
},
|
||||
layout:
|
||||
storageLocal.getItem("responsive-layout")?.layout.match(/(.*)-/)[1] ??
|
||||
"vertical",
|
||||
device: deviceDetection() ? "mobile" : "desktop"
|
||||
}),
|
||||
getters: {
|
||||
getSidebarStatus() {
|
||||
return this.sidebar.opened;
|
||||
},
|
||||
getDevice() {
|
||||
return this.device;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
TOGGLE_SIDEBAR() {
|
||||
this.sidebar.opened = !this.sidebar.opened;
|
||||
this.sidebar.withoutAnimation = false;
|
||||
if (this.sidebar.opened) {
|
||||
storageLocal.setItem("sidebarStatus", 1);
|
||||
} else {
|
||||
storageLocal.setItem("sidebarStatus", 0);
|
||||
}
|
||||
},
|
||||
CLOSE_SIDEBAR(withoutAnimation: boolean) {
|
||||
storageLocal.setItem("sidebarStatus", 0);
|
||||
this.sidebar.opened = false;
|
||||
this.sidebar.withoutAnimation = withoutAnimation;
|
||||
},
|
||||
TOGGLE_DEVICE(device: string) {
|
||||
this.device = device;
|
||||
},
|
||||
async toggleSideBar() {
|
||||
await this.TOGGLE_SIDEBAR();
|
||||
},
|
||||
closeSideBar(withoutAnimation) {
|
||||
this.CLOSE_SIDEBAR(withoutAnimation);
|
||||
},
|
||||
toggleDevice(device) {
|
||||
this.TOGGLE_DEVICE(device);
|
||||
},
|
||||
setLayout(layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function useAppStoreHook() {
|
||||
return useAppStore(store);
|
||||
}
|
62
src/store/modules/permission.ts
Normal file
62
src/store/modules/permission.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { store } from "/@/store";
|
||||
import { cacheType } from "./types";
|
||||
import { constantRoutesArr, ascending, filterTree } from "/@/router/index";
|
||||
|
||||
export const usePermissionStore = defineStore({
|
||||
id: "pure-permission",
|
||||
state: () => ({
|
||||
// 静态路由
|
||||
constantRoutes: constantRoutesArr,
|
||||
wholeRoutes: [],
|
||||
buttonAuth: [],
|
||||
// 缓存页面keepAlive
|
||||
cachePageList: []
|
||||
}),
|
||||
actions: {
|
||||
asyncActionRoutes(routes) {
|
||||
if (this.wholeRoutes.length > 0) return;
|
||||
this.wholeRoutes = filterTree(
|
||||
ascending(this.constantRoutes.concat(routes))
|
||||
);
|
||||
|
||||
const getButtonAuth = (arrRoutes: Array<string>) => {
|
||||
if (!arrRoutes || !arrRoutes.length) return;
|
||||
arrRoutes.forEach((v: any) => {
|
||||
if (v.meta && v.meta.authority) {
|
||||
this.buttonAuth.push(...v.meta.authority);
|
||||
}
|
||||
if (v.children) {
|
||||
getButtonAuth(v.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
getButtonAuth(this.wholeRoutes);
|
||||
},
|
||||
async changeSetting(routes) {
|
||||
await this.asyncActionRoutes(routes);
|
||||
},
|
||||
cacheOperate({ mode, name }: cacheType) {
|
||||
switch (mode) {
|
||||
case "add":
|
||||
this.cachePageList.push(name);
|
||||
this.cachePageList = [...new Set(this.cachePageList)];
|
||||
break;
|
||||
case "delete":
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const delIndex = this.cachePageList.findIndex(v => v === name);
|
||||
this.cachePageList.splice(delIndex, 1);
|
||||
break;
|
||||
}
|
||||
},
|
||||
// 清空缓存页面
|
||||
clearAllCachePage() {
|
||||
this.cachePageList = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function usePermissionStoreHook() {
|
||||
return usePermissionStore(store);
|
||||
}
|
39
src/store/modules/settings.ts
Normal file
39
src/store/modules/settings.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { store } from "/@/store";
|
||||
import { getConfig } from "/@/config";
|
||||
|
||||
interface SettingState {
|
||||
title: string;
|
||||
fixedHeader: boolean;
|
||||
}
|
||||
|
||||
export const useSettingStore = defineStore({
|
||||
id: "pure-setting",
|
||||
state: (): SettingState => ({
|
||||
title: getConfig().Title,
|
||||
fixedHeader: getConfig().FixedHeader
|
||||
}),
|
||||
getters: {
|
||||
getTitle() {
|
||||
return this.title;
|
||||
},
|
||||
getFixedHeader() {
|
||||
return this.fixedHeader;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
CHANGE_SETTING({ key, value }) {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (this.hasOwnProperty(key)) {
|
||||
this[key] = value;
|
||||
}
|
||||
},
|
||||
changeSetting(data) {
|
||||
this.CHANGE_SETTING(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function useSettingStoreHook() {
|
||||
return useSettingStore(store);
|
||||
}
|
6
src/store/modules/types.ts
Normal file
6
src/store/modules/types.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { RouteRecordName } from "vue-router";
|
||||
|
||||
export type cacheType = {
|
||||
mode: string;
|
||||
name?: RouteRecordName;
|
||||
};
|
Reference in New Issue
Block a user