<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>
微信网页授权登录
最新推荐文章于 2024-04-06 02:35:45 发布