CaseRowDetail.tsx
6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { EnvironmentOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import type { BucketRow, MetaFile } from '@/features/heatmap/aggregate/types';
import { useHeatmapStore } from '@/store/useHeatmapStore';
import { districtNameOf, fmtDateTime, streetNameOf } from '@/utils/format';
const WEEKDAY_NAMES = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
/**
* 行首展开箭头那一列的宽度。
*
* 必须由建列的地方一起从正文宽里扣掉:表格是 tableLayout="fixed",地址列的宽度
* 是按「正文宽 − 其余固定列」算出来的,漏了这一列,整张表就会比正文宽 28px,
* 右边被 .hm-drawer-glass 的 overflow-x:hidden 裁掉一截。两处引用同一个常量,不各写一个数。
*/
export const CASE_EXPAND_W = 28;
/**
* 一条案件在清单里的身份:案件号 + 报案时间。
*
* 定位之后要把「刚才点的是哪一行」标出来(见 store 的 CasePin.key):
* 行上、展开区里那颗按钮点下去传的都是这一个串,两处才标得在同一行上。
* 案件号在源表里可能重复登记(同一张保单报两次),加上时间就基本唯一;
* 也不用下标 —— 翻页之后下标会变,而定位标记不随翻页消失。
*/
export function caseRowKey(row: Pick<BucketRow, 'caseNo' | 'ts'>): string {
return `${row.caseNo}|${row.ts}`;
}
/**
* 字典下标 → 可读汉字;缺填(下标 0)返回 undefined。
*
* 口径与 worker 一致:下标 0 是「这一项没写」,不是叫「未填」的一个分类,
* 所以这里不把它念成一个值,由调用方决定写「—」还是「未填」。
*/
export function attrNameOf(i: number | undefined, dict?: string[]): string | undefined {
if (i == null) return undefined;
const v = dict?.[i];
return v ? v : undefined;
}
/** 一条案件的全部字段,按「先认得是哪一件、再是车、最后是位置」排 */
function detailItems(row: BucketRow, meta?: MetaFile | null): Array<[string, string]> {
const d = meta?.dict;
return [
['案件号', row.caseNo || '—'],
[
'报案时间',
`${fmtDateTime(row.ts)} ${WEEKDAY_NAMES[new Date(row.ts * 1000).getDay()] ?? ''}`.trim(),
],
['行政区', districtNameOf(d?.districts?.[row.district]) || '未标注'],
['街道', streetNameOf(d?.streets?.[row.street]) || '未标注'],
// 营运区分是反推出来的那一维,所以放在最前:核对一条案子先看它算不算营运车,
// 后面四列是推出这个结论的依据 —— 归错了当场就能看出是哪一列的问题。
['营运区分', attrNameOf(row.operating, d?.operatingSegments) ?? '未填'],
['使用性质', attrNameOf(row.useNature, d?.useNatures) ?? '未填'],
['所属性质', attrNameOf(row.ownNature, d?.ownNatures) ?? '未填'],
['是否新能源', attrNameOf(row.newEnergy, d?.newEnergy) ?? '未填'],
['车种大类', attrNameOf(row.vehicleClass, d?.vehicleClasses) ?? '未填'],
['车辆种类', attrNameOf(row.vehicleKind, d?.vehicleKinds) ?? '未填'],
['车辆结构', attrNameOf(row.vehicleStruct, d?.vehicleStructs) ?? '未填'],
['车系', attrNameOf(row.carSeries, d?.carSeries) ?? '未填'],
['车型', attrNameOf(row.vehicleModel, d?.vehicleModels) ?? '未填'],
['经纬度', `${row.lng.toFixed(6)}, ${row.lat.toFixed(6)}`],
];
}
/**
* 行展开后那一块:把从行里让出来的字段一次列全。
*
* 为什么要有它:案件清单一行原本挤着八列(序号、时间、行政区、使用性质、是否新能源、
* 车种大类、地点、定位),在抽屉宽度(最窄 392、最宽 560)里,地址列被压到两百来像素,
* 一半行都是省略号 —— 每一列都看得见、每一列都读不全。现在行上只留「什么时候、在哪儿、
* 什么性质的车、定位」这四件扫一眼就要知道的事,其余(案件号、行政区、街道、
* 是否新能源、车种大类、完整时间与经纬度)收进这一块。
*
* 这里放的是「核对时要念出来」的值,不是又一份概览:所以每条都给标签、
* 完整地址整段折行显示(行上那一截是省略号)、案件号与坐标可直接选中复制。
*
* 组件只在行展开时挂载 —— 一页一百行全渲染一遍是白花的,
* 而展开是用户自己点的,一次只展开一两行。
*/
export function CaseRowDetail({ row, meta }: { row: BucketRow; meta?: MetaFile | null }) {
const items = detailItems(row, meta);
return (
<div className="hm-rowdetail">
<div className="hm-rowdetail__grid">
{items.map(([k, v]) => (
<div className="hm-rowdetail__item" key={k}>
<span className="hm-rowdetail__k">{k}</span>
<span className="hm-rowdetail__v">{v}</span>
</div>
))}
<div className="hm-rowdetail__item hm-rowdetail__item--wide">
<span className="hm-rowdetail__k">出险地址</span>
<span className="hm-rowdetail__v hm-rowdetail__v--wrap">
{row.address || '详细地址载入中'}
</span>
</div>
</div>
<div className="hm-rowdetail__foot">
<Button
type="link"
size="small"
icon={<EnvironmentOutlined />}
className="hm-locate"
onClick={() =>
useHeatmapStore.getState().focusCasePoint({
lng: row.lng,
lat: row.lat,
address: row.address || row.caseNo,
operating: attrNameOf(row.operating, meta?.dict.operatingSegments),
useNature: attrNameOf(row.useNature, meta?.dict.useNatures),
newEnergy: attrNameOf(row.newEnergy, meta?.dict.newEnergy),
vehicleClass: attrNameOf(row.vehicleClass, meta?.dict.vehicleClasses),
caseNo: row.caseNo,
ts: row.ts,
key: caseRowKey(row),
})
}
>
在地图上定位这一处
</Button>
<span className="hm-rowdetail__tip">案件号与坐标可直接选中复制</span>
</div>
</div>
);
}