index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. props: {
  32. // 弹出隐私窗口时是否隐藏tabbar
  33. hideTabBar: {
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. data() {
  39. return {
  40. // 隐私协议弹窗
  41. showPrivacy: false,
  42. // 商城基本信息
  43. storeInfo: undefined,
  44. }
  45. },
  46. created() {
  47. // 获取商城基本信息
  48. this.getStoreInfo()
  49. // #ifdef MP-WEIXIN
  50. // 弹出隐私协议 (微信小程序端)
  51. this.needAuthorization()
  52. // #endif
  53. },
  54. methods: {
  55. // 获取商城基本信息
  56. getStoreInfo() {
  57. StoreModel.storeInfo().then(storeInfo => this.storeInfo = storeInfo)
  58. },
  59. // 弹出隐私协议 (微信小程序端)
  60. needAuthorization() {
  61. const app = this
  62. uni.getPrivacySetting({
  63. success({ needAuthorization, privacyContractName }) {
  64. console.info('getPrivacySetting', { needAuthorization, privacyContractName })
  65. // 需要弹出隐私协议
  66. if (needAuthorization) {
  67. app.showPrivacy = true
  68. app.hideTabBar && uni.hideTabBar()
  69. }
  70. }
  71. })
  72. },
  73. // 查看隐私协议内容
  74. handlePrivacyContract() {
  75. uni.openPrivacyContract()
  76. },
  77. // 用户同意隐私协议事件回调
  78. handleAgreePrivacyAuthorization() {
  79. // 用户点击了同意,才可以调用隐私接口和组件,例如:
  80. // wx.getUserProfile()
  81. // wx.chooseImage()
  82. // wx.saveImageToPhotosAlbum()
  83. // wx.setClipboardData()
  84. this.hideTabBar && uni.showTabBar()
  85. this.showPrivacy = false
  86. },
  87. // 用户不同意隐私协议
  88. handleDisagree() {
  89. this.$toast('很抱歉,请先同意后可继续使用~', 2000)
  90. },
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .privacy-container {
  96. padding: 40rpx 60rpx;
  97. .title {
  98. text-align: center;
  99. margin-bottom: 40rpx;
  100. font-size: 32rpx;
  101. font-weight: bold;
  102. }
  103. .content {
  104. margin-bottom: 50rpx;
  105. font-size: 28rpx;
  106. line-height: 50rpx;
  107. }
  108. .actions {
  109. display: flex;
  110. justify-content: space-between;
  111. padding: 0 20rpx;
  112. .btn-item {
  113. width: 280rpx;
  114. height: 80rpx;
  115. line-height: 80rpx;
  116. border-radius: 20rpx;
  117. text-align: center;
  118. &.btn-grey {
  119. background: #f8f8f8;
  120. color: #000;
  121. }
  122. &.btn-main {
  123. background: linear-gradient(to right, $main-bg, $main-bg2);
  124. color: $main-text;
  125. }
  126. }
  127. }
  128. }
  129. </style>