index.vue 3.4 KB

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