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


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

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

    隐私 代码  css

    1. .privacy-auth-dialog {
    2. position: absolute;
    3. top: 50%;
    4. left: 50%;
    5. transform: translate(-50%, -50%);
    6. background-color: #fff;
    7. border-radius: 32rpx;
    8. width: 650rpx;
    9. height: auto;
    10. overflow: hidden;
    11. .title {
    12. padding: 32rpx;
    13. font-size: 30rpx;
    14. font-weight: bold;
    15. border-bottom: 1rpx solid #eee;
    16. text-align: center;
    17. }
    18. .content {
    19. padding: 32rpx;
    20. font-size: 28rpx;
    21. word-break: break-all;
    22. word-wrap: break-word;
    23. .active {
    24. display: inline-block;
    25. color: $default-color;
    26. }
    27. border-bottom: 1rpx solid #eee;
    28. }
    29. .footer {
    30. display: flex;
    31. justify-content: space-between;
    32. align-items: center;
    33. .reject {
    34. flex: 1;
    35. height: 92rpx;
    36. line-height: 92rpx;
    37. text-align: center;
    38. font-size: 32rpx;
    39. border-right: 1rpx solid #eee;
    40. }
    41. .btn {
    42. flex: 1;
    43. color: $default-color;
    44. }
    45. }
    46. }
    47. // 初始化按钮样式
    48. button::after {
    49. border: none !important;
    50. }
    51. button {
    52. border-radius: 0;
    53. background-color: transparent;
    54. padding-top: 0;
    55. padding-right: 0;
    56. padding-bottom: 0;
    57. padding-left: 0;
    58. }

    隐私  js 代码

    1. Component({
    2. // 组件的属性列表
    3. properties: {
    4. isDirectHandle: {
    5. type: Boolean,
    6. value: false,
    7. observer(val) {
    8. if (!val || !wx.getPrivacySetting) return
    9. wx.getPrivacySetting({
    10. success: (res) => {
    11. if (res.needAuthorization) {
    12. this.showDialog()
    13. }
    14. },
    15. })
    16. },
    17. },
    18. },
    19. // 组件的初始数据
    20. data: {
    21. show: false,
    22. },
    23. // 全局样式生效
    24. options: {
    25. addGlobalClass: true,
    26. },
    27. // 组件的生命周期
    28. lifetimes: {
    29. // 在组件实例刚刚被创建时执行
    30. created() {
    31. if (wx.onNeedPrivacyAuthorization) {
    32. wx.onNeedPrivacyAuthorization((resolve) => {
    33. this.resolve = resolve
    34. this.showDialog()
    35. })
    36. }
    37. },
    38. // 在组件实例进入页面节点树时执行
    39. attached() {},
    40. // 在组件在视图层布局完成后执行
    41. ready() {},
    42. // 在组件实例被从页面节点树移除时执行
    43. detached() {},
    44. },
    45. // 组件的方法列表
    46. methods: {
    47. showDialog() {
    48. this.setData({ show: true })
    49. },
    50. hideDialog() {
    51. this.setData({ show: false })
    52. },
    53. // 跳转至隐私协议页面。
    54. openPrivacyContract() {
    55. wx.openPrivacyContract()
    56. },
    57. // 拒绝
    58. handleReject() {
    59. this.hideDialog()
    60. this.resolve && this.resolve({ event: "disagree" })
    61. this.triggerEvent("handlePrivacy", { event: "disagree" })
    62. },
    63. // 同意
    64. handleAgree() {
    65. this.hideDialog()
    66. this.resolve && this.resolve({ buttonId: "argee-btn", event: "agree" })
    67. this.triggerEvent("handlePrivacy", { event: "agree" })
    68. },
    69. },
    70. })

    使用方法

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

    model 的封装

    html 

    1. <view class="container" catch:touchmove="" catch:tap="handleClickMask" wx:if="{{isShow}}">
    2. <view catch:tap>
    3. <slot>slot>
    4. view>
    5. view>

    css

    1. .container {
    2. position: fixed;
    3. top: 0;
    4. right: 0;
    5. bottom: 0;
    6. left: 0;
    7. z-index: 10086;
    8. animation: showModal ease 0.3s;
    9. background: rgba(0, 0, 0, 0.7);
    10. }
    11. @keyframes showModal {
    12. 0% {
    13. opacity: 0;
    14. }
    15. 100% {
    16. opacity: 1;
    17. }
    18. }

    js

    1. Component({
    2. data: {},
    3. properties: {
    4. isShow: {
    5. type: Boolean,
    6. value: false,
    7. },
    8. canClose: {
    9. type: Boolean,
    10. value: true,
    11. },
    12. },
    13. observers: {},
    14. methods: {
    15. handleClickMask() {
    16. if (!this.data.canClose) return
    17. this.setData({
    18. isShow: false,
    19. })
    20. this.triggerEvent("close")
    21. },
    22. },
    23. })

    拿走不谢

  • 相关阅读:
    在 M1 芯片 Mac 上使用 Homebrew
    Maven下载、安装、配置教程
    星图地球数据云,便捷加载各类在线地图服务的又一神器
    18-Java迭代器模式 ( Iterator Pattern )
    代码随想录算法训练营 动态规划part14
    Linux文件与文件系统的压缩
    什么是模型监控?(Valohai)
    rust迭代器
    浅谈Python中的类型转换
    【641. 设计循环双端队列】
  • 原文地址:https://blog.csdn.net/zq18877149886/article/details/132886990