lxl
2022-10-26 e3196bc81327e82748c7683c5cad9849b4b228b6
src/store/index.js
@@ -1,8 +1,8 @@
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 { getToken, setToken, removeToken } from '@/utils/auth';
import { Loading, Message } from 'element-ui';
import { login, getPublicKey } from '@/api/api';
var encrypt = new JSEncrypt();
Vue.use(Vuex);
@@ -23,9 +23,21 @@
    apiCount: 0,
    //loading实例
    loadingInstance: null,
    key: null
    key: null,
    //系统监控WebSocket
    ws: null,
    //权限合集
    permsEntity: [],
    currentPerms: "",
  },
  mutations: {
    //获取权限合集
    getPermsEntity(state, msg) {
      state.permsEntity = msg
    },
    currentPerms(state, msg) {
      state.currentPerms = msg
    },
    // 获取完整面包屑路径
    changeCata(state, msg) {
      state.catalogueName = msg;
@@ -43,7 +55,6 @@
    changeName(state, msg) {
      state.menuNode = msg;
      // console.log(msg);
    },
    verChangeNode(state, msg) {
      state.verCateNode = msg;
@@ -62,8 +73,8 @@
    START_LOADING(state, msg) {
      state.loadingInstance = Loading.service({
        lock: true,
        text: msg ? msg : "加载中...",
        background: "rgba(0, 0, 0, 0.7)",
        text: msg ? msg : '加载中...',
        background: 'rgba(0, 0, 0, 0.7)',
      });
    },
    /* 关闭loading */
@@ -73,13 +84,13 @@
    },
    /* 更新请求线程池 */
    UPDATE_API_COUNT(state, handle) {
      if (handle == "add") {
      if (handle == 'add') {
        state.apiCount++;
        this.commit("START_LOADING");
        this.commit('START_LOADING');
      } else {
        state.apiCount--;
        if (state.apiCount <= 0) {
          this.commit("CLOSE_LOADING");
          this.commit('CLOSE_LOADING');
        }
      }
    },
@@ -97,7 +108,7 @@
      return new Promise((resolve, reject) => {
        var data = {
          uid: encrypt.encrypt(userInfo.uid),
          pwd: encrypt.encrypt(userInfo.pwd)
          pwd: encrypt.encrypt(userInfo.pwd),
        };
        login(data)
          .then((response) => {
@@ -105,11 +116,11 @@
            if (data.code !== 200) {
              return Message({
                message: data.msg,
                type: "error",
                type: 'error',
                duration: 5 * 1000,
              });
            }
            commit("SET_TOKEN", data.result.token);
            commit('SET_TOKEN', data.result.token);
            setToken(data.result.token);
            resolve(data);
          })
@@ -119,12 +130,11 @@
      });
    },
    getpublickey({ commit, state }, userInfo) {
      return new Promise((resolve, reject) => {
        getPublicKey(userInfo)
          .then((response) => {
            const data = response;
            commit("SET_KEY", data.result);
            commit('SET_KEY', data.result);
            encrypt.setPublicKey(data.result); // 设置公钥
            resolve();
@@ -133,7 +143,7 @@
            reject(error);
          });
      });
    }
    },
  },
  modules: {},
});