layout-store.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. {
  26. id: "Pj1101051029",
  27. name: "北京万达广场",
  28. pwd: "saga123456"
  29. },
  30. {
  31. id: "Pj1101050029",
  32. name: "东坝万达广场",
  33. pwd: "saga123456"
  34. },
  35. {
  36. id: "Pj4403070003",
  37. name: "深圳龙岗万达广场",
  38. pwd: "saga123456"
  39. },
  40. {
  41. id: "Pj5001120003",
  42. name: "香港置地约克北郡",
  43. pwd: "saga123456"
  44. },
  45. {
  46. id: "Pj1101050013",
  47. name: "BIM测试项目_亚投行",
  48. pwd: "saga123456"
  49. },
  50. {
  51. id: "Pj1101080259",
  52. name: "博锐尚格北京总部办公楼",
  53. pwd: "saga123456"
  54. },], // 14 全平台测试环境
  55. // projects: [
  56. // {
  57. // id: "Pj1101051029",
  58. // name: "北京万达广场",
  59. // pwd: "saga123456"
  60. // }, {
  61. // id: "Pj0001110001",
  62. // name: "飞龙商场",
  63. // pwd: "saga123456"
  64. // },
  65. // {
  66. // id: "Pj1101050029",
  67. // name: "东坝万达广场",
  68. // pwd: "saga123456"
  69. // },
  70. // {
  71. // id: "Pj4403070003",
  72. // name: "深圳龙岗万达广场",
  73. // pwd: "saga123456"
  74. // },
  75. // {
  76. // id: "Pj4403050019",
  77. // name: "招商深圳太子广场汇港二期",
  78. // pwd: "saga123456"
  79. // },
  80. // {
  81. // id: "Pj5001120003",
  82. // name: "香港置地约克北郡",
  83. // pwd: "saga123456"
  84. // },
  85. // {
  86. // id: "Pj3201110003",
  87. // name: "弘阳集团弘云智慧管理平台",
  88. // pwd: "saga123456"
  89. // }, {
  90. // id: "Pj3702020002",
  91. // name: "青岛海天中心",
  92. // pwd: "saga123456"
  93. // }, {
  94. // id: "Pj1101010006",
  95. // name: "亚投行",
  96. // pwd: "saga123456"
  97. // },
  98. // {
  99. // id: "Pj1101050013",
  100. // name: "BIM测试项目_亚投行",
  101. // pwd: "saga123456"
  102. // },
  103. // {
  104. // id: "Pj1101080259",
  105. // name: "博锐尚格北京总部办公楼",
  106. // pwd: "saga123456"
  107. // },
  108. // {
  109. // id: "Pj1101150002",
  110. // name: "华润生命科学园",
  111. // pwd: "saga123456"
  112. // },{
  113. // id: "Pj3101150007",
  114. // name: "招商上海森兰花园城",
  115. // pwd: "saga123456"
  116. // },{
  117. // id: "Pj5101080004",
  118. // name: "成都招商花园城",
  119. // pwd: "saga123456"
  120. // },{
  121. // id: "Pj3201130004",
  122. // name: "招商南京燕子矶花园城",
  123. // pwd: "saga123456"
  124. // },{
  125. // id: "Pj3702120001",
  126. // name: "金融中心",
  127. // pwd: "saga123456"
  128. // },{
  129. // id: "Pj1101051130",
  130. // name: "万达模型测试项目2",
  131. // pwd: "saga123456"
  132. // }
  133. // ], // 39,18环境
  134. breadcrumb: [],
  135. uploaderList: [], //当前上传文件列表
  136. secret: "saga123456", //项目密码
  137. userId: "06328a53c69a41bb8f5bb1a552c6e8d6", //用户id
  138. rowEdit: false,//表格数据变化
  139. errorReport: [],//扫楼错误报告
  140. },
  141. getters: {
  142. sidebarClosed: state => state.sidebarClosed,
  143. secret: state => state.secret,
  144. userId: state => state.userId,
  145. sidebarSelected: state => {
  146. // if (!state.pageSidebarSelected) {
  147. // let menu = storage.get(KEY_MENU_SELECTED)
  148. // if (menu) {
  149. // state.pageSidebarSelected = menu
  150. // }
  151. // }
  152. // return state.pageSidebarSelected
  153. return state.sidebarSelected
  154. },
  155. userInfo: state => state.userInfo,
  156. permissions: state => state.permissions,
  157. projects: state => state.projects,
  158. uploaderList: state => state.uploaderList,
  159. projectId: state => {
  160. if (!state.projectId) {
  161. let pid = storage.get(KEY_PROJECT_SELECTED)
  162. if (pid) {
  163. state.projectId = pid
  164. }
  165. }
  166. return state.projectId
  167. },
  168. breadcrumb: state => {
  169. if (!state.breadcrumb) {
  170. let arr = storage.get(KEY_PAGE_BRANDCRUMB)
  171. if (arr) {
  172. state.breadcrumb = arr
  173. }
  174. }
  175. return state.breadcrumb
  176. }
  177. },
  178. mutations: {
  179. setRowEdit: (state, val) => (state.rowEdit = val),
  180. setErrorReport: (state, val) => (state.errorReport = val),
  181. setSidebarClosed: (state, val) => (state.sidebarClosed = val),
  182. setSidebarSelected: (state, val) => {
  183. state.sidebarSelected = val
  184. storage.set(KEY_MENU_SELECTED, val)
  185. lStorage.set('screen_data', { path: val, data: {} })
  186. },
  187. setprojectId: (state, val) => {
  188. lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存)
  189. let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {}
  190. state.projectId = val
  191. localStorage.setItem('projectId', val)
  192. if (cacheInfo[state.userInfo.userName]) {
  193. // cacheInfo[state.userInfo.userName].projectId = val
  194. cacheInfo[state.userInfo.userName] = [...new Set([val, ...cacheInfo[state.userInfo.userName]])].slice(0, 3)
  195. lStorage.set('historyInfo', cacheInfo)
  196. } else {
  197. cacheInfo[state.userInfo.userName] = [val]
  198. lStorage.set('historyInfo', cacheInfo)
  199. }
  200. storage.set(KEY_PROJECT_SELECTED, val)
  201. state.projects.map((item) => {
  202. if (item.id == val) {
  203. state.secret = item.pwd
  204. localStorage.setItem('secret', item.pwd)
  205. }
  206. })
  207. },
  208. setUploaderList: (state, val) => {
  209. state.uploaderList = val ? val : []
  210. },
  211. },
  212. actions: {
  213. setRowEdit(contentx, value) {
  214. contentx.commit('setRowEdit', value)
  215. },
  216. setErrorReport(contentx, value) {
  217. contentx.commit('setErrorReport', value)
  218. },
  219. loadUserInfo({ state }) {
  220. console.log(state)
  221. // 获取 userInfo 信息
  222. return new Promise((resolve, reject) => {
  223. frameworkApi.loadUserInfo().then(resp => {
  224. console.log(resp)
  225. if (resp.Result == 'success' && resp.UserId) {
  226. state.userInfo = { userName: resp.Username, userId: resp.UserId }
  227. state.userId = resp.UserId
  228. storage.set('user_name', resp.Username)
  229. storage.set('user_id', resp.UserId)
  230. state.permissions = {}
  231. if (resp.Permissions) {
  232. resp.Permissions.forEach(p => (state.permissions[p] = true))
  233. }
  234. state.projects = []
  235. if (resp.Projects) {
  236. if (resp.Projects[0] && resp.Projects[0].ProjId) {
  237. state.projectId = resp.Projects[0].ProjId
  238. state.secret = resp.Projects[0].Secret ? resp.Projects[0].Secret : ""
  239. }
  240. resp.Projects.forEach(proj =>
  241. state.projects.push({
  242. id: proj.ProjId,
  243. name: proj.ProjLocalName,
  244. pwd: proj.Secret ? proj.Secret : ""
  245. })
  246. )
  247. }
  248. } else {
  249. state.userInfo = null
  250. }
  251. resolve(resp)
  252. })
  253. })
  254. },
  255. setBreadcrumb: {
  256. root: true,
  257. handler({ state, commit }, val) {
  258. let label = val[0].label;
  259. if (label === "消息中心") {
  260. commit("setSidebarSelected", "message"); // 当进入消息中心页面的时候不选中导航栏
  261. }
  262. state.breadcrumb = []
  263. state.breadcrumb = val
  264. storage.set(KEY_PAGE_BRANDCRUMB, val)
  265. }
  266. }
  267. }
  268. }