Hwf преди 8 месеца
родител
ревизия
50d8c6cf2f
променени са 2 файла, в които са добавени 57 реда и са изтрити 79 реда
  1. 50 47
      src/permission.ts
  2. 7 32
      src/views/login.vue

+ 50 - 47
src/permission.ts

@@ -13,53 +13,56 @@ NProgress.configure({ showSpinner: false });
 const whiteList = ['/login', '/register', '/social-callback'];
 
 router.beforeEach(async (to, from, next) => {
-  // NProgress.start();
-  // if (getToken()) {
-  //   to.meta.title && useSettingsStore().setTitle(to.meta.title);
-  //   /* has token*/
-  //   if (to.path === '/login') {
-  //     next({ path: '/' });
-  //     NProgress.done();
-  //   } else if (whiteList.indexOf(to.path as string) !== -1) {
-  //     next();
-  //   } else {
-  //     if (useUserStore().roles.length === 0) {
-  //       isRelogin.show = true;
-  //       // 判断当前用户是否已拉取完user_info信息
-  //       const [err] = await tos(useUserStore().getInfo());
-  //       if (err) {
-  //         await useUserStore().logout();
-  //         ElMessage.error(err);
-  //         next({ path: '/' });
-  //       } else {
-  //         isRelogin.show = false;
-  //         const accessRoutes = await usePermissionStore().generateRoutes();
-  //         // 根据roles权限生成可访问的路由表
-  //         accessRoutes.forEach((route) => {
-  //           if (!isHttp(route.path)) {
-  //             router.addRoute(route); // 动态添加可访问路由表
-  //           }
-  //         });
-  //         next({ path: to.path, replace: true, params: to.params, query: to.query, hash: to.hash, name: to.name as string }); // hack方法 确保addRoutes已完成
-  //       }
-  //     } else {
-  //       next();
-  //     }
-  //   }
-  // } else {
-  //   next();
-  //   // 没有token
-  //   if (whiteList.indexOf(to.path as string) !== -1) {
-  //     // 在免登录白名单,直接进入
-  //     next();
-  //   } else {
-  //     const redirect = encodeURIComponent(to.fullPath || '/');
-  //     next(`/login?redirect=${redirect}`); // 否则全部重定向到登录页
-  //     NProgress.done();
-  //   }
-  // }
-  next();
-  usePermissionStore().setMenu(to);
+  NProgress.start();
+  if (getToken()) {
+    to.meta.title && useSettingsStore().setTitle(to.meta.title);
+    /* has token*/
+    if (to.path === '/login') {
+      next({ path: '/' });
+      usePermissionStore().setMenu(to);
+      NProgress.done();
+    } else if (whiteList.indexOf(to.path as string) !== -1) {
+      usePermissionStore().setMenu(to);
+      next();
+    } else {
+      if (useUserStore().roles.length === 0) {
+        isRelogin.show = true;
+        // 判断当前用户是否已拉取完user_info信息
+        const [err] = await tos(useUserStore().getInfo());
+        if (err) {
+          await useUserStore().logout();
+          ElMessage.error(err);
+          next({ path: '/' });
+          usePermissionStore().setMenu(to);
+        } else {
+          isRelogin.show = false;
+          const accessRoutes = await usePermissionStore().generateRoutes();
+          // 根据roles权限生成可访问的路由表
+          accessRoutes.forEach((route) => {
+            if (!isHttp(route.path)) {
+              router.addRoute(route); // 动态添加可访问路由表
+            }
+          });
+          usePermissionStore().setMenu(to);
+          next({ path: to.path, replace: true, params: to.params, query: to.query, hash: to.hash, name: to.name as string }); // hack方法 确保addRoutes已完成
+        }
+      } else {
+        usePermissionStore().setMenu(to);
+        next();
+      }
+    }
+  } else {
+    // 没有token
+    if (whiteList.indexOf(to.path as string) !== -1) {
+      // 在免登录白名单,直接进入
+      usePermissionStore().setMenu(to);
+      next();
+    } else {
+      const redirect = encodeURIComponent(to.fullPath || '/');
+      next(`/login?redirect=${redirect}`); // 否则全部重定向到登录页
+      NProgress.done();
+    }
+  }
 });
 
 router.afterEach(() => {

+ 7 - 32
src/views/login.vue

@@ -2,12 +2,6 @@
   <div class="login">
     <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
       <h3 class="title">应急指挥一张图</h3>
-      <el-form-item v-if="tenantEnabled" prop="tenantId">
-        <el-select v-model="loginForm.tenantId" filterable placeholder="请选择/输入公司名称" style="width: 100%">
-          <el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"></el-option>
-          <template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
-        </el-select>
-      </el-form-item>
       <el-form-item prop="username">
         <el-input v-model="loginForm.username" type="text" size="large" auto-complete="off" placeholder="账号">
           <template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
@@ -27,38 +21,16 @@
         </div>
       </el-form-item>
       <el-checkbox v-model="loginForm.rememberMe" style="margin: 0 0 25px 0">记住密码</el-checkbox>
-      <!--
-      <el-form-item style="float: right">
-        <el-button circle title="微信登录" @click="doSocialLogin('wechat')">
-          <svg-icon icon-class="wechat" />
-        </el-button>
-        <el-button circle title="MaxKey登录" @click="doSocialLogin('maxkey')">
-          <svg-icon icon-class="maxkey" />
-        </el-button>
-        <el-button circle title="TopIam登录" @click="doSocialLogin('topiam')">
-          <svg-icon icon-class="topiam" />
-        </el-button>
-        <el-button circle title="Gitee登录" @click="doSocialLogin('gitee')">
-          <svg-icon icon-class="gitee" />
-        </el-button>
-        <el-button circle title="Github登录" @click="doSocialLogin('github')">
-          <svg-icon icon-class="github" />
-        </el-button>
-      </el-form-item>
-      -->
       <el-form-item style="width: 100%">
         <el-button :loading="loading" size="large" type="primary" style="width: 100%" @click.prevent="handleLogin">
           <span v-if="!loading">登 录</span>
           <span v-else>登 录 中...</span>
         </el-button>
-        <div v-if="register" style="float: right">
-          <router-link class="link-type" :to="'/register'">立即注册</router-link>
-        </div>
       </el-form-item>
     </el-form>
     <!--  底部  -->
     <div class="el-login-footer">
-      <span v-if="false">Copyright © 2018-2024 疯狂的狮子Li All Rights Reserved.</span>
+      <span v-if="false">Copyright © 2018-2024</span>
     </div>
   </div>
 </template>
@@ -73,6 +45,7 @@ const userStore = useUserStore();
 const router = useRouter();
 
 const loginForm = ref<LoginData>({
+  tenantId: '000000',
   username: 'admin',
   password: 'admin123',
   rememberMe: false,
@@ -90,8 +63,8 @@ const codeUrl = ref('');
 const loading = ref(false);
 // 验证码开关
 const captchaEnabled = ref(true);
+
 // 注册开关
-const register = ref(false);
 const redirect = ref(undefined);
 const loginRef = ref<ElFormInstance>();
 
@@ -155,6 +128,7 @@ const getLoginData = () => {
   const password = localStorage.getItem('password');
   const rememberMe = localStorage.getItem('rememberMe');
   loginForm.value = {
+    tenantId: '000000',
     username: username === null ? String(loginForm.value.username) : username,
     password: password === null ? String(loginForm.value.password) : String(password),
     rememberMe: rememberMe === null ? false : Boolean(rememberMe)
@@ -173,8 +147,9 @@ onMounted(() => {
   justify-content: center;
   align-items: center;
   height: 100%;
-  background-image: url('../assets/images/login-background.jpg');
-  background-size: cover;
+  background-color: #020935;
+  //background-image: url('../assets/images/login-background.jpg');
+  //background-size: cover;
 }
 
 .title {