uniapp授权小程序隐私弹窗效果demo(整理)


bash 复制代码
9月15号前要配置这句话
"__usePrivacyCheck__": true,

必设项:
1、开通调用微信接口-比如获取当前位置
2、更新隐私说明


官方"小程序隐私协议开发指南"文档

1、开通调用微信接口-比如获取当前位置

2、更新隐私说明

bash 复制代码
<template>
<view class="dealBox">
	<view class="txtBox padding10">
		<!-- 查看协议 -->
		在您使用施工现场五星计划小程序之前,请仔细阅读
		<text class="goToPrivacy" @click="handleOpenPrivacyContract">{{dealTxt}}</text>
		如您同意{{dealTxt}},请点击"同意"开始使用[施工现场五星计划]。如您拒绝,将无法进入。
	</view>

	<view class="row-me row-center space-between btnBox margin-top20">
		<view class="width100Percent height80 refuseBtn" @click="rejectClick">拒绝</view>
		<button id="agree-btn" class="wxagree-btn" open-type="agreePrivacyAuthorization"
			@agreeprivacyauthorization="handleAgreePrivacyAuthorization">
			同意
		</button>
	</view>
</view>
</template>
<script>
export default {
	components: {

	},
	data() {
		return {
			showBtn: '',//判断有没有进行授权
			dealTxt: '', //返回协议名称
		}
	},
	// 页面加载
	onLoad(e) {
		// this.$refs.pop.show();
		var that = this;
		wx.getPrivacySetting({
			success: res => {
				console.log(res, 'resres--隐私协议-getPrivacySetting')
				this.showBtn = res.needAuthorization;

				// 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
				if (res.needAuthorization == true) {
					this.dealTxt = res.privacyContractName;
				} else {
					// this.showPrivacy = false;
					// this.dealTxt = '测试测试测试测试测试'
					// 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用隐私接口
				}
			},
			fail: () => {},
		})
	},
	// 方法
	methods: {
		// 点击拒绝-拒绝就是没有授权同意协议
		rejectClick() {
			this.showBtn = true;
		},
		// 点击同意
		handleAgreePrivacyAuthorization() {
			console.log('同意')
			var that = this;
			// 用户点击同意按钮后
			wx.requirePrivacyAuthorize({
				success: (res) => {
					// 用户同意授权
					// 继续小程序逻辑
					that.showBtn = false;
					that.resolvePrivacyAuthorization({
						buttonId: 'agree-btn',
						event: 'agree'
					})
				},
				fail: (res) => {
					console.log(res, '22222222')
				}, // 用户拒绝授权
				complete: (res) => {
					console.log(res, '33333333333333')
				}
			})
		},
		// 点击查看协议
		handleOpenPrivacyContract() {
			console.log('点击了隐私协议')
			// 打开隐私协议页面
			wx.openPrivacyContract({
				success: res => {
					console.log('openPrivacyContract success', res)
				},
				fail: res => {
					console.error('openPrivacyContract fail', res)
				}
			})
		},
	}
}
</script>
相关推荐
00后程序员张18 小时前
苹果App Store上架指南:费用、原理与步骤详解
android·ios·小程序·https·uni-app·iphone·webview
特创数字科技1 天前
【uni-app x】告别系统相机限制!三端通用自定义相机组件:任意布局、静默拍照、录像、水印叠加、连拍回图一次搞定
前端·数码相机·uni-app
Martin -Tang1 天前
uniapp app嵌套webview 弹窗方式
android·ios·uni-app
郑州光合科技余经理2 天前
同城电商系统:库存变更怎么同步到订单
java·开发语言·前端·后端·uni-app·php·ai编程
CHB2 天前
一文讲透原生渲染和自渲染
flutter·react native·uni-app
码兄科技8 天前
24小时自助健身房系统软件开发实战指南:功能设计与部署方案
java·spring boot·uni-app
2501_916007478 天前
苹果商店iOS应用上架费用全面解析:开发者计划与审核费用计算
android·ios·小程序·https·uni-app·iphone·webview
2501_916008898 天前
如何实现iOS App代码混淆:SwiftShield使用指南
android·ios·小程序·https·uni-app·iphone·webview
2501_916008898 天前
怎么用 Godot 导出 iOS 应用并上架 App Store?签名字段该填什么?
android·ios·小程序·https·uni-app·iphone·webview
郑州光合科技余经理9 天前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程