Commit e3fb1ec493ceb7e702b6b99710e736d6f0b50bf3

Authored by ww
1 parent e6353bc8

wip: visual board map component

... ... @@ -5,7 +5,7 @@
5 5 </script>
6 6 <script lang="ts" setup>
7 7 import type { ECharts, EChartsOption } from 'echarts';
8   - import { PropType, watch } from 'vue';
  8 + import { watch } from 'vue';
9 9 import { nextTick, onMounted, onUnmounted, ref, unref, computed } from 'vue';
10 10 import { init } from 'echarts';
11 11 import {
... ... @@ -26,29 +26,23 @@
26 26 import { Tooltip } from 'ant-design-vue';
27 27 import { useThrottleFn } from '@vueuse/shared';
28 28 import { buildUUID } from '/@/utils/uuid';
29   - import { FrontComponent } from '../help';
30   -
31   - const props = defineProps({
32   - add: {
33   - type: Function,
34   - },
35   - layout: {
36   - type: Object as PropType<DashboardComponentLayout>,
37   - default: () => ({}),
38   - },
39   - value: {
40   - type: Object as PropType<DashBoardValue>,
41   - default: () => ({ id: buildUUID() }),
42   - },
43   - radio: {
44   - type: Object as PropType<RadioRecord>,
45   - default: () => DEFAULT_RADIO_RECORD,
46   - },
47   - random: {
48   - type: Boolean,
49   - default: true,
50   - },
51   - });
  29 + import { FrontComponent } from '../../const/const';
  30 +
  31 + const props = withDefaults(
  32 + defineProps<{
  33 + add?: Function;
  34 + layout?: DashboardComponentLayout;
  35 + value?: DashBoardValue;
  36 + radio?: RadioRecord;
  37 + random?: boolean;
  38 + }>(),
  39 + {
  40 + layout: () => ({} as unknown as DashboardComponentLayout),
  41 + value: () => ({ id: buildUUID() }),
  42 + radio: () => DEFAULT_RADIO_RECORD,
  43 + random: true,
  44 + }
  45 + );
52 46
53 47 const getControlsWidgetId = () => `widget-chart-${props.value.id}`;
54 48
... ...
... ... @@ -4,9 +4,29 @@
4 4 };
5 5 </script>
6 6 <script lang="ts" setup>
7   - import { nextTick, onMounted, ref, unref } from 'vue';
  7 + import { computed, nextTick, onMounted, ref, unref } from 'vue';
  8 + import { RadioRecord } from '../../detail/config/util';
8 9 import { useScript } from '/@/hooks/web/useScript';
9 10 import { BAI_DU_MAP_URL } from '/@/utils/fnUtils';
  11 + import { MapComponentLayout, MapComponentValue } from './map.config';
  12 + import {
  13 + ClockCircleOutlined,
  14 + PlayCircleOutlined,
  15 + PauseCircleOutlined,
  16 + } from '@ant-design/icons-vue';
  17 + import { Button, Tooltip } from 'ant-design-vue';
  18 + import { useVisualBoardContext } from '../../hook/useVisualBoardContext';
  19 +
  20 + const {} = useVisualBoardContext();
  21 +
  22 + withDefaults(
  23 + defineProps<{
  24 + value?: MapComponentValue;
  25 + layout?: MapComponentLayout;
  26 + radio?: RadioRecord;
  27 + }>(),
  28 + {}
  29 + );
10 30
11 31 const wrapRef = ref<HTMLDivElement | null>(null);
12 32 const { toPromise } = useScript({ src: BAI_DU_MAP_URL });
... ... @@ -26,10 +46,47 @@
26 46 onMounted(() => {
27 47 initMap();
28 48 });
  49 +
  50 + const getTimeRange = computed(() => {
  51 + return ` - 从 ${'2020-10-20 10:10:10'} 到 ${'2020-10-20 10:10:10'}`;
  52 + });
  53 +
  54 + const handleTrackSwitch = () => {};
  55 +
  56 + const pauseFlag = ref(true);
  57 +
  58 + const handlePlay = () => {
  59 + pauseFlag.value = false;
  60 + };
  61 +
  62 + const handlePause = () => {
  63 + pauseFlag.value = true;
  64 + };
