一、manifest.json中配置
"__usePrivacyCheck__": true
二、編寫封裝后的組件
<template>
<view class="privacy" v-if="showPrivacy">
<view class="content">
<view class="title">隱私保護指引</view>
<view class="des">
在使用當(dāng)前小程序服務(wù)之前,請仔細(xì)閱讀
<text class="link" @click="openPrivacyContract">{{ privacyContractName }}</text>
。如果你同意{{ privacyContractName }},請點擊“同意”開始使用。
</view>
<view class="btns">
<button class="item reject" @click="exitMiniProgram">拒絕</button>
<button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
privacyContractName: '', //需要彈窗展示的隱私協(xié)議名稱
showPrivacy: false, //全局控制彈窗顯隱
};
},
created() {
this.getPrivacySet();
},
methods: {
getPrivacySet(){
let that = this;
uni.getPrivacySetting({
success(res) {
if (res.needAuthorization) {
that.privacyContractName = res.privacyContractName;
that.showPrivacy = true;
} else that.showPrivacy = false;
}
});
},
// 同意隱私協(xié)議
handleAgreePrivacyAuthorization() {
const that = this;
wx.requirePrivacyAuthorize({
success: res => {
that.showPrivacy = false;
getApp().globalData.showPrivacy = false;
}
});
},
// 拒絕隱私協(xié)議
exitMiniProgram() {
const that = this;
uni.showModal({
content: '如果拒絕,我們將無法獲取您的信息, 包括手機號、位置信息、相冊等該小程序十分重要的功能,您確定要拒絕嗎?',
success: res => {
if (res.confirm) {
that.showPrivacy = false;
uni.exitMiniProgram({
success: () => {
console.log('退出小程序成功');
}
});
}
}
});
},
// 跳轉(zhuǎn)協(xié)議頁面
// 點擊高亮的名字會自動跳轉(zhuǎn)頁面 微信封裝好的不用操作
openPrivacyContract() {
wx.openPrivacyContract({
fail: () => {
uni.showToast({
title: '網(wǎng)絡(luò)錯誤',
icon: 'error'
});
}
});
}
}
};
</script>
<style lang="scss" scoped>
.privacy {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9999999;
display: flex;
align-items: center;
justify-content: center;
.content {
width: 85vw;
padding: 50rpx;
box-sizing: border-box;
background: #fff;
border-radius: 16rpx;
.title {
text-align: center;
color: #333;
font-weight: bold;
font-size: 34rpx;
}
.des {
font-size: 26rpx;
color: #666;
margin-top: 40rpx;
text-align: justify;
line-height: 1.6;
.link {
color: #07c160;
text-decoration: underline;
}
}
.btns {
margin-top: 60rpx;
display: flex;
justify-content: space-between;
.item {
justify-content: space-between;
width: 244rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 16rpx;
box-sizing: border-box;
border: none;
}
.reject {
background: #f4f4f5;
color: #909399;
}
.agree {
background: #07c160;
color: #fff;
}
}
}
}
</style>
三、頁面引入試用
import privacyPopup from '../components/privacyPopup.vue';
components:{privacyPopup},
<!-- #ifdef MP-WEIXIN -->
<privacyPopup></privacyPopup>
<!-- #endif -->
文章來源地址http://www.zghlxwxcb.cn/news/detail-732380.html
文章來源:http://www.zghlxwxcb.cn/news/detail-732380.html
到了這里,關(guān)于uni-app 新增 微信小程序之新版隱私協(xié)議的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!