1、 ios白屏问题
tsconfig.json 参数useDefineForClassFields 改为false可解决这个问题
2、 禁止查看网址源
index.html 下添加
<script type="text/javascript">
/**
* @param {Object} e禁止查看网址源
*/
document.body.addEventListener('touchmove', function (e) {
e.preventDefault();
}, { passive: false });
</script>
3、static文件配置动态url window.baseurls = 'http://10.74.106.26:8090/';
// 开发、测试环境地址
4、获取手机验证码
<template>
<view style="width: 220rpx;text-align: right;" @click="getPhoneCode()">{{Verification}}</view>
</template>
<script>
data() {
return {
Verification: "获取验证码"
}
},
methods: {
//获取手机验证码
getPhoneCode: function() {
if (!/^1[3456789]\d{9}$/.test(this.supplierPhone)) {
uni.showToast({
title: '请检查联系电话是否填写正确!',
icon: 'none'
})
} else {
this.getSmsCode();
}
},
/**
* 获取手机验证码
*/
getSmsCode: function() {
sendSmsCode(this.supplierPhone).then(res => {
if (res.data.resultCode == 1) {
this.countDownTimer();
} else {
uni.showToast({
title: res.data.resultMsg,
icon: 'none'
})
}
}).catch(err => {
console.log(err)
})
},
//获取验证码倒计时
countDownTimer: function() {
this.Verification= this.count + "秒后重新获取";
this.timer = setInterval(() => {
this.count -= 1;
if (this.count > 0) {
this.Verification= this.count + "秒后重新获取";
} else {
this.Verification= "获取验证码";
this.count = 60;
clearInterval(this.timer);
}
}, 1000);
}
}
</script>
5、获取微信code授权
wxAuthorize() {
let link = window.location.href;
let params = this.getUrlParam('code'); // 地址解析
console.log("code:", params);
// 如果拿到code,调用授权接口,没有拿到就跳转微信授权链接获取
if (params) {
console.log("获取到code");
getOpenId(params).then(res => {
this.$store.commit('updateUid', res.data.data);
}).catch(err => {
console.log(err)
})
} else {
console.log("没有code");
let appid = 'wx534a5132g24118k1'; //修改为你的appid
//1.使用encodeURIComponent以及JSON.stringify()方法对对象进行字符串化和编码,这样可以控制url参数的长度,参考示例代码(uni-app书写方式,微信小程序自己改。)
let uri = encodeURIComponent(link);
//2.接受信息的页面使用JSON.parse()以及decodeURIComponent()接收和解码参数。
//snsapi_base //snsapi_base scope = snsapi_base(不弹出授权页面,直接跳转,只能获取用户 openid )。
//snsapi_userinfo 弹出
let authURL =
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`;
window.location.href = authURL;
}
},
getUrlParam(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
let url = window.location.href.split('#')[0]
let search = url.split('?')[1]
if (search) {
var r = search.substr(0).match(reg)
if (r !== null) return unescape(r[2])
return null
} else {
return null
}
}
小白一个,一起学习哈