uniapp微信小程序用户隐私保护指引弹窗组件

news/2024/7/20 3:46:30 标签: uni-app, 微信小程序, 小程序
<template>
	<view v-if="showPrivacy" :class="privacyClass">
		<view :class="contentClass">
			<view class="title">用户隐私保护指引</view>
			<view class="des">
				感谢您选择使用我们的小程序,我们非常重视您的个人信息安全和隐私保护。使用我们的产品前,请您仔细阅读“
				<text class="link" @tap="openPrivacyContract">{{privacyContractName}} </text>”,
				如您同意此隐私保护指引,请点击同意按钮,开始使用此小程序,我们将尽全力保护您的个人信息及合法权益,感谢您的信任!<br />
			</view>
			<view class="btns">
				<button class="item reject" @tap="exitMiniProgram">拒绝</button>
				<button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization"
					@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'PrivacyPopup',
		data() {
			return {
				isRead: false,
				showPrivacy: false,
				privacyContractName: '',
				resolvePrivacyAuthorization: null,
			};
		},
		props: {
			position: {
				type: String,
				default: 'center'
			}
		},
		computed: {
			privacyClass() {
				return this.position === 'bottom' ? 'privacy privacy-bottom' : 'privacy';
			},
			contentClass() {
				return this.position === 'bottom' ? 'content2 content-bottom' : 'content2';
			}
		},
		mounted() {
			if (wx.onNeedPrivacyAuthorization) {
				wx.onNeedPrivacyAuthorization((resolve) => {
					this.resolvePrivacyAuthorization = resolve;
				});
			}

			if (wx.getPrivacySetting) {
				wx.getPrivacySetting({
					success: (res) => {
						console.log(res, 'getPrivacySetting');
						if (res.needAuthorization) {
							this.privacyContractName = res.privacyContractName;
							this.showPrivacy = true;
						}
					},
				});
			}
		},

		methods: {
			openPrivacyContract() {
				wx.openPrivacyContract({
					success: () => {
						this.isRead = true;
					},
					fail: () => {
						uni.showToast({
							title: '遇到错误',
							icon: 'error',
						});
					},
				});
			},
			exitMiniProgram() {

				wx.exitMiniProgram();

			},
			handleAgreePrivacyAuthorization() {
				this.showPrivacy = false;
				if (typeof this.resolvePrivacyAuthorization === 'function') {
					this.resolvePrivacyAuthorization({
						buttonId: 'agree-btn',
						event: 'agree',
					});
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.privacy {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background: rgba(0, 0, 0, .5);
		z-index: 9999999;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.privacy-bottom {
		align-items: flex-end;
	}

	.content2 {
		width: 632rpx;
		padding: 48rpx;
		box-sizing: border-box;
		background: #fff;
		border-radius: 16rpx;
	}

	.content-bottom {
		position: absolute;
		bottom: 0;
		width: 100%;
		padding: 36rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		border-radius: 16rpx 16rpx 0 0;
	}

	.content2 .title {
		text-align: center;
		color: #333;
		font-weight: bold;
		font-size: 32rpx;
	}

	.content2 .des {
		font-size: 26rpx;
		color: #666;
		margin-top: 40rpx;
		text-align: justify;
		line-height: 1.6;
	}

	.content2 .des .link {
		color: #07c160;
		text-decoration: underline;
	}

	.btns {
		margin-top: 48rpx;
		margin-bottom: 12rpx;
		display: flex;
	}

	.btns .item {
		width: 200rpx;
		height: 72rpx;
		overflow: visible;
		display: flex;
		align-items: center;

		justify-content: center;
		/* border-radius: 16rpx; */
		box-sizing: border-box;
		border: none !important;
	}

	.btns .reject {
		background: #f4f4f5;
		color: #07c160;
		font-size: 14px;
		font-weight: 300;
		margin-right: 16rpx;
		width: 240rpx;
		&::after{
			border: none;
		}
	}

	.btns .agree {
		width: 240rpx;
		background: #07c160;
		color: #fff;
		font-size: 16px;
		&::after{
			border: none;
		}
	}

	.privacy-bottom .btns .agree {
		width: 240rpx;

	}
</style>

然后在用到的页面进行引入

<template>
	<popup ref="privacyComponent" position="bottom"  />
</template>

<script setup>
	import popup from '/components/privacy-popup.vue'
</script>


http://www.niftyadmin.cn/n/5026753.html

相关文章

hive 中正则表表达式使用

一 概念 概念&#xff1a;正则表达式&#xff08;Regular Expression&#xff09;&#xff0c;又称规则表达式&#xff0c;是记录文本规则的代码。通常被用来检索、替换那些符合某个模式(规则)的文本。 特性&#xff1a;最初是由Unix中的工具软件&#xff08;例如sed和grep&a…

【多线程案例】单例模式

单例模式是设计模式的一种&#xff0c;先谈谈什么是设计模式&#xff1f; 大家应该都知道棋谱、剑谱之类的&#xff0c;就是一些“高手”在经历过长期的累计之后&#xff0c;更具经验写出的具有固定套路的处理“方法”&#xff0c;只要按照这个套路来&#xff0c;在对局之中必然…

如何选择合适的预测性维护工具和平台

随着技术的不断进步&#xff0c;预测性维护&#xff08;Predictive Maintenance&#xff0c;简称PdM&#xff09;已经成为许多企业提高生产效率、减少停机时间和维护成本的核心策略。然而&#xff0c;选择适合自己业务需求的PdM工具和平台可能并不容易。本文将为您提供一些关键…

基于STM32CUBEMX驱动TOF模块VL53l0x(3)----驱动多个VL53L0X

基于STM32CUBEMX驱动TOF模块VL53l0x----3.驱动多个VL53L0X 概述视频教学样品申请修改设备地址配置VL53L0X主程序测试结果 概述 在本章中&#xff0c;我们将探讨如何同时驱动多个VL53L0X传感器进行距离测量。我们将介绍如何有效地管理多个传感器之间的通信和控制&#xff0c;以…

负载均衡算法介绍及应用连接池负载不均问题分析

在分布式系统架构下&#xff0c;为了满足高并发和高扩展性的要求&#xff0c;负载均衡设备得以广泛的使用。结合应用连接池的配置&#xff0c;在实际使用过程中可能会出现负载不均的问题。本文简单介绍了负载均衡算法、Druid连接池配置以及连接池负载不均的问题分析及优化方法。…

每天学一个MySQL函数(一):CONCAT

MySQL CONCAT() 函数 MySQL CONCAT() 函数用来按顺序拼接指定的 2 个或多个字符串&#xff0c;并返回拼接后的字符串。如果您需要使用分隔符连接多个字符串&#xff0c;请您使用 CONCAT_WS() 函数。 如果拼接的参数中一个为 NULL, 则返回 NULL。 CONCAT() 语法 这里是 MySQ…

php+mysql实现补齐24小时时间段同时赋值0的后端解决方案

javascript对象数据合并实现补齐24小时时间段同时赋值0的解决方案(1)javascript对象数据合并实现补齐24小时时间段同时赋值0升级版解决方案(2) 项目需求 在php中使用mysql生成 arr [{"dataKey": "00","totalTrans": "4","tot…

【chrome扩展开发】消息通讯之onMessage消息监听

前言 chrome.runtime.onMessage.addListener 是 Chrome 扩展程序中用于监听其他模块发送的消息并做出响应的 API 当从扩展进程 (by runtime.sendMessage) 或内容脚本 (by tabs.sendMessage)发送消息时触发 语法 chrome.runtime.onMessage.addListener(callback: function, )ca…