zhangyuhan 8 месяцев назад
Родитель
Сommit
08c873fd5d
4 измененных файлов с 63 добавлено и 27 удалено
  1. 8 5
      src/App.vue
  2. 0 22
      src/components/Login.vue
  3. 5 0
      src/router.js
  4. 50 0
      src/views/autoLogin.vue

+ 8 - 5
src/App.vue

@@ -1,6 +1,9 @@
 <template>
     <div id="app">
-        <Login v-if="!isLogin"></Login>
+        <div  v-if="!isLogin">
+          <router-view v-if="$route.name === 'auto'"></router-view>
+          <Login v-else></Login>
+        </div>
         <div class="main layout" v-if="isLogin">
             <div style="min-height: calc(100vh - 80px);">
                 <Layout>
@@ -105,10 +108,10 @@ export default {
     mounted() {
         this.$router.onReady(() => {
             this.initialize();
-        if(this.$route.query && this.$route.query.LeftMenu == 'hide'){ 
+        if(this.$route.query && this.$route.query.LeftMenu == 'hide'){
             this.defaultWidth = '0px';
-        } 
-        }); 
+        }
+        });
     },
     methods: {
         // 初始化系统
@@ -184,4 +187,4 @@ export default {
         text-align: center;
         color: #aea79f;
     }
-</style>
+</style>

+ 0 - 22
src/components/Login.vue

@@ -116,12 +116,6 @@
             this.getQwCode()
         },
         mounted() {
-            const params =  new URLSearchParams(window.location.search)
-            const state = params.get('state')
-            const code = params.get('code')
-            if (state === 'WWLogin' && code) {
-              this.doLogin({ code })
-            }
             window.addEventListener('keyup', this.enterClick)
         },
         methods: {
@@ -173,22 +167,6 @@
                     this.valHandler()
                 }).post()
             },
-            doLogin ({ code }) {
-              this.$request("/login").data({ wxCode: code }).success((r) => {
-                // 设置登录
-                this.$store.dispatch('login', r.data);
-                // 重新初始化系统
-                this.$request("/load").success((r) => {
-                  this.$store.dispatch('initialize', r.data)
-                  setTitle(this.$route)
-                }).error(() => {
-                  this.$Notice.error({title: '系统初始化发送异常', desc: r.info, duration: 5})
-                  this.$store.dispatch('logout');
-                }).get();
-              }).error(() => {
-                this.$Message.error({content: '企业微信登录异常'})
-              }).post()
-            },
             handleSubmit(name) {
                 let _this = this;
                 this.$refs[name].validate((valid) => {

+ 5 - 0
src/router.js

@@ -16,6 +16,11 @@ const routes = [
         name: 'index',
         component: () => import('./views/index.vue')
     },
+    {
+        path: '/auto',
+        name: 'auto',
+        component: () => import('./views/autoLogin.vue')
+    },
     // {
     //     path: '*',
     //     component: () => import('./views/error.vue')

+ 50 - 0
src/views/autoLogin.vue

@@ -0,0 +1,50 @@
+<template>
+    <div v-loading.fullscreen.lock="loading"></div>
+</template>
+
+<script>
+import {setTitle} from "@/router";
+import {config} from "@/helper";
+
+export default {
+  data () {
+    return {
+      loading: true
+    }
+  },
+  created() {
+    const params = new URLSearchParams(window.location.search)
+    const state = params.get('state')
+    const code = params.get('code')
+    if (state === 'WWLogin' && code) {
+      this.doLogin({code})
+    } else {
+      this.goHome()
+    }
+  },
+  methods: {
+    goHome () {
+      this.$router.replace(config('INDEX_URL'))
+    },
+    doLogin ({ code }) {
+      this.$request("/login").data({ wxCode: code }).success((r) => {
+        this.loading = false
+        // 设置登录
+        this.$store.dispatch('login', r.data);
+        // 重新初始化系统
+        this.$request("/load").success((r) => {
+          this.$store.dispatch('initialize', r.data)
+          setTitle(this.$route)
+        }).error(() => {
+          this.$Notice.error({title: '系统初始化发送异常', desc: r.info, duration: 5})
+          this.$store.dispatch('logout');
+        }).get();
+        this.goHome()
+      }).error(() => {
+        this.$Message.error({content: '企业微信登录异常'})
+        this.goHome()
+      }).post()
+    },
+  }
+}
+</script>