drew 5 年之前
父节点
当前提交
3d78989fe1
共有 5 个文件被更改,包括 49 次插入18 次删除
  1. 3 0
      src/App.vue
  2. 27 7
      src/pages/login.vue
  3. 6 8
      src/pages/my.vue
  4. 9 0
      src/pages/register.vue
  5. 4 3
      src/store/index.js

+ 3 - 0
src/App.vue

@@ -19,6 +19,9 @@ export default {
                         success: res => {
                             if (res && res.statusCode === 200) {
                                 resolve(res.data);
+                                if (res.data && res.data.link) {
+                                    this.$store.dispatch('getUserInfo');
+                                }
                             } else {
                                 reject(res);
                             }

+ 27 - 7
src/pages/login.vue

@@ -12,7 +12,9 @@
             <span class="link forgot" @click.stop="forgot">忘记密码</span>
         </div>
         <div style="padding: 0 16px; margin-top: 40px;">
-            <van-button @click="login" :color="$colors.prim" block>立即登录</van-button>
+            <van-button :color="$colors.prim" block open-type="getUserInfo" @getuserinfo="getUserInfo">
+                立即登录
+            </van-button>
         </div>
     </div>
 </template>
@@ -27,7 +29,7 @@ export default {
                 url: '/pages/register'
             });
         },
-        login() {
+        getUserInfo(e) {
             if (!/^1\d{10}$/.test(this.mobile)) {
                 wx.showToast({
                     icon: 'none',
@@ -46,10 +48,22 @@ export default {
                 mask: true,
                 title: ''
             });
-            this.$http
-                .post('/applets/bindaccount', {
-                    username: this.mobile,
-                    password: this.password
+            Promise.resolve()
+                .then(() => {
+                    if (this.$store.state.loginInfo && this.$store.state.loginInfo.hasUnionId) {
+                        return Promise.resolve();
+                    } else {
+                        return this.$http.post('/applets/dealuserinfo', {
+                            ...e.detail,
+                            userInfo: JSON.stringify(e.detail.userInfo)
+                        });
+                    }
+                })
+                .then(() => {
+                    return this.$http.post('/applets/bindaccount', {
+                        username: this.mobile,
+                        password: this.password
+                    });
                 })
                 .then(res => {
                     if (res.code === 200) {
@@ -59,11 +73,17 @@ export default {
                     }
                 })
                 .then(() => {
-                    wx.hideLoading();
                     this.$store.commit('setLoginInfo', {
                         hasUnionId: true,
                         link: true
                     });
+                    this.$store.dispatch('getUserInfo');
+                    wx.hideLoading();
+                    wx.showToast({
+                        icon: 'none',
+                        title: '登录成功'
+                    });
+                    wx.navigateBack();
                 })
                 .catch(e => {
                     wx.hideLoading();

+ 6 - 8
src/pages/my.vue

@@ -31,18 +31,16 @@
     </div>
 </template>
 <script>
+import { mapState } from 'vuex';
 export default {
     data() {
-        return {
-            userInfo: null
-        };
+        return {};
     },
     onShow() {
-        this.$http.get('/applets/customerdetail').then(res => {
-            if (res.data) {
-                this.userInfo = res.data;
-            }
-        });
+        this.$store.dispatch('getUserInfo');
+    },
+    computed: {
+        ...mapState(['userInfo'])
     },
     methods: {
         call() {

+ 9 - 0
src/pages/register.vue

@@ -146,7 +146,16 @@ export default {
                     }
                 })
                 .then(() => {
+                    this.$store.commit('setLoginInfo', {
+                        hasUnionId: true,
+                        link: true
+                    });
+                    this.$store.dispatch('getUserInfo');
                     wx.hideLoading();
+                    wx.showToast({
+                        icon: 'none',
+                        title: '登录成功'
+                    });
                     wx.navigateBack();
                 })
                 .catch(e => {

+ 4 - 3
src/store/index.js

@@ -27,9 +27,10 @@ export default new Vuex.Store({
     },
     actions: {
         getUserInfo(context) {
-            http.http.get('/user/my').then(res => {
-                console.log(res);
-                context.commit('setUserInfo', res);
+            http.http.get('/applets/customerdetail').then(res => {
+                if (res.data) {
+                    context.commit('setUserInfo', res.data);
+                }
             });
         }
     }