index.vue
4.81 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
<script lang="ts" setup>
import { ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
import { option } from './config';
import HistoryDataModel from './HistoryDataModal.vue';
import { useModal } from '/@/components/Modal';
import { Button, Tooltip, Spin } from 'ant-design-vue';
import {
PlayCircleOutlined,
PauseCircleOutlined,
ClockCircleOutlined,
} from '@ant-design/icons-vue';
import { computed, ref, toRaw, unref } from 'vue';
import { buildUUID } from '/@/utils/uuid';
import { useBaiduMapSDK } from '../../../hook/useBaiduMapSDK';
import { HistoryModalOkEmitParams, TrackAnimationStatus } from './type';
import { useMapTrackPlayback } from './useMapTrackPlayback';
// import { shallowRef } from 'vue';
import { formatToDateTime } from '/@/utils/dateUtil';
import { useI18n } from '/@/hooks/web/useI18n';
const props = defineProps<{
config: ComponentPropsConfigType<typeof option>;
}>();
const { t } = useI18n();
const wrapRef = ref();
const wrapId = `bai-map-${buildUUID()}`;
const mapInstance = ref<Nullable<Recordable>>(null);
const rangString = ref<Nullable<string>>(null);
const [register, { openModal }] = useModal();
const handleTrackSwitch = () => {
openModal(true, toRaw(props.config.option.dataSource));
};
const { genTrackPlaybackAnimation, playStatus, playFn, continueFn, pauseFn } =
useMapTrackPlayback(mapInstance);
const getIsWidgetLibSelectMode = computed(() => {
return !props.config.option.dataSource;
});
const handleRenderHistroyData = (data: HistoryModalOkEmitParams) => {
const { track, value } = data;
const { startTs, endTs } = value;
const formatType = 'YYYY-MM-DD HH:mm:ss';
rangString.value = `从${formatToDateTime(startTs, formatType)} 到 ${formatToDateTime(
endTs,
formatType
)}`;
genTrackPlaybackAnimation(track as any[]);
};
const handlePlay = () => {
if (unref(playStatus) === TrackAnimationStatus.PAUSE) {
unref(continueFn)?.();
return;
}
if (unref(playStatus) === TrackAnimationStatus.DONE) {
unref(playFn)?.();
return;
}
if (unref(playStatus) === TrackAnimationStatus.PLAY) {
unref(pauseFn)?.();
return;
}
};
async function initMap() {
const wrapEl = unref(wrapRef);
if (!wrapEl) return;
if (!Reflect.has(window, 'BMapGL')) return;
const BMapGL = (window as any).BMapGL;
mapInstance.value = new BMapGL.Map(wrapId);
// 定位当前城市
const localcity = new BMapGL.LocalCity();
localcity.get(
(e: { center: Record<'lat' | 'lng', number>; code: number; level: number; name: string }) => {
const { center } = e;
const { lat, lng } = center;
const point = new BMapGL.Point(lng, lat);
unref(mapInstance)!.centerAndZoom(point, 15);
}
);
unref(mapInstance)!.enableScrollWheelZoom(true);
unref(getIsWidgetLibSelectMode) && genTrackPlaybackAnimation();
}
const { loading } = useBaiduMapSDK(initMap);
</script>
<template>
<main class="w-full h-full flex flex-col p-2 justify-center items-center">
<div class="w-full flex justify-end">
<Button
type="text"
class="!px-2 flex-auto !text-left truncate mr-2"
:disabled="getIsWidgetLibSelectMode"
@click="handleTrackSwitch"
>
<div class="w-full truncate text-gray-500 flex items-center">
<ClockCircleOutlined class="mx-1" />
<span>{{ t('component.areaChart.historyText') }}</span>
<span class="mx-1">-</span>
<Tooltip :title="rangString || t('common.chooseText')">
<span class="truncate"> {{ rangString || t('common.chooseText') }} </span>
</Tooltip>
</div>
</Button>
<Button type="text" class="!px-2 !text-gray-500" @click="handlePlay">
<PlayCircleOutlined v-show="playStatus !== TrackAnimationStatus.PLAY" />
<PauseCircleOutlined class="!ml-0" v-show="playStatus === TrackAnimationStatus.PLAY" />
<Tooltip :title="t('visual.board.timePeriodText')">
<span>
{{
playStatus !== TrackAnimationStatus.PLAY
? t('visual.board.playTrajectoryText')
: t('visual.board.pausePlayText')
}}
</span>
</Tooltip>
</Button>
</div>
<Spin
:spinning="loading"
wrapper-class-name="map-spin-wrapper !w-full !h-full !flex justify-center items-center pointer-events-none"
:tip="t('visual.board.mapLoadingText')"
/>
<div ref="wrapRef" :id="wrapId" class="w-full h-full no-drag"> </div>
<HistoryDataModel @register="register" @ok="handleRenderHistroyData" />
</main>
</template>
<style lang="less" scoped>
.map-spin-wrapper {
:deep(.ant-spin-container) {
@apply justify-center items-center p-2 w-full h-full;
}
}
</style>