layout-store.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import frameworkApi from '@/api/framework'
  2. import storage from '@/framework/utils/storage'
  3. import lStorage from '@/utils/localStorage'
  4. const KEY_MENU_SELECTED = 'menu_selected'
  5. const KEY_PROJECT_SELECTED = 'global_project_selected'
  6. const KEY_PAGE_BRANDCRUMB = 'page_brandcrumb'
  7. export default {
  8. namespaced: true,
  9. state: {
  10. sidebarClosed: false,
  11. sidebarSelected: '', // sidebar选中的选项
  12. // userInfo: null, //{ username: 'admin' },
  13. userInfo: {
  14. username: 'yanruolan',
  15. userId: '06328a53c69a41bb8f5bb1a552c6e8d6'
  16. },
  17. permissions: {
  18. "system:role:delete": true,
  19. "system:role:create": true,
  20. "system:role:query": true,
  21. "system:role:setOpts": true
  22. },
  23. projectId: 'Pj5101050001',
  24. projects: [{
  25. id: "Pj5101050001",
  26. name: "成都青羊万达广场",
  27. pwd: "saga123456"
  28. },{
  29. id: "Pj1101080260",
  30. name: "万达测试",
  31. pwd: "saga123456"
  32. }],
  33. breadcrumb: [],
  34. uploaderList: [], //当前上传文件列表
  35. secret: "saga123456", //项目密码
  36. userId: "06328a53c69a41bb8f5bb1a552c6e8d6", //用户id
  37. rowEdit: false,//表格数据变化
  38. errorReport: [],//扫楼错误报告
  39. },
  40. getters: {
  41. sidebarClosed: state => state.sidebarClosed,
  42. secret: state => state.secret,
  43. userId: state => state.userId,
  44. sidebarSelected: state => {
  45. // if (!state.pageSidebarSelected) {
  46. // let menu = storage.get(KEY_MENU_SELECTED)
  47. // if (menu) {
  48. // state.pageSidebarSelected = menu
  49. // }
  50. // }
  51. // return state.pageSidebarSelected
  52. return state.sidebarSelected
  53. },
  54. userInfo: state => state.userInfo,
  55. permissions: state => state.permissions,
  56. projects: state => state.projects,
  57. uploaderList: state => state.uploaderList,
  58. projectId: state => {
  59. if (!state.projectId) {
  60. let pid = storage.get(KEY_PROJECT_SELECTED)
  61. if (pid) {
  62. state.projectId = pid
  63. }
  64. }
  65. return state.projectId
  66. },
  67. breadcrumb: state => {
  68. if (!state.breadcrumb) {
  69. let arr = storage.get(KEY_PAGE_BRANDCRUMB)
  70. if (arr) {
  71. state.breadcrumb = arr
  72. }
  73. }
  74. return state.breadcrumb
  75. }
  76. },
  77. mutations: {
  78. setRowEdit: (state, val) => (state.rowEdit = val),
  79. setErrorReport: (state, val) => (state.errorReport = val),
  80. setSidebarClosed: (state, val) => (state.sidebarClosed = val),
  81. setSidebarSelected: (state, val) => {
  82. state.sidebarSelected = val
  83. storage.set(KEY_MENU_SELECTED, val)
  84. lStorage.set('screen_data', {path: val, data: {}})
  85. },
  86. setprojectId: (state, val) => {
  87. lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存)
  88. let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {}
  89. state.projectId = val
  90. localStorage.setItem('projectId', val)
  91. if (cacheInfo[state.userInfo.userName]) {
  92. // cacheInfo[state.userInfo.userName].projectId = val
  93. cacheInfo[state.userInfo.userName] = [...new Set([val, ...cacheInfo[state.userInfo.userName]])].slice(0, 3)
  94. lStorage.set('historyInfo', cacheInfo)
  95. } else {
  96. cacheInfo[state.userInfo.userName] = [val]
  97. lStorage.set('historyInfo', cacheInfo)
  98. }
  99. storage.set(KEY_PROJECT_SELECTED, val)
  100. state.projects.map((item) => {
  101. if (item.id == val) {
  102. state.secret = item.pwd
  103. localStorage.setItem('secret', item.pwd)
  104. }
  105. })
  106. },
  107. setUploaderList: (state, val) => {
  108. state.uploaderList = val ? val : []
  109. },
  110. },
  111. actions: {
  112. setRowEdit(contentx, value) {
  113. contentx.commit('setRowEdit', value)
  114. },
  115. setErrorReport(contentx, value) {
  116. contentx.commit('setErrorReport', value)
  117. },
  118. loadUserInfo({state}) {
  119. console.log(state)
  120. // 获取 userInfo 信息
  121. return new Promise((resolve, reject) => {
  122. frameworkApi.loadUserInfo().then(resp => {
  123. console.log(resp)
  124. if (resp.Result == 'success' && resp.UserId) {
  125. state.userInfo = {userName: resp.Username, userId: resp.UserId}
  126. state.userId = resp.UserId
  127. storage.set('user_name', resp.Username)
  128. storage.set('user_id', resp.UserId)
  129. state.permissions = {}
  130. if (resp.Permissions) {
  131. resp.Permissions.forEach(p => (state.permissions[p] = true))
  132. }
  133. state.projects = []
  134. if (resp.Projects) {
  135. if (resp.Projects[0] && resp.Projects[0].ProjId) {
  136. state.projectId = resp.Projects[0].ProjId
  137. state.secret = resp.Projects[0].Secret ? resp.Projects[0].Secret : ""
  138. }
  139. resp.Projects.forEach(proj =>
  140. state.projects.push({
  141. id: proj.ProjId,
  142. name: proj.ProjLocalName,
  143. pwd: proj.Secret ? proj.Secret : ""
  144. })
  145. )
  146. }
  147. } else {
  148. state.userInfo = null
  149. }
  150. resolve(resp)
  151. })
  152. })
  153. },
  154. setBreadcrumb: {
  155. root: true,
  156. handler({state, commit}, val) {
  157. let label = val[0].label;
  158. if (label === "消息中心") {
  159. commit("setSidebarSelected", "message"); // 当进入消息中心页面的时候不选中导航栏
  160. }
  161. state.breadcrumb = []
  162. state.breadcrumb = val
  163. storage.set(KEY_PAGE_BRANDCRUMB, val)
  164. }
  165. }
  166. }
  167. }