snow 2 tahun lalu
induk
melakukan
8a73997a24

+ 25 - 15
src/layout/components/company-select/index.vue

@@ -32,40 +32,33 @@
 import { mapState } from "vuex";
 
 import { requsetSupertubeCompany, requsetBindCompany } from "@/apis/user";
+import { setUserCompany } from "@/utils/auth";
 
 export default {
+  /**
+   * @param selectAll 超管账号是否可以选择所有公司
+   * @param size 选择器尺寸
+   * @param placeholder
+   * @param disabled 是否禁用
+   * @param global 是否设置全局选中公司(全局使用/组件独立使用)
+   */
   props: {
-    /**
-     *@description 超管账号是否可以选择所有公司
-     */
     selectAll: {
       type: Boolean,
       default: false
     },
-    /**
-     * @description 选择器尺寸
-     */
     size: {
       type: String,
       default: "small"
     },
-    /**
-     * @description 选择器placeholder
-     */
     placeholder: {
       type: String,
       default: ""
     },
-    /**
-     * @description 是否禁用选择器
-     */
     disabled: {
       type: Boolean,
       default: false
     },
-    /***
-     * @description 是否设置全局选中公司
-     */
     global: {
       type: Boolean,
       default: false
@@ -84,6 +77,7 @@ export default {
     return {
       companylist: [],
       ScrollWrapper: null,
+      inital:true,
       state: {
         loading: false,
         noMore: false
@@ -122,6 +116,22 @@ export default {
       //作为通用组件使用不设置全局选中公司
       if (!this.global) return null;
       this.$store.commit("user/setCurrentCompany", currentCompany);
+      setUserCompany(currentCompany);
+      
+      //非超管用户刷新路由
+      if(this.inital) return this.inital = false;
+      this.changeRouterWithCompany();
+    },
+    changeRouterWithCompany() {
+      const { path, query: sourceQuery } = this.$route;
+      const isDetail = path.indexOf("Detail") >= 0;
+
+      // const query = {
+      //   ...sourceQuery,
+      //   reload: this.currentCompany
+      // };
+
+      this.$router.replace(path + "?company=" + this.currentCompany);
     },
 
     getScrollWrapper() {

+ 1 - 1
src/mixins/reloadData.js

@@ -24,7 +24,7 @@ const reloadData = {
         //超管角色刷新列表 todo:区分是否超管 非超管不执行
         const isSupertube = true;
         if(!isSupertube) return null;
-        onCompanyChange ? onCompanyChange() : onCompanyChangeInner();
+        // onCompanyChange ? onCompanyChange() : onCompanyChangeInner();
       },
       //
       deep: true

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

@@ -33,6 +33,7 @@ import {
   get_role_level,
   set_role_level,
   remove_role_level,
+  getUserCompany,
 } from "@/utils/auth";
 import store from "..";
 const state = {
@@ -48,8 +49,7 @@ const state = {
   business_companyNo: get_business_companyNo() || "",
   private_field: get_private_field() || [],
   roleProcess: get_action_data() || [],
-  currentCompany: "",
-  companyList: []
+  currentCompany: getUserCompany()
 };
 const mutations = {
   SET_TOKEN: (state, token) => {
@@ -149,20 +149,6 @@ 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()) {

+ 14 - 0
src/utils/auth.js

@@ -10,6 +10,20 @@ const businessCompanyNoKey = "Purchase-Console-businessCompanyNo";
 const privateFieldKey = "Purchase-Console-privateField";
 const actionDataKey = "Purchase-Console-actionData";
 const roleLevelKey="Purchase-Console-roleLevel";
+const companyKey = "Purchase-Console-company";
+
+export function setUserCompany(company){
+  return sessionStorage.setItem(companyKey,company);
+}
+
+export function removeUserCompany(){
+  return sessionStorage.removeItem(companyKey)
+}
+
+export function getUserCompany(){
+  return sessionStorage.getItem(companyKey) || ""
+}
+
 export function getToken() {
   return Cookies.get(TokenKey);
 }

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

@@ -235,7 +235,6 @@ export default {
               console.log(res);
               if (res.code === 0) {
                 this.getMenu();
-                this.getCompany();
               } else {
                 this.$message.warning(res.message);
                 this.loading = false;
@@ -251,12 +250,6 @@ 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)

+ 10 - 0
src/views/reload/index.vue

@@ -0,0 +1,10 @@
+<script>
+export default {
+  created() {
+    console.log(11);
+  },
+  render: function(h) {
+    return "reload"
+  }
+}
+</script>