Explorar el Código

feat:公司筛选

snow hace 2 años
padre
commit
7d289224b1

+ 8 - 0
src/App.vue

@@ -19,6 +19,7 @@ export default {
       await this.testing();
     } else {
       await this.getMenu();
+      await this.getCompany();
     }
   },
   methods: {
@@ -32,6 +33,12 @@ export default {
         }
       });
     },
+    async getCompany(){
+      const result =  await this.$store.dispatch("user/getCompanyList");
+      if(result === "noToken"){
+        await this.logout();
+      }
+    },
     async setcode(code) {
       let model = { code: code };
       this.$store
@@ -39,6 +46,7 @@ export default {
         .then(async (res) => {
           if (res === "success") {
             await this.getMenu();
+            await this.getCompany();
           } else {
             await this.logout();
           }

+ 9 - 0
src/apis/user/index.js

@@ -48,3 +48,12 @@ export function roleProcessInfo(data) {
     data,
   });
 }
+
+//获取用户的企业列表
+export function requsetCompanyList(data){
+  return http({
+    url: `${urlConfig.baseURL}admin/businesslist`,
+    method: "post",
+    data,
+  });
+}

+ 8 - 1
src/layout/components/Navbar.vue

@@ -6,6 +6,10 @@
     <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
 
     <div class="right-menu">
+        <div class="right-menu-item">
+          <comapny-select />
+        </div>
+
       <template v-if="device !== 'mobile'">
         <i v-if="isShow" class="el-icon-message-solid right-menu-item hover-effect shake" @click="openNotice()"
           style="height: 50px; width: 40px; line-height: 52px; font-size: 22px" />
@@ -94,6 +98,7 @@ import { mapGetters } from "vuex";
 import asyncRequest from "@/apis/service/system/updates";
 import resToken from "@/mixins/resToken";
 import { getNotice, setNotice } from "@/utils/auth";
+import ComapnySelect from "./company-select";
 
 export default {
   computed: {
@@ -117,6 +122,9 @@ export default {
       activeMsg: null, //消息展示对象
     };
   },
+  components:{
+    ComapnySelect
+  },
   mounted() {
     this.openNotice(true);
   },
@@ -309,7 +317,6 @@ export default {
 
   .right-menu {
     float: right;
-
     height: 100%;
     line-height: 50px;
 

+ 24 - 0
src/layout/components/company-select/index.vue

@@ -0,0 +1,24 @@
+<template>
+  <el-select style="width:380px" size="small" placeholder="请选择公司" :value="currentCompany" @change="setCurrentCompany">
+    <el-option v-for="(company,index) in companyList" :key="index" :label="company.companyNo + '/' + company.company" :value="company.companyNo" />
+  </el-select>
+</template>
+
+
+<script>
+import { mapState } from "vuex";
+
+export default {
+  computed:{
+    ...mapState({
+      companyList:(state) => state.user.companyList,
+      currentCompany:(state) => state.user.currentCompany
+    })
+  },
+  methods:{
+    setCurrentCompany(currentCompany){
+      this.$store.commit("user/setCurrentCompany",currentCompany)
+    }
+  }
+}
+</script>

+ 32 - 2
src/store/modules/user.js

@@ -6,6 +6,7 @@ import {
   dingdingdetail,
   usergetinfo,
   roleProcessInfo,
+  requsetCompanyList
 } from "@/apis/user";
 import {
   getToken,
@@ -43,6 +44,8 @@ const state = {
   business_companyNo: get_business_companyNo() || "",
   private_field: get_private_field() || [],
   roleProcess: get_action_data() || [],
+  currentCompany: null,
+  companyList: []
 };
 const mutations = {
   SET_TOKEN: (state, token) => {
@@ -66,6 +69,11 @@ const mutations = {
   SET_ROLES: (state, roles) => {
     state.roles = roles;
   },
+  SET_COMPANY_LIST: (state, companyList) => {
+    state.companyList = companyList;
+    //设置当前公司
+    state.currentCompany = companyList[0].companyNo;
+  },
   // mainListFn(state, val) {
   //   if (!val) {
   //     val = [];
@@ -73,6 +81,9 @@ const mutations = {
   //   state.mainList = val;
   //   setMainList(val)
   // },
+  setCurrentCompany(state, currentCompany) {
+    state.currentCompany = currentCompany;
+  },
   navListFn(state, val) {
     if (!val) {
       val = [];
@@ -144,6 +155,25 @@ const actions = {
         });
     });
   },
+
+  //保存用户的业务公司列表
+  // isSuperUser 是否超管用户
+  async getCompanyList({ commit }, isSuperUser) {
+    const result = await requsetCompanyList({});
+
+    const { code, data } = result;
+
+    if (code === 0) {
+      commit("SET_COMPANY_LIST", data.list);
+    }
+
+    if (code >= 100 && code <= 104) {
+      return "noToken"
+    }
+
+    return result;
+  },
+
   async getMenuList({ commit, that }) {
     return new Promise(async (resolve, reject) => {
       if (!getToken()) {
@@ -250,10 +280,10 @@ async function getUserInfo() {
   };
 }
 
-async function initalUserInfo(){
+async function initalUserInfo() {
   const { data } = await usergetinfo({});
   console.log(data.nickname)
-  store.commit('user/SET_NAME',data.nickname);
+  store.commit('user/SET_NAME', data.nickname);
 }
 
 async function getRoleProcess(roleid) {

+ 7 - 0
src/views/login/index.vue

@@ -233,6 +233,7 @@ export default {
                 //   query: this.otherQuery,
                 // });
                 this.getMenu();
+                this.getCompany();
               } else {
                 this.$message.warning(res.message);
                 this.loading = false;
@@ -248,6 +249,12 @@ export default {
         }
       });
     },
+    async getCompany(){
+      const result =  await this.$store.dispatch("user/getCompanyList");
+      if(result === "noToken"){
+        await this.logout();
+      }
+    },
     getMenu() {
       this.$store
         .dispatch("user/getMenuList", this)