index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import {defineStore} from 'pinia'
  2. import pinia from "~src/store/init"
  3. import appConfig from '~src/config/app';
  4. import authStore from '~src/api/util/auth'
  5. import appStore from '~uti/storage'
  6. export const useAppStore = defineStore('main', {
  7. state: () =>({
  8. //主题信息
  9. theme: appStore.getStoreData('theme') || appConfig.theme, //用户可选择类型:auto,light, dark
  10. themeVal: appStore.getStoreData('themeVal') || '', //实际主题:light, dark
  11. color: appStore.getStoreData('color') || appConfig.color,
  12. homeTheme: appStore.getStoreData('homeTheme') || appConfig.homeTheme,
  13. //用户信息
  14. token: appStore.getStoreData( 'token') || '',
  15. refreshToken: appStore.getStoreData('refreshToken') || '',
  16. tenantId: appStore.getStoreData('tenantId') || '',
  17. userInfo: appStore.getStoreData('userInfo') || {},
  18. //菜单信息
  19. menus: appStore.getStoreData('menus') || [],
  20. buttons: appStore.getStoreData('buttons') || {},
  21. //项目合同段数据
  22. projectContract: appStore.getStoreData('projectContract') || [],
  23. projectInfo: appStore.getStoreData('projectInfo') || {},
  24. contractInfo: appStore.getStoreData('contractInfo') || {},
  25. projectId: appStore.getStoreData('projectId') || '',
  26. contractId: appStore.getStoreData('contractId') || '',
  27. //其他配置信息
  28. bubble: appStore.getStoreData('bubble') || false,
  29. orderServiceTipModal: appStore.getStoreData('orderServiceTipModal') ?? 1, //0不弹出,1弹出
  30. shotWebRtc: appStore.getStoreData('shotWebRtc') || 0, //WebRtc截图方式: 0关闭,1开启
  31. fullScreen: appStore.getStoreData('fullScreen') || 0, //全屏截图:0关闭,1开启
  32. isCollapse: appStore.getStoreData('isCollapse') || false, //菜单折叠
  33. isScreenShort: false,
  34. }),
  35. getters: {
  36. //主题信息
  37. getTheme: state => state.theme,
  38. getThemeVal: state => state.themeVal,
  39. getColor: state => state.color,
  40. getHomeTheme: state => state.homeTheme,
  41. //用户信息
  42. getToken: state => state.token,
  43. getRefreshToken: state => state.refreshToken,
  44. getTenantId: state => state.tenantId,
  45. getUserInfo: state => state.userInfo,
  46. //菜单信息
  47. getMenus: state => state.menus,
  48. getButtons: state => state.buttons,
  49. //项目合同段数据
  50. getProjectContract: state => state.projectContract,
  51. getProjectInfo: state => state.projectInfo,
  52. getContractInfo: state => state.contractInfo,
  53. getProjectId: state => state.projectId,
  54. getContractId: state => state.contractId,
  55. //其他配置信息
  56. getBubble: state => state.bubble,
  57. getScreenShort: state => state.isScreenShort,
  58. getOrderServiceTipModal: state => state.orderServiceTipModal,
  59. getShotWebRtc: state => state.shotWebRtc,
  60. getFullScreen: state => state.fullScreen,
  61. getCollapse: state => state.isCollapse
  62. },
  63. actions: {
  64. //主题信息
  65. setTheme(value) {
  66. this.theme = value
  67. appStore.setStoreData('theme',value)
  68. },
  69. setThemeVal(value) {
  70. this.themeVal = value
  71. appStore.setStoreData('themeVal',value)
  72. },
  73. setColor(value) {
  74. this.color = value
  75. appStore.setStoreData('color',value)
  76. },
  77. setHomeTheme(value) {
  78. this.homeTheme = value
  79. appStore.setStoreData('homeTheme',value)
  80. },
  81. //用户信息
  82. setToken(value){
  83. this.token = value
  84. authStore.setToken(value)
  85. appStore.setStoreData('token',value)
  86. },
  87. setRefreshToken(value){
  88. this.refreshToken = value
  89. authStore.setRefreshToken(value)
  90. appStore.setStoreData('refreshToken',value)
  91. },
  92. setTenantId(value){
  93. this.tenantId = value
  94. appStore.setStoreData('tenantId',value)
  95. },
  96. setUserInfo(value){
  97. this.userInfo = value
  98. appStore.setStoreData('userInfo',value)
  99. },
  100. //菜单信息
  101. setMenus(value){
  102. this.menus = value
  103. appStore.setStoreData('menus',value)
  104. },
  105. setButtons(value){
  106. this.buttons = value
  107. appStore.setStoreData('buttons',value)
  108. },
  109. getButtonsVal(value) {
  110. return this.buttons[value] || false;
  111. },
  112. //项目合同段数据
  113. setProjectContract(value) {
  114. this.projectContract = value
  115. appStore.setStoreData('projectContract',value)
  116. },
  117. setProjectInfo(value) {
  118. this.projectInfo = value
  119. appStore.setStoreData('projectInfo',value)
  120. },
  121. setContractInfo(value) {
  122. this.contractInfo = value
  123. appStore.setStoreData('contractInfo',value)
  124. },
  125. setProjectId(value) {
  126. this.projectId = value
  127. appStore.setStoreData('projectId',value)
  128. },
  129. setContractId(value) {
  130. this.contractId = value
  131. appStore.setStoreData('contractId',value)
  132. },
  133. //其他配置信息
  134. setBubble(value) {
  135. this.bubble = value
  136. appStore.setStoreData('bubble',value)
  137. },
  138. setOrderServiceTipModal(value) {
  139. this.orderServiceTipModal = value
  140. appStore.setStoreData('orderServiceTipModal',value)
  141. },
  142. setScreenShort(value) {
  143. this.isScreenShort = value
  144. },
  145. setShotWebRtc(value) {
  146. this.shotWebRtc = value
  147. appStore.setStoreData('shotWebRtc',value)
  148. },
  149. setFullScreen(value) {
  150. this.fullScreen = value
  151. appStore.setStoreData('fullScreen',value)
  152. },
  153. setCollapse(value) { //菜单折叠
  154. this.isCollapse = value
  155. appStore.setStoreData('isCollapse',value)
  156. },
  157. //清除缓存和token
  158. clearStoreData() {
  159. //清除状态
  160. this.token = null
  161. this.refreshToken = null
  162. this.tenantId = null
  163. this.userInfo = null
  164. this.menus = null
  165. this.buttons = null
  166. this.projectContract = null
  167. this.projectInfo = null
  168. this.contractInfo = null
  169. this.projectId = null
  170. this.contractId = null
  171. this.orderServiceTipModal = null
  172. this.shotWebRtc = null
  173. this.fullScreen = null
  174. this.isCollapse = false
  175. //清除缓存
  176. appStore.clearAllStore()
  177. authStore.removeToken()
  178. authStore.removeRefreshToken()
  179. },
  180. }
  181. })
  182. export default function useUserStoreWidthOut() {
  183. return useAppStore(pinia);
  184. }