|
@@ -1,131 +1,147 @@
|
|
|
-import { defineStore } from 'pinia'
|
|
|
-import pinia from '~src/store/init'
|
|
|
-import website from '~src/config/index'
|
|
|
-import logoIcon from '~src/assets/logo/icon.png'
|
|
|
-import { clearStoreAll } from 'hc-vue3-ui'
|
|
|
-import { getStoreValue, setStoreValue } from '~src/utils/storage'
|
|
|
-import { removeRefreshToken, removeToken, setRefreshToken, setToken } from '~src/api/auth'
|
|
|
+import { defineStore } from "pinia";
|
|
|
+import pinia from "~src/store/init";
|
|
|
+import website from "~src/config/index";
|
|
|
+import logoIcon from "~src/assets/logo/icon.png";
|
|
|
+import { clearStoreAll } from "hc-vue3-ui";
|
|
|
+import { getStoreValue, setStoreValue } from "~src/utils/storage";
|
|
|
+import {
|
|
|
+ removeRefreshToken,
|
|
|
+ removeToken,
|
|
|
+ setRefreshToken,
|
|
|
+ setToken,
|
|
|
+} from "~src/api/auth";
|
|
|
|
|
|
-export const useAppStore = defineStore('main', {
|
|
|
+export const useAppStore = defineStore("main", {
|
|
|
state: () => ({
|
|
|
//系统信息
|
|
|
- title: getStoreValue('title') || website.title,
|
|
|
- logoIcon: getStoreValue('logoIcon') || logoIcon,
|
|
|
- logoName: getStoreValue('logoName') || website.name,
|
|
|
+ title: getStoreValue("title") || website.title,
|
|
|
+ logoIcon: getStoreValue("logoIcon") || logoIcon,
|
|
|
+ logoName: getStoreValue("logoName") || website.name,
|
|
|
//主题信息
|
|
|
- theme: getStoreValue('theme') || website.theme,
|
|
|
- color: getStoreValue('color') || website.color,
|
|
|
+ theme: getStoreValue("theme") || website.theme,
|
|
|
+ color: getStoreValue("color") || website.color,
|
|
|
//用户信息
|
|
|
- token: getStoreValue('token') || '',
|
|
|
- refreshToken: getStoreValue('refreshToken') || '',
|
|
|
- tenantId: getStoreValue('tenantId') || '',
|
|
|
- userInfo: getStoreValue('userInfo') || {},
|
|
|
+ token: getStoreValue("token") || "",
|
|
|
+ refreshToken: getStoreValue("refreshToken") || "",
|
|
|
+ tenantId: getStoreValue("tenantId") || "",
|
|
|
+ userInfo: getStoreValue("userInfo") || {},
|
|
|
//菜单信息
|
|
|
- menus: getStoreValue('menus') || [],
|
|
|
- buttons: getStoreValue('buttons') || {},
|
|
|
+ menus: getStoreValue("menus") || [],
|
|
|
+ buttons: getStoreValue("buttons") || {},
|
|
|
//其他配置信息
|
|
|
- isCollapse: getStoreValue('isCollapse') || false, //菜单折叠
|
|
|
+ isCollapse: getStoreValue("isCollapse") || false, //菜单折叠
|
|
|
+ //表单显示配置
|
|
|
+ isShowName: getStoreValue("isShowName") || true, //表单显示名称
|
|
|
}),
|
|
|
getters: {
|
|
|
//系统信息
|
|
|
- getTitle: state => state.title,
|
|
|
- getLogoIcon: state => state.logoIcon,
|
|
|
- getLogoName: state => state.logoName,
|
|
|
+ getTitle: (state) => state.title,
|
|
|
+ getLogoIcon: (state) => state.logoIcon,
|
|
|
+ getLogoName: (state) => state.logoName,
|
|
|
//主题信息
|
|
|
- getTheme: state => state.theme,
|
|
|
- getColor: state => state.color,
|
|
|
+ getTheme: (state) => state.theme,
|
|
|
+ getColor: (state) => state.color,
|
|
|
//用户信息
|
|
|
- getToken: state => state.token,
|
|
|
- getRefreshToken: state => state.refreshToken,
|
|
|
- getTenantId: state => state.tenantId,
|
|
|
- getUserInfo: state => state.userInfo,
|
|
|
+ getToken: (state) => state.token,
|
|
|
+ getRefreshToken: (state) => state.refreshToken,
|
|
|
+ getTenantId: (state) => state.tenantId,
|
|
|
+ getUserInfo: (state) => state.userInfo,
|
|
|
//菜单信息
|
|
|
- getMenus: state => state.menus,
|
|
|
- getButtons: state => state.buttons,
|
|
|
+ getMenus: (state) => state.menus,
|
|
|
+ getButtons: (state) => state.buttons,
|
|
|
//其他配置信息
|
|
|
- getCollapse: state => state.isCollapse,
|
|
|
+ getCollapse: (state) => state.isCollapse,
|
|
|
+ //表单显示配置
|
|
|
+ getIsShowName: (state) => state.isShowName,
|
|
|
},
|
|
|
actions: {
|
|
|
//系统信息
|
|
|
setTitle(value) {
|
|
|
- this.title = value
|
|
|
- setStoreValue('title', value)
|
|
|
+ this.title = value;
|
|
|
+ setStoreValue("title", value);
|
|
|
},
|
|
|
setLogoIcon(value) {
|
|
|
- this.logoIcon = value
|
|
|
- setStoreValue('logoIcon', value)
|
|
|
+ this.logoIcon = value;
|
|
|
+ setStoreValue("logoIcon", value);
|
|
|
},
|
|
|
setLogoName(value) {
|
|
|
- this.logoName = value
|
|
|
- setStoreValue('logoName', value)
|
|
|
+ this.logoName = value;
|
|
|
+ setStoreValue("logoName", value);
|
|
|
},
|
|
|
//主题信息
|
|
|
setTheme(value) {
|
|
|
- this.theme = value
|
|
|
- setStoreValue('theme', value)
|
|
|
+ this.theme = value;
|
|
|
+ setStoreValue("theme", value);
|
|
|
},
|
|
|
setColor(value) {
|
|
|
- this.color = value
|
|
|
- setStoreValue('color', value)
|
|
|
+ this.color = value;
|
|
|
+ setStoreValue("color", value);
|
|
|
},
|
|
|
//用户信息
|
|
|
setTokenVal(value) {
|
|
|
- this.token = value
|
|
|
- setToken(value)
|
|
|
- setStoreValue('token', value)
|
|
|
+ this.token = value;
|
|
|
+ setToken(value);
|
|
|
+ setStoreValue("token", value);
|
|
|
},
|
|
|
setRefreshTokenVal(value) {
|
|
|
- this.refreshToken = value
|
|
|
- setRefreshToken(value)
|
|
|
- setStoreValue('refreshToken', value)
|
|
|
+ this.refreshToken = value;
|
|
|
+ setRefreshToken(value);
|
|
|
+ setStoreValue("refreshToken", value);
|
|
|
},
|
|
|
setTenantId(value) {
|
|
|
- this.tenantId = value
|
|
|
- setStoreValue('tenantId', value)
|
|
|
+ this.tenantId = value;
|
|
|
+ setStoreValue("tenantId", value);
|
|
|
},
|
|
|
setUserInfo(value) {
|
|
|
- this.userInfo = value
|
|
|
- setStoreValue('userInfo', value)
|
|
|
+ this.userInfo = value;
|
|
|
+ setStoreValue("userInfo", value);
|
|
|
},
|
|
|
//菜单信息
|
|
|
setMenus(value) {
|
|
|
- this.menus = value
|
|
|
- setStoreValue('menus', value)
|
|
|
+ this.menus = value;
|
|
|
+ setStoreValue("menus", value);
|
|
|
},
|
|
|
setButtons(value) {
|
|
|
- this.buttons = value
|
|
|
- setStoreValue('buttons', value)
|
|
|
+ this.buttons = value;
|
|
|
+ setStoreValue("buttons", value);
|
|
|
},
|
|
|
getButtonsVal(value) {
|
|
|
- return this.buttons[value] || false
|
|
|
+ return this.buttons[value] || false;
|
|
|
},
|
|
|
//其他配置信息
|
|
|
- setCollapse(value) { //菜单折叠
|
|
|
- this.isCollapse = value
|
|
|
- setStoreValue('isCollapse', value)
|
|
|
+ setCollapse(value) {
|
|
|
+ //菜单折叠
|
|
|
+ this.isCollapse = value;
|
|
|
+ setStoreValue("isCollapse", value);
|
|
|
+ },
|
|
|
+ //表单显示
|
|
|
+ setIsShowName(value) {
|
|
|
+ this.isShowName = value;
|
|
|
+ setStoreValue("isShowName", value);
|
|
|
},
|
|
|
//清除缓存和token
|
|
|
clearStoreData() {
|
|
|
- this.title = null
|
|
|
- this.logoIcon = null
|
|
|
- this.logoName = null
|
|
|
- this.theme = website.theme
|
|
|
- this.color = website.color
|
|
|
- this.token = null
|
|
|
- this.refreshToken = null
|
|
|
- this.tenantId = null
|
|
|
- this.userInfo = null
|
|
|
- this.menus = null
|
|
|
- this.buttons = null
|
|
|
- this.isCollapse = false
|
|
|
+ this.title = null;
|
|
|
+ this.logoIcon = null;
|
|
|
+ this.logoName = null;
|
|
|
+ this.theme = website.theme;
|
|
|
+ this.color = website.color;
|
|
|
+ this.token = null;
|
|
|
+ this.refreshToken = null;
|
|
|
+ this.tenantId = null;
|
|
|
+ this.userInfo = null;
|
|
|
+ this.menus = null;
|
|
|
+ this.buttons = null;
|
|
|
+ this.isCollapse = false;
|
|
|
+ this.isShowName = true;
|
|
|
//清除缓存
|
|
|
- clearStoreAll()
|
|
|
- removeToken()
|
|
|
- removeRefreshToken()
|
|
|
+ clearStoreAll();
|
|
|
+ removeToken();
|
|
|
+ removeRefreshToken();
|
|
|
},
|
|
|
},
|
|
|
-})
|
|
|
+});
|
|
|
|
|
|
export default function useUserStoreWidthOut() {
|
|
|
- return useAppStore(pinia)
|
|
|
+ return useAppStore(pinia);
|
|
|
}
|