privacyPopup.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="privacy" v-if="showPrivacy">
  3. <view class="content">
  4. <view class="title">隐私保护指引</view>
  5. <view class="des">
  6. 在使用当前小程序服务之前,请仔细阅读
  7. <text class="link" @click="openPrivacyContract">{{ privacyContractName }}</text>
  8. 如果你同意{{ privacyContractName }},请点击“同意”开始使用。如您拒绝,将无法更好的体验小程序。
  9. </view>
  10. <view class="btns">
  11. <button class="item reject" @click="exitMiniProgram">拒绝</button>
  12. <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'privacyPopup',
  20. data() {
  21. return {
  22. privacyContractName: '',
  23. showPrivacy: false
  24. };
  25. },
  26. created() {
  27. setTimeout(() => {
  28. this.showPrivacy = getApp().globalData.showPrivacy;
  29. this.privacyContractName = getApp().globalData.privacyContractName;
  30. }, 500);
  31. },
  32. methods: {
  33. // 同意隐私协议
  34. handleAgreePrivacyAuthorization() {
  35. const that = this;
  36. wx.requirePrivacyAuthorize({
  37. success: res => {
  38. that.showPrivacy = false;
  39. getApp().globalData.showPrivacy = false;
  40. }
  41. });
  42. },
  43. // 拒绝隐私协议
  44. exitMiniProgram() {
  45. const that = this;
  46. uni.showModal({
  47. content: '如果拒绝,我们将无法获取您的信息, 包括手机号、位置信息、相册等该小程序十分重要的功能,您确定要拒绝吗?',
  48. success: res => {
  49. if (res.confirm) {
  50. that.showPrivacy = false;
  51. uni.exitMiniProgram({
  52. success: () => {
  53. console.log('退出小程序成功');
  54. }
  55. });
  56. }
  57. }
  58. });
  59. },
  60. // 跳转协议页面
  61. // 点击高亮的名字会自动跳转页面 微信封装好的不用操作
  62. openPrivacyContract() {
  63. wx.openPrivacyContract({
  64. fail: () => {
  65. uni.showToast({
  66. title: '网络错误',
  67. icon: 'error'
  68. });
  69. }
  70. });
  71. }
  72. }
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. .privacy {
  77. position: fixed;
  78. top: 0;
  79. right: 0;
  80. bottom: 0;
  81. left: 0;
  82. background: rgba(0, 0, 0, 0.5);
  83. z-index: 9999999;
  84. display: flex;
  85. align-items: center;
  86. justify-content: center;
  87. .content {
  88. width: 85vw;
  89. padding: 50rpx;
  90. box-sizing: border-box;
  91. background: #fff;
  92. border-radius: 16rpx;
  93. .title {
  94. text-align: center;
  95. color: #333;
  96. font-weight: bold;
  97. font-size: 34rpx;
  98. }
  99. .des {
  100. font-size: 28rpx;
  101. color: #666;
  102. margin-top: 40rpx;
  103. text-align: justify;
  104. line-height: 1.6;
  105. .link {
  106. color: #07c160;
  107. }
  108. }
  109. .btns {
  110. margin-top: 60rpx;
  111. display: flex;
  112. justify-content: space-between;
  113. .item {
  114. justify-content: space-between;
  115. width: 244rpx;
  116. height: 80rpx;
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. border-radius: 16rpx;
  121. box-sizing: border-box;
  122. border: none;
  123. }
  124. .reject {
  125. background: #f4f4f5;
  126. color: #909399;
  127. }
  128. .agree {
  129. background: #07c160;
  130. color: #fff;
  131. }
  132. }
  133. }
  134. }
  135. </style>