jiangping
2025-07-16 8ee015485bfd69afcc276e84a2998c64b0256458
small-program/pages/login/login.vue
@@ -2,21 +2,56 @@
   <view class="box">
      <view class="box-title">欢迎使用近快</view>
      <view class="box-tips">请登录</view>
      <view class="box-btn">手机号一键登录</view>
      <view class="box-btn" >
         <button  class="box-btn"  v-if="agree" open-type="getPhoneNumber" @getphonenumber="getPhone" >手机号一键登录</button>
          <button  class="box-btn"  v-if="!agree" @click="tipAgree">手机号一键登录</button>
      </view>
      <view class="box-footer">
         <image src="/static/icon/ic_notagree@2x.png" mode="widthFix"></image>
         <!-- <image src="/static/icon/ic_agree@2x.png" mode="widthFix"></image> -->
         <text>我已阅读并同意《用户协议》,《隐私协议政策》</text>
         <image src="/static/icon/ic_notagree@2x.png" mode="widthFix" v-if="!agree" @click="agreeDo"></image>
         <image src="/static/icon/ic_agree@2x.png" mode="widthFix" v-if="agree" @click="agreeDo"></image>
         <text @click="agreeDo">我已阅读并同意《用户协议》,《隐私协议政策》</text>
      </view>
   </view>
</template>
<script>
import { mapState } from 'vuex'
   export default {
      computed: {
         ...mapState(['userInfo','openid'])
      },
      data() {
         return {
         };
            agree:false
         }
      },
      methods: {
         agreeDo(){
            this.agree = !this.agree
         },
         tipAgree(){
            uni.showToast({ title: '请先已阅读并同意《用户协议》,《隐私协议政策》', icon: 'error', duration: 2000 });
         },
         getPhone(e) {
            console.log(e)
            if(!this.agree ){
               return
            }
            if (e.detail.errMsg !== 'getPhoneNumber:ok') {
               uni.showToast({ title: '获取授权手机号失败', icon: 'error', duration: 2000 });
               return
            }
            var that = this;
            that.$u.api.wxAuthPhone({
               code: e.detail.code,
               openid: that.openid||''
            }).then(result => {
               if (result.code === 200) {
                  that.$store.commit('setUserInfo', result.data.member)
                  that.$store.commit('setToken', result.data.token)
                  uni.navigateBack({ delta: 1 });
               }
            })
         }
      }
   }
</script>