fix: 修复分类商品项布局问题并添加窗口resize监听

1. 调整diy-category-item的price-wrap和name-wrap样式,修复布局偏移
2. 移除冗余的主题变量定义,修正flex布局参数为正确的1
3. 添加窗口尺寸变化监听,实现主题色动态重算
4. 更新语言审计报告的代码调用统计数值
This commit is contained in:
2026-07-07 11:15:07 +08:00
parent 3713cd2cf6
commit b60ea984e5
4 changed files with 70 additions and 31 deletions

54
main.js
View File

@@ -118,6 +118,8 @@ async function bootstrap() {
store
});
app.$mount();
setupResizeListener();
}
bootstrap()
// #endif
@@ -130,4 +132,54 @@ const app = new Vue({
store
});
app.$mount();
// #endif
// #endif
// ============================================================
// 窗口尺寸变化监听
// ------------------------------------------------------------
// 背景: themeColorSet 会把 token 中的 rpx 转 px,转比例基于 window.innerWidth/750
// 缓存 key 已含 window.innerWidth,所以 cacheKey 不匹配时会自动重算;
// 但需要 resize 事件触发一次 themeColorSet 才会让 cacheKey 重新计算。
//
// 兼容点: 不同发布产物的 resize 来源不一样
// 1. 优先用 uni.onWindowResize — uni-app 跨端 API, H5 / App-Plus 支持
// 2. 兜底用 window.addEventListener('resize') — 纯 H5 产物中直接可用
// 3. 全部 try-catch,某条路径失败不影响其他路径
// 4. 用 200ms 去抖,避免拖动窗口时频繁触发(实测连续 resize 事件可达 60fps)
//
// 调用时机: 仅 H5 端在 $mount() 之后调用;小程序/鸿蒙端
// - 微信小程序: 屏幕尺寸由设备决定,运行时不会变化,无需监听
// - 鸿蒙: 待验证,目前不在这里注册以避免在不支持的环境下抛错
// ============================================================
function setupResizeListener() {
let resizeTimer = null;
const fire = () => {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
resizeTimer = null;
try {
store.dispatch('themeColorSet');
} catch (e) {
console.warn('[theme] resize -> themeColorSet fail', e);
}
}, 200);
};
// 路径 1: uni 跨端 API(H5 / App-Plus 上有效)
try {
if (typeof uni !== 'undefined' && typeof uni.onWindowResize === 'function') {
uni.onWindowResize(fire);
}
} catch (e) {
console.warn('[theme] uni.onWindowResize bind fail', e);
}
// 路径 2: 原生 window resize 事件(H5 兜底,某些自定义 H5 产物可能没装 uni)
try {
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
window.addEventListener('resize', fire);
}
} catch (e) {
console.warn('[theme] window.resize bind fail', e);
}
}