Explorar o código

动态获取企业ID+标题

Tang %!s(int64=2) %!d(string=hai) anos
pai
achega
f006cffeed

+ 2 - 2
src/App.vue

@@ -14,8 +14,8 @@ export default {
         this.$store.state.settings.title,
       titleTemplate: (title) => {
         return title
-          ? `${title} - ${process.env.VUE_APP_TITLE}`
-          : process.env.VUE_APP_TITLE;
+          ? `${title} - ${this.$store.state.user.companyName}`
+          : this.$store.state.user.companyName;
       },
     };
   },

BIN=BIN
src/assets/images/left@2x.png


BIN=BIN
src/assets/images/left_slices/left@2x.png


+ 6 - 2
src/layout/components/Navbar.vue

@@ -373,7 +373,11 @@ export default {
       })
         .then(() => {
           this.$store.dispatch("LogOut").then(() => {
-            location.href = "/index";
+            if (this.$route.query.TenantId) {
+              location.href = "/index?TenantId=" + this.$route.query.TenantId;
+            } else {
+              location.href = "/index";
+            }
           });
         })
         .catch(() => {
@@ -678,7 +682,7 @@ export default {
   width: 400px !important;
   padding: 0px !important;
   & > .el-notification__group {
-  width: 100%;
+    width: 100%;
     margin: 0px;
     & > .el-notification__title {
       text-align: center;

+ 3 - 3
src/layout/components/Sidebar/Logo.vue

@@ -3,11 +3,11 @@
     <transition name="sidebarLogoFade">
       <router-link v-if="collapse" key="collapse" class="sidebar-logo-link" to="/">
         <img v-if="logo" :src="sideTheme === 'theme-dark'? logo : logoYT" class="sidebar-logo" />
-        <h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
+        <h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ $store.state.user.companyName }} </h1>
       </router-link>
       <router-link v-else key="expand" class="sidebar-logo-link" to="/">
         <img v-if="logo" :src="sideTheme === 'theme-dark'? logo : logoYT" class="sidebar-logo" />
-        <h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
+        <h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ $store.state.user.companyName }} </h1>
       </router-link>
     </transition>
   </div>
@@ -36,7 +36,7 @@ export default {
   },
   data() {
     return {
-      title: '中正云教育',
+      title: '',
       logo: logoImg,
       logoYT:logoYTImg,
     }

+ 12 - 0
src/newApi/userInformationManagement.js

@@ -42,4 +42,16 @@ export default {
               },
         })
     },
+    //获取系统配置
+    commonfreeconfig(data) {
+        return request({
+            url: '/common/free/config',
+            method: 'get',
+            params: data,
+            headers: {
+                isToken: false
+              },
+        })
+    },
+
 }

+ 21 - 7
src/permission.js

@@ -11,16 +11,21 @@ NProgress.configure({ showSpinner: false })
 
 const whiteList = ['/login', '/auth-redirect', '/bind', '/register']
 
