qingyiay
2023-05-30 4b74ae71c84d7c3a2fcc83d1ef75f11f8f8c05e0
pages/login/login.vue
@@ -5,28 +5,52 @@
      <user-password :btnText="0" />
      <!-- 微信openid登录 -->
      <view class="loginBtn">
         <u-button class="button" @click.stop="beforeLoginEvent" :disabled="btnLoading" :loading="btnLoading" type="primary" text="微信一键登录"></u-button>
         <u-button class="button"
            @click.stop="beforeLoginEvent"
            :disabled="btnLoading"
            :loading="btnLoading"
            type="primary"
            text="微信一键登录"></u-button>
      </view>
      <view class="register" @click="registerClick"><text>注册</text></view>
      <view class="register"
         @click="registerClick"><text>注册</text></view>
      <view class="login-bottom-box">
         <view class="copyright">冀中能源无人值守微信小程序</view>
         <view class="copyright">小程序仅供已拥有系统账号特定内部人员使用</view>
      </view>
      <!-- 微信授权前的弹框 -->
      <view class="loginPopup">
         <u-popup :show="loginPopupShow" mode="bottom" @close="closePopup" @open="openPopup" round="10" :safeAreaInsetBottom="true">
         <u-popup :show="loginPopupShow"
            mode="bottom"
            @close="closePopup"
            @open="openPopup"
            round="10"
            :safeAreaInsetBottom="true">
            <view class="popup-warp">
               <view class="body"><text>本小程序,仅供已拥有系统账号特定内部人员登录使用,点击同意即表示您已同意相应信息授权。</text></view>
               <view class="btn">
                  <u-button @click="loginPopupShow = false" type="error" text="不同意" shape="circle" :plain="true"></u-button>
                  <u-button @click="wxLogin" type="error" text="同意" throttleTime="3000" shape="circle"></u-button>
                  <u-button @click="loginPopupShow = false"
                     type="error"
                     text="不同意"
                     shape="circle"
                     :plain="true"></u-button>
                  <u-button @click="wxLogin"
                     type="error"
                     text="同意"
                     throttleTime="3000"
                     shape="circle"></u-button>
               </view>
            </view>
         </u-popup>
      </view>
      <!-- 询问是否绑定微信 -->
      <view class="bindWxModel">
         <u-modal :show="bindWxModelShow" :title="bindWxModelTitle" showCancelButton :content="bindWxContent" @confirm="bindWxConfirm" @cancel="bindWxCancel"></u-modal>
         <u-modal :show="bindWxModelShow"
            :title="bindWxModelTitle"
            showCancelButton
            :content="bindWxContent"
            @confirm="bindWxConfirm"
            @cancel="bindWxCancel"></u-modal>
      </view>
   </view>
</template>
@@ -51,7 +75,7 @@
      userPassword
   },
   methods: {
      ...mapMutations(['setUserTabbar']),
         ...mapMutations(['setUserTabbar', 'changeisLogin']),
      // 访问wx.login,获取code
      beforeLoginEvent() {
         this.loginPopupShow = true;
@@ -74,27 +98,25 @@
      },
      // 登录接口
      apiLogin(code) {
         /**
          * @openid
          * 获取微信用户openid,微信一键登录暂无相关接口,用于测试呼叫客服功能
          */
            // 获取微信用户openid,微信一键登录暂无相关接口,用于测试呼叫客服功能
         uni.showLoading({
            title: '加载中...'
         });
         // wx.request({
         //    url: `https://api.weixin.qq.com/sns/jscode2session?appid=wx4a62fc1684c429a9&secret=ee90afe376cdcec2fdd947c0a4db961a&js_code=${code}&grant_type=authorization_code`,
         //    success(res) {
         //       uni.setStorageSync('openid', res.data.openid);
            wx.request({
               url: `https://api.weixin.qq.com/sns/jscode2session?appid=wx4a62fc1684c429a9&secret=ee90afe376cdcec2fdd947c0a4db961a&js_code=${code}&grant_type=authorization_code`,
               success(res) {
                  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);
                  // 登陆成功,存储相关信息
                  setToken(res.access_token);
                  setRefreshToken(res.refresh_token);
@@ -145,6 +167,7 @@
<style lang="scss">
@import 'index.scss';
.login {
   // height: 100vh;
   // display: flex;
@@ -168,10 +191,12 @@
   // }
   .loginBtn {
      margin-top: vww(20);
      .u-button {
         width: 80%;
      }
   }
   .logo {
      width: 80%;
      font-size: 64rpx;
@@ -253,13 +278,16 @@
               .popup-warp {
                  height: vww(200);
                  padding: vww(10) vww(20);
                  .body {
                     width: 100%;
                     height: 70%;
                  }
                  .btn {
                     display: flex;
                     justify-content: space-between;
                     .u-button {
                        width: 40%;
                     }