付延余
2023-03-23 1cb780b1762c62751c7f5f26132f3a7aa4ef3e2f
pages/login/login.vue
@@ -2,7 +2,7 @@
   <view class="login">
      <view class="logo">无人值守</view>
      <!--用户名密码登录-->
      <user-password :btnText='0'/>
      <user-password :btnText="0" />
      <!-- 微信openid登录 -->
      <view class="loginBtn">
         <u-button class="button" @click.stop="beforeLoginEvent" :disabled="btnLoading" :loading="btnLoading" type="primary" text="微信一键登录"></u-button>
@@ -39,7 +39,6 @@
export default {
   data() {
      return {
         wxcode: '', // 司机1
         btnLoading: false,
         loginPopupShow: false,
         // 绑定微信模态框
@@ -62,8 +61,7 @@
         uni.login({
            success: res => {
               if (res.code) {
                  this.wxcode = res.code;
                  this.apiLogin();
                  this.apiLogin(res.code);
               } else {
                  uni.showToast({
                     title: '微信登录失败!',
@@ -74,37 +72,18 @@
         });
      },
      // 登录接口
      apiLogin() {
         // apiLoginWx({ code: this.wxcode })
         //    .then(res => {
         //       console.log('请求登录', res);
         //       if (res.msg == '需绑定') {
         //          uni.navigateTo({
         //             url: `/pages/register/register?code=${res.data}`
         //          });
         //       }
         //       if (res.msg == '登录成功') {
         //          uni.setStorageSync('userInfo', res.data);
         //          this.setUserTabbar(res.data.type);
         //          uni.switchTab({
         //             url: '/pages/tabbar-page/index-tabbar/index-tabbar'
         //          });
         //       }
         //    })
         //    .catch(err => {
         //       console.log('错误', err);
         //    });
      apiLogin(code) {
         /**
          * @openid
          * 获取微信用户openid,微信一键登录暂无相关接口,用于测试呼叫客服功能
          */
         uni.showLoading({
            title: '加载中...'
         });
         wx.request({
            url: `https://api.weixin.qq.com/sns/jscode2session?appid=wx4a62fc1684c429a9&secret=ee90afe376cdcec2fdd947c0a4db961a&js_code=${this.wxcode}&grant_type=authorization_code`,
            url: `https://api.weixin.qq.com/sns/jscode2session?appid=wx4a62fc1684c429a9&secret=ee90afe376cdcec2fdd947c0a4db961a&js_code=${code}&grant_type=authorization_code`,
            success(res) {
               let id = res.data.openid;
               uni.setStorageSync('openid', id);
               uni.setStorageSync('openid', res.data.openid);
               uni.showToast({
                  title: '成功获取测试openid',
                  icon: 'none'
@@ -113,6 +92,7 @@
         });
         this.$nextTick(() => {
            apiLoginWx({ code: uni.getStorageSync('openid') }).then(res => {
               uni.hideLoading();
               if (res.code != 1) {
                  this.$u.toast('恭喜您,登录成功!');
                  // 登陆成功,存储相关信息
@@ -135,7 +115,6 @@
               }
            });
         });
         this.loginPopupShow = false;
      },
      bindWxConfirm() {