policy-consent-host.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="policy-consent-host">
  3. <policy-consent-modal
  4. ref="policyModal"
  5. @accepted="onPolicyAccepted"
  6. @visibility-change="onPolicyModalVisibility"
  7. />
  8. <!-- #ifdef MP-WEIXIN -->
  9. <privacy-authorize-popup
  10. ref="privacyPopup"
  11. @visibility-change="onPrivacyModalVisibility"
  12. />
  13. <!-- #endif -->
  14. </view>
  15. </template>
  16. <script>
  17. import PolicyConsentModal from '@/components/policy-consent-modal.vue'
  18. import { eventBus } from '@/utils/event-bus'
  19. import {
  20. markHomeRefreshAfterPolicy,
  21. registerPolicyHost,
  22. setPolicyConsented,
  23. setTabbarBlockedState,
  24. unregisterPolicyHost,
  25. } from '@/utils/policy-consent-manager.js'
  26. // #ifdef MP-WEIXIN
  27. import PrivacyAuthorizePopup from '@/components/privacy-authorize-popup.vue'
  28. // #endif
  29. export default {
  30. components: {
  31. PolicyConsentModal,
  32. // #ifdef MP-WEIXIN
  33. PrivacyAuthorizePopup,
  34. // #endif
  35. },
  36. data() {
  37. return {
  38. policyModalVisible: false,
  39. privacyModalVisible: false,
  40. }
  41. },
  42. computed: {
  43. tabbarBlocked() {
  44. return this.policyModalVisible || this.privacyModalVisible
  45. },
  46. },
  47. watch: {
  48. tabbarBlocked: {
  49. immediate: true,
  50. handler(val) {
  51. setTabbarBlockedState(val)
  52. },
  53. },
  54. },
  55. mounted() {
  56. registerPolicyHost(this)
  57. this.tryOpenPolicyModal()
  58. },
  59. beforeDestroy() {
  60. setTabbarBlockedState(false)
  61. unregisterPolicyHost(this)
  62. },
  63. methods: {
  64. onPolicyModalVisibility(visible) {
  65. this.policyModalVisible = visible
  66. },
  67. onPrivacyModalVisibility(visible) {
  68. this.privacyModalVisible = visible
  69. },
  70. tryOpenPolicyModal() {
  71. const app = getApp()
  72. if (!app || !app.globalData || !app.globalData.needPolicyConsent) return
  73. this.$nextTick(() => {
  74. if (this.$refs.policyModal) {
  75. setTabbarBlockedState(true)
  76. this.$refs.policyModal.open()
  77. }
  78. })
  79. },
  80. tryOpenPrivacyPopup() {
  81. // #ifdef MP-WEIXIN
  82. this.$nextTick(() => {
  83. if (this.$refs.privacyPopup) {
  84. setTabbarBlockedState(true)
  85. this.$refs.privacyPopup.open()
  86. }
  87. })
  88. // #endif
  89. },
  90. onPolicyAccepted() {
  91. setPolicyConsented()
  92. const app = getApp()
  93. if (app && app.globalData) {
  94. app.globalData.needPolicyConsent = false
  95. }
  96. markHomeRefreshAfterPolicy()
  97. eventBus.emit('policyAccepted')
  98. if (app && typeof app.runPendingLaunchLogin === 'function') {
  99. app.runPendingLaunchLogin()
  100. }
  101. },
  102. },
  103. }
  104. </script>