Browse Source

refactor:登录流程

Tim_Walker 1 year ago
parent
commit
fea89eb032
3 changed files with 42 additions and 9 deletions
  1. 0 9
      src/App.vue
  2. 7 0
      src/pages.json
  3. 35 0
      src/pages/index.vue

+ 0 - 9
src/App.vue

@@ -1,19 +1,10 @@
 <script>
 import { updateVersion } from './utils/system';
-import { getWxLoginCode } from '@/api/login';
 export default {
   async onLaunch() {
     //#ifdef MP-WEIXIN
     updateVersion();
     //#endif
-    const wxCode = await getWxLoginCode();
-    await this.$store.dispatch('LoginByWxCode', {
-      client_id: 'chelvc_client',
-      client_secret: 'qWBe6jD%GCuPPTkP',
-      grant_type: 'wechat',
-      token: wxCode,
-    });
-    await this.$store.dispatch('GetUserInfo');
   },
 };
 </script>

+ 7 - 0
src/pages.json

@@ -3,6 +3,13 @@
     "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
   },
   "pages": [
+    {
+      "path": "pages/index",
+      "style": {
+        "navigationBarTitleText": "首页",
+        "navigationStyle": "custom"
+      }
+    },
     {
       "path": "pages/tabbar/home/index",
       "style": {

+ 35 - 0
src/pages/index.vue

@@ -0,0 +1,35 @@
+<template>
+  <view>
+    <u-loading-page :loading="loading"></u-loading-page>
+  </view>
+</template>
+
+<script>
+import { getWxLoginCode } from '@/api/login';
+export default {
+  data(){
+    return{
+      loading:false
+    }
+  },
+  async onLoad(){
+    try {
+      this.loading = true;
+      const wxCode = await getWxLoginCode();
+      await this.$store.dispatch('LoginByWxCode', {
+        client_id: 'chelvc_client',
+        client_secret: 'qWBe6jD%GCuPPTkP',
+        grant_type: 'wechat',
+        token: wxCode,
+      });
+      await this.$store.dispatch('GetUserInfo');
+      this.$Router.pushTab('/pages/tabbar/home/index')
+      this.loading = false
+    } catch (error) {
+      this.loading = false
+      this.$Router.push('/pages/login/index')
+      console.log("初始化登录异常",error)
+    }
+  }
+}
+</script>