fix: 解决在快应用环境中不显示用户隐私提示窗体的问题

This commit is contained in:
2026-01-08 14:52:01 +08:00
parent ee4fbb277c
commit 5a8663eb48
4 changed files with 72 additions and 30 deletions

View File

@@ -1169,8 +1169,24 @@ export default {
*/ */
isQuickApp() { isQuickApp() {
// #ifndef QUICKAPP-WEBVIEW // #ifndef QUICKAPP-WEBVIEW
const systemInfo = this.getDeviceInfo(); let _isQuickApp = false;
return systemInfo.platform === 'quickapp' || process.env.UNI_PLATFORM === 'quickapp'; try {
const ua = navigator?.userAgent?.toLowerCase();
console.log('ua = ', ua);
_isQuickApp = ua.indexOf('quickapp') !== -1;
if (!_isQuickApp) {
// 特殊说明由于网站是嵌入到快应用的Webview组件中<web>UA中不会包含quickapp字符串
// 但是会包含uniacid参数所以这里通过uniacid参数来判断是否为快应用环境
_isQuickApp = ua.indexOf('uniacid=') !== -1;
}
} catch (e) {}
if (!_isQuickApp) {
const systemInfo = this.getDeviceInfo();
_isQuickApp = systemInfo?.platform === 'quickapp' || process?.env?.UNI_PLATFORM === 'quickapp';
}
return _isQuickApp;
// #endif // #endif
return true; return true;

View File

@@ -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) {
@@ -132,7 +148,7 @@ export default {
// #endif // #endif
// 主动查询用户隐私政策授权状态,针对快速应用 // 主动查询用户隐私政策授权状态,针对快速应用
this.getPrivacySettingByQuickApp(); this.getPrivacySettingByQuickApp();
}, },
// 主动查询用户隐私政策授权状态 // 主动查询用户隐私政策授权状态
proactive() { proactive() {
@@ -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: 30rpx; font-size: 30rpx;
// #ifdef QUICKAPP-WEBVIEW || H5 || WEB
font-size: 28rpx;
// #endif
font-weight: 500; font-weight: 500;
line-height: 100rpx; line-height: 100rpx;
text-align: center; text-align: center;

View File

@@ -1,6 +1,6 @@
export const lang = { export const lang = {
//title为每个页面的标题 //title为每个页面的标题
title: '退款', title: '售后',
checkDetail: '查看详情', checkDetail: '查看详情',
emptyTips: '暂无退款记录' emptyTips: '暂无售后记录'
} }

View File

@@ -400,7 +400,7 @@
.price { .price {
color: var(--price-color); color: var(--price-color);
color: #fff !important; color: #fff !important;
font-size: 15rpx !important; font-size: 27rpx !important;
font-weight: bold !important; font-weight: bold !important;
} }
} }