uniapp公众号遇到的问题

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
				}
			}

小白一个,一起学习哈

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值