weChatOffAcc.vue 3.37 KB
<template>
  <view class="container">
    <div>微信公众号-授权认证中</div>
  </view>
</template>

<script>

const {Base64} = require('js-base64');
export default {
  data() {
    return {
      currentModeIndex: 2, //1账号密码 2验证码 3忘记密码
      inputType: 'password',
      codeDisabled: false,
      codeTips: '',
      formData: {
        mobile: '',
        password: '',
      },
      flag: true,
      rules: {
        mobile: [{
          type: 'string',
          required: true,
          message: '请输入手机号',
          trigger: ['blur', 'change']
        },
          // {
          //   // 自定义验证函数,见上说明
          //   validator: (rule, value, callback) => {
          //     // 上面有说,返回true表示校验通过,返回false表示不通过
          //     // uni.$u.test.mobile()就是返回true或者false的
          //     return uni.$u.test.mobile(value)
          //   },
          //   message: '手机号码不正确',
          //   // 触发器可以同时用blur和change
          //   trigger: ['change', 'blur']
          // }
        ],
        password: {
          type: 'string',
          min: 4,
          max: 16,
          required: true,
          message: '密码长度4-16位密码',
          trigger: ['blur', 'change']
        },
        code: {
          type: 'integer',
          len: 4,
          required: true,
          message: '请填写4位验证码',
          trigger: ['blur', 'change']
        }
      },
      isAutoLogin: [], //是否自动登录
      hasForgot: false, //忘记密码
      loginText: "短信登录",
      btnText: "发送验证码",
      checkValue: ['agree'],
      accountTile: "短信验证码登录",
      accountTip: "未注册手机号登录后自动生成账号",
      accountPlaceholder: "请输入手机号",
      appid: this.$config.appid,
      openId: null
    }
  },
  created() {
    this.handleAuthorization();
  },
  methods: {
    handleAuthorization() {
      console.log("================================");
      this.code = "";
      let local = window.location.href;
      console.log("local", local);
      console.log("this.code", this.code);
      let scope = "snsapi_base"; //静默授权 用户无感知
      console.log("this.scope", scope);
      this.code = this.getUrlCode().code;
      console.log("this.code", this.code);

      this.getOpenId(this.code);
      console.log("================================");
    },
    getOpenId(code) {
      let that = this;
      this.$api.loginApi.getWechatOpenId(code).then(res => {
        console.log("11111that.res ", res);
        if (res.status == 1000) {
          that.openId = res.data.openId;
          console.log("that.openId ", that.openId);
        } else {
          Toast(res.message);
        }
      });

    },
    getUrlCode() {
      let fullUrl = window.location.href;
      console.log("fullUrl ", fullUrl);
      let theRequest = new Object();
      if (fullUrl.indexOf("?") != -1) {
        var temp = fullUrl.split("?");
        let str = temp[1];
        let strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
          theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
        }
      }
      return theRequest;
    },
  }
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
</style>