surprise
2024-03-05 1ce1b525e7470ebaaeb0d5cd1e59bd905c1a7114
src/store/index.js
@@ -1,23 +1,247 @@
import Vue from 'vue'
import Vuex from 'vuex'
import layerTree from './modules/layerTree';
import mapStatus from './modules/mapStatus';
import mapTools from './modules/mapTools';
import user from './modules/user';
import createPersistedState from "vuex-persistedstate"  //持久化所有state
import Vue from 'vue';
import Vuex from 'vuex';
import { getToken, setToken, removeToken } from '@/utils/auth';
import { Loading, Message } from 'element-ui';
import { login, getPublicKey } from '@/api/api';
import variables from '@/assets/element-variables.scss';
var encrypt = new JSEncrypt();
Vue.use(Vuex);
Vue.use(Vuex)  // 安装插件
export default new Vuex.Store({
  state: {
    oldTree: null,
    catalogueName: '',
    cataNode: {},
    lang: 'zh',
    menuNode: {},
    verCateNode: {},
    verCateNodes: {},
    styleDirCateNodes: {},
    styleDepCateNodes: {},
    iframeMsg: '',
    token: getToken(),
    //请求计数
    apiCount: 0,
    //loading实例
    loadingInstance: null,
    key: null,
    //系统监控WebSocket
    ws: null,
    //权限合集
    permsEntity: [],
    currentPerms: '',
    //综合展示
    syntiesis: {},
    mapMenuBoolean: false,
    mapPopBoolean: false,
    mapPopBoxFlag: null,
    mapMenuBoxFlag: null,
    mapSpaceQueryLayer: null,
    mapMenuShpFile: null,
    propertiesFlag: null,
    propertiesName: null,
    propertiesInfo: null,
    pickUpPointInfo: null,
let store = new Vuex.Store({  // 实例化Vuex仓库
    modules: {
        layerTree,
        mapStatus,
        mapTools,
        user
    //主题切换
    theme: variables.theme,
    //登录用户名
    uname: null,
    unid: null,
    //项目管理
    projeOl: null,
    download: false,
    showAllLayers: true,
    primitLayer: null,
    loading: false,
    pipelineEntity: [],
    reporturl: null,
    layerMnage: false,
    themeflag: false,
    language: true,
    isNaviget: false,
    treeData: null,
    checkedKeys: [],
    queryInfo: [],
    Map3: [],
    histogramLayer: [],
    attachModel: false,
    attachinfo: null,
    catModel: false,
    catModelInfo: null,
    showPopBoxFlag: false,
    pickoption: null,
    previewLayer: null,
    histLenged: false,
    setAlphaDity: null,
    setAlphaList: [],
    isProjectLayer: [],
    pigCode: null,
    listenTime: null,
    //地表变形
    surfaceDeForm: {
      falg: false,
      gid: null,
      val: null
    },
    plugins: [createPersistedState({
        storage: window.sessionStorage   //存储到sessionStorage
    })]
})
    setChangeBaseMap:true,
    kgBuilderText:null,
    showEchartCount:false,
    lineRoam:false,
    setLoading:false,
    knowledgeFlag:false,
  },
  mutations: {
    UPDATE_LISTEN_TIME(state, msg) {
      state.listenTime = msg;
    },
    //获取权限合集
    getPermsEntity(state, msg) {
      state.permsEntity = msg;
    },
    currentPerms(state, msg) {
      state.currentPerms = msg;
    },
    // 获取完整面包屑路径
    changeCata(state, msg) {
      state.catalogueName = msg;
    },
    // 获取点击的目录点对象
    changeNode(state, msg) {
      state.cataNode = msg;
    },
    changeLang(state, msg) {
      state.lang = msg;
    },
    getIframe(state, msg) {
      state.iframeMsg = msg;
    },
    changeName(state, msg) {
      state.menuNode = msg;
      // console.log(msg);
    },
    verChangeNode(state, msg) {
      state.verCateNode = msg;
    },
    verChangeNodes(state, msg) {
      state.verCateNodes = msg;
    },
    //样式管理
    styleDepChangeNode(state, msg) {
      state.styleDepCateNodes = msg;
    },
    styleDirChangeNode(state, msg) {
      state.styleDirCateNodes = msg;
    },
    /* 打开Loading */
    START_LOADING(state, msg) {
      // state.loadingInstance = Loading.service({
      //   lock: true,
      //   text: msg ? msg : '加载中...',
      //   background: 'rgba(0, 0, 0, 0.7)',
      // });
    },
    /* 关闭loading */
export default store
    CLOSE_LOADING(state) {
      // state.loadingInstance.close();
    },
    /* 更新请求线程池 */
    UPDATE_API_COUNT(state, handle) {
      if (handle == 'add') {
        state.apiCount++;
        this.commit('START_LOADING');
      } else {
        state.apiCount--;
        if (state.apiCount <= 0) {
          this.commit('CLOSE_LOADING');
        }
      }
    },
    SET_UNAME(state, name) {
      state.uname = name;
    },
    SET_TOKEN(state, token) {
      state.token = token;
    },
    SET_KEY(state, key) {
      state.key = key;
    },
    CHANGE_SETTING: (state, { key, value }) => {
      // console.log(state, { key, value });
      if (state.hasOwnProperty(key)) {
        state[key] = value;
      }
    },
  },
  actions: {
    // 用户登录 login
    login({ commit, state }, userInfo) {
      return new Promise((resolve, reject) => {
        var data = {
          uid: encrypt.encrypt(userInfo.uid),
          pwd: encrypt.encrypt(userInfo.pwd),
        };
        login(data)
          .then((response) => {
            const data = response;
            if (data.code !== 200) {
              resolve(data);
              return
              // return Message({
              //   message: data.msg,
              //   type: 'error',
              //   duration: 5 * 1000,
              // });
            }
            commit('SET_UNAME', data.result.uname);
            commit('SET_TOKEN', data.result.token);
            setToken(data.result.token);
            resolve(data);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    setCookies(res) {
      var value = localStorage.getItem('LFToken');
      if (value != null) {
        this.rmCookies();
      }
      var timeData = moment(res.result.expire).format('YYYY-MM-DD HH:mm:ss');
      var token = res.result;
      var LfPrems = {
        token: token,
        time: timeData,
      };
      LfPrems = JSON.stringify(LfPrems);
      localStorage.setItem('LFToken', LfPrems);
    },
    rmCookies() {
      localStorage.removeItem('LFToken');
    },
    getpublickey({ commit, state }, userInfo) {
      return new Promise((resolve, reject) => {
        getPublicKey(userInfo)
          .then((response) => {
            const data = response;
            commit('SET_KEY', data.result);
            encrypt.setPublicKey(data.result); // 设置公钥
            resolve();
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    //主题切换
    changeSetting({ commit }, data) {
      commit('CHANGE_SETTING', data);
    },
  },
  modules: {},
});