import frameworkApi from '@/api/framework' import storage from '@/framework/utils/storage' import lStorage from '@/utils/localStorage' const KEY_MENU_SELECTED = 'menu_selected' const KEY_PROJECT_SELECTED = 'global_project_selected' const KEY_PAGE_BRANDCRUMB = 'page_brandcrumb' export default { namespaced: true, state: { sidebarClosed: false, sidebarSelected: '', // sidebar选中的选项 // userInfo: null, //{ username: 'admin' }, userInfo: { username: 'yanruolan', userId: '06328a53c69a41bb8f5bb1a552c6e8d6' }, permissions: { "system:role:delete": true, "system:role:create": true, "system:role:query": true, "system:role:setOpts": true }, projectId: 'Pj1101051029', projects: [{ id: "Pj1101051029", name: "北京万达广场", pwd: "saga123456" }, { id: "Pj4403070003", name: "深圳龙岗万达广场", pwd: "saga123456" }, { id: "Pj4403050019", name: "招商深圳太子广场汇港二期", pwd: "saga123456" }, { id: "Pj5001120003", name: "香港置地约克北郡", pwd: "saga123456" }, { id: "Pj3201110003", name: "弘阳集团弘云智慧管理平台", pwd: "saga123456" }, { id: "Pj3702020002", name: "青岛海天中心", pwd: "saga123456" }, { id: "Pj1101010006", name: "亚投行", pwd: "saga123456" }, { id: "Pj1101050013", name: "BIM测试项目_亚投行", pwd: "saga123456" }, { id: "Pj1101080259", name: "博锐尚格北京总部办公楼", pwd: "saga123456" },{ id: "Pj1101150002", name: "华润生命科学园", pwd: "saga123456" },{ id: "Pj3101150007", name: "招商上海森兰花园城", pwd: "saga123456" },{ id: "Pj5101080004", name: "成都招商花园城", pwd: "saga123456" },{ id: "Pj3201130004", name: "招商南京燕子矶花园城", pwd: "saga123456" }], breadcrumb: [], uploaderList: [], //当前上传文件列表 secret: "saga123456", //项目密码 userId: "06328a53c69a41bb8f5bb1a552c6e8d6", //用户id rowEdit: false,//表格数据变化 errorReport: [],//扫楼错误报告 }, getters: { sidebarClosed: state => state.sidebarClosed, secret: state => state.secret, userId: state => state.userId, sidebarSelected: state => { // if (!state.pageSidebarSelected) { // let menu = storage.get(KEY_MENU_SELECTED) // if (menu) { // state.pageSidebarSelected = menu // } // } // return state.pageSidebarSelected return state.sidebarSelected }, userInfo: state => state.userInfo, permissions: state => state.permissions, projects: state => state.projects, uploaderList: state => state.uploaderList, projectId: state => { if (!state.projectId) { let pid = storage.get(KEY_PROJECT_SELECTED) if (pid) { state.projectId = pid } } return state.projectId }, breadcrumb: state => { if (!state.breadcrumb) { let arr = storage.get(KEY_PAGE_BRANDCRUMB) if (arr) { state.breadcrumb = arr } } return state.breadcrumb } }, mutations: { setRowEdit: (state, val) => (state.rowEdit = val), setErrorReport: (state, val) => (state.errorReport = val), setSidebarClosed: (state, val) => (state.sidebarClosed = val), setSidebarSelected: (state, val) => { state.sidebarSelected = val storage.set(KEY_MENU_SELECTED, val) lStorage.set('screen_data', { path: val, data: {} }) }, setprojectId: (state, val) => { lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存) let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {} state.projectId = val localStorage.setItem('projectId', val) if (cacheInfo[state.userInfo.userName]) { // cacheInfo[state.userInfo.userName].projectId = val cacheInfo[state.userInfo.userName] = [...new Set([val, ...cacheInfo[state.userInfo.userName]])].slice(0, 3) lStorage.set('historyInfo', cacheInfo) } else { cacheInfo[state.userInfo.userName] = [val] lStorage.set('historyInfo', cacheInfo) } storage.set(KEY_PROJECT_SELECTED, val) state.projects.map((item) => { if (item.id == val) { state.secret = item.pwd localStorage.setItem('secret', item.pwd) } }) }, setUploaderList: (state, val) => { state.uploaderList = val ? val : [] }, }, actions: { setRowEdit(contentx, value) { contentx.commit('setRowEdit', value) }, setErrorReport(contentx, value) { contentx.commit('setErrorReport', value) }, loadUserInfo({ state }) { console.log(state) // 获取 userInfo 信息 return new Promise((resolve, reject) => { frameworkApi.loadUserInfo().then(resp => { console.log(resp) if (resp.Result == 'success' && resp.UserId) { state.userInfo = { userName: resp.Username, userId: resp.UserId } state.userId = resp.UserId storage.set('user_name', resp.Username) storage.set('user_id', resp.UserId) state.permissions = {} if (resp.Permissions) { resp.Permissions.forEach(p => (state.permissions[p] = true)) } state.projects = [] if (resp.Projects) { if (resp.Projects[0] && resp.Projects[0].ProjId) { state.projectId = resp.Projects[0].ProjId state.secret = resp.Projects[0].Secret ? resp.Projects[0].Secret : "" } resp.Projects.forEach(proj => state.projects.push({ id: proj.ProjId, name: proj.ProjLocalName, pwd: proj.Secret ? proj.Secret : "" }) ) } } else { state.userInfo = null } resolve(resp) }) }) }, setBreadcrumb: { root: true, handler({ state, commit }, val) { let label = val[0].label; if (label === "消息中心") { commit("setSidebarSelected", "message"); // 当进入消息中心页面的时候不选中导航栏 } state.breadcrumb = [] state.breadcrumb = val storage.set(KEY_PAGE_BRANDCRUMB, val) } } } }