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>
相关推荐
PedroQue9920 小时前
Vue Router 4.x风格导航守卫全面升级
前端·uni-app
Haibakeji1 天前
APP小程序定制开发项目频繁延期?前期规避方法与落地避坑指南
小程序·uni-app·软件需求
anyup1 天前
迁移uni-app x,我是如何让 AI 把我一步步搞崩溃的...
前端·uni-app·trae
2501_916007471 天前
申请 iOS 推送证书并配置 APNs 群发推送教程
android·ios·小程序·https·uni-app·iphone·webview
博客zhu虎康1 天前
uni-app云打包显示编译成功,但是一直没有进入打包队列,后面也一直没反应
uni-app
JavaDog程序狗2 天前
【指南】uni-app微信小程序多环境CI-CD完全指南
ci/cd·uni-app·jenkins
PedroQue992 天前
uni-router v2.1.0 升级:导航守卫全面支持返回值模式
前端·uni-app
2501_915909063 天前
iOS test 测试怎么做?功能、性能、兼容、稳定与安全五类测试指南
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者84 天前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
游戏开发爱好者84 天前
iOS 推送怎么配置,APNs 推送证书、设备库与群发
android·ios·小程序·https·uni-app·iphone·webview