index.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. isLayout: getStoreValue('isLayout') || '', //是否显示layout
  45. }),
  46. getters: {
  47. //系统信息
  48. getTitle: state => state.title,
  49. getLogoIcon: state => state.logoIcon,
  50. getLogoName: state => state.logoName,
  51. //主题信息
  52. getTheme: state => state.theme,
  53. getThemeVal: state => state.themeVal,
  54. getColor: state => state.color,
  55. getHomeTheme: state => state.homeTheme,
  56. getIndexModel:state => state.indexModel,
  57. //用户信息
  58. getToken: state => state.token,
  59. getRefreshToken: state => state.refreshToken,
  60. getTenantId: state => state.tenantId,
  61. getUserInfo: state => state.userInfo,
  62. //菜单信息
  63. getMenus: state => state.menus,
  64. getButtons: state => state.buttons,
  65. //项目合同段数据
  66. getProjectContract: state => state.projectContract,
  67. getProjectInfo: state => state.projectInfo,
  68. getContractInfo: state => state.contractInfo,
  69. getProjectId: state => state.projectId,
  70. getContractId: state => state.contractId,
  71. //其他配置信息
  72. getBubble: state => state.bubble,
  73. getScreenShort: state => state.isScreenShort,
  74. getOrderServiceTipModal: state => state.orderServiceTipModal,
  75. getShotWebRtc: state => state.shotWebRtc,
  76. getFullScreen: state => state.fullScreen,
  77. getCollapse: state => state.isCollapse,
  78. getDragModalSortTop: state => state.dragModalSortTop,
  79. getIsSource: state => state.isSource,
  80. getIsLayout: state => state.isLayout,
  81. },
  82. actions: {
  83. //系统信息
  84. setTitle(value) {
  85. this.title = value
  86. setStoreValue('title', value)
  87. },
  88. setLogoIcon(value) {
  89. this.logoIcon = value
  90. setStoreValue('logoIcon', value)
  91. },
  92. setLogoName(value) {
  93. this.logoName = value
  94. setStoreValue('logoName', value)
  95. },
  96. //主题信息
  97. setTheme(value) {
  98. this.theme = value
  99. setStoreValue('theme', value)
  100. },
  101. setThemeVal(value) {
  102. this.themeVal = value
  103. setStoreValue('themeVal', value)
  104. },
  105. setColor(value) {
  106. this.color = value
  107. setStoreValue('color', value)
  108. },
  109. setHomeTheme(value) {
  110. this.homeTheme = value
  111. setStoreValue('homeTheme', value)
  112. },
  113. //设置首页模式
  114. setIndexModel(value) {
  115. this.indexModel = value
  116. setStoreValue('indexModel', value)
  117. },
  118. //用户信息
  119. setTokenVal(value) {
  120. this.token = value
  121. setToken(value)
  122. setStoreValue('token', value)
  123. },
  124. setRefreshTokenVal(value) {
  125. this.refreshToken = value
  126. setRefreshToken(value)
  127. setStoreValue('refreshToken', value)
  128. },
  129. setTenantId(value) {
  130. this.tenantId = value
  131. setStoreValue('tenantId', value)
  132. },
  133. setUserInfo(value) {
  134. this.userInfo = value
  135. setStoreValue('userInfo', value)
  136. },
  137. //菜单信息
  138. setMenus(value) {
  139. this.menus = value
  140. setStoreValue('menus', value)
  141. },
  142. setButtons(value) {
  143. this.buttons = value
  144. setStoreValue('buttons', value)
  145. },
  146. getButtonsVal(value) {
  147. return this.buttons[value] || false
  148. },
  149. //项目合同段数据
  150. setProjectContract(value) {
  151. this.projectContract = value
  152. setStoreValue('projectContract', value)
  153. },
  154. setProjectInfo(value) {
  155. this.projectInfo = value
  156. setStoreValue('projectInfo', value)
  157. },
  158. setContractInfo(value) {
  159. this.contractInfo = value
  160. setStoreValue('contractInfo', value)
  161. },
  162. setProjectId(value) {
  163. this.projectId = value
  164. setStoreValue('projectId', value)
  165. },
  166. setContractId(value) {
  167. this.contractId = value
  168. setStoreValue('contractId', value)
  169. },
  170. //其他配置信息
  171. setBubble(value) {
  172. this.bubble = value
  173. setStoreValue('bubble', value)
  174. },
  175. setOrderServiceTipModal(value) {
  176. this.orderServiceTipModal = value
  177. setStoreValue('orderServiceTipModal', value)
  178. },
  179. setScreenShort(value) {
  180. this.isScreenShort = value
  181. },
  182. setShotWebRtc(value) {
  183. this.shotWebRtc = value
  184. setStoreValue('shotWebRtc', value)
  185. },
  186. setFullScreen(value) {
  187. this.fullScreen = value
  188. setStoreValue('fullScreen', value)
  189. },
  190. setCollapse(value) { //菜单折叠
  191. this.isCollapse = value
  192. setStoreValue('isCollapse', value)
  193. },
  194. setDragModalSortTop(value) {
  195. this.dragModalSortTop = value
  196. },
  197. setIsSource(value) {
  198. this.isSource = value
  199. setStoreValue('isSource', value)
  200. },
  201. setIsLayout(value) {
  202. this.isLayout = value
  203. setStoreValue('isLayout', value)
  204. },
  205. //清除缓存和token
  206. clearStoreData() {
  207. //清除状态
  208. this.title = null
  209. this.logoIcon = null
  210. this.logoName = null
  211. this.token = null
  212. this.refreshToken = null
  213. this.tenantId = null
  214. this.userInfo = null
  215. this.menus = null
  216. this.buttons = null
  217. this.projectContract = null
  218. this.projectInfo = null
  219. this.contractInfo = null
  220. this.projectId = null
  221. this.contractId = null
  222. this.orderServiceTipModal = null
  223. this.shotWebRtc = null
  224. this.fullScreen = null
  225. this.isCollapse = false
  226. this.dragModalSortTop = []
  227. this.isSource = ''
  228. this.isLayout = ''
  229. //清除缓存
  230. clearStoreAll()
  231. removeToken()
  232. removeRefreshToken()
  233. },
  234. },
  235. })
  236. export default function useUserStoreWidthOut() {
  237. return useAppStore(pinia)
  238. }