1、manifest.json 配置修改
在mp-weixin: 参数修改(没有就添加)
"__usePrivacyCheck__": true,
***2、注意 微信开发者工具调整
不然一直报错 找不到 getPrivacySetting
废话不多说 上代码
3、 编辑首页 或者用户授权界面
<uni-popup ref="popup"><view class="popupWrap"><view class="popupTxt">在你使用【********】之前,请仔细阅读<text class="blueColor" @click="handleOpenPrivacyContract">《隐私保护指引》</text>。如你同意《******隐私保护指引》,请点击“同意”开始使用【******】。</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>
// onload 代码
// #ifdef MPwx.getPrivacySetting({success: res => {console.log("是否需要授权:",res, res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)//如果需要授权的话 显示弹窗if(res.needAuthorization){this.$refs.popup.open('center') }},fail: () => {},complete: () => {},})
// #endif
methods: {// 用户隐私handleDisagree(e) {this.$refs.popup.close()},handleAgreePrivacyAuthorization(res) {// 用户同意隐私协议事件回调// 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了this.$refs.popup.close()console.log(res,"handleAgreePrivacyAuthorization");},handleOpenPrivacyContract(){// 打开隐私协议页面wx.openPrivacyContract({success: () => {}, // 打开成功fail: () => {}, // 打开失败complete: (res) => {console.log(res,"openPrivacyContract complete");}})},// end用户隐私
}
css
.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;}}