Procházet zdrojové kódy

登录、试驾验证码

drew před 5 roky
rodič
revize
f4d5ffc7c4
3 změnil soubory, kde provedl 93 přidání a 77 odebrání
  1. 22 23
      src/pages/login.vue
  2. 36 43
      src/pages/register.vue
  3. 35 11
      src/pages/testDrive.vue

+ 22 - 23
src/pages/login.vue

@@ -35,24 +35,25 @@ export default {
                 return;
             }
             if (!/^1\d{10}$/.test(this.mobile)) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '请输入正确的手机号'
-                });
+                this.$toast('请输入正确的手机号');
                 return;
             }
             if (!this.password) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '请输入密码'
-                });
+                this.$toast('请输入密码');
                 return;
             }
-            wx.showLoading({
-                mask: true,
-                title: ''
-            });
-            Promise.resolve()
+            this.$loading();
+            this.$http
+                .get('/applets/checkmobileexist', {
+                    mobile: this.mobile
+                })
+                .then(res => {
+                    if (res.code === 500) {
+                        return Promise.resolve();
+                    } else {
+                        return Promise.reject('该手机号未注册');
+                    }
+                })
                 .then(() => {
                     if (this.$store.state.loginInfo && this.$store.state.loginInfo.hasUnionId) {
                         return Promise.resolve();
@@ -83,19 +84,17 @@ export default {
                         link: true
                     });
                     this.$store.dispatch('getUserInfo');
-                    wx.hideLoading();
-                    wx.showToast({
-                        icon: 'none',
-                        title: '登录成功'
-                    });
+                    this.$loading.close();
+                    this.$toast('登录成功');
                     wx.navigateBack();
                 })
                 .catch(e => {
-                    wx.hideLoading();
-                    wx.showToast({
-                        icon: 'none',
-                        title: e
-                    });
+                    this.$loading.close();
+                    if (typeof e === 'string') {
+                        this.$toast(e);
+                    } else {
+                        this.$toast('登录失败,请稍后再试');
+                    }
                 });
         }
     }

+ 36 - 43
src/pages/register.vue

@@ -41,22 +41,25 @@ export default {
             console.log(this.mobile);
             if (this.time > 0) return;
             if (!/^1\d{10}$/.test(this.mobile)) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '请输入正确的手机号'
-                });
+                this.$toast('请输入正确的手机号');
                 return;
             }
+            this.$loading('');
             this.$http
                 .get('/applets/checkmobileexist', {
                     mobile: this.mobile
                 })
-                .then(res => {});
-            this.$http
-                .get('/applets/sendmobilecode', {
-                    mobile: this.mobile
+                .then(res => {
+                    if (res.code === 500) {
+                        return Promise.reject(res.message);
+                    } else {
+                        return this.$http.get('/applets/sendmobilecode', {
+                            mobile: this.mobile
+                        });
+                    }
                 })
                 .then(res => {
+                    this.$loading.close();
                     this.time = 60;
                     this.i = setInterval(() => {
                         this.time--;
@@ -64,6 +67,14 @@ export default {
                             clearInterval(this.i);
                         }
                     }, 1000);
+                })
+                .catch(e => {
+                    this.$loading.close();
+                    if (typeof e === 'string') {
+                        this.$toast(e);
+                    } else {
+                        this.$toast('短信发送失败,请稍后再试');
+                    }
                 });
         },
         getUserInfo(e) {
@@ -71,37 +82,26 @@ export default {
                 return;
             }
             if (!/^1\d{10}$/.test(this.mobile)) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '请输入正确的手机号'
-                });
+                this.$toast('请输入正确的手机号');
                 return;
             }
             if (!this.code) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '请输入验证码'
-                });
+                this.$toast('请输入验证码');
                 return;
             }
             if (!this.password) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '请输入密码'
