PrivacyPopup.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <script lang="ts" setup>
  2. import { onBeforeMount, ref } from 'vue'
  3. interface Props {
  4. title?: string // 标题
  5. desc?: string // 描述
  6. subDesc?: string // 字描述
  7. protocol?: string // 协议名称
  8. }
  9. withDefaults(defineProps<Props>(), {
  10. title: '用户隐私保护提示',
  11. desc: '感谢您使用本应用,您使用本应用的服务之前请仔细阅读并同意',
  12. subDesc: '。当您点击同意并开始时用产品服务时,即表示你已理解并同意该条款内容,该条款将对您产生法律约束力。如您拒绝,将无法使用相应服务。',
  13. protocol: '《用户隐私保护指引》',
  14. })
  15. const emit = defineEmits(['agree', 'disagree'])
  16. const showPopup = ref<boolean>(false) // 是否展示popup
  17. const privacyResolves = ref(new Set()) // onNeedPrivacyAuthorization的reslove
  18. function privacyHandler(resolve: any) {
  19. showPopup.value = true
  20. privacyResolves.value.add(resolve)
  21. }
  22. onBeforeMount(() => {
  23. // #ifdef MP-WEIXIN
  24. // 注册监听
  25. if (wx.onNeedPrivacyAuthorization) {
  26. wx.onNeedPrivacyAuthorization((resolve: any) => {
  27. if (typeof privacyHandler === 'function') {
  28. privacyHandler(resolve)
  29. }
  30. })
  31. }
  32. // #endif
  33. })
  34. /**
  35. * 同意隐私协议
  36. */
  37. function handleAgree() {
  38. showPopup.value = false
  39. privacyResolves.value.forEach((resolve: any) => {
  40. resolve({
  41. event: 'agree',
  42. buttonId: 'agree-btn',
  43. })
  44. })
  45. privacyResolves.value.clear()
  46. emit('agree')
  47. }
  48. /**
  49. * 拒绝隐私协议
  50. */
  51. function handleDisagree() {
  52. showPopup.value = false
  53. privacyResolves.value.forEach((resolve: any) => {
  54. resolve({
  55. event: 'disagree',
  56. })
  57. })
  58. privacyResolves.value.clear()
  59. }
  60. /**
  61. * 打开隐私协议
  62. */
  63. function openPrivacyContract() {
  64. // #ifdef MP-WEIXIN
  65. wx.openPrivacyContract({})
  66. // #endif
  67. }
  68. /**
  69. * 弹出框关闭时清空
  70. */
  71. function handleClose() {
  72. privacyResolves.value.clear()
  73. }
  74. </script>
  75. <script lang="ts">
  76. export default {
  77. options: {
  78. virtualHost: true,
  79. addGlobalClass: true,
  80. styleIsolation: 'shared',
  81. },
  82. }
  83. </script>
  84. <template>
  85. <view>
  86. <wd-popup v-model="showPopup" :close-on-click-modal="false" custom-class="wd-privacy-popup" @close="handleClose">
  87. <view class="wd-privacy-popup__header">
  88. <!-- 标题 -->
  89. <view class="wd-picker__title">
  90. {{ title }}
  91. </view>
  92. </view>
  93. <view class="wd-privacy-popup__container">
  94. <text>{{ desc }}</text>
  95. <text class="wd-privacy-popup__container-protocol" @click="openPrivacyContract">
  96. {{ protocol }}
  97. </text>
  98. <text>{{ subDesc }}</text>
  99. </view>
  100. <view class="wd-privacy-popup__footer">
  101. <button id="disagree-btn" class="is-block is-round is-medium is-plain wd-privacy-popup__footer-disagree wd-button" @click="handleDisagree">
  102. 拒绝
  103. </button>
  104. <!-- #ifdef MP-WEIXIN -->
  105. <button
  106. id="agree-btn"
  107. class="wd-button is-block is-round is-medium is-primary wd-privacy-popup__footer-agree"
  108. open-type="agreePrivacyAuthorization"
  109. @agreeprivacyauthorization="handleAgree"
  110. >
  111. 同意
  112. </button>
  113. <!-- #endif -->
  114. <!-- #ifndef MP-WEIXIN -->
  115. <button
  116. id="agree-btn"
  117. class="wd-button is-block is-round is-medium is-primary wd-privacy-popup__footer-agree"
  118. @click="handleAgree"
  119. >
  120. 同意
  121. </button>
  122. <!-- #endif -->
  123. </view>
  124. </wd-popup>
  125. </view>
  126. </template>
  127. <style lang="scss" scoped>
  128. @import 'wot-design-uni/components/wd-button/index.scss';
  129. :deep(.wd-privacy-popup) {
  130. width: 600rpx;
  131. padding: 0 24rpx;
  132. box-sizing: border-box;
  133. border-radius: 32rpx;
  134. overflow: hidden;
  135. }
  136. .wd-privacy-popup {
  137. &__header {
  138. width: 100%;
  139. height: 128rpx;
  140. line-height: 128rpx;
  141. color: rgba(0, 0, 0, 0.85);
  142. font-size: 30rpx;
  143. padding: 0 12rpx;
  144. box-sizing: border-box;
  145. }
  146. &__container {
  147. width: 100%;
  148. box-sizing: border-box;
  149. padding: 0 12rpx;
  150. margin-bottom: 32rpx;
  151. font-size: 28rpx;
  152. line-height: 1.8;
  153. color: #3e3e3e;
  154. text-align: left;
  155. font-weight: 550;
  156. &-protocol {
  157. color: #4d80f0;
  158. }
  159. }
  160. &__footer {
  161. display: flex;
  162. justify-content: space-between;
  163. padding-bottom: 36rpx;
  164. button {
  165. border: none;
  166. outline: none;
  167. }
  168. }
  169. }
  170. </style>