import { defineStore } from 'pinia' import pinia from "~src/store/init" import appConfig from '~src/config/app'; import logoIcon from "~src/assets/logo/icon.png"; import logoName from "~src/assets/logo/name.png"; import {getStoreValue, setStoreValue, clearStoreAll} from '~src/utils/storage' import {setToken, setRefreshToken, removeToken,removeRefreshToken} from '~src/api/util/auth' export const useAppStore = defineStore('main', { state: () =>({ //系统信息 title: getStoreValue('title') || appConfig.title, logoIcon: getStoreValue('logoIcon') || logoIcon, logoName: getStoreValue('logoName') || logoName, //主题信息 theme: getStoreValue('theme') || appConfig.theme, //用户可选择类型:auto,light, dark themeVal: getStoreValue('themeVal') || '', //实际主题:light, dark color: getStoreValue('color') || appConfig.color, homeTheme: getStoreValue('homeTheme') || appConfig.homeTheme, //用户信息 token: getStoreValue( 'token') || '', refreshToken: getStoreValue('refreshToken') || '', tenantId: getStoreValue('tenantId') || '', userInfo: getStoreValue('userInfo') || {}, role_id: getStoreValue('role_id') || {}, //菜单信息 menus: getStoreValue('menus') || [], buttons: getStoreValue('buttons') || {}, //项目合同段数据 projectContract: getStoreValue('projectContract') || [], projectInfo: getStoreValue('projectInfo') || {}, contractInfo: getStoreValue('contractInfo') || {}, projectId: getStoreValue('projectId') || '', contractId: getStoreValue('contractId') || '', //其他配置信息 bubble: getStoreValue('bubble') || false, orderServiceTipModal: getStoreValue('orderServiceTipModal') ?? 1, //0不弹出,1弹出 shotWebRtc: getStoreValue('shotWebRtc') || 0, //WebRtc截图方式: 0关闭,1开启 fullScreen: getStoreValue('fullScreen') || 0, //全屏截图:0关闭,1开启 isCollapse: getStoreValue('isCollapse') || false, //菜单折叠 isScreenShort: false, barMenuName: '', }), getters: { //系统信息 getTitle: state => state.title, getLogoIcon: state => state.logoIcon, getLogoName: state => state.logoName, //主题信息 getTheme: state => state.theme, getThemeVal: state => state.themeVal, getColor: state => state.color, getHomeTheme: state => state.homeTheme, //用户信息 getToken: state => state.token, getRefreshToken: state => state.refreshToken, getTenantId: state => state.tenantId, getUserInfo: state => state.userInfo, getRoleId: state => state.role_id, //菜单信息 getMenus: state => state.menus, getButtons: state => state.buttons, //项目合同段数据 getProjectContract: state => state.projectContract, getProjectInfo: state => state.projectInfo, getContractInfo: state => state.contractInfo, getProjectId: state => state.projectId, getContractId: state => state.contractId, //其他配置信息 getBubble: state => state.bubble, getScreenShort: state => state.isScreenShort, getOrderServiceTipModal: state => state.orderServiceTipModal, getShotWebRtc: state => state.shotWebRtc, getFullScreen: state => state.fullScreen, getCollapse: state => state.isCollapse }, actions: { //系统信息 setTitle(value) { this.title = value setStoreValue('title', value) }, setLogoIcon(value) { this.logoIcon = value setStoreValue('logoIcon', value) }, setLogoName(value) { this.logoName = value setStoreValue('logoName', value) }, //主题信息 setTheme(value) { this.theme = value setStoreValue('theme',value) }, setThemeVal(value) { this.themeVal = value setStoreValue('themeVal',value) }, setColor(value) { this.color = value setStoreValue('color',value) }, setHomeTheme(value) { this.homeTheme = value setStoreValue('homeTheme',value) }, //用户信息 setTokenVal(value){ this.token = value setToken(value) setStoreValue('token',value) }, setRefreshTokenVal(value){ this.refreshToken = value setRefreshToken(value) setStoreValue('refreshToken',value) }, setTenantId(value){ this.tenantId = value setStoreValue('tenantId',value) }, setUserInfo(value){ this.userInfo = value setStoreValue('userInfo',value) }, setRoleId(value){ this.role_id = value setStoreValue('role_id',value) }, //菜单信息 setMenus(value){ this.menus = value setStoreValue('menus',value) }, setButtons(value){ this.buttons = value setStoreValue('buttons',value) }, getButtonsVal(value) { return this.buttons[value] || false; }, //项目合同段数据 setProjectContract(value) { this.projectContract = value setStoreValue('projectContract',value) }, setProjectInfo(value) { this.projectInfo = value setStoreValue('projectInfo',value) }, setContractInfo(value) { this.contractInfo = value setStoreValue('contractInfo',value) }, setProjectId(value) { this.projectId = value setStoreValue('projectId',value) }, setContractId(value) { this.contractId = value setStoreValue('contractId',value) }, //其他配置信息 setBubble(value) { this.bubble = value setStoreValue('bubble',value) }, setOrderServiceTipModal(value) { this.orderServiceTipModal = value setStoreValue('orderServiceTipModal',value) }, setScreenShort(value) { this.isScreenShort = value }, setShotWebRtc(value) { this.shotWebRtc = value setStoreValue('shotWebRtc',value) }, setFullScreen(value) { this.fullScreen = value setStoreValue('fullScreen',value) }, setCollapse(value) { //菜单折叠 this.isCollapse = value setStoreValue('isCollapse',value) }, //清除缓存和token clearStoreData() { //清除状态 this.title = null this.logoIcon = null this.logoName = null this.token = null this.refreshToken = null this.tenantId = null this.userInfo = null this.menus = null this.buttons = null this.projectContract = null this.projectInfo = null this.contractInfo = null this.projectId = null this.contractId = null this.orderServiceTipModal = null this.shotWebRtc = null this.fullScreen = null this.isCollapse = false //清除缓存 clearStoreAll() removeToken() removeRefreshToken() }, } }) export default function useUserStoreWidthOut() { return useAppStore(pinia); }