fix: preserve turnover deep-link snapshots and clarify data status
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
import type { Quantity } from './types'
|
||||
import type { TurnoverCharts, TurnoverTotal, TurnoverWindowMetric } from './turnoverTypes'
|
||||
import type { EChartsOption } from 'echarts'
|
||||
import { reasonsText } from './state'
|
||||
const turnoverLabels: Record<string, string> = {
|
||||
INSUFFICIENT: '合格日库存样本不足', ZERO_AVERAGE_STOCK: '每日观测未捕获存量,无法计算周转',
|
||||
INVENTORY_UNKNOWN_OR_STALE: '当前库存未知、异常或已过期', NOT_APPLICABLE: '货主不计算整体可售天数',
|
||||
SALES_OR_STOCK_UNASSESSABLE: '部分商品的销量或库存不足以判断',
|
||||
SALES_WINDOW_UNAVAILABLE: '同期销量或商品观察证据不足',
|
||||
}
|
||||
export function turnoverReasonsText(reasons: readonly string[] | null | undefined) {
|
||||
return reasons?.map(reason => turnoverLabels[reason] ?? reasonsText([reason])).join('、') || '—'
|
||||
}
|
||||
export function turnoverNumber(value: Quantity | undefined, decimals = 2) {
|
||||
if (value == null || value === '' || !Number.isFinite(Number(value))) return '—'
|
||||
const n = Number(value)
|
||||
@@ -8,6 +18,7 @@ export function turnoverNumber(value: Quantity | undefined, decimals = 2) {
|
||||
return n.toLocaleString('zh-CN', { maximumFractionDigits: decimals })
|
||||
}
|
||||
export function totalText(total: TurnoverTotal) {
|
||||
if (total.value == null && total.knownSubtotal == null && total.unknownSkuCount === 0) return turnoverReasonsText(total.reasonCodes)
|
||||
return total.value != null ? turnoverNumber(total.value) : `已知 ${turnoverNumber(total.knownSubtotal)};${total.unknownSkuCount} SKU待核验`
|
||||
}
|
||||
export function windowText(metric: TurnoverWindowMetric | undefined) {
|
||||
@@ -18,7 +29,8 @@ export function turnoverChart(charts: TurnoverCharts, kind: 'owners' | 'daily'):
|
||||
const owners = kind === 'owners'
|
||||
const rows = owners ? charts.ownerPhysicalTop : charts.averageDaily
|
||||
return {
|
||||
aria: { enabled: true }, animationDuration: 450, color: ['#6c7bea'],
|
||||
aria: { enabled: true }, animation: typeof window === 'undefined' || !window.matchMedia?.('(prefers-reduced-motion: reduce)').matches,
|
||||
animationDuration: 450, color: ['#6c7bea'],
|
||||
tooltip: { trigger: 'axis', renderMode: 'richText' }, grid: { left: 12, right: 24, top: 16, bottom: 20, containLabel: true },
|
||||
xAxis: owners ? { type: 'value', name: '件' } : { type: 'category', data: charts.averageDaily.map(w => `${w.days}日`) },
|
||||
yAxis: owners ? { type: 'category', inverse: true, data: charts.ownerPhysicalTop.map(w => w.customerName || w.customerCode) } : { type: 'value', name: '件/日' },
|
||||
|
||||
Reference in New Issue
Block a user