研发图纸文件管理系统-前端项目
longyvfengyun
2022-08-10 1b9835e104c966f115804266b9f6296c99cdf22b
内容修改
3个文件已修改
64 ■■■■■ 已修改文件
.env 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/login/Login.vue 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/modules/account.js 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.env
@@ -11,3 +11,5 @@
VUE_APP_ROLE_LIST=admin.roleList
VUE_APP_DEPARTMENT_LIST=admin.departmentList
VUE_APP_DOWNLOAD_FLAG=admin.downloadFlag
VUE_APP_PROJECT_MANAGER_LIST= admin.projectManagerList
VUE_APP_GENERAL_MANAGER_LIST = admin.generalManagerList
src/pages/login/Login.vue
@@ -87,7 +87,7 @@
import {mapMutations} from 'vuex'
import { userLogin } from './apis'
import { values } from 'lodash';
import {getAllRole} from "@/pages/user/apis";
import {getAllRole, getUserByRoleId} from "@/pages/user/apis";
import { hasAnyRole } from '@/utils/authority-utils';
export default {
  name: 'Login',
@@ -107,7 +107,8 @@
    }
  },
  methods: {
    ...mapMutations('account', ['setUser', 'setPermissions', 'setRoles', 'setRoleList', 'setDepartmentList', 'setDownloadFlag']),
    ...mapMutations('account', ['setUser', 'setPermissions', 'setRoles', 'setRoleList',
      'setDepartmentList', 'setDownloadFlag', 'setProjectManagerList', 'setGeneralManagerList']),
    onSubmit (e) {
      let vm = this;
      e.preventDefault()
@@ -143,6 +144,8 @@
        this.setRoleList(roleList);
        this.setDepartmentList(departmentList);
        this.setDownloadFlag(downloadFlag);
        this.getUserByRoleId(1002);
        this.getUserByRoleId(1003);
        setAuthorization({token: loginRes.data.token, expireAt: new Date(loginRes.data.expireAt)})
        // 获取路由配置
@@ -221,6 +224,27 @@
      }).catch(error=>{
        console.log(error);
      });
    },
    getUserByRoleId(id) {
      getUserByRoleId(id).then(res=>{
        let rs = res.data;
        let data = [];
        if(rs.code == 1 && rs.data) {
          data = rs.data2.map(item=>{
            item.key = item.name;
            return item;
          });
        }
        console.log(data);
        // 根据id设置列表
        if(id==1002) {
          this.setProjectManagerList(data);
        }else {
          this.setGeneralManagerList(data);
        }
      }).catch(error => {
        console.log(error);
      });
    }
  },
  mounted() {
src/store/modules/account.js
@@ -8,6 +8,8 @@
    roleList: null,
    departmentList: null,
    downloadFlag: null,
    projectManagerList: null,   // 项目经理列表
    generalManagerList: null,   // 总经理列表
  },
  getters: {
    user: state => {
@@ -85,6 +87,30 @@
      const downloadFlag = localStorage.getItem(process.env.VUE_APP_DOWNLOAD_FLAG);
      state.downloadFlag = downloadFlag;
      return state.downloadFlag == 1?true:false;
    },
    projectManagerList: state=>{
      if(!state.projectManagerList) {
        try {
          const projectManagerList = localStorage.getItem(process.env.VUE_APP_PROJECT_MANAGER_LIST);
          state.projectManagerList = JSON.parse(projectManagerList);
          state.projectManagerList = state.projectManagerList?state.projectManagerList:[];
        }catch (e){
          console.error(e.message);
        }
      }
      return state.projectManagerList;
    },
    generalManagerList: state=>{
      if(!state.generalManagerList) {
        try {
          const generalManagerList = localStorage.getItem(process.env.VUE_APP_GENERAL_MANAGER_LIST);
          state.generalManagerList = JSON.parse(generalManagerList);
          state.generalManagerList = state.generalManagerList?state.generalManagerList:[];
        }catch (e){
          console.error(e.message);
        }
      }
      return state.generalManagerList;
    }
  },
  mutations: {
@@ -115,6 +141,14 @@
    setDownloadFlag(state, downloadFlag) {
      state.downloadFlag = downloadFlag;
      localStorage.setItem(process.env.VUE_APP_DOWNLOAD_FLAG, downloadFlag);
    },
    setProjectManagerList(state, projectManagerList) {
      state.projectManagerList = projectManagerList;
      localStorage.setItem(process.env.VUE_APP_PROJECT_MANAGER_LIST, JSON.stringify(projectManagerList));
    },
    setGeneralManagerList(state, generalManagerList) {
      state.generalManagerList = generalManagerList;
      localStorage.setItem(process.env.VUE_APP_GENERAL_MANAGER_LIST, JSON.stringify(generalManagerList));
    }
  }
}