privacy.uvue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="uni-padding-wrap">
  3. <page-head :title="title"></page-head>
  4. <view class="item-box">
  5. <text>当前应用隐私授权状态:</text>
  6. <text>{{ appPrivacy }}</text>
  7. </view>
  8. <!-- #ifdef MP-WEIXIN -->
  9. <view class="item-box">
  10. <text>隐私授权协议的名称:</text>
  11. <text>{{ privacyContractName }}</text>
  12. </view>
  13. <!-- #endif -->
  14. <view>
  15. <button class="privacy-button" type="primary" @tap="getPrivacySetting">
  16. 获取隐私协议授权状态
  17. </button>
  18. <button class="privacy-button" type="primary" open-type="agreePrivacyAuthorization">
  19. 同意隐私协议专用按钮
  20. </button>
  21. <!-- #ifdef APP -->
  22. <button class="privacy-button" type="primary" @tap="resetPrivacyAuthorization">
  23. 重置隐私协议授权状态
  24. </button>
  25. <button class="privacy-button" @tap="openPrivacyDialog">
  26. 显示隐私政策弹框
  27. </button>
  28. <!-- #endif -->
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. title: '隐私信息授权',
  37. appPrivacy: '未获取',
  38. privacyContractName: "",
  39. listenId: 0
  40. }
  41. },
  42. onReady() {
  43. // #ifdef APP
  44. //添加 隐私协议监听
  45. const id = uni.onPrivacyAuthorizationChange((res) => {
  46. this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
  47. const privacyState = "监听到隐私协议状态已变更为 " + this.appPrivacy;
  48. uni.showToast({
  49. "position": "bottom",
  50. "title": privacyState
  51. })
  52. })
  53. this.listenId = id;
  54. uni.showToast({
  55. "position": "bottom",
  56. "title": "开启监听隐私协议状态"
  57. })
  58. // #endif
  59. },
  60. onUnload() {
  61. // #ifdef APP
  62. //注销监听
  63. uni.offPrivacyAuthorizationChange(this.listenId)
  64. this.listenId = 0;
  65. uni.showToast({
  66. "position": "bottom",
  67. "title": "已停止监听隐私协议状态"
  68. })
  69. // #endif
  70. },
  71. methods: {
  72. getPrivacySetting() {
  73. uni.getPrivacySetting({
  74. success: (res) => {
  75. this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
  76. // #ifdef MP-WEIXIN
  77. this.privacyContractName = res.privacyContractName
  78. // #endif
  79. }
  80. })
  81. },
  82. resetPrivacyAuthorization(){
  83. uni.resetPrivacyAuthorization()
  84. },
  85. openPrivacyDialog(){
  86. uni.openDialogPage({
  87. url: '/pages/component/button/privacy',
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. .item-box {
  95. margin-bottom: 10px;
  96. display: flex;
  97. flex-direction: row;
  98. justify-content: space-between;
  99. }
  100. .privacy-button{
  101. margin-top: 5px;
  102. margin-bottom: 5px;
  103. }
  104. </style>