• uni-app 新增 微信小程序之新版隐私协议


    一、manifest.json中配置

    "__usePrivacyCheck__": true

    二、编写封装后的组件

    1. <template>
    2. <view class="privacy" v-if="showPrivacy">
    3. <view class="content">
    4. <view class="title">隐私保护指引view>
    5. <view class="des">
    6. 在使用当前小程序服务之前,请仔细阅读
    7. <text class="link" @click="openPrivacyContract">{{ privacyContractName }}text>
    8. 。如果你同意{{ privacyContractName }},请点击“同意”开始使用。
    9. view>
    10. <view class="btns">
    11. <button class="item reject" @click="exitMiniProgram">拒绝button>
    12. <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意button>
    13. view>
    14. view>
    15. view>
    16. template>
    17. <script>
    18. export default {
    19. data() {
    20. return {
    21. privacyContractName: '', //需要弹窗展示的隐私协议名称
    22. showPrivacy: false, //全局控制弹窗显隐
    23. };
    24. },
    25. created() {
    26. this.getPrivacySet();
    27. },
    28. methods: {
    29. getPrivacySet(){
    30. let that = this;
    31. uni.getPrivacySetting({
    32. success(res) {
    33. if (res.needAuthorization) {
    34. that.privacyContractName = res.privacyContractName;
    35. that.showPrivacy = true;
    36. } else that.showPrivacy = false;
    37. }
    38. });
    39. },
    40. // 同意隐私协议
    41. handleAgreePrivacyAuthorization() {
    42. const that = this;
    43. wx.requirePrivacyAuthorize({
    44. success: res => {
    45. that.showPrivacy = false;
    46. getApp().globalData.showPrivacy = false;
    47. }
    48. });
    49. },
    50. // 拒绝隐私协议
    51. exitMiniProgram() {
    52. const that = this;
    53. uni.showModal({
    54. content: '如果拒绝,我们将无法获取您的信息, 包括手机号、位置信息、相册等该小程序十分重要的功能,您确定要拒绝吗?',
    55. success: res => {
    56. if (res.confirm) {
    57. that.showPrivacy = false;
    58. uni.exitMiniProgram({
    59. success: () => {
    60. console.log('退出小程序成功');
    61. }
    62. });
    63. }
    64. }
    65. });
    66. },
    67. // 跳转协议页面
    68. // 点击高亮的名字会自动跳转页面 微信封装好的不用操作
    69. openPrivacyContract() {
    70. wx.openPrivacyContract({
    71. fail: () => {
    72. uni.showToast({
    73. title: '网络错误',
    74. icon: 'error'
    75. });
    76. }
    77. });
    78. }
    79. }
    80. };
    81. script>
    82. <style lang="scss" scoped>
    83. .privacy {
    84. position: fixed;
    85. top: 0;
    86. right: 0;
    87. bottom: 0;
    88. left: 0;
    89. background: rgba(0, 0, 0, 0.5);
    90. z-index: 9999999;
    91. display: flex;
    92. align-items: center;
    93. justify-content: center;
    94. .content {
    95. width: 85vw;
    96. padding: 50rpx;
    97. box-sizing: border-box;
    98. background: #fff;
    99. border-radius: 16rpx;
    100. .title {
    101. text-align: center;
    102. color: #333;
    103. font-weight: bold;
    104. font-size: 34rpx;
    105. }
    106. .des {
    107. font-size: 26rpx;
    108. color: #666;
    109. margin-top: 40rpx;
    110. text-align: justify;
    111. line-height: 1.6;
    112. .link {
    113. color: #07c160;
    114. text-decoration: underline;
    115. }
    116. }
    117. .btns {
    118. margin-top: 60rpx;
    119. display: flex;
    120. justify-content: space-between;
    121. .item {
    122. justify-content: space-between;
    123. width: 244rpx;
    124. height: 80rpx;
    125. display: flex;
    126. align-items: center;
    127. justify-content: center;
    128. border-radius: 16rpx;
    129. box-sizing: border-box;
    130. border: none;
    131. }
    132. .reject {
    133. background: #f4f4f5;
    134. color: #909399;
    135. }
    136. .agree {
    137. background: #07c160;
    138. color: #fff;
    139. }
    140. }
    141. }
    142. }
    143. style>

    三、页面引入试用

    1. import privacyPopup from '../components/privacyPopup.vue';
    2. components:{privacyPopup},
    3. <privacyPopup>privacyPopup>

  • 相关阅读:
    Objective-C中weak实现原理
    【TypeScript】模块化和类型声明规则
    一篇解决JavaScript
    RobotFramework 自动化测试实战基础篇
    Airtest学习笔记之自定义启动器
    【吴恩达老师《机器学习》】课后习题5之【偏差与方差】
    接口测试场景:怎么实现登录之后,需要进行昵称修改?
    【MySQL】 B+ 树存储的原理
    synchronized 关键字和 volatile 关键字有什么区别?
    Python实现九九乘法表的几种方式,入门必备案例~超级简单~
  • 原文地址:https://blog.csdn.net/qq_42717015/article/details/132881090