front/src/views/home/workplace/biz-ops/UsDestDetailMap.vue
zzh 3ce8955472
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m11s
feat: 经营地图放大下钻与中美口岸标注,并完善扫码/品牌/培训
地图支持全屏漫游、美国邮编港口与中国城市口岸图层;同步入出库扫码与培训手册等改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 13:55:47 +08:00

354 lines
8.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="us-map">
<div class="us-map__chrome">
<nav class="us-map__crumb" aria-label="地图层级">
<button type="button" class="us-map__crumb-link" @click="$emit('back-world')">全球</button>
<span class="us-map__crumb-sep">›</span>
<strong>美国</strong>
</nav>
<div class="us-map__actions">
<div class="us-map__layers" role="group" aria-label="图层">
<button
type="button"
class="us-map__layer"
:class="{ 'is-on': showZip }"
@click="showZip = !showZip"
>
邮编分布
</button>
<button
type="button"
class="us-map__layer"
:class="{ 'is-on': showPorts }"
@click="showPorts = !showPorts"
>
港口
</button>
</div>
<button type="button" class="us-map__collapse" @click="$emit('collapse')">收起</button>
</div>
</div>
<VCharts v-if="ready" class="us-map__chart" :option="option" autoresize />
<div v-else-if="loadError" class="us-map__loading is-err">{{ loadError }}</div>
<div v-else class="us-map__loading">美国地图加载中…</div>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import '@/utils/echarts'
import VCharts from 'vue-echarts'
import { formatCount } from './mock/bizOpsMock'
import {
ensureUsaGeoMap,
ensureUsOverlays,
type UsPortPoint,
type UsZip3Point,
} from './useGeoMaps'
defineEmits<{
(e: 'back-world'): void
(e: 'collapse'): void
}>()
const ready = ref(false)
const loadError = ref('')
const showZip = ref(true)
const showPorts = ref(true)
const ports = ref<UsPortPoint[]>([])
const zip3 = ref<UsZip3Point[]>([])
onMounted(async () => {
try {
await ensureUsaGeoMap()
const overlays = await ensureUsOverlays()
ports.value = overlays.ports
zip3.value = overlays.zip3
ready.value = true
} catch (err) {
loadError.value = err instanceof Error ? err.message : '美国地图加载失败'
}
})
const option = computed(() => {
const maxZip = Math.max(...zip3.value.map((z) => z.orderCount), 1)
const series: Record<string, unknown>[] = [
{
type: 'map',
map: 'usa',
geoIndex: 0,
data: [],
silent: true,
},
]
if (showZip.value) {
series.push({
name: '邮编分布',
type: 'scatter',
coordinateSystem: 'geo',
zlevel: 2,
symbolSize(val: number[]) {
const v = val?.[2] ?? 0
return 6 + (v / maxZip) * 22
},
itemStyle: {
color: 'rgba(232, 89, 12, 0.55)',
borderColor: 'rgba(196, 65, 12, 0.35)',
borderWidth: 0.5,
},
data: zip3.value.map((z) => ({
name: z.zip3,
value: [...z.coord, z.orderCount],
labelName: z.name,
orderCount: z.orderCount,
})),
})
}
if (showPorts.value) {
series.push({
name: '港口',
type: 'effectScatter',
coordinateSystem: 'geo',
zlevel: 3,
rippleEffect: { brushType: 'stroke', scale: 2.6, period: 3.2 },
symbolSize: 9,
itemStyle: {
color: '#1d7281',
shadowBlur: 8,
shadowColor: 'rgba(29, 114, 129, 0.35)',
},
label: {
show: true,
formatter(params: any) {
const d = params.data
const zh = d?.nameZh || d?.name || params.name
const code = d?.code || ''
return code ? `${zh} ${code}` : zh
},
position: 'right',
distance: 6,
fontSize: 11,
fontWeight: 600,
color: 'rgba(26, 46, 56, 0.78)',
textBorderColor: 'rgba(255,255,255,0.92)',
textBorderWidth: 2,
},
data: ports.value.map((p) => ({
name: p.nameZh || p.name,
nameZh: p.nameZh || p.name,
nameEn: p.name,
value: [...p.coord, 1],
code: p.code,
locode: p.locode,
portType: p.type,
})),
})
}
return {
backgroundColor: 'transparent',
tooltip: {
trigger: 'item',
backgroundColor: 'rgba(255,255,255,0.96)',
borderColor: 'rgba(29, 114, 129, 0.2)',
borderWidth: 1,
textStyle: { color: '#1a2e38', fontSize: 12 },
formatter(params: any) {
if (params.seriesName === '港口') {
const d = params.data
return [
`<div style="font-weight:600;margin-bottom:4px">${d?.nameZh || d?.name || params.name}</div>`,
`${d?.nameEn || ''}`,
`港码 ${d?.code || '—'} · LOCODE ${d?.locode || '—'}`,
]
.filter(Boolean)
.join('<br/>')
}
if (params.seriesName === '邮编分布') {
const d = params.data
return [
`<div style="font-weight:600;margin-bottom:4px">ZIP3 ${d?.name}</div>`,
`${d?.labelName || ''}`,
`单量 ${formatCount(d?.orderCount || 0)}(演示)`,
]
.filter(Boolean)
.join('<br/>')
}
return params.name
},
},
visualMap: showZip.value
? {
show: true,
min: 0,
max: maxZip,
seriesIndex: 1,
orient: 'vertical',
right: 12,
bottom: 16,
itemWidth: 8,
itemHeight: 72,
text: ['高', '低'],
textStyle: { color: 'rgba(26,46,56,0.45)', fontSize: 10 },
inRange: {
color: ['#fff5eb', '#ffd8a8', '#ff922b', '#f76707', '#d9480f'],
},
}
: { show: false },
geo: {
map: 'usa',
roam: true,
zoom: 1.15,
center: [-98.5, 39.5],
scaleLimit: { min: 0.8, max: 8 },
itemStyle: {
areaColor: '#faf7f4',
borderColor: 'rgba(29, 114, 129, 0.22)',
borderWidth: 0.7,
},
emphasis: {
itemStyle: {
areaColor: '#e6f4f6',
borderColor: '#1d7281',
},
label: { show: false },
},
},
series,
}
})
</script>
<style scoped lang="less">
.us-map {
position: relative;
height: 100%;
min-height: 0;
display: flex;
flex-direction: column;
}
.us-map__chrome {
position: absolute;
top: 10px;
left: 12px;
right: 12px;
z-index: 4;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.us-map__crumb,
.us-map__actions,
.us-map__layers,
.us-map__layer,
.us-map__collapse,
.us-map__crumb-link {
pointer-events: auto;
}
.us-map__crumb {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 10px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.94);
border: 1px solid rgba(26, 46, 56, 0.08);
font-size: 12px;
color: #1a2e38;
strong {
font-weight: 650;
}
}
.us-map__crumb-link {
margin: 0;
padding: 0;
border: none;
background: transparent;
color: var(--app-primary-color, #1d7281);
cursor: pointer;
font-size: 12px;
&:hover {
text-decoration: underline;
}
}
.us-map__crumb-sep {
color: rgba(26, 46, 56, 0.35);
}
.us-map__actions {
display: inline-flex;
align-items: center;
gap: 8px;
}
.us-map__layers {
display: inline-flex;
gap: 4px;
padding: 3px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.94);
border: 1px solid rgba(26, 46, 56, 0.08);
}
.us-map__layer,
.us-map__collapse {
height: 28px;
padding: 0 10px;
border-radius: 6px;
border: 1px solid transparent;
background: transparent;
font-size: 12px;
color: rgba(26, 46, 56, 0.55);
cursor: pointer;
}
.us-map__layer.is-on {
background: rgba(29, 114, 129, 0.1);
color: var(--app-primary-color, #1d7281);
font-weight: 600;
}
.us-map__collapse {
background: rgba(255, 255, 255, 0.94);
border-color: rgba(26, 46, 56, 0.08);
color: #1a2e38;
&:hover {
border-color: rgba(29, 114, 129, 0.35);
color: var(--app-primary-color, #1d7281);
}
}
.us-map__chart {
flex: 1;
min-height: 0;
width: 100%;
}
.us-map__loading {
flex: 1;
display: grid;
place-items: center;
color: rgba(26, 46, 56, 0.4);
font-size: 13px;
&.is-err {
color: #c45c4a;
padding: 24px;
text-align: center;
}
}
</style>