- 新增 ToolbarButtonGroup 组件及类型定义,订单、波次等页面统一使用, 工具栏按钮样式分类(刷新/设置/操作/取消)收敛到一处 - 订单共享模块迁移至 views/order/shared:创建订单会话、通用表单、 导出、工具栏动作、订单元数据缓存;stockPickerHelpers 归入 stock/utils - 抽离 ScanBox 字段工厂、货主/快递下拉选项映射、状态文本工具, 新增 list-page.scss、status-text.scss,order-common-config 改为再导出 - UpperTable 虚拟滚动优化:实测行高兜底、渲染行数组引用复用、 rowKey/复制码/收起文本缓存、窗口行数按 4 行量化、ResizeObserver 同步视口, 减少滚动抖动与整表重建 - 列表页状态列改用轻量文本样式替代 el-tag,降低大列表渲染开销; 标签页缓存默认上限由 3 调整为 8 - 补充标签页性能测量结论、页面模板抽离现状与实施方案文档
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
/**
|
||
* 订单模块「基础参照数据」请求缓存(快递公司 / 平台 / 店铺)。
|
||
*
|
||
* 背景:订单管理 8 个页签各自在 mounted 里拉取这 3 个列表(仅用于 ScanBox 筛选下拉与
|
||
* 「分配快递号」等弹窗的选项)。页签切换(KeepAlive 淘汰后重建)会重复请求同一份
|
||
* 几乎不变的数据,属于无效开销。
|
||
*
|
||
* 设计:
|
||
* - 缓存的是**原始接口响应**,调用方仍按各自逻辑解析,互不影响;
|
||
* - 缓存 key 带当前 token:切换账号后自动失效,避免跨租户脏数据;
|
||
* - 请求失败即从缓存移除,下次进入页面会重试;
|
||
* - 默认 TTL 60s,参照数据变更(设置页新增快递公司等)最迟 1 分钟内可见。
|
||
*/
|
||
import { getToken } from '@/utils/auth'
|
||
import * as indexApi from '@/api/index/index'
|
||
import type { GetExpressListParams, GetPlatformListParams } from '@/api/index/index'
|
||
|
||
/** 参照数据缓存有效期(毫秒) */
|
||
export const ORDER_META_CACHE_TTL = 60_000
|
||
|
||
type CacheEntry = { at: number; promise: Promise<any> }
|
||
|
||
const cache = new Map<string, CacheEntry>()
|
||
|
||
function sessionKey(name: string) {
|
||
return `${name}|${getToken() ?? ''}`
|
||
}
|
||
|
||
function cachedRequest<T>(name: string, loader: () => Promise<T>, ttl = ORDER_META_CACHE_TTL): Promise<T> {
|
||
const key = sessionKey(name)
|
||
const now = Date.now()
|
||
const hit = cache.get(key)
|
||
if (hit && now - hit.at < ttl) return hit.promise as Promise<T>
|
||
|
||
const promise = loader().catch((error) => {
|
||
// 失败不留在缓存里,避免一次网络抖动导致整段时间都用不到数据
|
||
if (cache.get(key)?.promise === promise) cache.delete(key)
|
||
throw error
|
||
})
|
||
cache.set(key, { at: now, promise })
|
||
return promise
|
||
}
|
||
|
||
/** 快递公司列表(systemOnly 不同视为不同缓存项) */
|
||
export function loadExpressListCached(params?: GetExpressListParams) {
|
||
const name = params?.systemOnly === 'true' ? 'express:systemOnly' : 'express:all'
|
||
return cachedRequest(name, () => indexApi.getExpressList(params))
|
||
}
|
||
|
||
/** 平台列表(订单页统一用 systemOnly=true) */
|
||
export function loadPlatformListCached(params: GetPlatformListParams = { systemOnly: 'true' }) {
|
||
const name = params.systemOnly === 'true' ? 'platform:systemOnly' : 'platform:all'
|
||
return cachedRequest(name, () => indexApi.getPlatformList(params))
|
||
}
|
||
|
||
/** 货主店铺列表(ScanBox 货主筛选项) */
|
||
export function loadStoresCached() {
|
||
return cachedRequest('stores', () => indexApi.loadStores())
|
||
}
|
||
|
||
/** 清空参照数据缓存(如基础数据被编辑后可手动调用) */
|
||
export function clearOrderMetaCache() {
|
||
cache.clear()
|
||
}
|