index.js 9.4 KB

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