当前位置: 首页 > news >正文

uniapp开发:首次进入 App 弹出隐私协议窗口

前言:在移动应用开发中,隐私协议弹窗是一个非常重要的功能。它不仅符合法律法规的要求(如 GDPR、CCPA 等),还能增强用户对 App 的信任感。本文将介绍如何在 Uniapp 开发的 App 中实现“首次进入弹出隐私协议窗口,用户确认后进入,否则退出 App”的功能。

实现思路:一、自定义协议弹框组件,用户点击同意按钮时,存储flag值为true;二、引入到登录页面,首次进入页面判断flag值,ture则代表非首次进入,无需弹出,无或者false则需要弹窗;

一、自定义组件:

(1)根目录新建components文件夹,新建组件privacy-agreement,如图:

在这里插入图片描述
(2)组件内部代码实现 privacy-agreement.vue:

<template><u-popup :show="show" mode="center" bgColor="transparent" zIndex="10077"><view class="privacy_con"><view class="title">用户隐私政策</view><view class="content_privacy"><text>欢迎使用小绿人APP!为了更好的向您提供服务,我们需要收集您的相关信息,在您使用APP前,请务必审慎阅读、充分理解“用户隐私政策”和“CFCA数字证书服务协议”各条款,您可阅读</text><navigator url="/pages/agreement/index?agreement=1" class="navigator">《用户服务协议》</navigator><text></text><navigator url="/pages/agreement/index?agreement=2" class="navigator">《隐私权政策》</navigator><text>了解详细信息。如果您同意,请点击下面按钮开始接受我们的服务。</text></view><view class="btn"><button class="no_btn" @click="exitapply">暂不同意</button><button class="yes_btn" @click="agreeEnter">同意并接受</button></view></view></u-popup>
</template><script>
export default {name: 'privacy-agreement',data() {return {show: false,};},methods: {open() {this.show = true;},// 退出应用exitapply(){if (plus.os.name.toLowerCase() === 'android') {plus.runtime.quit(); // 安卓退出应用console.log('安安卓');} else { console.log('ios');plus.ios.import('UIApplication').sharedApplication().performSelector('exit');  // iOS退出应用}},// 同意并进入应用agreeEnter(){uni.setStorageSync("firstLaunchFlag", true)plus.runtime.agreePrivacy()this.show = false;}},
};
</script><style lang="scss" scoped>
.privacy_con{width: 630rpx;height: 512rpx;background: linear-gradient(to bottom, #f9f2e7, #ffffff);border-radius: 32rpx;.title{width: 630rpx;height: 100rpx;color: #422206;font-size: 34rpx;font-weight: 600;line-height: 100rpx;text-align: center;}.content_privacy{width: 100%;height: 252rpx;padding: 0 32rpx;color: #232323;font-size: 26rpx;margin-top: 20rpx;margin-bottom: 24rpx;line-height: 40rpx;.navigator {color: #ED9B1C;font-weight: 500;display: inline-block;}}.btn{height: 100rpx;display: flex;align-items: center;justify-content: space-evenly;button{width: 262rpx;height: 88rpx;border-radius: 78rpx 78rpx 78rpx 78rpx;font-weight: bold;font-size: 28rpx;line-height: 88rpx;text-align: center;}.no_btn{background: #FAFAF9;color: #898B96;}.yes_btn{background-color: #E2AC59;color: #FFFFFF;}}
}
</style>
二、引入到登录页或者首页(打开app进入的第一个页面)
<template><view><view class="">登录页或者首页其他内容。。。。。。。</view><!-- 首次进入app 隐私协议弹框 --><privacy-agreement ref="privacyPop"></privacy-agreement></view>
</template>
<script>data() {return {}},methods:{},onLoad() {// 首次进入app, 展示隐私协议// #ifdef APP-PLUS | H5let firstLaunchFlag = uni.getStorageSync("firstLaunchFlag");console.log("firstLaunchFlag", firstLaunchFlag);if (firstLaunchFlag) {return}else{uni.showLoading({mask: true})setTimeout(()=>{uni.hideLoading()this.$refs["privacyPop"].open()}, 300)}// #endif},
</script>

效果图:

在这里插入图片描述

Tips:组件内的样式和文案可以根据自己的需求改变~

http://www.lryc.cn/news/538815.html

相关文章:

  • 执行pnpm run dev报错:node:events:491 throw er; // Unhandled ‘error‘ event的解决方案
  • OpenCV机器学习(4)k-近邻算法(k-Nearest Neighbors, KNN)cv::ml::KNearest类
  • JVM中的线程池详解:原理→实践
  • SNARKs 和 UTXO链的未来
  • JavaScript设计模式 -- 外观模式
  • 百达翡丽(Patek Philippe):瑞士制表的巅峰之作(中英双语)
  • 阿里云一键部署DeepSeek-V3、DeepSeek-R1模型
  • 分享一款AI绘画图片展示和分享的小程序
  • 【练习】【双指针】力扣热题100 283. 移动零
  • QT 互斥锁
  • 什么是算法的空间复杂度和时间复杂度,分别怎么衡量。
  • VMware Workstation 17.0 Pro创建虚拟机并安装Ubuntu22.04与ubuntu20.04(双版本同时存在)《包含小问题总结》
  • Windows 10 ARM工控主板CAN总线实时性能测试
  • 如何在不依赖函数调用功能的情况下结合工具与大型语言模型
  • 【Linux AnolisOS】关于Docker的一系列问题。尤其是拉取东西时的网络问题,镜像源问题。
  • 【Elasticsearch】Mapping概述
  • GPT-4o悄然升级:能力与个性双突破,AI竞技场再掀波澜
  • 如何选择合适的超参数来训练Bert和TextCNN模型?
  • C# SpinLock 类 使用详解
  • 【linux】在 Linux 上部署 DeepSeek-r1:32/70b:解决下载中断问题
  • 机器学习所需要的数学知识【01】
  • 4.【线性代数】——矩阵的LU分解
  • 【清晰教程】本地部署DeepSeek-r1模型
  • Spring Cloud工程搭建
  • 使用Redis实现分布式锁,基于原本单体系统进行业务改造
  • 【MediaTek】 T750 openwrt-23.05编 cannot find dependency libexpat for libmesode
  • CHARMM-GUI EnzyDocker: 一个基于网络的用于酶中多个反应状态的蛋白质 - 配体对接的计算平台
  • c# 2025/2/17 周一
  • vite【详解】常用配置 vite.config.js / vite.config.ts
  • 最新智能优化算法: 阿尔法进化(Alpha Evolution,AE)算法求解23个经典函数测试集,MATLAB代码