index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {defineStore} from 'pinia'
  2. import pinia from "../store/init"
  3. import config from '../config/index';
  4. import {getStorage, setStorage, clearStorage} from "@/utils/storage";
  5. export const useAppStore = defineStore('main', {
  6. state: () => ({
  7. //系统信息
  8. title: config.theme,
  9. //用户信息
  10. tenantId: config.tenantId,
  11. userInfo: getStorage('userInfo') ?? {},
  12. //项目合同段数据
  13. projectInfo: getStorage('projectInfo') ?? {},
  14. contractInfo: getStorage('contractInfo') ?? {},
  15. projectId: getStorage('projectId') ?? '',
  16. contractId: getStorage('contractId') ?? '',
  17. isAnimation: getStorage('isAnimation') ?? false,
  18. //按钮权限
  19. buttons: getStorage('buttons') || {},
  20. //消息数据
  21. msgCountData: getStorage('msgCountData') ?? {},
  22. //检测升级
  23. appUpdate: getStorage('appUpdate') ?? {
  24. appVersion: '',
  25. version: '',
  26. isUpdate: false,
  27. toUpdate: true
  28. },
  29. //改变值时,触发更新
  30. onUpdate: null,
  31. }),
  32. actions: {
  33. //系统信息
  34. setTitle(value) {
  35. this.title = value
  36. },
  37. //用户信息
  38. setTenantId(value) {
  39. this.tenantId = value
  40. setStorage('tenantId', value)
  41. },
  42. setUserInfo(value) {
  43. this.userInfo = value
  44. setStorage('userInfo', value)
  45. },
  46. //项目合同段数据
  47. setProjectInfo(value) {
  48. this.projectInfo = value
  49. setStorage('projectInfo', value)
  50. },
  51. setContractInfo(value) {
  52. this.contractInfo = value
  53. setStorage('contractInfo', value)
  54. },
  55. setProjectId(value) {
  56. this.projectId = value
  57. setStorage('projectId', value)
  58. },
  59. setContractId(value) {
  60. this.contractId = value
  61. setStorage('contractId', value)
  62. },
  63. setAnimation(value) {
  64. this.isAnimation = value
  65. setStorage('isAnimation', value)
  66. },
  67. setMsgCountData(value) {
  68. this.msgCountData = value
  69. setStorage('msgCountData', value)
  70. },
  71. setAppUpdate(value) {
  72. this.appUpdate = value
  73. setStorage('appUpdate', value)
  74. },
  75. setOnUpdate(value) {
  76. this.onUpdate = value
  77. },
  78. //按钮权限
  79. setButtons(value) {
  80. this.buttons = value
  81. setStorage('buttons', value)
  82. },
  83. getButtonsVal(value) {
  84. return this.buttons[value] || false
  85. },
  86. //清除缓存和token
  87. clearStoreData() {
  88. //清除状态
  89. this.title = config.theme
  90. //用户信息
  91. this.tenantId = config.tenantId
  92. this.userInfo = {}
  93. //项目合同段数据
  94. this.projectInfo = {}
  95. this.contractInfo = {}
  96. this.projectId = ''
  97. this.contractId = ''
  98. this.msgCountData = {}
  99. this.appUpdate = {
  100. appVersion: '',
  101. version: '',
  102. isUpdate: false,
  103. toUpdate: true
  104. }
  105. this.buttons = null
  106. this.onUpdate = null
  107. clearStorage()
  108. },
  109. }
  110. })
  111. export default function useUserStoreWidthOut() {
  112. return useAppStore(pinia);
  113. }