29 65 </script>
30 66
31 67 <template>
32   - <div class="w-full h-full flex justify-center items-center">
  68 + <div class="w-full h-full flex justify-center items-center flex-col">
  69 + <div class="w-[95%] flex">
  70 + <Button type="text" class="!px-2 flex-auto !text-left truncate" @click="handleTrackSwitch">
  71 + <div class="w-full truncate text-gray-500 flex items-center">
  72 + <ClockCircleOutlined />
  73 + <span class="mx-1">实时</span>
  74 + <Tooltip :title="getTimeRange.replace('-', '')">
  75 + <span class="truncate">
  76 + {{ getTimeRange }}
  77 + </span>
  78 + </Tooltip>
  79 + </div>
  80 + </Button>
  81 + <Button v-show="pauseFlag" type="text" class="!px-2 !text-gray-500" @click="handlePlay">
  82 + <PlayCircleOutlined />
  83 + <span>播放轨迹</span>
  84 + </Button>
  85 + <Button v-show="!pauseFlag" type="text" class="!px-2 !text-gray-500" @click="handlePause">
  86 + <PauseCircleOutlined />
  87 + <span>暂停播放</span>
  88 + </Button>
  89 + </div>
33 90 <div ref="wrapRef" class="w-[95%] h-[95%]"></div>
34 91 </div>
35 92 </template>
... ...
1   -import { ComponentConfig } from '../help';
  1 +import { FrontComponent } from '../../const/const';
  2 +import { ComponentConfig } from '../../types/type';
  3 +
  4 +export interface MapComponentLayout {
  5 + componentType?: FrontComponent;
  6 +}
  7 +
  8 +export interface MapComponentValue {
  9 + icon?: string;
  10 + track?: Recordable[];
  11 +}
  12 +
  13 +interface Config {
  14 + layout?: MapComponentLayout;
  15 + value?: MapComponentValue;
  16 +}
  17 +
  18 +export const MaphistoryTrackConfig: Config = {
  19 + layout: {
  20 + componentType: FrontComponent.MAP_COMPONENT_TRACK_HISTORY,
  21 + },
  22 +};
  23 +
  24 +export const MapRealTrackConfig: Config = {
  25 + layout: {
  26 + componentType: FrontComponent.MAP_COMPONENT_TRACK_HISTORY,
  27 + },
  28 +};
