uinapp微信小程序隐私政策授权

🚀 隐私弹窗效果图:

1、启用隐私相关功能在manifest.json文件中配置 usePrivacyCheck: true
javascript 复制代码
"mp-weixin" : {
    "__usePrivacyCheck__" : true,
},
2、创建组件
javascript 复制代码
<template>
	<view>
		<!-- 隐私政策弹窗 -->
		<uni-popup ref="popup">
			<view class="popup-wrap">
				<view class="pop-title">用户隐私保护提示</view>
				<view class="popup-txt">
					感谢您使用本小程序,在使用前您应当阅读井同意
					<text class="blue-color" @click="handleOpenPrivacyContract">{{privacyContractName}}</text>
					,当点击同意并继续时,即表示您已理解并同意该条款内容,该条款将对您产生法律约束力;如您不同意,将无法继续使用小程序相关功能。
				</view>
				<view class="popup-bot">
					<button id="disagree-btn" type="default" @click="handleDisagree">不同意</button>
					<button id="agree-btn" type="primary" open-type="agreePrivacyAuthorization"
						@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意并继续</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
 
<script>
	export default {
		name: "privacyPopup",
		data() {
			return {
				privacyContractName: "" //协议名称
			};
		},
		mounted() {
			this.checkPrivacy()
		},
		methods: {
			// 判断是否授权协议
			checkPrivacy() {
				return new Promise((resolve,reject) => {
					uni.getPrivacySetting({
						success: res => {
							if (res.needAuthorization) {
								this.privacyContractName = res.privacyContractName;
								this.$refs.popup.open('center')
							} else {
								resolve(res)
							}
						},
						fail: (err) => {
							reject(err)
						}
					})
				})
			},
			// 关闭协议
			handleDisagree(e) {
				this.$refs.popup.close()
			},
			handleAgreePrivacyAuthorization(res) {
				// 用户同意隐私协议事件回调
				// 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
				this.$refs.popup.close()
                //通知父组件
				this.$emit("agreePrivacy")
			},
			handleOpenPrivacyContract() {
				// 打开隐私协议页面
				uni.openPrivacyContract({
					success: () => {}, // 打开成功
					fail: () => {}, // 打开失败
					complete: (res) => {
						console.log(res, "openPrivacyContract complete");
					}
				})
			},
		}
	}
</script>
 
<style lang="scss" scoped>
	.popup-wrap {
		width: 540upx;
		box-sizing: border-box;
		padding: 42upx;
		background: white;
		border-radius: 30upx;
		.pop-title {
			text-align: center;
			font-size: 31upx;
			color: #000;
			font-weight: bold;
			margin-bottom: 20upx;
		}
 
		.blue-color {
			color: rgba(39, 152, 240, 1);
		}
 
		.popup-txt {
			line-height: 48upx;
			font-size: 28upx;
		}
 
		.popup-bot {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 30upx;
			>button {
				color: #FFF;
				font-size: 26rpx;
				font-weight: 500;
				line-height: 80rpx;
				width: 46%;
				text-align: center;
				height: 80rpx;
				border-radius: 16rpx;
				border: none;
				background: #07c160;
			}
			>button:nth-of-type(1){
			  color: #07c160;
			  background: #f2f2f2;
			}
		}
	}
</style>
3、组件使用
javascript 复制代码
<privacyPopup @agreePrivacy="执行同意协议后的逻辑"></privacyPopup>

🚀 扩展:

因小程序中各个地方都会涉及到授权问题,依次引入组件过繁琐

1、可以将组件放置App.vue页面

2、通过vuex进入监听全局是否需要弹窗授权,可利用vux state变量进行触发

3、写一个公共方法判断是否授权协议去设置vuex即可

相关推荐
眨眼猫会务智能体13 分钟前
眨眼猫会务智能体会务系统的服务响应怎么样?出问题多久有人接?
安全·小程序·会务
微订校园外卖平台20 分钟前
校园跑腿小程序上线:四端架构与校园外卖系统履约链路拆解
小程序·架构·外卖系统·本地生活·微订
拖孩1 小时前
AI 时代,个人开发者到底能不能靠一个小程序赚到钱
前端·后端·微信小程序
m0_5873830013 小时前
广州 24 小时自助健身房解决方案技术实现与实战指南
java·spring·小程序·架构·需求分析
迪飞特科技17 小时前
智慧物业平台实战:Spring Boot 整合小程序实现报修巡检费用全流程
spring boot·后端·小程序
微笑的曙光20 小时前
第八期 · 情绪闯关挑战盒:一个「无惩罚」成就系统的数据建模
java·微信小程序
m0_587383001 天前
无人自助拼豆系统从需求分析到落地部署全流程实战开发指南
java·经验分享·后端·struts·小程序·架构·需求分析
小小王app小程序开发1 天前
DIY水晶小程序玩法开发功能分析
小程序
andrsted1 天前
练题簿在线免费刷题:顺序续练、优先新题与题型筛选,让复习一轮轮推进
微信小程序·小程序·刷题
拖孩1 天前
全程 AI 写的小程序,刚接上会员虚拟支付,上线第二天就有人真金白银买单了|双签名、定价、iOS 的坑我全踩了一遍
前端·后端·微信小程序