layout-store.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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: 'Pj1101051029',
  24. projects: [{
  25. id: "Pj1101051029",
  26. name: "北京万达广场",
  27. pwd: "saga123456"
  28. },
  29. {
  30. id: "Pj4403070003",
  31. name: "深圳龙岗万达广场",
  32. pwd: "saga123456"
  33. }, {
  34. id: "Pj4403050019",
  35. name: "招商深圳太子广场汇港二期",
  36. pwd: "saga123456"
  37. }, {
  38. id: "Pj5001120003",
  39. name: "香港置地约克北郡",
  40. pwd: "saga123456"
  41. }, {
  42. id: "Pj3201110003",
  43. name: "弘阳集团弘云智慧管理平台",
  44. pwd: "saga123456"
  45. }, {
  46. id: "Pj3702020002",
  47. name: "青岛海天中心",
  48. pwd: "saga123456"
  49. }, {
  50. id: "Pj1101010006",
  51. name: "亚投行",
  52. pwd: "saga123456"
  53. }, {
  54. id: "Pj1101050013",
  55. name: "BIM测试项目_亚投行",
  56. pwd: "saga123456"
  57. }],
  58. breadcrumb: [],
  59. uploaderList: [], //当前上传文件列表
  60. secret: "saga123456", //项目密码
  61. userId: "06328a53c69a41bb8f5bb1a552c6e8d6", //用户id
  62. rowEdit: false,//表格数据变化
  63. errorReport: [],//扫楼错误报告
  64. },
  65. getters: {
  66. sidebarClosed: state => state.sidebarClosed,
  67. secret: state => state.secret,
  68. userId: state => state.userId,
  69. sidebarSelected: state => {
  70. // if (!state.pageSidebarSelected) {
  71. // let menu = storage.get(KEY_MENU_SELECTED)
  72. // if (menu) {
  73. // state.pageSidebarSelected = menu
  74. // }
  75. // }
  76. // return state.pageSidebarSelected
  77. return state.sidebarSelected
  78. },
  79. userInfo: state => state.userInfo,
  80. permissions: state => state.permissions,
  81. projects: state => state.projects,
  82. uploaderList: state => state.uploaderList,
  83. projectId: state => {
  84. if (!state.projectId) {
  85. let pid = storage.get(KEY_PROJECT_SELECTED)
  86. if (pid) {
  87. state.projectId = pid
  88. }
  89. }
  90. return state.projectId
  91. },
  92. breadcrumb: state => {
  93. if (!state.breadcrumb) {
  94. let arr = storage.get(KEY_PAGE_BRANDCRUMB)
  95. if (arr) {
  96. state.breadcrumb = arr
  97. }
  98. }
  99. return state.breadcrumb
  100. }
  101. },
  102. mutations: {
  103. setRowEdit: (state, val) => (state.rowEdit = val),
  104. setErrorReport: (state, val) => (state.errorReport = val),
  105. setSidebarClosed: (state, val) => (state.sidebarClosed = val),
  106. setSidebarSelected: (state, val) => {
  107. state.sidebarSelected = val
  108. storage.set(KEY_MENU_SELECTED, val)
  109. lStorage.set('screen_data', { path: val, data: {} })
  110. },
  111. setprojectId: (state, val) => {
  112. lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存)
  113. let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {}
  114. state.projectId = val
  115. localStorage.setItem('projectId', val)
  116. if (cacheInfo[state.userInfo.userName]) {
  117. // cacheInfo[state.userInfo.userName].projectId = val
  118. cacheInfo[state.userInfo.userName] = [...new Set([val, ...cacheInfo[state.userInfo.userName]])].slice(0, 3)
  119. lStorage.set('historyInfo', cacheInfo)
  120. } else {
  121. cacheInfo[state.userInfo.userName] = [val]
  122. lStorage.set('historyInfo', cacheInfo)
  123. }
  124. storage.set(KEY_PROJECT_SELECTED, val)
  125. state.projects.map((item) => {
  126. if (item.id == val) {
  127. state.secret = item.pwd
  128. localStorage.setItem('secret', item.pwd)
  129. }
  130. })
  131. },
  132. setUploaderList: (state, val) => {
  133. state.uploaderList = val ? val : []
  134. },
  135. },
  136. actions: {
  137. setRowEdit(contentx, value) {
  138. contentx.commit('setRowEdit', value)
  139. },
  140. setErrorReport(contentx, value) {
  141. contentx.commit('setErrorReport', value)
  142. },
  143. loadUserInfo({ state }) {
  144. console.log(state)
  145. // 获取 userInfo 信息
  146. return new Promise((resolve, reject) => {
  147. frameworkApi.loadUserInfo().then(resp => {
  148. console.log(resp)
  149. if (resp.Result == 'success' && resp.UserId) {
  150. state.userInfo = { userName: resp.Username, userId: resp.UserId }
  151. state.userId = resp.UserId
  152. storage.set('user_name', resp.Username)
  153. storage.set('user_id', resp.UserId)
  154. state.permissions = {}
  155. if (resp.Permissions) {
  156. resp.Permissions.forEach(p => (state.permissions[p] = true))
  157. }
  158. state.projects = []
  159. if (resp.Projects) {
  160. if (resp.Projects[0] && resp.Projects[0].ProjId) {
  161. state.projectId = resp.Projects[0].ProjId
  162. state.secret = resp.Projects[0].Secret ? resp.Projects[0].Secret : ""
  163. }
  164. resp.Projects.forEach(proj =>
  165. state.projects.push({
  166. id: proj.ProjId,
  167. name: proj.ProjLocalName,
  168. pwd: proj.Secret ? proj.Secret : ""
  169. })
  170. )
  171. }
  172. } else {
  173. state.userInfo = null
  174. }
  175. resolve(resp)
  176. })
  177. })
  178. },
  179. setBreadcrumb: {
  180. root: true,
  181. handler({ state, commit }, val) {
  182. let label = val[0].label;
  183. if (label === "消息中心") {
  184. commit("setSidebarSelected", "message"); // 当进入消息中心页面的时候不选中导航栏
  185. }
  186. state.breadcrumb = []
  187. state.breadcrumb = val
  188. storage.set(KEY_PAGE_BRANDCRUMB, val)
  189. }
  190. }
  191. }
  192. }