-router.beforeEach(async(to, from, next) => {
+router.beforeEach(async (to, from, next) => {
   if (to.path !== from.path) {
     NProgress.start();
   }
-  
-  if (!store.state.TENANT_NANE) {
+  if (store.state.user.TENANT_NANE === null) {
     await store.dispatch('findTenantId')
   }
-  // TENANT_NANE
-  // TenantId
+  if (store.state.user.TENANT_NANE === '' && methods.getQueryVariable('TenantId')) {
+    sessionStorage.TenantId = methods.getQueryVariable('TenantId')
+  }
+  if (store.state.user.TENANT_NANE || sessionStorage.TenantId) {
+    if (!store.state.user.companyName) {
+      store.dispatch('footerData')
+    }
+  }
   if (getToken()) {
     to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
     /* has token*/
@@ -43,11 +48,16 @@ router.beforeEach(async(to, from, next) => {
           })
         })
       } else {
+        if (!store.state.user.TENANT_NANE && !to.query.TenantId) {
+          to.query.TenantId = sessionStorage.TenantId
+          next(to)
+        } else {
           if (!to.path.includes('/user/profile')) {
             checkFunc()
           }
-          console.log("to:",to)
+          console.log("to:", to)
           next()
+        }
       }
     }
   } else {
@@ -56,7 +66,11 @@ router.beforeEach(async(to, from, next) => {
       // 在免登录白名单,直接进入
       next()
     } else {
-      next(`/login`)
+      if (store.state.user.TENANT_NANE || sessionStorage.TenantId == undefined) {
+        next(`/login`) // 否则全部重定向到登录页
+      } else {
+        next(`/login?redirect=${to.fullPath}&TenantId=${sessionStorage.TenantId}`) // 否则全部重定向到登录页
+      }
       NProgress.done()
     }
   }

+ 36 - 5
src/store/modules/user.js

@@ -12,7 +12,8 @@ const user = {
     roles: [],
     permissions: [],
     userId: '',
-    TENANT_NANE:''
+    TENANT_NANE: null,
+    companyName: ''
   },
 
   mutations: {
@@ -36,8 +37,16 @@ const user = {
     },
     setTENANT_NANE(state, id) {
       state.TENANT_NANE = id
-      console.log(state.TENANT_NANE)
     },
+    outLogin(state) {
+      if (state.TENANT_NANE) {
+        sessionStorage.removeItem('TenantId')
+      }
+    },
+    set_companyName(state, data) {
+      state.companyName = data || ''
+      document.title = data || ''
+    }
   },
 
   actions: {
@@ -50,16 +59,37 @@ const user = {
         if (location.origin.includes("192.168.1") || location.origin.includes("localhost") || location.origin.includes("120.79.166.78")) {
           urls = "120.79.166.78:19012"
         }
-        api.commonfreefindTenantId({hostAdmin:urls})
-          .then(function (response) {
-            commit('setTENANT_NANE', response.data)
+        api.commonfreefindTenantId({ hostAdmin: urls })
+          .then(function (res) {
+            if (res.code === 200) {
+              commit('setTENANT_NANE', res.data)
+            } else {
+              commit('setTENANT_NANE', '')
+              sessionStorage.removeItem('TenantId')
+            }
             resolve()
           })
           .catch(function (error) {
+            resolve()
             console.log("TenantIDerror:", error);
           });
       })
     },
+    footerData({
+      commit
+    }) {
+      return new Promise(resolve => {
+        api.commonfreeconfig()
+          .then(function (response) {
+            commit('set_companyName', response.data.companyName)
+            resolve()
+          })
+          .catch(function (error) {
+            commit('set_companyName', '')
+            resolve()
+          });
+      })
+    },
     // 登录
     Login({ commit }, userInfo) {
       const username = userInfo.username.trim()
@@ -110,6 +140,7 @@ const user = {
           commit('SET_TOKEN', '')
           commit('SET_ROLES', [])
           commit('SET_PERMISSIONS', [])
+          commit('outLogin')
           removeToken()
           resolve()
         }).catch(error => {

+ 1 - 1
src/utils/request.js

@@ -23,7 +23,7 @@ service.interceptors.request.use(config => {
   if (getToken() && !isToken) {
     config.headers['AuthorizationToken'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
   }
-  config.headers.TenantId = store.state.user.TENANT_NANE
+  config.headers.TenantId = store.state.user.TENANT_NANE || sessionStorage.TenantId || methods.getQueryVariable('TenantId')
   // get请求映射params参数
   if (config.method === 'get' && config.params) {
     let url = config.url + '?';

+ 19 - 0
src/views/login.vue

@@ -1,6 +1,10 @@
 <template>
   <div class="login">
     <div class="login_Left">
+      <h2 class="topName">
+        <img src="@/assets/images/logo@2xSYT.png" alt="" />
+        {{ $store.state.user.companyName }}
+      </h2>
       <div class="anima1"></div>
       <div class="anima2"></div>
       <div class="anima3"></div>
@@ -275,6 +279,21 @@ export default {
     background: url("../assets/images/left@2x.png") no-repeat center;
     background-size: contain;
     overflow: hidden;
+    .topName {
+      user-select: none;
+      cursor: unset;
+      img {
+        width: 54.4px;
+        height: 38.4px;
+        vertical-align: bottom;
+      }
+      text-shadow: 0px 0px 3px rgba(41, 115, 255, 0.7);
+      position: absolute;
+      color: rgb(41, 115, 255);
+      top: 50px;
+      left: 150px;
+      font-size: 32px;
+    }
     .anima1 {
       position: fixed;
       top: 343px;