layout-store.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. id: "Pj1101080259",
  59. name: "博锐尚格北京总部办公楼",
  60. pwd: "saga123456"
  61. },{
  62. id: "Pj1101150002",
  63. name: "华润生命科学园",
  64. pwd: "saga123456"
  65. },{
  66. id: "Pj3101150007",
  67. name: "招商上海森兰花园城",
  68. pwd: "saga123456"
  69. },{
  70. id: "Pj5101080004",
  71. name: "成都招商花园城",
  72. pwd: "saga123456"
  73. },{
  74. id: "Pj3201130004",
  75. name: "招商南京燕子矶花园城",
  76. pwd: "saga123456"
  77. }],
  78. breadcrumb: [],
  79. uploaderList: [], //当前上传文件列表
  80. secret: "saga123456", //项目密码
  81. userId: "06328a53c69a41bb8f5bb1a552c6e8d6", //用户id
  82. rowEdit: false,//表格数据变化
  83. errorReport: [],//扫楼错误报告
  84. },
  85. getters: {
  86. sidebarClosed: state => state.sidebarClosed,
  87. secret: state => state.secret,
  88. userId: state => state.userId,
  89. sidebarSelected: state => {
  90. // if (!state.pageSidebarSelected) {
  91. // let menu = storage.get(KEY_MENU_SELECTED)
  92. // if (menu) {
  93. // state.pageSidebarSelected = menu
  94. // }
  95. // }
  96. // return state.pageSidebarSelected
  97. return state.sidebarSelected
  98. },
  99. userInfo: state => state.userInfo,
  100. permissions: state => state.permissions,
  101. projects: state => state.projects,
  102. uploaderList: state => state.uploaderList,
  103. projectId: state => {
  104. if (!state.projectId) {
  105. let pid = storage.get(KEY_PROJECT_SELECTED)
  106. if (pid) {
  107. state.projectId = pid
  108. }
  109. }
  110. return state.projectId
  111. },
  112. breadcrumb: state => {
  113. if (!state.breadcrumb) {
  114. let arr = storage.get(KEY_PAGE_BRANDCRUMB)
  115. if (arr) {
  116. state.breadcrumb = arr
  117. }
  118. }
  119. return state.breadcrumb
  120. }
  121. },
  122. mutations: {
  123. setRowEdit: (state, val) => (state.rowEdit = val),
  124. setErrorReport: (state, val) => (state.errorReport = val),
  125. setSidebarClosed: (state, val) => (state.sidebarClosed = val),
  126. setSidebarSelected: (state, val) => {
  127. state.sidebarSelected = val
  128. storage.set(KEY_MENU_SELECTED, val)
  129. lStorage.set('screen_data', { path: val, data: {} })
  130. },
  131. setprojectId: (state, val) => {
  132. lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存)
  133. let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {}
  134. state.projectId = val
  135. localStorage.setItem('projectId', val)
  136. if (cacheInfo[state.userInfo.userName]) {
  137. // cacheInfo[state.userInfo.userName].projectId = val
  138. cacheInfo[state.userInfo.userName] = [...new Set([val, ...cacheInfo[state.userInfo.userName]])].slice(0, 3)
  139. lStorage.set('historyInfo', cacheInfo)
  140. } else {
  141. cacheInfo[state.userInfo.userName] = [val]
  142. lStorage.set('historyInfo', cacheInfo)
  143. }
  144. storage.set(KEY_PROJECT_SELECTED, val)
  145. state.projects.map((item) => {
  146. if (item.id == val) {
  147. state.secret = item.pwd
  148. localStorage.setItem('secret', item.pwd)
  149. }
  150. })
  151. },
  152. setUploaderList: (state, val) => {
  153. state.uploaderList = val ? val : []
  154. },
  155. },
  156. actions: {
  157. setRowEdit(contentx, value) {
  158. contentx.commit('setRowEdit', value)
  159. },
  160. setErrorReport(contentx, value) {
  161. contentx.commit('setErrorReport', value)
  162. },
  163. loadUserInfo({ state }) {
  164. console.log(state)
  165. // 获取 userInfo 信息
  166. return new Promise((resolve, reject) => {
  167. frameworkApi.loadUserInfo().then(resp => {
  168. console.log(resp)
  169. if (resp.Result == 'success' && resp.UserId) {
  170. state.userInfo = { userName: resp.Username, userId: resp.UserId }
  171. state.userId = resp.UserId
  172. storage.set('user_name', resp.Username)
  173. storage.set('user_id', resp.UserId)
  174. state.permissions = {}
  175. if (resp.Permissions) {
  176. resp.Permissions.forEach(p => (state.permissions[p] = true))
  177. }
  178. state.projects = []
  179. if (resp.Projects) {
  180. if (resp.Projects[0] && resp.Projects[0].ProjId) {
  181. state.projectId = resp.Projects[0].ProjId
  182. state.secret = resp.Projects[0].Secret ? resp.Projects[0].Secret : ""
  183. }
  184. resp.Projects.forEach(proj =>
  185. state.projects.push({
  186. id: proj.ProjId,
  187. name: proj.ProjLocalName,
  188. pwd: proj.Secret ? proj.Secret : ""
  189. })
  190. )
  191. }
  192. } else {
  193. state.userInfo = null
  194. }
  195. resolve(resp)
  196. })
  197. })
  198. },
  199. setBreadcrumb: {
  200. root: true,
  201. handler({ state, commit }, val) {
  202. let label = val[0].label;
  203. if (label === "消息中心") {
  204. commit("setSidebarSelected", "message"); // 当进入消息中心页面的时候不选中导航栏
  205. }
  206. state.breadcrumb = []
  207. state.breadcrumb = val
  208. storage.set(KEY_PAGE_BRANDCRUMB, val)
  209. }
  210. }
  211. }
  212. }