test(隐私): 测试
This commit is contained in:
@@ -1,29 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- #ifdef MP -->
|
|
||||||
<view v-if="showPop">
|
<view v-if="showPop">
|
||||||
<view class="privacy-mask">
|
<view class="privacy-mask">
|
||||||
<view class="privacy-wrap">
|
<view class="privacy-wrap">
|
||||||
<view class="privacy-title">用户隐私保护提示</view>
|
<view class="privacy-title">用户隐私保护提示</view>
|
||||||
<view class="privacy-desc">
|
<view class="privacy-desc">
|
||||||
感谢您使用本小程序,在使用前您应当阅读并同意
|
感谢您使用{{ appName }},在使用前您应当阅读并同意
|
||||||
<text class="privacy-link" @tap="openPrivacyContract">{{privacyContractName}}</text>,
|
<text class="privacy-link" @tap="openPrivacyContract">{{ privacyContractName }}</text>
|
||||||
当点击同意并继续时,即表示您已理解并同意该条款内容,该条款将对您产生法律约束力;如您不同意,将无法继续使用小程序相关功能。
|
<!-- #ifdef QUICKAPP-WEBVIEW || H5 -->
|
||||||
|
<text class="privacy-link" @tap="openPrivacyService">{{ privacyServiceName }}</text>
|
||||||
|
<!-- #endif -->
|
||||||
|
,当点击同意并继续时,即表示您已理解并同意该条款内容,该条款将对您产生法律约束力;如您不同意,将无法继续使用{{ appName }}相关功能。
|
||||||
</view>
|
</view>
|
||||||
<view class="privacy-button-flex">
|
<view class="privacy-button-flex">
|
||||||
<button class="privacy-button-btn bg-disagree" @tap="handleDisagree">不同意</button>
|
<button class="privacy-button-btn bg-disagree" @tap="handleDisagree">不同意</button>
|
||||||
<button id="agree-btn" class="privacy-button-btn bg-agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgree">同意并继续</button>
|
<button id="agree-btn" class="privacy-button-btn bg-agree" open-type="agreePrivacyAuthorization"
|
||||||
|
@agreeprivacyauthorization="handleAgree">同意并继续</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
|
||||||
<!-- #ifdef WEB || H5 -->
|
|
||||||
<view v-if="showPop"></view>
|
|
||||||
<!-- #endif -->
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// #ifdef QUICKAPP-WEBVIEW
|
||||||
|
import has from '@system.has'
|
||||||
|
// #endif
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
name: 'PrivacyPopup',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
agree: false,
|
agree: false,
|
||||||
@@ -31,48 +35,114 @@
|
|||||||
privacyAuthorization: null,
|
privacyAuthorization: null,
|
||||||
privacyResolves: new Set(),
|
privacyResolves: new Set(),
|
||||||
closeOtherPagePopUpHooks: new Set(),
|
closeOtherPagePopUpHooks: new Set(),
|
||||||
privacyContractName: '用户隐私保护指引'
|
privacyContractName: '用户隐私保护指引',
|
||||||
|
appName: '本小程序',
|
||||||
|
// #ifdef WEB || H5
|
||||||
|
appName: '本应用',
|
||||||
|
privacyContractName: '《隐私条款》',
|
||||||
|
privacyServiceName: '《用户服务协议》',
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.init()
|
this.listenPrivacySettingChange()
|
||||||
this.curPageShow()
|
this.curPageShow()
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
let that = this
|
console.log(`隐私组件初始化,隐私政策名称:${this.privacyContractName}`)
|
||||||
//查询微信侧记录的用户是否有待同意的隐私政策信息
|
|
||||||
try {
|
try {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
//查询微信侧记录的用户是否有待同意的隐私政策信息
|
||||||
wx.getPrivacySetting({
|
wx.getPrivacySetting({
|
||||||
success(res) {
|
success: (res) => {
|
||||||
// console.log('隐私政策信息', res);
|
// console.log('隐私政策信息', res);
|
||||||
// console.log(res.privacyContractName);
|
// console.log(res.privacyContractName);
|
||||||
that.privacyContractName = res.privacyContractName
|
this.privacyContractName = res.privacyContractName
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef QUICKAPP-WEBVIEW || H5
|
||||||
|
if (this.$util.isQuickApp()) {
|
||||||
|
if (has?.getPrivacySetting) {
|
||||||
|
has.getPrivacySetting({
|
||||||
|
success: (res) => {
|
||||||
|
if (res.privacyContractName) {
|
||||||
|
this.privacyContractName = res.privacyContractName
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// console.log("=========低版本基础库==========")
|
console.error("=========低版本基础库==========", e)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 监听何时需要提示用户阅读隐私政策
|
getPrivacySettingByQuickApp() {
|
||||||
init() {
|
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
|
||||||
let that = this;
|
if (this.$util.isQuickApp()) {
|
||||||
|
if (has?.getPrivacySetting) {
|
||||||
|
has.getPrivacySetting({
|
||||||
|
success: (res) => {
|
||||||
|
// console.log(res)
|
||||||
|
if (res.needAuthorization) {
|
||||||
|
this.popUp()
|
||||||
|
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||||
|
this.closeOtherPagePopUp(this.disPopUp)
|
||||||
|
} else {
|
||||||
|
this.$emit('agree')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
|
||||||
|
listenPrivacySettingChange() {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
// 监听微信侧隐私政策授权变化事件
|
||||||
if (wx.onNeedPrivacyAuthorization) {
|
if (wx.onNeedPrivacyAuthorization) {
|
||||||
wx.onNeedPrivacyAuthorization((resolve) => {
|
wx.onNeedPrivacyAuthorization((resolve) => {
|
||||||
if (typeof that.privacyAuthorization === 'function') {
|
if (typeof this.privacyAuthorization === 'function') {
|
||||||
that.privacyAuthorization(resolve)
|
this.privacyAuthorization(resolve)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
|
||||||
|
if (this.$util.isQuickApp()) {
|
||||||
|
// 监听快速应用侧隐私政策授权变化事件
|
||||||
|
if (has?.onPrivacySettingChange) {
|
||||||
|
has.onPrivacySettingChange((res) => {
|
||||||
|
// console.log(res)
|
||||||
|
if (res.needAuthorization) {
|
||||||
|
this.popUp()
|
||||||
|
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||||
|
this.closeOtherPagePopUp(this.disPopUp)
|
||||||
|
} else {
|
||||||
|
this.$emit('agree')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// 主动查询用户隐私政策授权状态,针对快速应用
|
||||||
|
this.getPrivacySettingByQuickApp();
|
||||||
},
|
},
|
||||||
|
// 主动查询用户隐私政策授权状态
|
||||||
proactive() {
|
proactive() {
|
||||||
let that = this
|
// #ifdef MP-WEIXIN
|
||||||
if (wx.getPrivacySetting) {
|
if (wx.getPrivacySetting) {
|
||||||
wx.getPrivacySetting({
|
wx.getPrivacySetting({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
// console.log(res)
|
// console.log(res)
|
||||||
if (res.needAuthorization) {
|
if (res.needAuthorization) {
|
||||||
that.popUp()
|
this.popUp()
|
||||||
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
||||||
this.closeOtherPagePopUp(this.disPopUp)
|
this.closeOtherPagePopUp(this.disPopUp)
|
||||||
} else {
|
} else {
|
||||||
@@ -83,6 +153,11 @@
|
|||||||
} else {
|
} else {
|
||||||
this.$emit('agree')
|
this.$emit('agree')
|
||||||
}
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef QUICKAPP-WEBVIEW
|
||||||
|
this.getPrivacySettingByQuickApp();
|
||||||
|
// #endif
|
||||||
},
|
},
|
||||||
//初始化监听程序
|
//初始化监听程序
|
||||||
curPageShow() {
|
curPageShow() {
|
||||||
@@ -105,6 +180,7 @@
|
|||||||
},
|
},
|
||||||
//打开隐私协议
|
//打开隐私协议
|
||||||
openPrivacyContract() {
|
openPrivacyContract() {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
wx.openPrivacyContract({
|
wx.openPrivacyContract({
|
||||||
success(res) {
|
success(res) {
|
||||||
// console.log('打开隐私协议', res);
|
// console.log('打开隐私协议', res);
|
||||||
@@ -113,6 +189,45 @@
|
|||||||
// console.error('打开隐私协议失败', err)
|
// console.error('打开隐私协议失败', err)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
|
||||||
|
if (this.$util.isQuickApp()) {
|
||||||
|
if (has?.openPrivacySetting) {
|
||||||
|
has.openPrivacySetting({
|
||||||
|
success: (res) => {
|
||||||
|
// console.log('打开隐私协议', res);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
// console.error('打开隐私协议失败', err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// H5 环境下的处理逻辑
|
||||||
|
this.$util.redirectTo('/pages_tool/agreement/contenr?type=0');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
//打开用户服务协议
|
||||||
|
openPrivacyService() {
|
||||||
|
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
|
||||||
|
if (this.$util.isQuickApp()) {
|
||||||
|
if (has?.openPrivacySetting) {
|
||||||
|
has.openPrivacySetting({
|
||||||
|
success: (res) => {
|
||||||
|
// console.log('打开用户服务协议', res);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
// console.error('打开用户服务协议失败', err)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// H5 环境下的处理逻辑
|
||||||
|
this.$util.redirectTo('/pages_tool/agreement/contenr?type=1');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
},
|
},
|
||||||
// 不同意
|
// 不同意
|
||||||
handleDisagree() {
|
handleDisagree() {
|
||||||
@@ -157,7 +272,14 @@
|
|||||||
this.showPop = false
|
this.showPop = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
// 清理事件监听器和集合
|
||||||
|
this.privacyResolves.clear()
|
||||||
|
this.closeOtherPagePopUpHooks.clear()
|
||||||
|
// 注意:这里需要根据实际情况清理微信和快速应用的事件监听器
|
||||||
|
// 由于微信的 wx.onNeedPrivacyAuthorization 没有对应的 off 方法,这里可能需要其他方式处理
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user