privacy-popup.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!--
  2. * @author: Jay
  3. * @description: 小程序隐私协议 弹窗
  4. * @createTime: 2023-08-31 10:07:54
  5. -->
  6. <template>
  7. <view v-if="showPop">
  8. <view class="privacy-mask">
  9. <view class="privacy-wrap">
  10. <view class="privacy-title">
  11. 用户隐私保护提示
  12. </view>
  13. <view class="privacy-desc">
  14. 感谢您使用本小程序,在使用前您应当阅读井同意
  15. <text class="privacy-link" @tap="openPrivacyContract">《用户隐私保护指引》</text>,
  16. 当点击同意并继续时,即表示您已理解并同意该条款内容,该条款将对您产生法律约束力;如您不同意,将无法继续使用小程序相关功能。
  17. </view>
  18. <view class="privacy-button-flex">
  19. <button class="privacy-button-btn bg-disagree" @tap="handleDisagree">
  20. 不同意
  21. </button>
  22. <button id="agree-btn" class="privacy-button-btn bg-agree" open-type="agreePrivacyAuthorization"
  23. @agreeprivacyauthorization="handleAgree">
  24. 同意并继续
  25. </button>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. showPop: false,
  36. privacyAuthorization: null,
  37. privacyResolves: new Set(),
  38. closeOtherPagePopUpHooks: new Set(),
  39. }
  40. },
  41. mounted() {
  42. this.init()
  43. this.curPageShow()
  44. },
  45. created() {
  46. //查询微信侧记录的用户是否有待同意的隐私政策信息
  47. wx.getPrivacySetting({
  48. success(res) {
  49. console.log('隐私政策信息', res)
  50. // if (res.needAuthorization) {
  51. // //打开弹窗
  52. // that.popUp()
  53. // }
  54. }
  55. });
  56. },
  57. methods: {
  58. // 监听何时需要提示用户阅读隐私政策
  59. init() {
  60. let that = this;
  61. if (wx.onNeedPrivacyAuthorization) {
  62. wx.onNeedPrivacyAuthorization((resolve) => {
  63. if (typeof that.privacyAuthorization === 'function') {
  64. that.privacyAuthorization(resolve)
  65. }
  66. })
  67. }
  68. },
  69. //初始化监听程序
  70. curPageShow() {
  71. this.privacyAuthorization = resolve => {
  72. this.privacyResolves.add(resolve)
  73. //打开弹窗
  74. this.popUp()
  75. // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
  76. this.closeOtherPagePopUp(this.disPopUp)
  77. }
  78. this.closeOtherPagePopUpHooks.add(this.disPopUp)
  79. },
  80. // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
  81. closeOtherPagePopUp(closePopUp) {
  82. this.closeOtherPagePopUpHooks.forEach(hook => {
  83. if (closePopUp !== hook) {
  84. hook()
  85. }
  86. })
  87. },
  88. //打开隐私协议
  89. openPrivacyContract() {
  90. wx.openPrivacyContract({
  91. success(res) {
  92. console.log('打开隐私协议', res);
  93. },
  94. fail(err) {
  95. console.error('打开隐私协议失败', err)
  96. }
  97. });
  98. },
  99. // 不同意
  100. handleDisagree() {
  101. this.privacyResolves.forEach(resolve => {
  102. resolve({
  103. event: 'disagree',
  104. })
  105. })
  106. this.privacyResolves.clear()
  107. //关闭弹窗
  108. this.disPopUp()
  109. //退出小程序
  110. // wx.exitMiniProgram();
  111. },
  112. // 同意并继续
  113. handleAgree() {
  114. this.privacyResolves.forEach(resolve => {
  115. resolve({
  116. event: 'agree',
  117. buttonId: 'agree-btn'
  118. })
  119. })
  120. this.privacyResolves.clear()
  121. //关闭弹窗
  122. this.disPopUp()
  123. },
  124. //打开弹窗
  125. popUp() {
  126. if (this.showPop === false) {
  127. this.showPop = true
  128. }
  129. },
  130. //关闭弹窗
  131. disPopUp() {
  132. if (this.showPop === true) {
  133. this.showPop = false
  134. }
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .privacy-mask {
  141. position: fixed;
  142. z-index: 5000;
  143. top: 0;
  144. right: 0;
  145. left: 0;
  146. bottom: 0;
  147. background: rgba(0, 0, 0, 0.2);
  148. display: flex;
  149. align-items: center;
  150. justify-content: center;
  151. }
  152. .privacy-wrap {
  153. width: 632rpx;
  154. padding: 48rpx 30rpx;
  155. box-sizing: border-box;
  156. background: #fff;
  157. border-radius: 16rpx;
  158. }
  159. .privacy-title {
  160. padding: 0rpx 30rpx 40rpx 30rpx;
  161. font-weight: 700;
  162. font-size: 36rpx;
  163. text-align: center;
  164. }
  165. .privacy-desc {
  166. font-size: 30rpx;
  167. color: #555;
  168. line-height: 2;
  169. text-align: left;
  170. padding: 0 40rpx;
  171. }
  172. .privacy-link {
  173. color: #2f80ed;
  174. }
  175. .privacy-button-flex {
  176. display: flex;
  177. padding: 20rpx 40rpx;
  178. }
  179. .privacy-button-btn {
  180. color: #FFF;
  181. font-size: 30rpx;
  182. font-weight: 500;
  183. line-height: 100rpx;
  184. text-align: center;
  185. height: 100rpx;
  186. border-radius: 20rpx;
  187. border: none;
  188. background: #07c160;
  189. flex: 1;
  190. margin-right: 30rpx;
  191. justify-content: center;
  192. }
  193. .privacy-button-btn::after {
  194. border: none;
  195. }
  196. .bg-disagree {
  197. color: #07c160;
  198. background: #f2f2f2;
  199. }
  200. .bg-agree {
  201. margin-right: 0rpx;
  202. }
  203. </style>