BucketDrawer.tsx
14.2 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import { useMemo } from 'react';
import { useHeatmapStore } from '@/store/useHeatmapStore';
import { fmtDateTime, fmtDateTimeShort, fmtInt } from '@/utils/format';
import { useDrawerCompact, useDrawerWidth } from '@/layout/drawerWidth';
import type { BucketRow, MetaFile } from '@/features/heatmap/aggregate/types';
// 定位标记用地图针(EnvironmentOutlined)而不是 AnchorOutlined:后者在网络语境里是
// 「超链接锚点」,会被读成复制链接。口径同案件清单抽屉那一列。
import { EnvironmentOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import { CollapseButton, DrawerTitle } from '@hm/ui';
import { Button, Empty, Spin, Table, Tooltip, type TableColumnsType } from 'antd';
import { GlassDrawer } from '@/features/heatmap/components/GlassDrawer';
import { CaseRowDetail, CASE_EXPAND_W, attrNameOf, caseRowKey } from './CaseRowDetail';
/** 明细表的行:数据行 + 全局序号 + 行键,都在铺数据那一步算好 */
type DetailRow = BucketRow & { seq: number; _k: string };
/** 明细还没到位时给表体的那个空值:必须是常量引用,`?? []` 每次渲染都给新数组,memo 等于没做 */
const NO_DETAIL_ROWS: BucketRow[] = [];
/**
* 明细抽屉的列。点聚合桶与黑点两种取数范围共用它(行数与列完全一样,差别只在标题上的
* scopeLabel:这次圈了多大地方,由 MapStage 写清楚)。
*
* 列宽与案件清单抽屉逐列对齐(序号 52 / 时间 104·132 / 定位 34·40):两张抽屉列的是
* 同一批字段,横着摆在一起不该一宽一窄、一处有年份一处没有。出险地点按抽屉正文宽
* (drawerW − antd body 的 paddingLG 24×2)扣掉其余固定列算出来,配合 Table 的
* tableLayout="fixed",把 auto 布局下长地址把该列撑开、表格宽于正文被 overflow-x:hidden
* 裁切的坑关死(出险地点那一列因此必须定宽,机制同 CaseListDrawer 的 caseColumns)。
*
* 行上只留四件事:第几行、什么时候、什么性质的车、在哪儿,外加行末一颗定位;
* 案件号、是否新能源、车种大类、完整时间与坐标、完整地址全部收进展开区
* (同一个 CaseRowDetail,两处字段与说法完全一致)。原来八列并排时地址列被压到
* 两百来像素,一半行都是省略号 —— 那样只是「列都在」,不是「看得见」。
*
* 这里本来就没有「行政区」那一列 —— 明细本身就是一个小范围,整列同一个区没有信息量
* (案件清单抽屉现在也把它收进了展开区,理由相同:区名就是地址的第一截)。
*
* 定位那一列的提示语走浏览器原生 title 而不是 antd Tooltip:一页就是一批浮层实例,
* 每次换页全建一遍、每次悬停算一次定位,而这句话只需要在鼠标停住时念出来。
*/
function detailColumns(
compact: boolean,
drawerW: number,
meta?: MetaFile | null,
): TableColumnsType<DetailRow> {
const seqW = 42;
const tsW = compact ? 104 : 132;
// 44 是「定位」两个字不折行的下限(28px 字宽 + 左右各 8 内边距)
const locateW = compact ? 44 : 48;
const contentW = Math.max(240, drawerW - 48);
// 使用性质:行上留下的唯一一列车辆属性。正文不满 500 时收掉,先保地址(口径同案件清单)
const natureW = !compact && contentW >= 500 ? 84 : 0;
const addressW = Math.max(96, contentW - CASE_EXPAND_W - seqW - tsW - natureW - locateW);
return [
{
title: '序号',
dataIndex: 'seq',
width: seqW,
align: 'right',
render: (v: number) => (
<span style={{ color: 'var(--hm-text-3)', fontVariantNumeric: 'tabular-nums' }}>{v}</span>
),
},
{
title: '报案时间',
dataIndex: 'ts',
width: tsW,
render: (v: number) => (
<span style={{ fontVariantNumeric: 'tabular-nums' }} title={fmtDateTime(v)}>
{compact ? fmtDateTimeShort(v) : fmtDateTime(v)}
</span>
),
},
// 营运区分:行上唯一保留的车辆属性列,使用性质 / 所属性质 / 车系 / 车型 等在展开区。
// 换掉原来的「使用性质」是因为那一列只有营业 / 非营业两档,而营运区分把营运那一半又细分到了
// 出租 / 网约 / 公交 / 货车 / 特种 —— 后者才是在这一行上要扫一眼的答案。
...(natureW > 0
? [
{
title: '营运区分',
dataIndex: 'operating',
width: natureW,
render: (v: number) => (
<span
style={{ color: 'var(--hm-text-2)', fontSize: 12 }}
title={attrNameOf(v, meta?.dict.operatingSegments) ?? '未填使用性质,无法判断营运与否'}
>
{attrNameOf(v, meta?.dict.operatingSegments) ?? '—'}
</span>
),
},
]
: []),
{
title: '出险地点',
dataIndex: 'address',
width: addressW,
// 只放地址:案件号不再垫在下面那一行(它让每行都长成两行高),
// 展开区里独占一行,完整地址也一并放在那里
render: (v: string, r) => (
<div className="hm-case-cell">
<span className="hm-case-cell__addr" title={v || '详细地址载入中'}>
{v || '—'}
</span>
{!v && <span className="hm-case-cell__no">{r.caseNo}</span>}
</div>
),
},
/**
* 定位到地图上的这一处。列的样式、位置和案件清单抽屉那一列完全一样:
* 同一个动作在所有名单里都长同一个样、都在最右一列,鼠标不用重新找。
* 单独一列而不是跟在地址文字后面 —— 地址长短不一,贴在后面时每行的
* 点击目标都落在不同的横向位置。
*/
{
title: '定位',
key: 'locate',
width: locateW,
align: 'center',
render: (_v: unknown, r) => (
<Button
type="text"
size="small"
className="hm-locate"
icon={<EnvironmentOutlined />}
title="在地图上定位这一处(明细保持打开)"
aria-label={`定位 ${r.caseNo}`}
onClick={(e) => {
// 翻页、点别的行都不该被这次点击顺带触发
e.stopPropagation();
// 牌子上写出险地址;地址列还没到位时那一段是空的,退回案件号,
// 免得标记旁边挂一块什么都没有的白牌
useHeatmapStore.getState().focusCasePoint({
lng: r.lng,
lat: r.lat,
address: r.address || r.caseNo,
useNature: attrNameOf(r.useNature, meta?.dict.useNatures),
newEnergy: attrNameOf(r.newEnergy, meta?.dict.newEnergy),
vehicleClass: attrNameOf(r.vehicleClass, meta?.dict.vehicleClasses),
caseNo: r.caseNo,
ts: r.ts,
key: caseRowKey(r),
});
}}
/>
),
},
];
}
/**
* 明细抽屉。两种取数范围共用它:
* - 点聚合桶:范围是当前像素网格的那一格;
* - 点黑点:范围是分析算出的地理连通域(半径几百米的圆)。
* 两者的行数与列完全一样,差别只在「这次圈了多大地方」,所以标题跟着 scopeLabel 走,
* 由 MapStage 在发起请求时写清楚,避免用户以为两个入口看到的是同一个范围。
*/
export function BucketDrawer() {
const open = useHeatmapStore((s) => s.drawerOpen);
const setDrawerOpen = useHeatmapStore((s) => s.setDrawerOpen);
const members = useHeatmapStore((s) => s.members);
const loading = useHeatmapStore((s) => s.membersLoading);
const selection = useHeatmapStore((s) => s.selection);
const scopeLabel = useHeatmapStore((s) => s.scopeLabel);
const mapScope = useHeatmapStore((s) => s.mapScope);
const clearHotspot = useHeatmapStore((s) => s.clearHotspot);
const clearCasePin = useHeatmapStore((s) => s.clearCasePin);
const meta = useHeatmapStore((s) => s.meta);
const rows = members?.rows ?? NO_DETAIL_ROWS;
// 序号与行键只在数据真的换了一份时才算一遍(见上面那段注释里的口径)
const tableRows = useMemo(
() => rows.map((r, i) => ({ ...r, seq: i + 1, _k: `${r.caseNo}-${i}` })),
[rows],
);
// 列只跟着「抽屉窄不窄」重建:拖动窗口才会变,翻页与取数都不动它
const drawerW = useDrawerWidth();
const compact = useDrawerCompact();
const detailCols = useMemo(
() => detailColumns(compact, drawerW, meta),
[compact, drawerW, meta],
);
/**
* 被钉到地图上的那一行(键由行末那颗针带进 casePin,见 CasePin.key)。
*
* 与案件清单抽屉同一套:比的是「这一行是不是刚才点的那一条」,
* 不是「地图上有没有针」—— 换了行、换了名单,旧的针会收走,高亮也跟着消失。
*/
const locatedKey = useHeatmapStore((s) => s.casePin?.key ?? null);
const rowClass = useMemo(
() => (r: BucketRow) => (locatedKey && caseRowKey(r) === locatedKey ? 'hm-row--located' : ''),
[locatedKey],
);
/**
* 这张抽屉的收法只有一处:右上角的叉、Esc 与标题上那颗「收起」走同一段。
*
* 原先这段直接写在 onClose 里,抽出来是因为两处都得连着清掉黑点高亮与定位标记 ——
* 少清一处,地图上就留着一圈对着已经不存在的明细的光圈,看着像选中态卡住了。
*/
const close = () => {
setDrawerOpen(false);
// 关掉抽屉就把黑点高亮一起撤掉,否则地图上留着一片发光的范围却没有对应的明细,
// 看起来像选中态卡住了
if (scopeLabel) clearHotspot();
// 定位标记同样在这里收回:store 只在「打开别的抽屉」时清它,自己关闭不清,
// 留着就是一枚指着已经不在名单里的案件的图钉(见 store 的 casePin)
clearCasePin();
};
return (
<GlassDrawer
title={
<DrawerTitle
title={scopeLabel ?? '方格案件明细'}
/**
* 地图被收窄时,这一格里数出来的起数只是「这一类在这一格里的」——
* 比面板上那一类的总数小是必然的,不交代一句会被读成漏统计。
* 收窄的说法与地图上那枚「只看 · X」是同一个 label,两处念的是同一刀。
*/
note={
members
? `共 ${fmtInt(members.count)} 起${members.truncated ? '(列表最多显示 300 起)' : ''}${
mapScope ? ` · 只看${mapScope.label}` : ''
}`
: undefined
}
/>
}
extra={
<>
<Tooltip
title="按报案时间倒序的只读明细:点一行展开全部字段、点行末在地图上定位,热力与黑点范围照旧在场。"
placement="bottomRight"
trigger={['hover', 'focus']}
styles={{ root: { maxWidth: 340 }, container: { fontSize: 12, lineHeight: 1.7 } }}
>
<button type="button" className="hm-list__help" aria-label="明细用法说明">
<QuestionCircleOutlined />
</button>
</Tooltip>
<CollapseButton
onClick={close}
dir="right"
hint="收起这张明细,屏幕立刻整块留给地图;再点屏上同一个方格(或同一条黑点)就回来"
/>
</>
}
// 这份明细不带遮罩尤其要紧(公共壳已统一 mask={false}):遮罩那层深色压在地图上不留缝,
// 要看的那一点正好躲在它底下 —— 明细要在「榜上那一行」与「屏上那一块」之间来回对。
open={open}
onClose={close}
>
{loading && (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 10,
padding: 48,
color: 'var(--hm-text-3)',
fontSize: 13,
}}
>
<Spin />
<span>正在加载{scopeLabel ? '该黑点' : '该方格'}的案件明细…</span>
</div>
)}
{!loading && rows.length === 0 && <Empty description="暂无案件记录" />}
{!loading && rows.length > 0 && (
// tableLayout="fixed":rc-table 默认 auto 布局下 <colgroup> 宽度只是建议值,
// 出险地点的长地址会当场把该列撑开、表格宽于抽屉正文,右边一截被
// .hm-drawer-glass 的 overflow-x:hidden 裁掉(机制同 CaseListDrawer)。
// fixed 之后列宽由 detailColumns 的 width 独裁,地址超长走 ellipsis。
<Table
size="small"
tableLayout="fixed"
pagination={{ pageSize: 20, size: 'small', showSizeChanger: false }}
// 不设 scroll.y:抽屉 body 本身就是滚动区,表格再套一层 max-height 就是两个滚动条。
// 表头改由 CSS 钉住(design.css 的 .hm-drawer-glass 段),滚动只留一层。
// 序号在铺数据时按全局下标算好,不用 render 里的页内 index:
// 后者每页都从 1 开始,翻到第二页就对不上「共 N 起」,也不能用来口述第几行。
// 各列宽度和案件清单抽屉对齐:两张抽屉列的是同一批字段,横着摆在一起不该一宽一窄。
dataSource={tableRows}
rowKey="_k"
rowClassName={rowClass}
columns={detailCols}
// 一行可展开:案件号、是否新能源、车种大类、完整时间与坐标、完整地址都在展开区。
// expandRowByClick:点行即可开,不必去戳 28px 的三角;行末定位按钮会 stopPropagation。
expandable={{
columnWidth: CASE_EXPAND_W,
expandRowByClick: true,
expandedRowRender: (r) => <CaseRowDetail row={r} meta={meta} />,
}}
/>
)}
{selection && members && (
<div style={{ marginTop: 16, color: 'var(--hm-text-3)', fontSize: 12 }}>
网格中心:{selection.lat.toFixed(5)}, {selection.lng.toFixed(5)}
</div>
)}
</GlassDrawer>
);
}