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

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

🚀 隐私弹窗效果图:

在这里插入图片描述

1、启用隐私相关功能在manifest.json文件中配置 usePrivacyCheck: true
"mp-weixin" : {"__usePrivacyCheck__" : true,
},
2、创建组件
<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、组件使用
<privacyPopup @agreePrivacy="执行同意协议后的逻辑"></privacyPopup>

🚀 扩展:

因小程序中各个地方都会涉及到授权问题,依次引入组件过繁琐
1、可以将组件放置App.vue页面
2、通过vuex进入监听全局是否需要弹窗授权,可利用vux state变量进行触发
3、写一个公共方法判断是否授权协议去设置vuex即可

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

相关文章:

  • 使用Java工作流简单介绍
  • 数字媒体技术基础之:ICC 配置文件
  • 解析SD-WAN组网方式及应用场景,全面了解典型案例
  • 中小学智慧校园电子班牌管理系统源码
  • 日常踩坑-[sass]Error: Expected newline
  • UI设计感蓝色商务数据后台网站模板源码
  • 二、计算机组成原理与体系结构
  • MySQL-sql的优化
  • 一致性哈希在分库分表的应用
  • PostCSS通过px2rem插件和lib-flexible将px单位转换为rem(root em)单位实现大屏适配
  • 什么是缓冲区溢出?
  • 论文浅尝 | ChatKBQA:基于微调大语言模型的知识图谱问答框架
  • 软件测试的目的---防范项目风险
  • 自己动手写编译器:创建由 C 语言编译而成的语法解析器
  • 接口设计-增删改查
  • 持续持续集成部署-k8s-配置与存储-配置管理:Secret 的应用
  • ZYNQ7020开发(一):开发环境搭建
  • Spring Boot插件化开发概念原理及实现
  • Ps:PSDT 模板文件
  • Linux-----nginx的简介,nginx搭载负载均衡以及nginx部署前后端分离项目
  • presto插件机制揭秘:探索无限可能的数据处理舞台
  • acwing算法基础之数据结构--并查集算法
  • k8s:二进制搭建 Kubernetes v1.20
  • SpringBoot系列-1启动流程
  • 【记】一次common模块导入无效的bug
  • 1.Netty概述
  • YOLO目标检测——真实道路车辆检测数据集【含对应voc、coco和yolo三种格式标签】
  • 【Solidity】Solidity中的基本数据类型和复合数据类型
  • Flutter Set存储自定义对象时 如何保证唯一
  • Docker容器中执行throttle.sh显示权限报错:RTNETLINK answers: Operation not permitted