songfeiyang 1 year ago
parent
commit
771e2398dd
3 changed files with 332 additions and 246 deletions
  1. 85 66
      src/pages/login/index.vue
  2. 229 175
      src/pages/login/phoneLogin.vue
  3. 18 5
      src/pages/login/register.vue

+ 85 - 66
src/pages/login/index.vue

@@ -1,94 +1,113 @@
 html
 <template>
   <view class="container">
-    <u-image src="@/static/logo.png" mode="widthFix" class="logo-image"></u-image>
+    <u-image
+      src="@/static/logo.png"
+      mode="widthFix"
+      class="logo-image"
+    ></u-image>
     <view class="login-btn-wrap">
-      <u-button shape="circle" type="primary" :loading="loading" @tap="login">微信用户一键登录</u-button>
-      <u-button shape="circle" :customStyle="{ 'margin-top': '20rpx' }"
-        @tap="$Router.push('/pages/login/phoneLogin')">手机号登录/注册</u-button>
+      <u-button shape="circle" type="primary" :loading="loading" @tap="login"
+        >微信用户一键登录</u-button
+      >
+      <u-button
+        shape="circle"
+        :customStyle="{ 'margin-top': '20rpx' }"
+        @tap="$Router.push('/pages/login/phoneLogin')"
+        >手机号登录/注册</u-button
+      >
     </view>
     <br />
-    <view style="display: flex">
+    <view style="display: flex; justify-content: space-between">
       <u-icon name="gift-fill" color="#2979ff" size="28"></u-icon>
-      <text @click="userAgreementClick" style="font-weight: bold">随便看看</text>
+      <text
+        @click="userAgreementClick"
+        style="font-weight: bold; margin-right: 135rpx"
+        >随便看看</text
+      >
       <u-icon name="gift-fill" color="#2979ff" size="28"></u-icon>
-      <text @click="userAgreementClick" style="font-weight: bold">联系客服</text>
+      <text @click="userAgreementClick" style="font-weight: bold"
+        >联系客服</text
+      >
     </view>
     <br />
     <br />
     <view style="font-size: 12px">
       温馨提示:登录前请详细阅读
-      <text @click="userAgreementClick" style="font-weight: bold">《用户协议》</text><text @click="privacyPolicyClick"
-        style="font-weight: bold">《隐私政策》</text>
+      <text @click="userAgreementClick" style="font-weight: bold"
+        >《用户协议》</text
+      ><text @click="privacyPolicyClick" style="font-weight: bold"
+        >《隐私政策》</text
+      >
     </view>
   </view>
 </template>
 
 <script>
-  import {
-    getWxLoginCode
-  } from '@/api/login.js';
+import { getWxLoginCode } from '@/api/login.js';
 
