index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <!-- 用户隐私保护弹窗 -->
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view v-if="storeInfo" class="privacy-popup">
  5. <u-popup v-model="showPrivacy" mode="bottom" border-radius="20" :safe-area-inset-bottom="true" :mask-close-able="false"
  6. :mask-custom-style="{ background: 'rgba(0, 0, 0, 0.7)' }">
  7. <view class="privacy-container">
  8. <view class="title">用户隐私保护提示</view>
  9. <view class="content">
  10. <text>感谢您使用{{ storeInfo.store_name }},同意并继续表示您已阅读并同意</text>
  11. <text class="col-m" @click="handlePrivacyContract()">《隐私政策》</text>
  12. <text>,否则将无法正常使用相关功能。</text>
  13. </view>
  14. <view class="actions">
  15. <view class="btn-item btn-grey" @click="handleDisagree()">
  16. <text>不同意</text>
  17. </view>
  18. <button class="btn-item btn-main btn-normal" open-type="agreePrivacyAuthorization"
  19. @agreeprivacyauthorization="handleAgreePrivacyAuthorization()">
  20. <text>同意并继续</text>
  21. </button>
  22. </view>
  23. </view>
  24. </u-popup>
  25. </view>
  26. <!-- #endif -->
  27. </template>
  28. <script>
  29. import StoreModel from '@/common/model/Store'
  30. export default {
  31. emits: ['end'],
  32. props: {
  33. // 弹出隐私窗口时是否隐藏tabbar
  34. hideTabBar: {
  35. type: Boolean,
  36. default: false
  37. }
  38. },
  39. data() {
  40. return {
  41. // 隐私协议弹窗
  42. showPrivacy: false,
  43. // 商城基本信息
  44. storeInfo: undefined,
  45. }
  46. },
  47. async created() {
  48. // 获取商城基本信息
  49. await this.getStoreInfo()
  50. // #ifdef MP-WEIXIN
  51. // 弹出隐私协议 (微信小程序端)
  52. this.needAuthorization()
  53. // #endif
  54. },
  55. methods: {
  56. // 获取商城基本信息
  57. async getStoreInfo() {
  58. await StoreModel.storeInfo().then(storeInfo => this.storeInfo = storeInfo)
  59. },
  60. // 弹出隐私协议 (微信小程序端)
  61. needAuthorization() {
  62. const app = this
  63. uni.getPrivacySetting({
  64. success({ needAuthorization, privacyContractName }) {
  65. console.info('getPrivacySetting', { needAuthorization, privacyContractName })
  66. // 需要弹出隐私协议
  67. if (needAuthorization) {
  68. app.showPrivacy = true
  69. app.hideTabBar && uni.hideTabBar()
  70. } else {
  71. app.$emit('end')
  72. }
  73. }
  74. })
  75. },
  76. // 查看隐私协议内容
  77. handlePrivacyContract() {
  78. uni.openPrivacyContract()
  79. },
  80. // 用户同意隐私协议事件回调
  81. handleAgreePrivacyAuthorization() {
  82. // 用户点击了同意,才可以调用隐私接口和组件,例如:
  83. // wx.getUserProfile()
  84. // wx.chooseImage()
  85. // wx.saveImageToPhotosAlbum()
  86. // wx.setClipboardData()
  87. this.hideTabBar && uni.showTabBar()
  88. this.showPrivacy = false
  89. this.$emit('end')
  90. },
  91. // 用户不同意隐私协议
  92. handleDisagree() {
  93. this.$toast('很抱歉,请先同意后可继续使用~', 2000)
  94. },
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .privacy-container {
  100. padding: 40rpx 60rpx;
  101. .title {
  102. text-align: center;
  103. margin-bottom: 40rpx;
  104. font-size: 32rpx;
  105. font-weight: bold;
  106. }
  107. .content {
  108. margin-bottom: 50rpx;
  109. font-size: 28rpx;
  110. line-height: 50rpx;
  111. }
  112. .actions {
  113. display: flex;
  114. justify-content: space-between;
  115. padding: 0 20rpx;
  116. .btn-item {
  117. width: 280rpx;
  118. height: 80rpx;
  119. line-height: 80rpx;
  120. border-radius: 20rpx;
  121. text-align: center;
  122. &.btn-grey {
  123. background: #f8f8f8;
  124. color: #000;
  125. }
  126. &.btn-main {
  127. background: linear-gradient(to right, $main-bg, $main-bg2);
  128. color: $main-text;
  129. }
  130. }
  131. }
  132. }
  133. </style>