index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {defineStore} from 'pinia'
  2. import pinia from "../store/init"
  3. import config from '../config/index';
  4. import {clearStorage,getStorage, setStorage,} from "@/utils/storage";
  5. export const useAppStore = defineStore('main', {
  6. //getStorage, setStorage,
  7. state: () => ({
  8. onUpdate: null,
  9. //用户信息
  10. tenantId: config.tenantId,
  11. userInfo: getStorage('userInfo') ?? {},
  12. }),
  13. actions: {
  14. setOnUpdate(value) {
  15. this.onUpdate = value
  16. },
  17. //用户信息
  18. setTenantId(value) {
  19. this.tenantId = value
  20. setStorage('tenantId', value)
  21. },
  22. setUserInfo(value) {
  23. this.userInfo = value
  24. setStorage('userInfo', value)
  25. },
  26. //清除缓存和token
  27. clearStoreData() {
  28. this.onUpdate = null
  29. //用户信息
  30. this.tenantId = config.tenantId
  31. this.userInfo = {}
  32. clearStorage()
  33. },
  34. }
  35. })
  36. export default function useUserStoreWidthOut() {
  37. return useAppStore(pinia);
  38. }