| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- import {
- getAllProject
- } from "@/api/scan/request";
- import {
- getUserInfo,getUserInfoByUserId
- } from "@/api/system/persagy-sso-server";
- import tools from "@/utils/scan/tools"
- import storage from '@/framework/utils/storage'
- import lStorage from '@/utils/localStorage'
- import store from '@/store'
- import project from "./project";
- 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
- },
- menus: [], //系统菜单列表
- projectId: '',
- projectName: '',
- group_code: '',
- // projects: project["14"],
- projects: [],
- breadcrumb: [],
- uploaderList: [], //当前上传文件列表
- secret: "", //项目密码
- userId: "", //用户id
- // 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,
- menus: state => state.menus,
- 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
- } else if (state.projects && state.projects.length) {
- state.projectId = state.projects[0].id
- }
- }
- return state.projectId
- },
- projectName: state => state.projectName,
- group_code: state => state.group_code,
- 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),
- setUserInfo: (state, val) => (state.userInfo = val),
- setGroupCode: (state, val) => (state.group_code = val),
- setUserId: (state, val) => (state.userId = val),
- setSidebarSelected: (state, val) => {
- state.sidebarSelected = val
- storage.set(KEY_MENU_SELECTED, val)
- lStorage.set('screen_data', {
- path: val,
- data: {}
- })
- },
- setProjects: (state, val) => (state.projects = val),
- setprojectId: (state, val) => {
- lStorage.remove('cacheInfo') //待删除(删除用户浏览器无用缓存)
- let cacheInfo = lStorage.get('historyInfo') ? lStorage.get('historyInfo') : {}
- state.projectId = val
- lStorage.set('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
- state.projectName = item.name
- state.group_code = item.group_code
- lStorage.set('group_code', item.group_code)
- lStorage.set('secret', item.pwd)
- }
- })
- },
- setMenus: (state, val) => (state.menus = val),
- setUploaderList: (state, val) => {
- state.uploaderList = val ? val : []
- },
- },
- actions: {
- setRowEdit(contentx, value) {
- contentx.commit('setRowEdit', value)
- },
- setErrorReport(contentx, value) {
- contentx.commit('setErrorReport', value)
- },
- /**
- * @info 获取全部项目
- */
- getAllProject({
- state
- }) {
- return new Promise((resolve, reject) => {
- getAllProject({
- pageNumber: 1,
- pageSize: 1000
- }, res => {
- if (res.result === "success" && res.content && res.content.length) {
- state.projects = []
- // if (res.content[0] && res.content[0].id) {
- // state.projectId = res.content[0].id
- // state.projectName = res.content[0].localName || res.content[0].name || ""
- // state.secret = res.content[0].secret || ""
- // }
- res.content.forEach(proj =>
- state.projects.push({
- id: proj.id,
- name: proj.localName || proj.name || "",
- pwd: proj.secret || "",
- group_code: proj.groupCode || ""
- })
- )
- resolve(res)
- } else {
- reject()
- }
- })
- })
- },
- /**
- * 根据登录返回code获取用户信息和项目信息
- */
- loadUserInfo({
- state
- }) {
- return new Promise(async (resolve, reject) => {
- /**
- * 改为调用运维平台的根据用户ID获取用户信息的接口
- * nh 2021.10.25
- */
- let userId = store.state.ssoToken ?
- store.state.ssoToken :
- lStorage.get("ssoToken");
- let pd = lStorage.get("ssoPd");
- var infoData = await getUserInfoByUserId({ userId: userId, pd: pd });
- if (infoData.result === 'success') {
- const data = (infoData.content || [])[0] || {};
- state.userInfo = {
- userName: data.userName,
- userId: data.userId
- };
- state.userId = data.userId;
- state.projects = []; //初始化项目列表
- storage.set('user_name', data.userName);
- storage.set('user_id', data.userId);
- // 获取系统菜单成功
- if (data.authorizations && data.authorizations.length) {
- var menuArr=tools.formatMenu(data.authorizations);
- state.menus = menuArr;
- } else {
- state.menus = [];
- }
- // 获取项目信息成功
- if (data.projects && data.projects.length) {
- // 设置项目列表
- data.projects.forEach(proj =>
- state.projects.push({
- id: proj.projectId,
- name: proj.projectLocalName,
- pwd: proj.secret ? proj.secret : "",
- group_code: proj.groupCode
- })
- )
- }
- resolve(infoData);
- } else {
- state.userInfo = {
- userName: 'yanruolan',
- userId: '06328a53c69a41bb8f5bb1a552c6e8d6'
- };
- resolve(infoData);
- }
- return;
- var infoData = await getUserInfo({});
- if (infoData.code === 'Success') {
- const data = infoData.data;
- state.userInfo = {
- userName: data.name,
- userId: data.id
- };
- state.userId = data.id;
- state.projects = []; //初始化项目列表
- storage.set('user_name', data.username);
- storage.set('user_id', data.id);
- // 获取系统菜单成功
- if (data.menuList && data.menuList.length) {
- state.menus = tools.formatMenu(data.menuList);
- } else {
- state.menus = [];
- }
- // 获取项目信息成功
- if (data.projectList && data.projectList.length) {
- // 设置项目列表
- data.projectList.forEach(proj =>
- state.projects.push({
- id: proj.id,
- name: proj.localName,
- pwd: proj.secret ? proj.secret : "",
- group_code: proj.groupCode
- })
- )
- }
- resolve(infoData);
- } else {
- state.userInfo = {
- userName: 'yanruolan',
- userId: '06328a53c69a41bb8f5bb1a552c6e8d6'
- };
- resolve(infoData);
- }
- })
- },
- 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)
- }
- }
- }
- }
|