• uniapp实现微信小程序隐私协议组件封装


    uniapp实现微信小程序隐私协议组件封装。

    1. <template>
    2. <view class="diygw-modal basic" v-if="showPrivacy" :class="showPrivacy?'show':''" style="z-index: 1000000">
    3. <view class="diygw-dialog diygw-dialog-modal basis-lg">
    4. <view class="justify-end diygw-bar">
    5. <view class="content"> {{title}} </view>
    6. </view>
    7. <view>
    8. <view class="flex diygw-dialog-content flex-direction-column privacy-content">
    9. <view class="diygw-col-24"> {{contentstart}}<text :style="{color:agreebg}" @tap="handleOpenPrivacyContract">{{privacy}}</text>。{{contentend}} </view>
    10. <view class="flex diygw-col-24">
    11. <button id="agree-btn" :style="{background:agreebg,color:agreecolor}" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgree" class="diygw-btn radius flex-sub margin-xs">同意并继续</button>
    12. </view>
    13. <view class="flex diygw-col-24">
    14. <button id="disagree-btn" :style="{background:disagreebg,color:disagreecolor}" class="diygw-btn radius flex-sub margin-xs" @tap="handleDisagree">不同意</button>
    15. </view>
    16. </view>
    17. </view>
    18. </view>
    19. </view>
    20. </template>
    21. <script>
    22. export default {
    23. props: {
    24. title: {
    25. type: String,
    26. default: '用户隐私保护提示'
    27. },
    28. contentstart:{
    29. type: String,
    30. default:'亲爱的用户,感谢您信任并使用本小程序。请您在点击同意之前仔细阅读并充分理解',
    31. },
    32. privacy:{
    33. type: String,
    34. default:'《用户隐私保护指引》',
    35. },
    36. contentend:{
    37. type: String,
    38. default:'当点击同意并继续时,即表示您已理解并同意该条款内容,该条款将对您产生法律约束力;如您不同意,将无法继续使用小程序相关功能。',
    39. },
    40. agreebg:{
    41. type: String,
    42. default:'#07c160',
    43. },
    44. agreecolor:{
    45. type: String,
    46. default:'#fff',
    47. },
    48. disagreebg:{
    49. type: String,
    50. default:'#aaaaaa',
    51. },
    52. disagreecolor:{
    53. type: String,
    54. default:'#fff',
    55. },
    56. isexit:{
    57. type:Boolean,
    58. default:true
    59. },
    60. },
    61. data() {
    62. return {
    63. showPrivacy: false,
    64. resolvePrivacyAuthorization: null,
    65. privacyResolves: new Set()
    66. }
    67. },
    68. mounted() {
    69. this.init()
    70. },
    71. methods: {
    72. // 监听何时需要提示用户阅读隐私政策
    73. init() {
    74. let thiz = this;
    75. // #ifdef MP-WEIXIN
    76. if (wx.onNeedPrivacyAuthorization) {
    77. wx.requirePrivacyAuthorize({
    78. success: (e) => {
    79. // 用户同意授权
    80. // 继续小程序逻辑
    81. console.log(e)
    82. // 用户同意授权
    83. // 继续小程序逻辑
    84. },
    85. fail: (e) => {
    86. console.log(e)
    87. }, // 用户拒绝授权
    88. complete: () => {}
    89. })
    90. wx.onNeedPrivacyAuthorization((resolve) => {
    91. thiz.resolvePrivacyAuthorization = resolve
    92. thiz.openPrivacy()
    93. })
    94. }
    95. // #endif
    96. },
    97. //打开隐私协议
    98. openPrivacyContract() {
    99. wx.openPrivacyContract({
    100. success(res) {
    101. console.log('打开隐私协议', res);
    102. },
    103. fail(err) {
    104. console.error('打开隐私协议失败', err)
    105. }
    106. });
    107. },
    108. // 不同意
    109. handleDisagree() {
    110. this.resolvePrivacyAuthorization({
    111. event: 'disagree',
    112. buttonId: 'disagree-btn'
    113. });
    114. //关闭弹窗
    115. this.disopenPrivacy()
    116. if(this.isexit){
    117. //退出小程序
    118. wx.exitMiniProgram();
    119. }
    120. },
    121. // 同意并继续
    122. handleAgree() {
    123. this.resolvePrivacyAuthorization({
    124. event: 'agree',
    125. buttonId: 'agree-btn'
    126. });
    127. //关闭弹窗
    128. this.disopenPrivacy()
    129. },
    130. //打开弹窗
    131. openPrivacy() {
    132. if (this.showPrivacy === false) {
    133. this.showPrivacy = true
    134. }
    135. },
    136. //关闭弹窗
    137. disopenPrivacy() {
    138. if (this.showPrivacy === true) {
    139. this.showPrivacy = false
    140. }
    141. },
    142. }
    143. }
    144. </script>
    145. <style>
    146. .privacy-content{
    147. padding:10px;
    148. line-height: 1.5;
    149. font-size: 28rpx;
    150. }
    151. </style>

    隐私协议封装组件后快速调用。

  • 相关阅读:
    Docker部署 Nacos
    flutter arr 依赖
    汇佳学校冰球/高尔夫/影视艺术/中英朗诵均获大奖
    MyBatisPlus实现连表操作、批量处理
    微波系统中散射参量S、阻抗参量Z及导纳参量Y之间的关系及MATLAB验证
    C#/.net程序调用python
    浅谈无线测温产品在菲律宾某工厂配电项目的应用
    物通博联5G工业智能网关赋能智能制造,打造智能工厂
    【PCB学习笔记】绘制智能车四层板 ---PCB封装库的创建方法及现有封装调用
    江苏MES
  • 原文地址:https://blog.csdn.net/luck332/article/details/133523412