-                });
+                this.$toast('请输入密码');
+                return;
+            }
+            if (this.password.length < 6) {
+                this.$toast('密码长度至少为6位');
                 return;
             }
             if (this.password !== this.password1) {
-                wx.showToast({
-                    icon: 'none',
-                    title: '两次密码输入不一致'
-                });
+                this.$toast('两次密码输入不一致');
                 return;
             }
-            wx.showLoading({
-                title: '',
-                mask: true
-            });
+            this.$loading();
             Promise.resolve()
                 .then(() => {
                     if (this.$store.state.loginInfo && this.$store.state.loginInfo.hasUnionId) {
@@ -115,7 +115,9 @@ export default {
                     }
                 })
                 .then(res => {
-                    return this.$http.get('/applets/checkmobileexist');
+                    return this.$http.get('/applets/sendmobilecode', {
+                        mobile: this.mobile
+                    });
                 })
                 .then(res => {
                     if (res.code === 200) {
@@ -155,26 +157,17 @@ export default {
                         link: true
                     });
                     this.$store.dispatch('getUserInfo');
-                    wx.hideLoading();
-                    wx.showToast({
-                        icon: 'none',
-                        title: '登录成功'
-                    });
+                    this.$loading.close();
+                    this.$toast('登录成功');
                     wx.navigateBack();
                 })
                 .catch(e => {
                     console.log(e);
-                    wx.hideLoading();
+                    this.$loading.close();
                     if (typeof e === 'string') {
-                        wx.showToast({
-                            icon: 'none',
-                            title: e
-                        });
+                        this.$toast(e);
                     } else {
-                        wx.showToast({
-                            icon: 'none',
-                            title: '操作失败,请稍后再试'
-                        });
+                        this.$toast('操作失败,请稍后再试');
                     }
                 });
         },

+ 35 - 11
src/pages/testDrive.vue

@@ -155,6 +155,18 @@ export default {
         });
     },
     created() {
+        if (process.env.NODE_ENV === 'development') {
+            this.provinceId = 32;
+            this.provinceName = '江苏省';
+            this.cityId = 3201;
+            this.cityName = '南京市';
+            this.mobile = '15077886171';
+            this.dealerId = 5668;
+            this.dealerName = 'sandy测试经销商';
+            this.dealerCode = '100001';
+            this.name = '熊竹';
+        }
+
         this.$http
             .get(
                 'https://dealer.jetour.com.cn/api-basic/api/region/findAllProvinces',
@@ -332,17 +344,24 @@ export default {
             }
             this.$loading();
             this.$http
-                .post('https://www.jetour.com.cn/cmsapi/business/LeaveLeads/save', {
-                    cityId: this.cityId,
-                    city: this.cityName,
-                    dealerCode: this.dealerCode,
-                    dealerId: this.dealerId,
-                    fromSource: '小程序-官网商城小程序留资',
-                    leadsType: 2,
-                    mobile: this.mobile,
-                    name: this.name,
-                    province: this.provinceName,
-                    provinceId: this.provinceId
+                .post(`https://www.jetour.com.cn/cmsapi/business/LeaveLeads/checkCode/${this.mobile}/${this.code}`)
+                .then(res => {
+                    if (res.data === '验证成功') {
+                        return this.$http.post('https://www.jetour.com.cn/cmsapi/business/LeaveLeads/save', {
+                            cityId: this.cityId,
+                            city: this.cityName,
+                            dealerCode: this.dealerCode,
+                            dealerId: this.dealerId,
+                            fromSource: '小程序-官网商城小程序留资',
+                            leadsType: 2,
+                            mobile: this.mobile,
+                            name: this.name,
+                            province: this.provinceName,
+                            provinceId: this.provinceId
+                        });
+                    } else {
+                        return Promise.reject(res.data);
+                    }
                 })
                 .then(res => {
                     this.$loading.close();
@@ -357,6 +376,11 @@ export default {
                 })
                 .catch(e => {
                     console.log(e);
+                    if (typeof e === 'string') {
+                        this.$toast(e);
+                    } else {
+                        this.$toast('提交失败,请稍后再试');
+                    }
                 });
         }
     },