layout-store.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. id: "Pj5107030002",
  34. name: "绵阳CBD万达广场",
  35. pwd: "saga123456"
  36. },{
  37. id: "Pj1101050029",
  38. name: "北京东坝万达广场",
  39. pwd: "saga123456"
  40. },{
  41. id: "Pj4419000005",
  42. name: "莞城万科城市广场",
  43. pwd: "saga123456"
  44. },{
  45. id: "Pj1101080259",
  46. name: "博锐尚格北京总部办公楼",
  47. pwd: "saga123456"
  48. },{
  49. id: "Pj4101020002",
  50. name: "郑州亿达科技新城展厅",
  51. pwd: "saga123456"
  52. },{
  53. id: "Pj1102270001",
  54. name: "北京怀柔万达广场",
  55. pwd: "saga123456"
  56. }],
  57. breadcrumb: [],
  58. uploaderList: [], //当前上传文件列表
  59. secret: "saga123456", //项目密码
  60. userId: "06328a53c69a41bb8f5bb1a552c6e8d6", //用户id
  61. rowEdit: false,//表格数据变化
  62. errorReport: [],//扫楼错误报告
  63. },
  64. getters: {
  65. sidebarClosed: state => state.sidebarClosed,
  66. secret: state => state.secret,
  67. userId: state => state.userId,
  68. sidebarSelected: state => {
  69. // if (!state.pageSidebarSelected) {
  70. // let menu = storage.get(KEY_MENU_SELECTED)
  71. // if (menu) {
  72. // state.pageSidebarSelected = menu
  73. // }
  74. // }
  75. // return state.pageSidebarSelected
  76. return state.sidebarSelected
  77. },
  78. userInfo: state => state.userInfo,
  79. permissions: state => state.permissions,
  80. projects: state => state.projects,
  81. uploaderList: state => state.uploaderList,
  82. projectId: state => {
  83. if (!state.projectId) {
  84. let pid = storage.get(KEY_PROJECT_SELECTED)
  85. if (pid) {
  86. state.projectId = pid
  87. }
  88. }
  89. return state.projectId
  90. },
  91. breadcrumb: state => {
  92. if (!state.breadcrumb) {
  93. let arr = storage.get(KEY_PAGE_BRANDCRUMB)
  94. if (arr) {
  95. state.breadcrumb = arr
  96. }
  97. }
  98. return state.breadcrumb
  99. }
  100. },
  101. mutations: {
  102. setRowEdit: (state, val) => (state.rowEdit = val),
  103. setErrorReport: (state, val) => (state.errorReport = val),
  104. setSidebarClosed: (state, val) => (state.sidebarClosed = val),
  105. setSidebarSelected: (state, val) => {
  106. state.sidebarSelected = val
  107. storage.set(KEY_MENU_SELECTED, val)
  108. lStorage.set('screen_data', {path: val, data: {}})
  109. },
  110. setprojectId: (state, val) => {
  111. lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存)
  112. let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {}
  113. state.projectId = val
  114. localStorage.setItem('projectId', val)
  115. if (cacheInfo[state.userInfo.userName]) {
  116. // cacheInfo[state.userInfo.userName].projectId = val
  117. cacheInfo[state.userInfo.userName] = [...new Set([val, ...cacheInfo[state.userInfo.userName]])].slice(0, 3)
  118. lStorage.set('historyInfo', cacheInfo)
  119. } else {
  120. cacheInfo[state.userInfo.userName] = [val]
  121. lStorage.set('historyInfo', cacheInfo)
  122. }
  123. storage.set(KEY_PROJECT_SELECTED, val)
  124. state.projects.map((item) => {
  125. if (item.id == val) {
  126. state.secret = item.pwd
  127. localStorage.setItem('secret', item.pwd)
  128. }
  129. })
  130. },
  131. setUploaderList: (state, val) => {
  132. state.uploaderList = val ? val : []
  133. },
  134. },
  135. actions: {
  136. setRowEdit(contentx, value) {
  137. contentx.commit('setRowEdit', value)
  138. },
  139. setErrorReport(contentx, value) {
  140. contentx.commit('setErrorReport', value)
  141. },
  142. loadUserInfo({state}) {
  143. console.log(state)
  144. // 获取 userInfo 信息
  145. return new Promise((resolve, reject) => {
  146. frameworkApi.loadUserInfo().then(resp => {
  147. console.log(resp)
  148. if (resp.Result == 'success' && resp.UserId) {
  149. state.userInfo = {userName: resp.Username, userId: resp.UserId}
  150. state.userId = resp.UserId
  151. storage.set('user_name', resp.Username)
  152. storage.set('user_id', resp.UserId)
  153. state.permissions = {}
  154. if (resp.Permissions) {
  155. resp.Permissions.forEach(p => (state.permissions[p] = true))
  156. }
  157. state.projects = []
  158. if (resp.Projects) {
  159. if (resp.Projects[0] && resp.Projects[0].ProjId) {
  160. state.projectId = resp.Projects[0].ProjId
  161. state.secret = resp.Projects[0].Secret ? resp.Projects[0].Secret : ""
  162. }
  163. resp.Projects.forEach(proj =>
  164. state.projects.push({
  165. id: proj.ProjId,
  166. name: proj.ProjLocalName,
  167. pwd: proj.Secret ? proj.Secret : ""
  168. })
  169. )
  170. }
  171. } else {
  172. state.userInfo = null
  173. }
  174. resolve(resp)
  175. })
  176. })
  177. },
  178. setBreadcrumb: {
  179. root: true,
  180. handler({state, commit}, val) {
  181. let label = val[0].label;
  182. if (label === "消息中心") {
  183. commit("setSidebarSelected", "message"); // 当进入消息中心页面的时候不选中导航栏
  184. }
  185. state.breadcrumb = []
  186. state.breadcrumb = val
  187. storage.set(KEY_PAGE_BRANDCRUMB, val)
  188. }
  189. }
  190. }
  191. }