2 29
3 30 export const transfromMapComponentConfig: ComponentConfig['transformConfig'] = (
4 31 _componentConfig,
... ...
1 1 <script lang="ts" setup>
2 2 import { useUpdateCenter } from '../../hook/useUpdateCenter';
3 3 import { FrontDataSourceRecord } from '../../types/type';
  4 + import { createVisualBoardContext } from '../../hook/useVisualBoardContext';
4 5
5 6 const props = defineProps<{
6 7 dataSource: FrontDataSourceRecord[];
... ... @@ -8,6 +9,8 @@
8 9
9 10 const { update, add, remove } = useUpdateCenter();
10 11
  12 + createVisualBoardContext({ update, add, remove });
  13 +
11 14 defineExpose({ update });
12 15 </script>
13 16
... ...
... ... @@ -27,7 +27,11 @@ import ToggleSwitch from './ControlComponent/ToggleSwitch.vue';
27 27 import SlidingSwitch from './ControlComponent/SlidingSwitch.vue';
28 28 import SwitchWithIcon from './ControlComponent/SwitchWithIcon.vue';
29 29 import MapComponent from './MapComponent/MapComponent.vue';
30   -import { transfromMapComponentConfig } from './MapComponent/map.config';
  30 +import {
  31 + MaphistoryTrackConfig,
  32 + MapRealTrackConfig,
  33 + transfromMapComponentConfig,
  34 +} from './MapComponent/map.config';
31 35 import { ComponentConfig } from '../types/type';
32 36 import { FrontComponent, FrontComponentCategory } from '../const/const';
33 37
... ... @@ -135,10 +139,20 @@ frontComponentMap.set(FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH, {
135 139 transformConfig: transformControlConfig,
136 140 });
137 141
138   -frontComponentMap.set(FrontComponent.MAP_COMPONENT_TRACK, {
  142 +frontComponentMap.set(FrontComponent.MAP_COMPONENT_TRACK_REAL, {
139 143 Component: MapComponent,
140 144 ComponentName: '实时轨迹',
141   - ComponentKey: FrontComponent.MAP_COMPONENT_TRACK,
  145 + ComponentKey: FrontComponent.MAP_COMPONENT_TRACK_REAL,
  146 + ComponentConfig: MapRealTrackConfig,
  147 + ComponentCategory: FrontComponentCategory.MAP,
  148 + transformConfig: transfromMapComponentConfig,
  149 +});
  150 +
  151 +frontComponentMap.set(FrontComponent.MAP_COMPONENT_TRACK_HISTORY, {
  152 + Component: MapComponent,
  153 + ComponentName: '历史轨迹',
  154 + ComponentKey: FrontComponent.MAP_COMPONENT_TRACK_HISTORY,
  155 + ComponentConfig: MaphistoryTrackConfig,
142 156 ComponentCategory: FrontComponentCategory.MAP,
143 157 transformConfig: transfromMapComponentConfig,
144 158 });
... ...
... ... @@ -27,7 +27,8 @@ export enum FrontComponent {
27 27 CONTROL_COMPONENT_TOGGLE_SWITCH = 'control-component-toggle-switch',
28 28 CONTROL_COMPONENT_SWITCH_WITH_ICON = 'control-component-switch-with-icon',
29 29 CONTROL_COMPONENT_SLIDING_SWITCH = 'control-component-sliding-switch',
30   - MAP_COMPONENT_TRACK = 'map-component-track',
  30 + MAP_COMPONENT_TRACK_REAL = 'map-component-track-real',
  31 + MAP_COMPONENT_TRACK_HISTORY = 'map-component-track-history',
31 32 }
32 33
33 34 export enum Gradient {
... ...
... ... @@ -7,7 +7,8 @@ import MapDataSourceForm from './MapDataSourceForm.vue';
7 7 const dataSourceComponentMap = new Map<FrontComponent, Component>();
8 8
9 9 dataSourceComponentMap.set(FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH, ControlDataSourceForm);
10   -dataSourceComponentMap.set(FrontComponent.MAP_COMPONENT_TRACK, MapDataSourceForm);
  10 +dataSourceComponentMap.set(FrontComponent.MAP_COMPONENT_TRACK_REAL, MapDataSourceForm);
  11 +dataSourceComponentMap.set(FrontComponent.MAP_COMPONENT_TRACK_HISTORY, MapDataSourceForm);
11 12
12 13 export const getDataSourceComponent = (frontId: FrontComponent) => {
13 14 if (dataSourceComponentMap.has(frontId)) return dataSourceComponentMap.get(frontId)!;
... ...
  1 +export type UpdateCenter = ReturnType<typeof useUpdateCenter>;
  2 +
1 3 export function useUpdateCenter() {
2 4 const eventCenter = new Map<string, Fn>();
3 5
... ...
  1 +import { inject, provide } from 'vue';
  2 +import { UpdateCenter } from './useUpdateCenter';
  3 +
  4 +const key = Symbol('visual-board-content');
  5 +
  6 +type Instance = UpdateCenter;
  7 +
  8 +export function createVisualBoardContext(instance: Instance) {
  9 + provide(key, instance);
  10 +}
  11 +
  12 +export function useVisualBoardContext() {
  13 + return inject(key) as Instance;
  14 +}
... ...