feat: security hardening, wechat pay v3 platform cert integration, companion certification revocation, and audit closed-loop

这个提交包含在:
xcbyy
2026-10-16 17:38:17 +08:00
父节点 3bf38db8b6
当前提交 78117bb4e1
共有 58 个文件被更改,包括 12971 次插入 和 952 次删除

查看文件

@@ -186,15 +186,40 @@ import { onShow } from '@dcloudio/uni-app';
import { ICONS } from '@/common/icons.js';
import { getCurrentThemeKey, applyThemeToNativeUI } from '@/common/theme.js';
import { getNavBarInfo } from '@/common/nav.js';
import { getUserSettings, updateUserSettings } from '@/common/api.js';
const currentThemeKey = ref(getCurrentThemeKey());
const navInfo = ref(getNavBarInfo());
// 本地设置状态
const ESSENTIAL_STORAGE_KEYS = [
'peiwan_token',
'peiwan_current_role',
'app_theme_key',
'privacy_hide_phone',
'notice_subscribe',
'userId',
'userInfo',
'user_has_logged_out',
'expert_cert_status',
'privacy_agreed',
'cache_cleaned_snapshot_kb'
];
const checkIsLoggedIn = () => {
const hasLoggedOut = uni.getStorageSync('user_has_logged_out') === '1';
if (hasLoggedOut) return false;
return true;
};
const currentUserId = computed(() => {
return Number(uni.getStorageSync('userId') || 1001);
});
// 本地与云端同步设置状态
const privacyHidePhone = ref(uni.getStorageSync('privacy_hide_phone') === '1');
const noticeSubscribe = ref(uni.getStorageSync('notice_subscribe') !== '0');
const cacheSizeText = ref('1.25 MB');
const isLoggedIn = ref(!!uni.getStorageSync('peiwan_token'));
const cacheSizeText = ref('0 KB');
const isLoggedIn = ref(checkIsLoggedIn());
// 顶部自定义导航栏适配
const navStyle = computed(() => {
@@ -210,80 +235,149 @@ const switchActiveColor = computed(() => {
return currentThemeKey.value === 'warm' ? '#EA580C' : '#6366F1';
});
// 计算本地缓存大小
// 真实计算可清理的本地临时缓存大小
const updateCacheSize = () => {
try {
const info = uni.getStorageInfoSync();
const kb = info.currentSize || 0;
if (kb > 1024) {
cacheSizeText.value = `${(kb / 1024).toFixed(2)} MB`;
const allKeys = Array.isArray(info.keys) ? info.keys : [];
const tempKeys = allKeys.filter(k => !ESSENTIAL_STORAGE_KEYS.includes(k));
const snapshotRaw = uni.getStorageSync('cache_cleaned_snapshot_kb');
const hasCleanedBefore = snapshotRaw !== '' && snapshotRaw !== null && snapshotRaw !== undefined;
let tempBytes = 0;
tempKeys.forEach((k) => {
try {
const val = uni.getStorageSync(k);
const serialized = typeof val === 'string' ? val : JSON.stringify(val || '');
tempBytes += (k.length + serialized.length) * 2;
} catch (_) {}
});
const currentKb = Number(info.currentSize || 0);
if (tempBytes > 0) {
const kb = Math.max(1, Math.ceil(tempBytes / 1024));
cacheSizeText.value = kb > 1024 ? `${(kb / 1024).toFixed(2)} MB` : `${kb} KB`;
} else if (!hasCleanedBefore && currentKb > 0) {
cacheSizeText.value = currentKb > 1024 ? `${(currentKb / 1024).toFixed(2)} MB` : `${currentKb} KB`;
} else {
cacheSizeText.value = `${kb} KB`;
const diffKb = Math.max(0, currentKb - Number(snapshotRaw || 0));
cacheSizeText.value = diffKb > 1024 ? `${(diffKb / 1024).toFixed(2)} MB` : `${diffKb} KB`;
}
} catch (_) {
cacheSizeText.value = '1.25 MB';
cacheSizeText.value = '0 KB';
}
};
// 切换手机号脱敏隐藏
const onToggleHidePhone = (e) => {
const val = e.detail.value;
// 同步远端用户的隐私与通知偏好
const syncSettingsFromServer = async () => {
if (!isLoggedIn.value) return;
try {
const res = await getUserSettings(currentUserId.value);
if (res && typeof res === 'object') {
if (typeof res.privacyHidePhone === 'boolean') {
privacyHidePhone.value = res.privacyHidePhone;
}
if (typeof res.noticeSubscribe === 'boolean') {
noticeSubscribe.value = res.noticeSubscribe;
}
}
} catch (_) {}
};
// 切换手机号脱敏隐藏(同步本地与后端并广播全站脱敏事件)
const onToggleHidePhone = async (e) => {
const val = !!e.detail.value;
privacyHidePhone.value = val;
uni.setStorageSync('privacy_hide_phone', val ? '1' : '0');
uni.$emit('privacy-settings-change', { privacyHidePhone: val });
await updateUserSettings(currentUserId.value, {
privacyHidePhone: val,
noticeSubscribe: noticeSubscribe.value
});
uni.showToast({
title: val ? '已开启手机号隐藏' : '已关闭手机号隐藏',
title: val ? '已开启手机号脱敏保护' : '已关闭手机号脱敏保护',
icon: 'none'
});
};
// 切换通知订阅
const onToggleNotice = (e) => {
const val = e.detail.value;
// 切换通知订阅(微信小程序端支持唤起订阅授权,并同步服务端)
const onToggleNotice = async (e) => {
const val = !!e.detail.value;
noticeSubscribe.value = val;
uni.setStorageSync('notice_subscribe', val ? '1' : '0');
// #ifdef MP-WEIXIN
if (val && typeof uni.requestSubscribeMessage === 'function') {
try {
uni.requestSubscribeMessage({
tmplIds: ['ORDER_STATUS_NOTICE_TMPL', 'ACTIVITY_TEAM_NOTICE_TMPL'],
complete: () => {}
});
} catch (_) {}
}
// #endif
uni.$emit('notice-subscribe-change', val);
await updateUserSettings(currentUserId.value, {
privacyHidePhone: privacyHidePhone.value,
noticeSubscribe: val
});
uni.showToast({
title: val ? '已开启服务提醒' : '已关闭服务提醒',
title: val ? '已开启订单与组局动态提醒' : '已关闭订单与组局动态提醒',
icon: 'none'
});
};
// 一键清理本地缓存
// 一键清理本地缓存(精准清理非核心临时键值与本地保存的临时文件)
const clearLocalCache = () => {
uni.showModal({
title: '清除缓存',
content: '清理将释放临时数据,保留登录账号与必要配置。确定继续?',
content: '清理将释放临时图片与历史交互缓存,保留当前登录账号与隐私配置。确定继续?',
confirmText: '确定清理',
cancelText: '取消',
confirmColor: '#EF4444',
success: (res) => {
if (res.confirm) {
try {
const token = uni.getStorageSync('peiwan_token');
const userRole = uni.getStorageSync('peiwan_current_role');
const themeKey = uni.getStorageSync('app_theme_key');
const hidePhone = uni.getStorageSync('privacy_hide_phone');
const noticeSub = uni.getStorageSync('notice_subscribe');
const userId = uni.getStorageSync('userId');
const userInfo = uni.getStorageSync('userInfo');
const info = uni.getStorageInfoSync();
const allKeys = Array.isArray(info.keys) ? info.keys : [];
let removedCount = 0;
allKeys.forEach((k) => {
if (!ESSENTIAL_STORAGE_KEYS.includes(k)) {
uni.removeStorageSync(k);
removedCount++;
}
});
uni.clearStorageSync();
// #ifdef MP-WEIXIN
if (typeof uni.getSavedFileList === 'function') {
uni.getSavedFileList({
success: (fileRes) => {
if (fileRes && Array.isArray(fileRes.fileList)) {
fileRes.fileList.forEach((f) => {
uni.removeSavedFile({ filePath: f.filePath, fail: () => {} });
});
}
},
fail: () => {}
});
}
// #endif
if (token) uni.setStorageSync('peiwan_token', token);
if (userRole) uni.setStorageSync('peiwan_current_role', userRole);
if (themeKey) uni.setStorageSync('app_theme_key', themeKey);
if (hidePhone) uni.setStorageSync('privacy_hide_phone', hidePhone);
if (noticeSub) uni.setStorageSync('notice_subscribe', noticeSub);
if (userId) uni.setStorageSync('userId', userId);
if (userInfo) uni.setStorageSync('userInfo', userInfo);
const afterInfo = uni.getStorageInfoSync();
uni.setStorageSync('cache_cleaned_snapshot_kb', Number(afterInfo.currentSize || 0));
const finalInfo = uni.getStorageInfoSync();
uni.setStorageSync('cache_cleaned_snapshot_kb', Number(finalInfo.currentSize || 0));
cacheSizeText.value = '0 KB';
uni.showToast({
title: '缓存清理完毕',
title: removedCount > 0 ? `已清理 ${removedCount} 项临时缓存` : '缓存清理完毕 (0 KB)',
icon: 'none'
});
} catch (_) {
cacheSizeText.value = '0 KB';
uni.showToast({
title: '清理成功',
title: '缓存清理完毕',
icon: 'none'
});
}
@@ -306,11 +400,11 @@ const handleSwitchAccount = () => {
});
};
// 退出登录
// 退出登录(与个人中心退出逻辑完全同步)
const handleLogout = () => {
uni.showModal({
title: '退出登录',
content: '确定退出当前账号登录吗?',
content: '退出登录后将清除本地会话,切换为未登录游客态。确定退出吗?',
confirmText: '确认退出',
cancelText: '取消',
confirmColor: '#EF4444',
@@ -319,9 +413,12 @@ const handleLogout = () => {
uni.removeStorageSync('peiwan_token');
uni.removeStorageSync('peiwan_current_role');
uni.removeStorageSync('userInfo');
uni.removeStorageSync('userId');
uni.removeStorageSync('userToken');
uni.setStorageSync('user_has_logged_out', '1');
isLoggedIn.value = false;
uni.showToast({
title: '已退出登录',
title: '已退出当前登录',
icon: 'none'
});
setTimeout(() => {
@@ -352,8 +449,9 @@ onShow(() => {
navInfo.value = getNavBarInfo();
privacyHidePhone.value = uni.getStorageSync('privacy_hide_phone') === '1';
noticeSubscribe.value = uni.getStorageSync('notice_subscribe') !== '0';
isLoggedIn.value = !!uni.getStorageSync('peiwan_token');
isLoggedIn.value = checkIsLoggedIn();
updateCacheSize();
syncSettingsFromServer();
});
</script>