-  export default {
-    data() {
-      return {
-        loading: false,
-        form: {
-          client_id: 'chelvc_client',
-          client_secret: 'qWBe6jD%GCuPPTkP',
-          grant_type: 'wechat',
-          token: '',
-        },
-      };
-    },
-    onShow() {},
-    methods: {
-      //点击微信用户一键登录
-      async login() {
-        this.loading = true;
-        this.form.token = await getWxLoginCode();
-        this.$store.dispatch('LoginByWxCode', this.form).then(() => {
-            this.loading = false;
-            uni.$u.toast('登录成功');
-            this.$Router.pushTab('/pages/tabbar/home/index');
-            // this.$store.dispatch('GetUserInfo').then(() => {
-            //   })
-            //   .catch(err => {
-            //     console.log(err);
-            //   });
-          })
-          .catch(() => {
-            this.loading = false;
-            uni.$u.toast('登录失败');
-          });
+export default {
+  data() {
+    return {
+      loading: false,
+      form: {
+        client_id: 'chelvc_client',
+        client_secret: 'qWBe6jD%GCuPPTkP',
+        grant_type: 'wechat',
+        token: '',
       },
+    };
+  },
+  onShow() {},
+  methods: {
+    //点击微信用户一键登录
+    async login() {
+      this.loading = true;
+      this.form.token = await getWxLoginCode();
+      this.$store
+        .dispatch('LoginByWxCode', this.form)
+        .then(() => {
+          this.loading = false;
+          uni.$u.toast('登录成功');
+          this.$Router.pushTab('/pages/tabbar/home/index');
+          // this.$store.dispatch('GetUserInfo').then(() => {
+          //   })
+          //   .catch(err => {
+          //     console.log(err);
+          //   });
+        })
+        .catch(() => {
+          this.loading = false;
+          uni.$u.toast('登录失败');
+        });
+    },
 
-      //点击用户协议
-      userAgreementClick() {},
+    //点击用户协议
+    userAgreementClick() {},
 
-      //点击忘记密码
-      forgetPassword() {},
+    //点击忘记密码
+    forgetPassword() {},
 
-      //点击隐私政策
-      privacyPolicyClick() {},
-    },
-  };
+    //点击隐私政策
+    privacyPolicyClick() {},
+  },
+};
 </script>
 
 <style scoped>
-  .container {
-    display: flex;
-    justify-content: center;
-    align-items: center;
-    flex-direction: column;
-  }
+.container {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  flex-direction: column;
+}
 
-  .login-btn-wrap {
-    margin-top: 40rpx;
-    width: 80%;
-  }
+.login-btn-wrap {
+  margin-top: 40rpx;
+  width: 80%;
+}
 
-  .logo-image {
-    margin: auto;
-  }
-</style>
+.logo-image {
+  margin: auto;
+}
+</style>

+ 229 - 175
src/pages/login/phoneLogin.vue

@@ -2,249 +2,303 @@
   <view class="container">
     <u-image src="@/static/logo.png"></u-image>
     <view class="login-form-wrap">
-      <u--form labelPosition="left" :model="loginForm" :rules="rules" ref="loginForm">
+      <u--form
+        labelPosition="left"
+        :model="loginForm"
+        :rules="rules"
+        ref="loginForm"
+      >
         <u-form-item prop="mobile" borderBottom label="账号">
-          <u-input v-model="loginForm.mobile" maxlength="11" border="none" focus placeholder="请输入账号/手机号">
+          <u-input
+            v-model="loginForm.mobile"
+            maxlength="11"
+            border="none"
+            focus
+            placeholder="请输入账号/手机号"
+          >
           </u-input>
         </u-form-item>
         <u-form-item prop="captcha" label="密码" borderBottom>
-          <u-input v-model="loginForm.password" maxlength="6" border="none" placeholder="请输入密码">
+          <u-input
+            v-model="loginForm.password"
+            maxlength="6"
+            border="none"
+            placeholder="请输入密码"
+          >
           </u-input>
         </u-form-item>
-        <u-checkbox shape="circle" @change="checkboxChange" :checked="isChecked"></u-checkbox>
-        <view @click="forgetPassword">记住密码</view>
-        <view class="phone-question" @click="forgetPassword">忘记密码?</view>
+        <view style="display: flex; justify-content: space-between">
+          <view style="display: flex">
+            <u-checkbox-group>
+              <u-checkbox
+                @change="checkboxChange"
+                v-model="isChecked"
+                :checked="isChecked"
+                shape="circle"
+                size="mini"
+              ></u-checkbox>
+            </u-checkbox-group>
+            <view class="phone-question" @click="forgetPassword">记住密码</view>
+          </view>
+          <view class="phone-question" @click="forgetPassword">忘记密码?</view>
+        </view>
         <u-form-item>
-          <u-button type="primary" :disabled="isDisabled" :loading="loading" shape="circle" @click="login">登录</u-button>
+          <u-button
+            type="primary"
+            :disabled="isDisabled"
+            :loading="loading"
+            shape="circle"
+            @click="login"
+            >登录</u-button
+          >
         </u-form-item>
         <u-form-item>
-          <u-button :loading="loading" shape="circle" @click="register">注册</u-button>
+          <u-button :loading="loading" shape="circle" @click="register"
+            >注册</u-button
+          >
         </u-form-item>
       </u--form>
       <view class="user-agreement">
         <u-checkbox-group>
-          <u-checkbox shape="circle" @change="checkboxChange" :checked="isChecked"></u-checkbox>
+          <u-checkbox
+            shape="circle"
+            @change="checkboxChange"
+            v-model="isChecked"
+            :checked="isChecked"
+          ></u-checkbox>
         </u-checkbox-group>
         <text class="user-agreement-text">
           我已阅读并同意
           <text class="terms">《用户协议》</text>
           <text class="terms">《隐私政策》</text>
-          <text class="terms">《儿童/青少年个人信息保护规则》</text>
+          <text class="terms">《商家/车主个人信息保护规则》</text>
         </text>
       </view>
     </view>
 
     <view>
       <u-popup :show="show" @close="close" mode="center">
-        <view style="
+        <view
+          style="
             height: 100rpx;
             width: 700rpx;
             align-items: center;
             display: flex;
             justify-content: center;
-          ">
+          "
+        >
           <text style="color: gray; font-size: 14px">我已阅读并同意</text>
           <text style="font-weight: bold">《用户协议》</text>
           <text style="font-weight: bold">《隐私政策》</text>
         </view>
-        <u-button @click="confirmShow" type="primary" :loading="loading">确认</u-button>
+        <u-button @click="confirmShow" type="primary" :loading="loading"
+          >确认</u-button
+        >
       </u-popup>
     </view>
   </view>
 </template>
 
 <script>
-  import {
-    getSmsCodeByPhone,
-    loginByPhoneAndSmsCode,
-
-    maintainSmsCaptcha
-  } from '@/api/login';
-  export default {
-    data() {
-      return {
-        loginForm: {
-          client_id: 'chelvc_client',
-          client_secret: 'qWBe6jD%GCuPPTkP',
-          grant_type: 'sms',
-          token: '',
-          mobile: '18380313545', //手机号
-          captcha: '363636', //验证码
-          password: '1', //密码
-        },
-        rules: {
-          mobile: [{
-              required: true,
-              trigger: ['change', 'blur'],
-              message: '请输入您的手机号',
-            },
-            {
-              validator: (rule, value, cb) => {
-                return uni.$u.test.mobile(value);
-              },
-              message: '手机号码格式不正确',
-              trigger: ['change', 'blur'],
+import {
+  getSmsCodeByPhone,
+  loginByPhoneAndSmsCode,
+  maintainSmsCaptcha,
+} from '@/api/login';
+export default {
+  data() {
+    return {
+      loginForm: {
+        client_id: 'chelvc_client',
+        client_secret: 'qWBe6jD%GCuPPTkP',
+        grant_type: 'sms',
+        token: '',
+        mobile: '18380313545', //手机号
+        captcha: '363636', //验证码
+        password: '1', //密码
+      },
+      rules: {
+        mobile: [
+          {
+            required: true,
+            trigger: ['change', 'blur'],
+            message: '请输入您的手机号',
+          },
+          {
+            validator: (rule, value, cb) => {
+              return uni.$u.test.mobile(value);
             },
-          ],
-          captcha: [{
+            message: '手机号码格式不正确',
+            trigger: ['change', 'blur'],
+          },
+        ],
+        captcha: [
+          {
             required: true,
             trigger: ['change', 'blur'],
             message: '请输入六位数验证码',
-          }, ],
-        },
-        seconds: 120,
-        tips: '',
-        isChecked: true,
-        show: false,
-        loading: false,
-      };
-    },
+          },
+        ],
+      },
+      seconds: 120,
+      tips: '',
+      isChecked: true,
+      show: false,
+      loading: false,
+    };
+  },
 
-    onReady() {
-      this.$refs.loginForm.setRules(this.rules);
-    },
+  onReady() {
+    this.$refs.loginForm.setRules(this.rules);
+  },
 
-    computed: {
-      isDisabled() {
-        return !(this.loginForm.mobile && this.loginForm.captcha.length === 6);
-      },
+  computed: {
+    isDisabled() {
+      return !(this.loginForm.mobile && this.loginForm.captcha.length === 6);
     },
+  },
 
-    methods: {
-      getCode() {
-        if (!this.loginForm.mobile) return uni.$u.toast('请输入您的手机号!');
-        if (!uni.$u.test.mobile(this.loginForm.mobile))
-          return uni.$u.toast('手机号码格式不正确!');
-        // TODO: 处理验证码倒计时
-        if (this.$refs.uCode.canGetCode) {
-          getSmsCodeByPhone(this.loginForm.mobile)
-            .then(res => {
-              if (res.code === 200) {
-                uni.$u.toast('验证码已发送');
-                this.loginForm.token = res.data.token;
-                this.$refs.uCode.start();
-              }
-            })
-            .catch(err => {
-              uni.$u.toast('无法发送验证码');
+  methods: {
+    getCode() {
+      if (!this.loginForm.mobile) return uni.$u.toast('请输入您的手机号!');
+      if (!uni.$u.test.mobile(this.loginForm.mobile))
+        return uni.$u.toast('手机号码格式不正确!');
+      // TODO: 处理验证码倒计时
+      if (this.$refs.uCode.canGetCode) {
+        getSmsCodeByPhone(this.loginForm.mobile)
+          .then(res => {
+            if (res.code === 200) {
+              uni.$u.toast('验证码已发送');
+              this.loginForm.token = res.data.token;
               this.$refs.uCode.start();
-            });
-        }
-      },
-
-      //点击登录
-      async login() {
-        if (!this.isChecked) {
-          this.show = true;
-          return;
-        }
-        this.loading = true;
-        let mobile = '18380313545'
-        maintainSmsCaptcha({
-            mobile: mobile
-          }).then(res => {
-            console.log('res', res);
-            //   this.loading = false;
-            //   if (res.access_token) {
-            //     uni.$u.toast('登录成功');
-            //     this.$store.commit('SET_ACCESS_TOKEN', res.access_token);
-            //     this.$store.commit('SET_REFRESH_TOKEN', res.refresh_token);
-            //     setTimeout(() => {
-            //       this.$Router.pushTab('/pages/tabbar/home/index');
-            //     }, 1500);
-            //   }
-            // })
-            // .catch(err => {
-            //   this.loading = false;
-            //   uni.$u.toast('登录失败-' + err.data.error_description);
-            //   this.loading = false;
-
-            // 下方登陆代码调通 token不知道放哪 不知道为什么要存两个token  上方代码没动 loginByPhoneAndSmsCode 这个是之前的接口
-            if (res.code == 200) {
-              uni.$u.toast('登录成功');
-              // this.$store.commit('SET_ACCESS_TOKEN', res.data.token);
-              // this.$store.commit('SET_REFRESH_TOKEN', res.data.token);
-              setTimeout(() => {
-                this.$Router.pushTab('/pages/tabbar/home/index');
-              }, 1500);
             }
           })
           .catch(err => {
-            this.loading = false;
-            uni.$u.toast('登录失败-' + err.data.error_description);
+            uni.$u.toast('无法发送验证码');
+            this.$refs.uCode.start();
           });
-      },
+      }
+    },
 
-      //点击注册
-      register() {
-        this.$Router.pushTab('/pages/login/register');
-      },
+    //点击登录
+    async login() {
+      if (!this.isChecked) {
+        this.show = true;
+        return;
+      }
+      this.loading = true;
+      let mobile = '18380313545';
+      maintainSmsCaptcha({
+        mobile: mobile,
+      })
+        .then(res => {
+          console.log('res', res);
+          //   this.loading = false;
+          //   if (res.access_token) {
+          //     uni.$u.toast('登录成功');
+          //     this.$store.commit('SET_ACCESS_TOKEN', res.access_token);
+          //     this.$store.commit('SET_REFRESH_TOKEN', res.refresh_token);
+          //     setTimeout(() => {
+          //       this.$Router.pushTab('/pages/tabbar/home/index');
+          //     }, 1500);
+          //   }
+          // })
+          // .catch(err => {
+          //   this.loading = false;
+          //   uni.$u.toast('登录失败-' + err.data.error_description);
+          //   this.loading = false;
 
-      //点击我已阅读
-      checkboxChange(v) {
-        this.isChecked = v;
-      },
+          // 下方登陆代码调通 token不知道放哪 不知道为什么要存两个token  上方代码没动 loginByPhoneAndSmsCode 这个是之前的接口
+          if (res.code == 200) {
+            uni.$u.toast('登录成功');
+            // this.$store.commit('SET_ACCESS_TOKEN', res.data.token);
+            // this.$store.commit('SET_REFRESH_TOKEN', res.data.token);
+            setTimeout(() => {
+              this.$Router.pushTab('/pages/tabbar/home/index');
+            }, 1500);
+          }
+        })
+        .catch(err => {
+          this.loading = false;
+          uni.$u.toast('登录失败-' + err.data.error_description);
+        });
+    },
 
-      //点击手机号无法使用?
-      noPhone() {
-        this.$message('要跳转到解决方案哦 还没写');
-      },
+    //点击注册
+    register() {
+      this.$Router.pushTab('/pages/login/register');
+    },
 
-      //点击弹框确认
-      confirmShow() {
-        this.isChecked = true;
-        this.show = false;
-        setTimeout(() => {
-          this.login();
-        }, 250);
-      },
+    //点击我已阅读
+    checkboxChange(v) {
+      console.log('vvvfv', v);
+      this.isChecked = v;
+    },
 
-      //关闭弹框f
-      close() {
-        this.show = false;
-      },
+    //点击手机号无法使用?
+    noPhone() {
+      this.$message('要跳转到解决方案哦 还没写');
+    },
+
+    //点击弹框确认
+    confirmShow() {
+      this.isChecked = true;
+      this.show = false;
+      setTimeout(() => {
+        this.login();
+      }, 250);
     },
-  };
+
+    //关闭弹框f
+    close() {
+      this.show = false;
+    },
+  },
+};
 </script>
 
 <style scoped lang="scss">
-  .container {
-    padding: 0 40rpx;
-    margin: 0 auto;
-  }
+.container {
+  padding: 0 40rpx;
+  margin: 0 auto;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  flex-direction: column;
+}
 
-  .login-form-wrap {
-    margin-top: 200rpx;
+.login-form-wrap {
+  margin-top: 200rpx;
 
-    .phone-prefix {
-      display: flex;
-      align-items: center;
-      padding-right: 20rpx;
-      border-right: 2rpx solid $uni-text-color-grey;
-      margin-right: 20rpx;
-    }
+  .phone-prefix {
+    display: flex;
+    align-items: center;
+    padding-right: 20rpx;
+    border-right: 2rpx solid $uni-text-color-grey;
+    margin-right: 20rpx;
+  }
 
-    .phone-question {
-      text-align: right;
-      font-size: 24rpx;
-      padding: 20rpx 0 20rpx 0;
-    }
+  .phone-question {
+    text-align: right;
+    font-size: 24rpx;
+    padding: 20rpx 0 20rpx 0;
+  }
 
-    .user-agreement {
-      display: flex;
-      padding: 0 10rpx;
+  .user-agreement {
+    display: flex;
+    padding: 0 10rpx;
 
-      .user-agreement-text {
-        font-size: 24rpx;
-        color: $uni-text-color-grey;
-        margin-top: 20rpx;
-        margin-left: 20rpx;
+    .user-agreement-text {
+      font-size: 24rpx;
+      color: $uni-text-color-grey;
+      margin-top: 20rpx;
+      margin-left: 20rpx;
 
-        .terms {
-          color: $uni-text-color;
-          font-weight: 400;
-        }
+      .terms {
+        color: $uni-text-color;
+        font-weight: 400;
       }
     }
   }
+}
 </style>

+ 18 - 5
src/pages/login/register.vue

@@ -1,6 +1,8 @@
 <template>
   <view class="container">
-    <u-image src="@/static/logo.png"></u-image>
+    <view class="header">
+      <img src="@/static/logo.png" class="logo" />
+    </view>
     <view class="login-form-wrap">
       <u--form
         labelPosition="left"
@@ -20,7 +22,7 @@
             <template slot="prefix">
               <view class="phone-prefix">
                 <text>+86</text>
-                <u-icon name="arrow-down-fill"></u-icon>
+                <!-- <u-icon name="arrow-down-fill"></u-icon> -->
               </view>
             </template>
           </u-input>
@@ -68,7 +70,7 @@
         </u-form-item>
       </u--form>
       <view class="user-agreement">
-        <u-checkbox-group>
+        <u-checkbox-group style="margin-top: 17rpx">
           <u-checkbox
             shape="circle"
             @change="checkboxChange"
@@ -79,7 +81,6 @@
           我已阅读并同意
           <text class="terms">《用户协议》</text>
           <text class="terms">《隐私政策》</text>
-          <!-- <text class="terms">《儿童/青少年个人信息保护规则》</text> -->
         </text>
       </view>
     </view>
@@ -252,6 +253,17 @@ export default {
 .container {
   padding: 0 40rpx;
   margin: 0 auto;
+  text-align: center; /* 设置容器内文本水平居中 */
+}
+.header {
+  width: 100%; /* 头部宽度占据整个屏幕 */
+  max-width: 700px; /* 设置最大宽度 */
+  margin: 20px auto; /* 上下居中 */
+}
+
+.logo {
+  display: block;
+  margin: 0 auto; /* 实现水平居中对齐 */
 }
 .login-form-wrap {
   margin-top: 200rpx;
@@ -266,12 +278,13 @@ export default {
     text-align: right;
     font-size: 24rpx;
     padding: 20rpx 0 20rpx 0;
+    margin-right: -22rpx;
   }
   .user-agreement {
     display: flex;
     padding: 0 10rpx;
     .user-agreement-text {
-      font-size: 24rpx;
+      font-size: 26rpx;
       color: $uni-text-color-grey;
       margin-top: 20rpx;
       margin-left: 20rpx;