BucketCard.tsx
5.3 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
import { useHeatmapStore } from '@/store/useHeatmapStore';
import type { Selection } from '@/store/useHeatmapStore';
import { fmtDateTime, fmtInt, placeNameOf } from '@/utils/format';
import { attrNameOf } from './CaseRowDetail';
import { ArrowRightOutlined, EnvironmentFilled } from '@ant-design/icons';
interface Props {
selection: Selection;
/** 地图可用区:left 是左侧被清单通栏占掉的宽度,width 已把左右两块玻璃都扣掉 */
containerSize: { left: number; width: number; height: number };
onClose: () => void;
}
const CARD_W = 328;
const CARD_H = 360;
/**
* 点击聚合圆圈后,在地图上方浮出的桶明细卡。
*
* 定位用点击时的屏幕坐标(selection.screenX/Y)。Worker 已把桶内案件列表算好
* (members),这里只负责展示前若干条 + 入口把更多交给抽屉。
*/
export function BucketCard({ selection, containerSize, onClose }: Props) {
const members = useHeatmapStore((s) => s.members);
const loading = useHeatmapStore((s) => s.membersLoading);
const meta = useHeatmapStore((s) => s.meta);
const setDrawerOpen = useHeatmapStore((s) => s.setDrawerOpen);
// 夹在「可用区」里,不是夹在整个视口里:左栏/右栏展开时卡片不能躲到玻璃面板底下
const minX = containerSize.left + 8;
const maxX = Math.max(containerSize.left + containerSize.width - CARD_W - 8, minX);
const left = Math.min(Math.max(selection.screenX + 16, minX), maxX);
const top = Math.min(
Math.max(selection.screenY - 24, 8),
Math.max(containerSize.height - 220, 8),
);
// 「主要区域」只念真读得出名字的区:districtCounts 按数量倒序,第一名可能就是
// 「未识别」,而它不是区名、是「这段地址取不出区」的记号 —— 直接显示会变成
// 「这个方格属于一个叫未识别的地方」。往后顺延找有名有姓的,全没有就留 '—'。
const districtName =
members?.districtCounts
.map(([idx]) => placeNameOf(meta?.dict.districts[idx]))
.find((name) => name !== '') ?? '—';
const rows = members?.rows ?? [];
const total = members?.count ?? selection.count;
const preview = rows.slice(0, 6);
return (
<div className="hm-bucket-card" style={{ left, top, maxHeight: CARD_H }}>
<div className="hm-bucket-card__head">
<div className="hm-bucket-card__count">
{fmtInt(total)}
<span>起事故</span>
</div>
<button
type="button"
onClick={onClose}
aria-label="关闭"
style={{
background: 'transparent',
border: 'none',
color: '#fff',
opacity: 0.85,
cursor: 'pointer',
fontSize: 14,
}}
>
✕
</button>
</div>
<div className="hm-bucket-card__body">
<div
className="hm-kv"
style={{ borderBottom: '1px dashed var(--hm-divider)', marginBottom: 4 }}
>
<span className="hm-kv__k">主要区域</span>
<span className="hm-kv__v">
<EnvironmentFilled style={{ color: 'var(--hm-accent-cyan)', marginRight: 4 }} />
{districtName}
</span>
</div>
{loading && (
<div style={{ padding: '14px 0', color: 'var(--hm-text-3)', fontSize: 12 }}>
正在加载该方格的案件…
</div>
)}
{!loading &&
preview.map((r, i) => {
// 每行多带两项最该先看到的属性:营运区分(主色)+ 车种大类(弱一档),
// 其余(使用性质 / 新能源 / 坐标)收进右缘抽屉的展开区,卡宽有限不堆全。
const opName = attrNameOf(r.operating, meta?.dict.operatingSegments) ?? '未分营运';
const vcName = attrNameOf(r.vehicleClass, meta?.dict.vehicleClasses) ?? '未填车种';
return (
<div className="hm-bucket-card__row" key={`${r.caseNo}-${i}`}>
<div className="hm-bucket-card__row-top">
<span className="hm-bucket-card__case">{r.caseNo}</span>
<span className="hm-bucket-card__time">{fmtDateTime(r.ts)}</span>
</div>
<div className="hm-bucket-card__attrs">
<span className="hm-bucket-card__attr">{opName}</span>
<span className="hm-bucket-card__attr hm-bucket-card__attr--dim">{vcName}</span>
</div>
<div className="hm-bucket-card__addr">{r.address}</div>
</div>
);
})}
{!loading && rows.length === 0 && (
<div style={{ padding: '14px 0', color: 'var(--hm-text-3)', fontSize: 12 }}>
该方格暂无案件记录
</div>
)}
</div>
<div className="hm-bucket-card__foot">
<span>
该方格 <b style={{ color: 'var(--hm-primary)' }}>{fmtInt(total)}</b> 起
</span>
{/* 同一个动线(点开 → 右缘抽屉)就用同一个入口长相:类名和风险概览两块榜下的
「查看全部」共用 .hm-more,不再各处写一份内联样式 */}
<button type="button" className="hm-more" onClick={() => setDrawerOpen(true)}>
查看全部 <ArrowRightOutlined />
</button>
</div>
</div>
);
}