隱私彈窗:
1. 啟用隱私相關(guān)功能在manifest.json文件中配置?__usePrivacyCheck__: true
:
"mp-weixin" : {
"__usePrivacyCheck__" : true,
},
2. 創(chuàng)建組件:
<template>
<view>
<!-- 隱私政策彈窗 -->
<uni-popup ref="popup">
<view class="popupWrap">
<view class="popupTxt">
在您使用【最美萬(wàn)年歷】之前,請(qǐng)仔細(xì)閱讀<text class="blueColor"
@click="handleOpenPrivacyContract">{{privacyContractName}}</text>。如您同意{{privacyContractName}},請(qǐng)點(diǎn)擊“同意”開(kāi)始使用【最美萬(wàn)年歷】。
</view>
<view class="popupBot">
<button id="disagree-btn" type="default" @click="handleDisagree">拒絕</button>
<button id="agree-btn" type="primary" open-type="agreePrivacyAuthorization"
@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
export default {
name: "privacyPopup",
data() {
return {
privacyContractName: "" //協(xié)議名稱
};
},
mounted() {
wx.getPrivacySetting({
success: res => {
console.log("是否需要授權(quán):", res, res.needAuthorization, "隱私協(xié)議的名稱為:", res.privacyContractName)
if (res.needAuthorization) {
this.privacyContractName = res.privacyContractName;
this.$refs.popup.open('center')
}
},
fail: () => {},
complete: () => {},
})
},
methods: {
handleDisagree(e) {
this.$refs.popup.close()
},
handleAgreePrivacyAuthorization(res) {
// 用戶同意隱私協(xié)議事件回調(diào)
// 用戶點(diǎn)擊了同意,之后所有已聲明過(guò)的隱私接口和組件都可以調(diào)用了
this.$refs.popup.close()
//通知父組件
this.$emit("agreePrivacy")
console.log(res, "handleAgreePrivacyAuthorization");
},
handleOpenPrivacyContract() {
// 打開(kāi)隱私協(xié)議頁(yè)面
wx.openPrivacyContract({
success: () => {}, // 打開(kāi)成功
fail: () => {}, // 打開(kāi)失敗
complete: (res) => {
console.log(res, "openPrivacyContract complete");
}
})
},
}
}
</script>
<style lang="scss">
.popupWrap {
width: 540rpx;
box-sizing: border-box;
padding: 42rpx;
background: white;
border-radius: 30rpx;
.blueColor {
color: rgba(39, 152, 240, 1);
}
.popupTxt {
line-height: 48rpx;
}
.popupBot {
display: flex;
justify-content: space-around;
align-items: center;
margin-top: 30rpx;
}
}
</style>
2. 在需要授權(quán)的頁(yè)面引入改組件
例:
<privacyPopup @agreePrivacy="執(zhí)行同意協(xié)議后的邏輯"></privacyPopup>
PS:
也可使用獲取手機(jī)號(hào)和隱私政策藕合方式 ,這樣在用戶拒絕隱私協(xié)議后 ,再次點(diǎn)擊授權(quán)手機(jī)號(hào) 可繼續(xù)彈出授權(quán)彈窗,直至用戶同意協(xié)議為止
<button id="agree-btn" type="primary"
open-type="getPhoneNumber|agreePrivacyAuthorization"
@getphonenumber="handleBindPhone"
@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
?官方文檔入口:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-693460.html
?小程序隱私協(xié)議開(kāi)發(fā)指南 | 微信開(kāi)放文檔文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-693460.html
到了這里,關(guān)于uniapp 微信小程序添加隱私保護(hù)指引的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!