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

封装微信小程序隐私信息授权

隐私 代码 html (modal  组件再后面封装有提供)

<modal isShow="{{show}}"><view class="privacy-auth-dialog"><view class="title">温馨提示</view><view class="content"><view>为切实保护用户隐私,优化用户体验,我们更新了<view class="active" bindtap="openPrivacyContract"> 《 XXXX你的产品名 隐私保护指引》 </view>,您可点击了解详情。</view><view>为向您提供服务,您需要同意更新后的<view class="active" bindtap="openPrivacyContract"> 《XXXX你的产品名 隐私保护指引》 </view>。我们将严格按照法律法规采取一切必要措施,以保障您的信息安全。</view></view><view class="footer"><view class="reject" hover-class="hover-style-3" hover-stay-time="100" bindtap="handleReject">拒绝并退出</view><button id="argee-btn" open-type="agreePrivacyAuthorization" class="btn" bindtap="handleAgree">同意</button></view></view>
</modal>

隐私 代码  css


.privacy-auth-dialog {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);background-color: #fff;border-radius: 32rpx;width: 650rpx;height: auto;overflow: hidden;.title {padding: 32rpx;font-size: 30rpx;font-weight: bold;border-bottom: 1rpx solid #eee;text-align: center;}.content {padding: 32rpx;font-size: 28rpx;word-break: break-all;word-wrap: break-word;.active {display: inline-block;color: $default-color;}border-bottom: 1rpx solid #eee;}.footer {display: flex;justify-content: space-between;align-items: center;.reject {flex: 1;height: 92rpx;line-height: 92rpx;text-align: center;font-size: 32rpx;border-right: 1rpx solid #eee;}.btn {flex: 1;color: $default-color;}}
}// 初始化按钮样式
button::after {border: none !important;
}
button {border-radius: 0;background-color: transparent;padding-top: 0;padding-right: 0;padding-bottom: 0;padding-left: 0;
}

隐私  js 代码

Component({// 组件的属性列表properties: {isDirectHandle: {type: Boolean,value: false,observer(val) {if (!val || !wx.getPrivacySetting) returnwx.getPrivacySetting({success: (res) => {if (res.needAuthorization) {this.showDialog()}},})},},},// 组件的初始数据data: {show: false,},//  全局样式生效options: {addGlobalClass: true,},// 组件的生命周期lifetimes: {// 在组件实例刚刚被创建时执行created() {if (wx.onNeedPrivacyAuthorization) {wx.onNeedPrivacyAuthorization((resolve) => {this.resolve = resolvethis.showDialog()})}},// 在组件实例进入页面节点树时执行attached() {},// 在组件在视图层布局完成后执行ready() {},// 在组件实例被从页面节点树移除时执行detached() {},},// 组件的方法列表methods: {showDialog() {this.setData({ show: true })},hideDialog() {this.setData({ show: false })},// 跳转至隐私协议页面。openPrivacyContract() {wx.openPrivacyContract()},// 拒绝handleReject() {this.hideDialog()this.resolve && this.resolve({ event: "disagree" })this.triggerEvent("handlePrivacy", { event: "disagree" })},// 同意handleAgree() {this.hideDialog()this.resolve && this.resolve({ buttonId: "argee-btn", event: "agree" })this.triggerEvent("handlePrivacy", { event: "agree" })},},
})

使用方法


<privacy-auth-dialog isDirectHandle="{{true}}" bind:handlePrivacy="handlePrivacy"></privacy-auth-dialog>// handlePrivacy 会返回用户的操作结果

model 的封装

html 

<view class="container" catch:touchmove="" catch:tap="handleClickMask" wx:if="{{isShow}}"><view catch:tap><slot></slot></view>
</view>

css

.container {position: fixed;top: 0;right: 0;bottom: 0;left: 0;z-index: 10086;animation: showModal ease 0.3s;background: rgba(0, 0, 0, 0.7);
}@keyframes showModal {0% {opacity: 0;}100% {opacity: 1;}
}

js

Component({data: {},properties: {isShow: {type: Boolean,value: false,},canClose: {type: Boolean,value: true,},},observers: {},methods: {handleClickMask() {if (!this.data.canClose) returnthis.setData({isShow: false,})this.triggerEvent("close")},},
})

拿走不谢

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

相关文章:

  • 【C#】FileInfo类 对文件进行操作
  • python中的字符串也是可迭代对象吗?
  • C++ 图像线特征提取【HoughLinesP算法】
  • Stable Diffusion WebUI内存不够爆CUDA Out of memory怎么办?
  • 模板学堂|数据可视化仪表板大屏设计流程梳理
  • 基于Xml方式Bean的配置-Bean的延时加载
  • python之pyQt5实例:Matplotlib的应用
  • 智囊AI-基于 ChatGPT 的 AI 工具产品 你的私人AI助手
  • nginx配置vue前端代理
  • 【C语言】【数据存储】用%u打印char类型?用char存128?
  • git-git命令汇总
  • 自定义实现简易版ArrayList
  • React中的Hooks--useReducer()
  • DM@数理逻辑@命题公式及其赋值@真值表@公式分类
  • HTTP协议(超级详细)
  • leetcode做题笔记135. 分发糖果
  • Oracle数据库体系结构(三)_逻辑结构
  • 在 Python 中计算两个 GPS 点之间的距离
  • 影刀RPA解决WPS不存在的问题
  • vue动态路由切换刷新保留历史路由搜索条件数据
  • 免费:CAD批量转PDF工具,附下载地址
  • 无涯教程-JavaScript - FACT函数
  • UART 协议
  • MySql中分割字符串
  • Ubuntu 22.04安装过程
  • 【算法|虚拟头节点|链表】移除链表元素
  • express静态路由匹配引发的404错误
  • VHOST-SCSI代码分析(4)VHOST KICK机制
  • Docker Volume(存储卷)
  • 【毕设选题】opencv 图像识别 指纹识别 - python