123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- 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', {
- state: () => ({
- //系统信息
- title: getStoreValue('title') || website.title,
- logoIcon: getStoreValue('logoIcon') || logoIcon,
- logoName: getStoreValue('logoName') || website.name,
- //主题信息
- theme: getStoreValue('theme') || website.theme,
- color: getStoreValue('color') || website.color,
- //用户信息
- token: getStoreValue('token') || '',
- refreshToken: getStoreValue('refreshToken') || '',
- tenantId: getStoreValue('tenantId') || '',
- userInfo: getStoreValue('userInfo') || {},
- //菜单信息
- menus: getStoreValue('menus') || [],
- buttons: getStoreValue('buttons') || {},
- //其他配置信息
- isCollapse: getStoreValue('isCollapse') || false, //菜单折叠
- //表单显示配置
- isShowName: getStoreValue('isShowName') || true, //表单显示名称
- //表单改变值Id
- tableId: getStoreValue('tableId') || true,
- }),
- getters: {
- //系统信息
- getTitle: (state) => state.title,
- getLogoIcon: (state) => state.logoIcon,
- getLogoName: (state) => state.logoName,
- //主题信息
- getTheme: (state) => state.theme,
- getColor: (state) => state.color,
- //用户信息
- getToken: (state) => state.token,
- getRefreshToken: (state) => state.refreshToken,
- getTenantId: (state) => state.tenantId,
- getUserInfo: (state) => state.userInfo,
- //菜单信息
- getMenus: (state) => state.menus,
- getButtons: (state) => state.buttons,
- //其他配置信息
- getCollapse: (state) => state.isCollapse,
- //表单显示配置
- getIsShowName: (state) => state.isShowName,
- getTableId: (state) => state.tableId,
- },
- 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)
- },
- setColor(value) {
- this.color = value
- setStoreValue('color', 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)
- },
- //菜单信息
- setMenus(value) {
- this.menus = value
- setStoreValue('menus', value)
- },
- setButtons(value) {
- this.buttons = value
- setStoreValue('buttons', value)
- },
- getButtonsVal(value) {
- return this.buttons[value] || false
- },
- //其他配置信息
- setCollapse(value) {
- //菜单折叠
- this.isCollapse = value
- setStoreValue('isCollapse', value)
- },
- //表单显示
- setIsShowName(value) {
- this.isShowName = value
- setStoreValue('isShowName', value)
- },
- setTableId(value) {
- this.tableId = value
- setStoreValue('tableId', 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.isShowName = true
- this.tableId = ''
- //清除缓存
- clearStoreAll()
- removeToken()
- removeRefreshToken()
- },
- },
- })
- export default function useUserStoreWidthOut() {
- return useAppStore(pinia)
- }
|