index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import { defineStore } from 'pinia'
  2. import pinia from '~src/store/init'
  3. import appConfig from '~src/config/app'
  4. import logoIcon from '~src/assets/logo/icon.png'
  5. import logoName from '~src/assets/logo/name.png'
  6. import { clearStoreAll, getStoreValue, setStoreValue } from '~src/utils/storage'
  7. import { removeRefreshToken, removeToken, setRefreshToken, setToken } from '~src/api/util/auth'
  8. export const useAppStore = defineStore('main', {
  9. state: () => ({
  10. //系统信息
  11. title: getStoreValue('title') || appConfig.title,
  12. logoIcon: getStoreValue('logoIcon') || logoIcon,
  13. logoName: getStoreValue('logoName') || logoName,
  14. //主题信息
  15. theme: getStoreValue('theme') || appConfig.theme, //用户可选择类型:auto,light, dark
  16. themeVal: getStoreValue('themeVal') || '', //实际主题:light, dark
  17. color: getStoreValue('color') || appConfig.color,
  18. homeTheme: getStoreValue('homeTheme') || appConfig.homeTheme,
  19. indexModel:getStoreValue('indexModel') || appConfig.indexModel, //首页模式
  20. //用户信息
  21. token: getStoreValue('token') || '',
  22. refreshToken: getStoreValue('refreshToken') || '',
  23. tenantId: getStoreValue('tenantId') || '',
  24. userInfo: getStoreValue('userInfo') || {},
  25. //菜单信息
  26. menus: getStoreValue('menus') || [],
  27. buttons: getStoreValue('buttons') || {},
  28. //项目合同段数据
  29. projectContract: getStoreValue('projectContract') || [],
  30. projectInfo: getStoreValue('projectInfo') || {},
  31. contractInfo: getStoreValue('contractInfo') || {},
  32. projectId: getStoreValue('projectId') || '',
  33. contractId: getStoreValue('contractId') || '',
  34. //其他配置信息
  35. bubble: getStoreValue('bubble') || false,
  36. orderServiceTipModal: getStoreValue('orderServiceTipModal') ?? 1, //0不弹出,1弹出
  37. shotWebRtc: getStoreValue('shotWebRtc') || 0, //WebRtc截图方式: 0关闭,1开启
  38. fullScreen: getStoreValue('fullScreen') || 0, //全屏截图:0关闭,1开启
  39. isCollapse: getStoreValue('isCollapse') || false, //菜单折叠
  40. dragModalSortTop: [], //拖拽弹窗排序
  41. isScreenShort: false,
  42. barMenuName: '',
  43. isSource: getStoreValue('isSource') || '', //来源
  44. }),
  45. getters: {
  46. //系统信息
  47. getTitle: state => state.title,
  48. getLogoIcon: state => state.logoIcon,
  49. getLogoName: state => state.logoName,
  50. //主题信息
  51. getTheme: state => state.theme,
  52. getThemeVal: state => state.themeVal,
  53. getColor: state => state.color,
  54. getHomeTheme: state => state.homeTheme,
  55. getIndexModel:state => state.indexModel,
  56. //用户信息
  57. getToken: state => state.token,
  58. getRefreshToken: state => state.refreshToken,
  59. getTenantId: state => state.tenantId,
  60. getUserInfo: state => state.userInfo,
  61. //菜单信息
  62. getMenus: state => state.menus,
  63. getButtons: state => state.buttons,
  64. //项目合同段数据
  65. getProjectContract: state => state.projectContract,
  66. getProjectInfo: state => state.projectInfo,
  67. getContractInfo: state => state.contractInfo,
  68. getProjectId: state => state.projectId,
  69. getContractId: state => state.contractId,
  70. //其他配置信息
  71. getBubble: state => state.bubble,
  72. getScreenShort: state => state.isScreenShort,
  73. getOrderServiceTipModal: state => state.orderServiceTipModal,
  74. getShotWebRtc: state => state.shotWebRtc,
  75. getFullScreen: state => state.fullScreen,
  76. getCollapse: state => state.isCollapse,
  77. getDragModalSortTop: state => state.dragModalSortTop,
  78. getIsSource: state => state.isSource,
  79. },
  80. actions: {
  81. //系统信息
  82. setTitle(value) {
  83. this.title = value
  84. setStoreValue('title', value)
  85. },
  86. setLogoIcon(value) {
  87. this.logoIcon = value
  88. setStoreValue('logoIcon', value)
  89. },
  90. setLogoName(value) {
  91. this.logoName = value
  92. setStoreValue('logoName', value)
  93. },
  94. //主题信息
  95. setTheme(value) {
  96. this.theme = value
  97. setStoreValue('theme', value)
  98. },
  99. setThemeVal(value) {
  100. this.themeVal = value
  101. setStoreValue('themeVal', value)
  102. },
  103. setColor(value) {
  104. this.color = value
  105. setStoreValue('color', value)
  106. },
  107. setHomeTheme(value) {
  108. this.homeTheme = value
  109. setStoreValue('homeTheme', value)
  110. },
  111. //设置首页模式
  112. setIndexModel(value) {
  113. this.indexModel = value
  114. setStoreValue('indexModel', value)
  115. },
  116. //用户信息
  117. setTokenVal(value) {
  118. this.token = value
  119. setToken(value)
  120. setStoreValue('token', value)
  121. },
  122. setRefreshTokenVal(value) {
  123. this.refreshToken = value
  124. setRefreshToken(value)
  125. setStoreValue('refreshToken', value)
  126. },
  127. setTenantId(value) {
  128. this.tenantId = value
  129. setStoreValue('tenantId', value)
  130. },
  131. setUserInfo(value) {
  132. this.userInfo = value
  133. setStoreValue('userInfo', value)
  134. },
  135. //菜单信息
  136. setMenus(value) {
  137. this.menus = value
  138. setStoreValue('menus', value)
  139. },
  140. setButtons(value) {
  141. this.buttons = value
  142. setStoreValue('buttons', value)
  143. },
  144. getButtonsVal(value) {
  145. return this.buttons[value] || false
  146. },
  147. //项目合同段数据
  148. setProjectContract(value) {
  149. this.projectContract = value
  150. setStoreValue('projectContract', value)
  151. },
  152. setProjectInfo(value) {
  153. this.projectInfo = value
  154. setStoreValue('projectInfo', value)
  155. },
  156. setContractInfo(value) {
  157. this.contractInfo = value
  158. setStoreValue('contractInfo', value)
  159. },
  160. setProjectId(value) {
  161. this.projectId = value
  162. setStoreValue('projectId', value)
  163. },
  164. setContractId(value) {
  165. this.contractId = value
  166. setStoreValue('contractId', value)
  167. },
  168. //其他配置信息
  169. setBubble(value) {
  170. this.bubble = value
  171. setStoreValue('bubble', value)
  172. },
  173. setOrderServiceTipModal(value) {
  174. this.orderServiceTipModal = value
  175. setStoreValue('orderServiceTipModal', value)
  176. },
  177. setScreenShort(value) {
  178. this.isScreenShort = value
  179. },
  180. setShotWebRtc(value) {
  181. this.shotWebRtc = value
  182. setStoreValue('shotWebRtc', value)
  183. },
  184. setFullScreen(value) {
  185. this.fullScreen = value
  186. setStoreValue('fullScreen', value)
  187. },
  188. setCollapse(value) { //菜单折叠
  189. this.isCollapse = value
  190. setStoreValue('isCollapse', value)
  191. },
  192. setDragModalSortTop(value) {
  193. this.dragModalSortTop = value
  194. },
  195. setIsSource(value) {
  196. this.isSource = value
  197. setStoreValue('isSource', value)
  198. },
  199. //清除缓存和token
  200. clearStoreData() {
  201. //清除状态
  202. this.title = null
  203. this.logoIcon = null
  204. this.logoName = null
  205. this.token = null
  206. this.refreshToken = null
  207. this.tenantId = null
  208. this.userInfo = null
  209. this.menus = null
  210. this.buttons = null
  211. this.projectContract = null
  212. this.projectInfo = null
  213. this.contractInfo = null
  214. this.projectId = null
  215. this.contractId = null
  216. this.orderServiceTipModal = null
  217. this.shotWebRtc = null
  218. this.fullScreen = null
  219. this.isCollapse = false
  220. this.dragModalSortTop = []
  221. this.isSource = ''
  222. //清除缓存
  223. clearStoreAll()
  224. removeToken()
  225. removeRefreshToken()
  226. },
  227. },
  228. })
  229. export default function useUserStoreWidthOut() {
  230. return useAppStore(pinia)
  231. }