<template>
  <view class="privacy" v-if="showPrivacy">
    <view class="content">
      <view class="title">隐私保护指引</view>
      <view class="des">
        请您仔细阅读并充分理解<text class="link" @click="handleOpenPrivacyContract">{{ privacyContractName }}</text>
        ，如您同意前述协议的全部内容，请点击“同意”开始使用。<text class="cancel">如您不同意，将被限制使用部分功能，或将在您使用具体功能前再次询问以取得您的授权同意。</text>
      </view>

      <view class="btns">
        <button class="reject" @click="handleDisagree">拒绝</button>
        <button class="agree" open-type="agreePrivacyAuthorization"
          @agreeprivacyauthorization="handleAgreePrivacyAuthorization">
          同意
        </button>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onShow } from "@dcloudio/uni-app";

const showPrivacy = ref(true)
const privacyContractName = ref('隐私保护指引')

onShow(() => {
  // 条件编译微信小程序
  // #ifdef MP-WEIXIN

  wx.getPrivacySetting({
    success: (res) => {
      console.log("cj隐私配置", res);
      if (res.errMsg == "getPrivacySetting:ok" && res.needAuthorization) {
        privacyContractName.value = res.privacyContractName;
        showPrivacy.value = res.needAuthorization
      }
    },
  });
  // #endif

  // 条件编译抖音小程序
  // #ifdef MP-TOUTIAO
  uni.getPrivacySetting({
    success: (res) => {
      console.log(res)
    }
  })
  // #endif
})



// 拒绝
const handleDisagree = () => {
  showPrivacy.value = false
}

// 同意
const handleAgreePrivacyAuthorization = () => {
  showPrivacy.value = false
}

// 打开隐私保护指引
const handleOpenPrivacyContract = () => {
  // 条件编译微信小程序
  // #ifdef MP-WEIXIN
  wx.openPrivacyContract({
    fail: () => { }
  })
  // #endif
}

</script>

<style scoped lang="scss">
@import './styles/index.scss'
</style>
