PrivacyPop.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="privacy" v-if="showPrivacy">
  3. <view class="content">
  4. <view class="title">隐私保护指引</view>
  5. <view class="des">
  6. 在使用当前小程序服务之前,请仔细阅读<text class="link" @tap="openPrivacyContract">{{ privacyContractName }}</text>。如你同意{{
  7. privacyContractName }},请点击“同意”开始使用。
  8. </view>
  9. <view class="btns">
  10. <button class="item reject" @tap="exitMiniProgram">拒绝</button>
  11. <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization"
  12. @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. privacyContractName: '《XXX隐私保护引导》',
  22. showPrivacy: false
  23. }
  24. },
  25. methods: {
  26. checkPrivacySetting(){
  27. uni.getPrivacySetting({
  28. success: res => {
  29. console.log("getPrivacySetting",res)
  30. this.showPrivacy = true
  31. this.privacyContractName = res.privacyContractName
  32. // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  33. // if (res.needAuthorization) {
  34. // // 需要弹出隐私协议
  35. // this.showPrivacy = false
  36. // } else {
  37. // this.showPrivacy = true
  38. // // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  39. // // wx.getUserProfile()
  40. // // wx.chooseMedia()
  41. // // wx.getClipboardData()
  42. // // wx.startRecord()
  43. // }
  44. },
  45. fail: () => {},
  46. complete: () => {}
  47. })
  48. },
  49. // 打开隐私协议
  50. openPrivacyContract() {
  51. uni.openPrivacyContract({
  52. fail: () => {
  53. uni.showToast({
  54. title: '遇到错误',
  55. icon: 'error'
  56. })
  57. }
  58. })
  59. },
  60. // 拒绝隐私协议
  61. exitMiniProgram() {
  62. console.log("拒绝隐私协议")
  63. const that = this;
  64. // 直接退出小程序
  65. // wx.exitMiniProgram()
  66. uni.showModal({
  67. // 如果拒绝,我们将无法获取您的信息, 包括手机号、位置信息、相册等该小程序十分重要的功能,您确定要拒绝吗?
  68. content: '您确定要拒绝吗?',
  69. success: res => {
  70. if (res.confirm) {
  71. that.showPrivacy = false;
  72. uni.exitMiniProgram({
  73. success: () => {
  74. console.log('退出小程序成功');
  75. }
  76. });
  77. }
  78. }
  79. });
  80. },
  81. // 同意隐私协议
  82. handleAgreePrivacyAuthorization() {
  83. wx.requirePrivacyAuthorize({
  84. success: (res) => {
  85. console.log(res,86);
  86. // 用户同意授权
  87. // 继续小程序逻辑
  88. this.showPrivacy = false
  89. },
  90. fail: () => {}, // 用户拒绝授权
  91. complete: () => {}
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped> .privacy {
  98. position: fixed;
  99. top: 0;
  100. right: 0;
  101. bottom: 0;
  102. left: 0;
  103. background: rgba(0, 0, 0, .5);
  104. z-index: 9999999;
  105. display: flex;
  106. align-items: center;
  107. justify-content: center;
  108. }
  109. .content {
  110. width: 632rpx;
  111. padding: 48rpx;
  112. box-sizing: border-box;
  113. background: #fff;
  114. border-radius: 16rpx;
  115. }
  116. .content .title {
  117. text-align: center;
  118. color: #333;
  119. font-weight: bold;
  120. font-size: 32rpx;
  121. }
  122. .content .des {
  123. font-size: 26rpx;
  124. color: #666;
  125. margin-top: 40rpx;
  126. text-align: justify;
  127. line-height: 1.6;
  128. }
  129. .content .des .link {
  130. color: #07c160;
  131. text-decoration: underline;
  132. }
  133. .btns {
  134. margin-top: 48rpx;
  135. display: flex;
  136. }
  137. .btns .item {
  138. justify-content: space-between;
  139. width: 244rpx;
  140. height: 80rpx;
  141. display: flex;
  142. align-items: center;
  143. justify-content: center;
  144. border-radius: 16rpx;
  145. box-sizing: border-box;
  146. border: none;
  147. }
  148. .btns .reject {
  149. background: #f4f4f5;
  150. color: #909399;
  151. }
  152. .btns .agree {
  153. background: #07c160;
  154. color: #fff;
  155. }
  156. </style>