privacy.uvue 2.0 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>
6 7 8 9
      <text>{{ appPrivacy }}</text>
    </view>
    <view>
      <button class="privacy-button" type="primary" @tap="getPrivacySetting">
10
        获取隐私协议授权状态
11 12 13 14 15
      </button>
      <button class="privacy-button" type="primary" open-type="agreePrivacyAuthorization">
        同意隐私协议
      </button>
      <button class="privacy-button" type="primary" @tap="resetPrivacyAuthorization">
16
        重置隐私协议授权状态
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
      </button>
    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			  title: '隐私信息授权',
			  appPrivacy: '未获取',
        listenId: 0
			}
		},
    onReady() {
      //添加 隐私协议监听
      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": "开启监听隐私协议状态"
      })
    },
    onUnload() {
      //注销监听
      uni.offPrivacyAuthorizationChange(this.listenId)
      this.listenId = 0;
      uni.showToast({
        "position": "bottom",
        "title": "已停止监听隐私协议状态"
      })
    },
		methods: {
			getPrivacySetting() {
			  uni.getPrivacySetting({
			    success: (res) => {
			      this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
			    }
			  })
			},
      resetPrivacyAuthorization(){
        uni.resetPrivacyAuthorization()
      }
		}
	}
</script>

<style>
.item-box {
73
    margin-bottom: 10px;
74 75 76 77 78
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }
.privacy-button{
79 80
  margin-top: 5px;
  margin-bottom: 5px;
81 82
}
</style>