微信网页授权登录

<template>
  <div class="box">
    <div class="wrap">
      <span>姓名</span>
      <input type="text" v-model="name" class="ipt1" />
    </div>
    <div class="wrap" style="margin-top: 0">
      <span>手机号</span>
      <input type="number" v-model="phone" class="ipt1" />
    </div>
    <button class="btn" @click="login">添加</button>
    <div>
    </div>
  </div>

  <!-- <span>{{ url }}</span> -->
</template>
<script>
import axios from "axios";
import { showToast } from "vant";

export default {
  data() {
    return {
      name: "",
      phone: "",
      admin_id: "",
      code: "",
      url: "",
      isValidPhoneNumber:false
    };
  },
  methods: {
    getUrlParam() {
      const currentUrl = window.location.href;
      // 根据问号 "?" 进行分割,获取查询参数部分
      const query = currentUrl.split("?")[1];
      if (query == undefined) {
        return {};
      }
      // 根据 "&" 进行分割,获取每个键值对
      const params = query.split("&");
      // 创建一个对象来存储键值对
      const values = {};
      // 遍历键值对,分割键和值,并存储到对象中
      for (let i = 0; i < params.length; i++) {
        const keyValue = params[i].split("=");
        const key = keyValue[0];
        const value = keyValue[1];
        values[key] = value;
      }
      return values;
    },
    async login() {
      const regex = /^1[3456789]\d{9}$/;
      this.isValidPhoneNumber = regex.test(this.phone);
      if (this.name == "") {
        showToast({
          message: "名字为空",
          position: "top",
        });
      } else if(this.isValidPhoneNumber==false){
        showToast({
          message: "手机号格式不对",
          position: "top",
        });
      }else{
       window.location.href=`https://zsff01.hiboxes.cn/api/accredit/public_oauth?admin_id=${this.admin_id}&name=${this.name}&mobile=${this.phone}` 
        // let { res } = await axios.post("/api/accredit/public_oauth", {
        //   name: this.name,
        //   mobile: this.phone,
        //   admin_id:this.admin_id,
        //   // code:this.code
        // });
        // console.log(res)
      }
    },
  },
  mounted() {
    let urlParam = this.getUrlParam();
    console.log(urlParam);
    if ("admin_id" in urlParam) {
      this.admin_id = urlParam.admin_id;
      localStorage.setItem("admin_id", this.admin_id);
    } else {
      this.admin_id = localStorage.getItem("admin_id");
    }
    // if ("code" in urlParam) {
    //   localStorage.setItem("code", this.code);
    //   this.code = urlParam.code;
    // } else {
    //   window.location.href =
    //     "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09afc2cd6286241&redirect_uri=https%3A%2F%2Fzsff01.hiboxes.cn%2Faccredit&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect";
    // }
  },
};
</script>
<style scoped lang="scss">
.box {
  width: 375px;

  // height: 812px;
  // background:red;
  .wrap {
    width: 375px;
    height: 80px;
    margin-top: 100px;
    display: flex;
    justify-content: center;
    align-items: center;

    .ipt1 {
      width: 200px;
      height: 30px;
    }

    span {
      margin-right: 30px;
    }
  }

  .btn {
    margin-left: 35px;
    width: 305px;
    height: 50px;
    background: black;
    color: white;
    border: none;
    border-radius: 20px;
    margin-top: 70rpx;
  }
}
</style>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值