uni-app 开发小程序接入隐私协议弹窗

一、template

<!-- 隐私保护指引 -->
<view class="privacy-guide-box" v-if="showPrivacyGuide" @touchmove.stop.prevent="toMoveHandle">
  <view class="container-box">
    <view class="pop-title">温馨提示</view>
    <view class="pop-cont-box">
      <text>在你使用【{{ dialogName }}】 服务之前,请仔细阅读</text>
      <text class="pop-link-tip" @click="toShowPact">《{{ dialogName }}隐私保护指引》</text>
      <text>。如你同意《{{ dialogName }}隐私保护指引》,请点击“同意”开始使用【{{ dialogName }}】。</text>
    </view>
    <view class="pop-btn-box">
      <button class="pop-reject-tip" @click.stop="toPopReject">拒绝</button>
      <button class="pop-agree-tip" id="agree-btn" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="toPopAgree">
        同意
      </button>
    </view>
  </view>
</view>

二、data

/* 隐私保护指引 */
showPrivacyGuide: false,
dialogName: "数智贵阳",
resolvePrivacyAuthorization: null,

三、onLoad

/* 隐私保护指引 */
wx.getPrivacySetting({
  success: res => {
    if (res.needAuthorization) this.showPrivacyGuide = true; // 需要弹出隐私协议
  }
});
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
  console.log("触发本次事件的接口是:", resolve, eventInfo, eventInfo.referrer);
  this.showPrivacyGuide = true; // 需要弹出隐私协议
  this.resolvePrivacyAuthorization = resolve;
});

四、methods

/* 隐私保护指引 */
toShowPact() {
  // 跳转至隐私协议页面
  wx.openPrivacyContract({});
},
toPopReject() {
  // 拒绝
  this.showPrivacyGuide = false;
},
toPopAgree() {
  // 同意
  this.showPrivacyGuide = false;
  this.resolvePrivacyAuthorization && this.resolvePrivacyAuthorization({ buttonId: "agree-btn", event: "agree" });
},
toMoveHandle() {},

五、style

/* 隐私保护指引 - style */
.privacy-guide-box {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999;
  .container-box {
    width: 80%;
    background: #fff;
    border-radius: 16rpx;
  }
  .pop-title {
    width: 100%;
    text-align: center;
    color: #000;
    font-size: 38rpx;
    margin-top: 30rpx;
    font-weight: 900;
  }
  .pop-cont-box {
    color: #969799;
    line-height: 1.5;
    font-size: 32rpx;
    padding: 30rpx 40rpx;
    text-align: justify;
    .pop-link-tip {
      color: #01a281;
    }
  }
  .pop-btn-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20rpx 20rpx 30rpx;
    button {
      width: 45%;
      border: 2px solid #01a281;
      border-radius: 50rpx;
    }
    .pop-reject-tip {
      color: #01a281;
    }
    .pop-agree-tip {
      color: #fff;
      background: #01a281;
    }
  }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值