yangan
2025-03-28 b0e249aa5d69791a5d9b9bec64d4e8897b4bae69
pages/login/login.vue
@@ -2,8 +2,9 @@
   <view class="login">
      <view class="logo">无人值守</view>
      <!--用户名密码登录-->
      <user-password :btnText="0" />
      <user-password :btnText="0"  :userList="userList"/>
      <!-- 微信openid登录 -->
        <!--  #ifdef MP-WEIXIN  -->
      <view class="loginBtn">
         <u-button class="button"
            @click.stop="beforeLoginEvent"
@@ -12,10 +13,13 @@
            type="primary"
            text="微信一键登录"></u-button>
      </view>
        <!--  #endif  -->
         <!--  #ifdef MP-WEIXIN  -->
      <view class="utils-block">
         <view @click="forgetPassword"><text>忘记密码?</text></view>
         <view @click="PrivacyAgreementHandle"><text>新用户注册</text></view>
      </view>
       <!--  #endif  -->
      <view class="login-bottom-box">
         <view class="copyright">冀中能源无人值守微信小程序</view>
@@ -74,10 +78,14 @@
            bindWxContent: '如果已拥有系统账号,可以直接跳转绑定微信页面',
            appid: "",
            secret: "",
            userList:[]
         };
      },
      components: {
         userPassword
      },
      onShow() {
         this.userList=uni.getStorageSync('userList')?JSON.parse(uni.getStorageSync('userList')):[];
      },
      methods: {
         ...mapMutations(['setUserTabbar', 'changeisLogin']),
@@ -114,22 +122,23 @@
            uni.showLoading({
               title: '加载中...'
            });
            wx.request({
               url: `https://api.weixin.qq.com/sns/jscode2session?appid=${this.appid}&secret=${this.secret}&js_code=${code}&grant_type=authorization_code`,
               success(res) {
                  console.log(res, 'openid');
                  uni.setStorageSync('openid', res.data.openid);
                  // uni.showToast({
                  //    title: '成功获取测试openid',
                  //    icon: 'none'
                  // });
               }
            });
            // wx.request({
            //    url: `https://api.weixin.qq.com/sns/jscode2session?appid=${this.appid}&secret=${this.secret}&js_code=${code}&grant_type=authorization_code`,
            //    success(res) {
            //       console.log(res, 'openid');
            //       uni.setStorageSync('openid', res.data.openid);
            //       // uni.showToast({
            //       //    title: '成功获取测试openid',
            //       //    icon: 'none'
            //       // });
            //    }
            // });
            this.$nextTick(() => {
               apiLoginWx({ code: code }).then(res => {
                  if (res.code != 1) {
                     this.$u.toast('登录成功');
                     this.changeisLogin(true);
                     this.getLoginInfo();
                     // 登陆成功,存储相关信息
                     setToken(res.access_token);
                     setRefreshToken(res.refresh_token);
@@ -151,6 +160,8 @@
                     this.$u.toast(res.msg);
                     this.bindWxModelShow = true;
                  }
               }).catch((err) => {
                  this.loginPopupShow = false;
               });
            });
            this.loginPopupShow = false;
@@ -161,6 +172,12 @@
            });
            this.bindWxModelShow = false;
         },
         //记录登录信息
         getLoginInfo(){
            this.$reqPost('setApplogonTime').then((res) => {
            })
         },
         bindWxCancel() {
            this.bindWxModelShow = false;
         },