policy-consent-host.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="policy-consent-host">
  3. <policy-consent-modal ref="policyModal" @accepted="onPolicyAccepted" />
  4. <!-- #ifdef MP-WEIXIN -->
  5. <privacy-authorize-popup ref="privacyPopup" />
  6. <!-- #endif -->
  7. </view>
  8. </template>
  9. <script>
  10. import PolicyConsentModal from '@/components/policy-consent-modal.vue'
  11. import { eventBus } from '@/utils/event-bus'
  12. import {
  13. registerPolicyHost,
  14. setPolicyConsented,
  15. unregisterPolicyHost,
  16. } from '@/utils/policy-consent-manager.js'
  17. // #ifdef MP-WEIXIN
  18. import PrivacyAuthorizePopup from '@/components/privacy-authorize-popup.vue'
  19. // #endif
  20. export default {
  21. components: {
  22. PolicyConsentModal,
  23. // #ifdef MP-WEIXIN
  24. PrivacyAuthorizePopup,
  25. // #endif
  26. },
  27. mounted() {
  28. registerPolicyHost(this)
  29. this.tryOpenPolicyModal()
  30. },
  31. beforeDestroy() {
  32. unregisterPolicyHost(this)
  33. },
  34. methods: {
  35. tryOpenPolicyModal() {
  36. const app = getApp()
  37. if (!app || !app.globalData || !app.globalData.needPolicyConsent) return
  38. this.$nextTick(() => {
  39. this.$refs.policyModal && this.$refs.policyModal.open()
  40. })
  41. },
  42. tryOpenPrivacyPopup() {
  43. // #ifdef MP-WEIXIN
  44. this.$nextTick(() => {
  45. this.$refs.privacyPopup && this.$refs.privacyPopup.open()
  46. })
  47. // #endif
  48. },
  49. onPolicyAccepted() {
  50. setPolicyConsented()
  51. const app = getApp()
  52. if (app && app.globalData) {
  53. app.globalData.needPolicyConsent = false
  54. }
  55. eventBus.emit('policyAccepted')
  56. if (app && typeof app.runPendingLaunchLogin === 'function') {
  57. app.runPendingLaunchLogin()
  58. }
  59. },
  60. },
  61. }
  62. </script>