@@ -1,6 +1,6 @@
< template >
< template >
< view v-if = "showPop" >
< view >
< view class = "privacy-mask" >
< view class = "privacy-mask" v-if = "showPop" >
< 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" >
@@ -13,8 +13,13 @@
< / 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 >
< ! - - # ifdef QUICKAPP -WEBVIEW | | MP -WEIXIN - - >
< button id = "agree-btn" class = "privacy-button-btn bg-agree" open -type = " agreePrivacyAuthorization "
< button id = "agree-btn" class = "privacy-button-btn bg-agree" open -type = " agreePrivacyAuthorization "
@agreeprivacyauthorization ="handleAgree" > 同意并继续 < / button >
@agreeprivacyauthorization ="handleAgree" > 同意并继续 < / button >
< ! - - # endif - - >
<!-- # ifdef WEB || H5 -- >
< button id = "agree-btn" class = "privacy-button-btn bg-agree" @tap ="handleAgree" @click ="handleAgree" > 同意并继续 < / button >
< ! - - # endif - - >
< / view >
< / view >
< / view >
< / view >
< / view >
< / view >
@@ -26,6 +31,10 @@
import has from '@system.has'
import has from '@system.has'
// #endif
// #endif
const closeOtherPagePopUpHooks = new Set ( ) ;
const privacyContractPage = '/pages_tool/agreement/contenr?type=0' ;
const privacyServicePage = '/pages_tool/agreement/contenr?type=1' ;
export default {
export default {
name : 'PrivacyPopup' ,
name : 'PrivacyPopup' ,
data ( ) {
data ( ) {
@@ -34,7 +43,6 @@ export default {
showPop : false ,
showPop : false ,
privacyAuthorization : null ,
privacyAuthorization : null ,
privacyResolves : new Set ( ) ,
privacyResolves : new Set ( ) ,
closeOtherPagePopUpHooks : new Set ( ) ,
privacyContractName : '用户隐私保护指引' ,
privacyContractName : '用户隐私保护指引' ,
appName : '本小程序' ,
appName : '本小程序' ,
// #ifdef WEB || H5
// #ifdef WEB || H5
@@ -49,7 +57,6 @@ export default {
this . curPageShow ( )
this . curPageShow ( )
} ,
} ,
created ( ) {
created ( ) {
console . log ( ` 隐私组件初始化,隐私政策名称: ${ this . privacyContractName } ` )
try {
try {
// #ifdef MP-WEIXIN
// #ifdef MP-WEIXIN
//查询微信侧记录的用户是否有待同意的隐私政策信息
//查询微信侧记录的用户是否有待同意的隐私政策信息
@@ -64,7 +71,7 @@ export default {
// #ifdef QUICKAPP-WEBVIEW || H5
// #ifdef QUICKAPP-WEBVIEW || H5
if ( this . $util . isQuickApp ( ) ) {
if ( this . $util . isQuickApp ( ) ) {
if ( has ? . getPrivacySetting ) {
if ( typeof has != 'undefined' && has ? . getPrivacySetting ) {
has . getPrivacySetting ( {
has . getPrivacySetting ( {
success : ( res ) => {
success : ( res ) => {
if ( res . privacyContractName ) {
if ( res . privacyContractName ) {
@@ -83,7 +90,7 @@ export default {
getPrivacySettingByQuickApp ( ) {
getPrivacySettingByQuickApp ( ) {
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
if ( this . $util . isQuickApp ( ) ) {
if ( this . $util . isQuickApp ( ) ) {
if ( has ? . getPrivacySetting ) {
if ( typeof has != 'undefined' && has ? . getPrivacySetting ) {
has . getPrivacySetting ( {
has . getPrivacySetting ( {
success : ( res ) => {
success : ( res ) => {
// console.log(res)
// console.log(res)
@@ -96,6 +103,15 @@ export default {
}
}
} ,
} ,
} )
} )
} else {
// 属于嵌入到快应用Webview组件中的情况, 按照H5的方式来处理, 判断是否已经授权
if ( uni . getStorageSync ( 'privacyAgreed' ) ) {
this . $emit ( 'agree' )
} else {
this . popUp ( )
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
this . closeOtherPagePopUp ( this . disPopUp )
}
}
}
}
}
// #endif
// #endif
@@ -116,7 +132,7 @@ export default {
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
if ( this . $util . isQuickApp ( ) ) {
if ( this . $util . isQuickApp ( ) ) {
// 监听快速应用侧隐私政策授权变化事件
// 监听快速应用侧隐私政策授权变化事件
if ( has ? . onPrivacySettingChange ) {
if ( typeof has != 'undefined' && has ? . onPrivacySettingChange ) {
has . onPrivacySettingChange ( ( res ) => {
has . onPrivacySettingChange ( ( res ) => {
// console.log(res)
// console.log(res)
if ( res . needAuthorization ) {
if ( res . needAuthorization ) {
@@ -161,6 +177,7 @@ export default {
} ,
} ,
//初始化监听程序
//初始化监听程序
curPageShow ( ) {
curPageShow ( ) {
closeOtherPagePopUpHooks . add ( this . disPopUp )
this . privacyAuthorization = resolve => {
this . privacyAuthorization = resolve => {
this . privacyResolves . add ( resolve )
this . privacyResolves . add ( resolve )
//打开弹窗
//打开弹窗
@@ -168,11 +185,10 @@ export default {
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
this . closeOtherPagePopUp ( this . disPopUp )
this . closeOtherPagePopUp ( this . disPopUp )
}
}
this . closeOtherPagePopUpHooks . add ( this . disPopUp )
} ,
} ,
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
// 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
closeOtherPagePopUp ( closePopUp ) {
closeOtherPagePopUp ( closePopUp ) {
this . closeOtherPagePopUpHooks . forEach ( hook => {
closeOtherPagePopUpHooks . forEach ( hook => {
if ( closePopUp !== hook ) {
if ( closePopUp !== hook ) {
hook ( )
hook ( )
}
}
@@ -193,7 +209,7 @@ export default {
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
if ( this . $util . isQuickApp ( ) ) {
if ( this . $util . isQuickApp ( ) ) {
if ( has ? . openPrivacySetting ) {
if ( typeof has != 'undefined' && has ? . openPrivacySetting ) {
has . openPrivacySetting ( {
has . openPrivacySetting ( {
success : ( res ) => {
success : ( res ) => {
// console.log('打开隐私协议', res);
// console.log('打开隐私协议', res);
@@ -202,10 +218,13 @@ export default {
// console.error('打开隐私协议失败', err)
// console.error('打开隐私协议失败', err)
}
}
} ) ;
} ) ;
} else {
// 属于嵌入到快应用Webview组件中的情况, 按照H5的方式来处理
this . $util . redirectTo ( privacyContractPage ) ;
}
}
} else {
} else {
// H5 环境下的处理逻辑
// H5 环境下的处理逻辑
this . $util . redirectTo ( '/pages_tool/agreement/contenr?type=0' ) ;
this . $util . redirectTo ( privacyContractPage ) ;
}
}
// #endif
// #endif
} ,
} ,
@@ -213,7 +232,7 @@ export default {
openPrivacyService ( ) {
openPrivacyService ( ) {
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
if ( this . $util . isQuickApp ( ) ) {
if ( this . $util . isQuickApp ( ) ) {
if ( has ? . openPrivacySetting ) {
if ( typeof has != 'undefined' && has ? . openPrivacySetting ) {
has . openPrivacySetting ( {
has . openPrivacySetting ( {
success : ( res ) => {
success : ( res ) => {
// console.log('打开用户服务协议', res);
// console.log('打开用户服务协议', res);
@@ -222,10 +241,13 @@ export default {
// console.error('打开用户服务协议失败', err)
// console.error('打开用户服务协议失败', err)
}
}
} ) ;
} ) ;
} else {
// 属于嵌入到快应用Webview组件中的情况, 按照H5的方式来处理
this . $util . redirectTo ( privacyServicePage ) ;
}
}
} else {
} else {
// H5 环境下的处理逻辑
// H5 环境下的处理逻辑
this . $util . redirectTo ( '/pages_tool/agreement/contenr?type=1' ) ;
this . $util . redirectTo ( privacyServicePage ) ;
}
}
// #endif
// #endif
} ,
} ,
@@ -258,25 +280,26 @@ export default {
this . privacyResolves . clear ( )
this . privacyResolves . clear ( )
//关闭弹窗
//关闭弹窗
this . disPopUp ( )
this . disPopUp ( )
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
// 保存用户授权状态到本地存储, 用于快应用Webview组件中的H5方式处理
uni . setStorageSync ( 'privacyAgreed' , true ) ;
// #endif
this . $emit ( 'agree' )
this . $emit ( 'agree' )
} ,
} ,
//打开弹窗
//打开弹窗
popUp ( ) {
popUp ( ) {
if ( this. showPop === false ) {
this . showPop = true ;
this . showPop = true
}
} ,
} ,
//关闭弹窗
//关闭弹窗
disPopUp ( ) {
disPopUp ( ) {
if ( this. showPop === true ) {
this . showPop = false ;
this . showPop = false
}
} ,
} ,
} ,
} ,
beforeDestroy ( ) {
beforeDestroy ( ) {
// 清理事件监听器和集合
// 清理事件监听器和集合
this . privacyResolves . clear ( )
this . privacyResolves . clear ( )
this . closeOtherPagePopUpHooks . clear ( )
closeOtherPagePopUpHooks . delete ( this . disPopUp )
// 注意:这里需要根据实际情况清理微信和快速应用的事件监听器
// 注意:这里需要根据实际情况清理微信和快速应用的事件监听器
// 由于微信的 wx.onNeedPrivacyAuthorization 没有对应的 off 方法,这里可能需要其他方式处理
// 由于微信的 wx.onNeedPrivacyAuthorization 没有对应的 off 方法,这里可能需要其他方式处理
} ,
} ,
@@ -332,6 +355,9 @@ export default {
. privacy - button - btn {
. privacy - button - btn {
color : # FFF ;
color : # FFF ;
font - size : 30 rpx ;
font - size : 30 rpx ;
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
font - size : 28 rpx ;
// #endif
font - weight : 500 ;
font - weight : 500 ;
line - height : 100 rpx ;
line - height : 100 rpx ;
text - align : center ;
text - align : center ;