privacy.uvue 2.7 KB
Newer Older
1 2 3 4
<template>
	<view class="uni-padding-wrap">
		<page-head :title="title"></page-head>
    <view class="item-box">
5
      <text>当前应用隐私授权状态:</text>
W
wanganxp 已提交
6 7 8 9 10 11 12 13
      <text>{{ appPrivacy }}</text>
    </view>
    <!-- #ifdef MP-WEIXIN -->
    <view class="item-box">
      <text>隐私授权协议的名称:</text>
      <text>{{ privacyContractName }}</text>
    </view>
    <!-- #endif -->
14 15
    <view>
      <button class="privacy-button" type="primary" @tap="getPrivacySetting">
16
        获取隐私协议授权状态
17 18
      </button>
      <button class="privacy-button" type="primary" open-type="agreePrivacyAuthorization">
W
wanganxp 已提交
19
        同意隐私协议专用按钮
20
      </button>
W
wanganxp 已提交
21
      <!-- #ifdef APP -->
22
      <button class="privacy-button" type="primary" @tap="resetPrivacyAuthorization">
23
        重置隐私协议授权状态
24
      </button>
25 26
      <button class="privacy-button" @tap="openPrivacyDialog">
        显示隐私政策弹框
W
wanganxp 已提交
27 28
      </button>
      <!-- #endif -->
29 30 31 32 33 34 35 36 37
    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			  title: '隐私信息授权',
W
wanganxp 已提交
38 39
			  appPrivacy: '未获取',
        privacyContractName: "",
40 41 42 43
        listenId: 0
			}
		},
    onReady() {
W
wanganxp 已提交
44
      // #ifdef APP
45 46 47 48 49 50 51 52 53 54 55 56 57
      //添加 隐私协议监听
      const id = uni.onPrivacyAuthorizationChange((res) => {
         this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
         const privacyState = "监听到隐私协议状态已变更为 " + this.appPrivacy;
         uni.showToast({
           "position": "bottom",
           "title": privacyState
         })
      })
      this.listenId = id;
      uni.showToast({
        "position": "bottom",
        "title": "开启监听隐私协议状态"
W
wanganxp 已提交
58 59
      })
      // #endif
60 61
    },
    onUnload() {
W
wanganxp 已提交
62
      // #ifdef APP
63 64 65 66 67 68
      //注销监听
      uni.offPrivacyAuthorizationChange(this.listenId)
      this.listenId = 0;
      uni.showToast({
        "position": "bottom",
        "title": "已停止监听隐私协议状态"
W
wanganxp 已提交
69 70
      })
      // #endif
71 72 73 74 75
    },
		methods: {
			getPrivacySetting() {
			  uni.getPrivacySetting({
			    success: (res) => {
W
wanganxp 已提交
76 77 78 79
			      this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
            // #ifdef MP-WEIXIN
            this.privacyContractName = res.privacyContractName
            // #endif
80 81 82 83 84
			    }
			  })
			},
      resetPrivacyAuthorization(){
        uni.resetPrivacyAuthorization()
85 86 87 88 89
      },
      openPrivacyDialog(){
        uni.openDialogPage({
          url: '/pages/component/button/privacy',
        })
90 91 92 93 94 95 96
      }
		}
	}
</script>

<style>
.item-box {
97
    margin-bottom: 10px;
98 99 100 101 102
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }
.privacy-button{
103 104
  margin-top: 5px;
  margin-bottom: 5px;
105 106
}
</style>