123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import {defineStore} from 'pinia'
- import pinia from "../store/init"
- import config from '../config/index';
- import {getStorage, setStorage, clearStorage} from "@/utils/storage";
- export const useAppStore = defineStore('main', {
- state: () => ({
- //系统信息
- title: config.theme,
- //用户信息
- tenantId: config.tenantId,
- userInfo: getStorage('userInfo') ?? {},
- //项目合同段数据
- projectInfo: getStorage('projectInfo') ?? {},
- contractInfo: getStorage('contractInfo') ?? {},
- projectId: getStorage('projectId') ?? '',
- contractId: getStorage('contractId') ?? '',
- isAnimation: getStorage('isAnimation') ?? false,
- //按钮权限
- buttons: getStorage('buttons') || {},
- //消息数据
- msgCountData: getStorage('msgCountData') ?? {},
- //检测升级
- appUpdate: getStorage('appUpdate') ?? {
- appVersion: '',
- version: '',
- isUpdate: false,
- toUpdate: true
- },
- //改变值时,触发更新
- onUpdate: null,
- }),
- actions: {
- //系统信息
- setTitle(value) {
- this.title = value
- },
- //用户信息
- setTenantId(value) {
- this.tenantId = value
- setStorage('tenantId', value)
- },
- setUserInfo(value) {
- this.userInfo = value
- setStorage('userInfo', value)
- },
- //项目合同段数据
- setProjectInfo(value) {
- this.projectInfo = value
- setStorage('projectInfo', value)
- },
- setContractInfo(value) {
- this.contractInfo = value
- setStorage('contractInfo', value)
- },
- setProjectId(value) {
- this.projectId = value
- setStorage('projectId', value)
- },
- setContractId(value) {
- this.contractId = value
- setStorage('contractId', value)
- },
- setAnimation(value) {
- this.isAnimation = value
- setStorage('isAnimation', value)
- },
- setMsgCountData(value) {
- this.msgCountData = value
- setStorage('msgCountData', value)
- },
- setAppUpdate(value) {
- this.appUpdate = value
- setStorage('appUpdate', value)
- },
- setOnUpdate(value) {
- this.onUpdate = value
- },
- //按钮权限
- setButtons(value) {
- this.buttons = value
- setStorage('buttons', value)
- },
- getButtonsVal(value) {
- return this.buttons[value] || false
- },
- //清除缓存和token
- clearStoreData() {
- //清除状态
- this.title = config.theme
- //用户信息
- this.tenantId = config.tenantId
- this.userInfo = {}
- //项目合同段数据
- this.projectInfo = {}
- this.contractInfo = {}
- this.projectId = ''
- this.contractId = ''
- this.msgCountData = {}
- this.appUpdate = {
- appVersion: '',
- version: '',
- isUpdate: false,
- toUpdate: true
- }
- this.buttons = null
- this.onUpdate = null
- clearStorage()
- },
- }
- })
- export default function useUserStoreWidthOut() {
- return useAppStore(pinia);
- }
|