Commit 9156c53a894f6206f9298171fe4a93a8ae87624e
1 parent
4a16e53a
refactof: visual board select component
Showing
10 changed files
with
101 additions
and
152 deletions
... | ... | @@ -22,6 +22,7 @@ |
22 | 22 | } from '../../detail/config/util'; |
23 | 23 | import { Tooltip } from 'ant-design-vue'; |
24 | 24 | import { useThrottleFn } from '@vueuse/shared'; |
25 | + import { buildUUID } from '/@/utils/uuid'; | |
25 | 26 | |
26 | 27 | const props = defineProps({ |
27 | 28 | add: { |
... | ... | @@ -33,7 +34,7 @@ |
33 | 34 | }, |
34 | 35 | value: { |
35 | 36 | type: Object as PropType<DashBoardValue>, |
36 | - default: () => ({}), | |
37 | + default: () => ({ id: buildUUID() }), | |
37 | 38 | }, |
38 | 39 | radio: { |
39 | 40 | type: Object as PropType<RadioRecord>, | ... | ... |
... | ... | @@ -16,12 +16,18 @@ |
16 | 16 | } from '../../detail/config/util'; |
17 | 17 | import { isNaN } from 'lodash'; |
18 | 18 | |
19 | - const props = defineProps<{ | |
20 | - layout: DigitalDashBoardLayout; | |
21 | - value: DigitalDashBoardValue; | |
22 | - radio?: RadioRecord; | |
23 | - random?: boolean; | |
24 | - }>(); | |
19 | + const props = withDefaults( | |
20 | + defineProps<{ | |
21 | + layout?: DigitalDashBoardLayout; | |
22 | + value?: DigitalDashBoardValue; | |
23 | + radio?: RadioRecord; | |
24 | + random?: boolean; | |
25 | + }>(), | |
26 | + { | |
27 | + value: () => ({}), | |
28 | + layout: () => ({ max: 5, keepNumber: 2 }), | |
29 | + } | |
30 | + ); | |
25 | 31 | |
26 | 32 | const changeValue = ref(0); |
27 | 33 | |
... | ... | @@ -188,11 +194,12 @@ |
188 | 194 | <style scoped lang="less"> |
189 | 195 | .digital-wrapper__int { |
190 | 196 | border-radius: 1px; |
191 | - box-shadow: inset 0px 1px 3px 0px rgba(0, 0, 0, 0.7); | |
192 | - background: url('/@/assets/images/digital-wrapper-bg-int.png') 0px -1px no-repeat; | |
197 | + box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.7); | |
198 | + background: url('/@/assets/images/digital-wrapper-bg-int.png') 0 -1px no-repeat; | |
193 | 199 | padding: 5px; |
194 | 200 | background-size: 100% 100%; |
195 | 201 | } |
202 | + | |
196 | 203 | .digital-text_int { |
197 | 204 | display: inline-block; |
198 | 205 | overflow-wrap: break-word; |
... | ... | @@ -203,11 +210,12 @@ |
203 | 210 | |
204 | 211 | .digital-wrapper__float { |
205 | 212 | border-radius: 1px; |
206 | - box-shadow: inset 0px 1px 3px 0px rgba(112, 22, 15, 1); | |
207 | - background: url('/@/assets/images/digital-wrapper-bg-float.png') 0px -1px no-repeat; | |
213 | + box-shadow: inset 0 1px 3px 0 rgba(112, 22, 15, 1); | |
214 | + background: url('/@/assets/images/digital-wrapper-bg-float.png') 0 -1px no-repeat; | |
208 | 215 | padding: 5px; |
209 | 216 | background-size: 100% 100%; |
210 | 217 | } |
218 | + | |
211 | 219 | .digital-text_float { |
212 | 220 | display: inline-block; |
213 | 221 | overflow-wrap: break-word; | ... | ... |
1 | 1 | import { EChartsOption } from 'echarts'; |
2 | -import { Component } from 'vue'; | |
3 | -import { WidgetComponentType } from '../../detail/config/visualOptions'; | |
4 | -import { | |
5 | - Instrument1DefaultConfig, | |
6 | - Instrument2DefaultConfig, | |
7 | - instrumentComponent1, | |
8 | - instrumentComponent2, | |
9 | - InstrumentComponentType, | |
10 | -} from './dashBoardComponent.config'; | |
11 | -import DashBoardComponent from './DashBoardComponent.vue'; | |
12 | -import DigitalDashBoard from './DigitalDashBoard.vue'; | |
13 | -import { buildUUID } from '/@/utils/uuid'; | |
2 | +import { InstrumentComponentType } from './dashBoardComponent.config'; | |
14 | 3 | |
15 | 4 | export interface DashboardComponentLayout { |
16 | 5 | chartOption: EChartsOption; |
17 | 6 | componentType: InstrumentComponentType; |
18 | 7 | } |
19 | - | |
20 | -interface InstrumentComponentConfig { | |
21 | - id: WidgetComponentType; | |
22 | - layout: DashboardComponentLayout; | |
23 | - component: Component; | |
24 | - value: Recordable; | |
25 | -} | |
26 | - | |
27 | -export const instrumentComponentConfig: InstrumentComponentConfig[] = [ | |
28 | - { | |
29 | - id: 'instrument-component-1', | |
30 | - layout: { | |
31 | - chartOption: instrumentComponent1(Instrument1DefaultConfig), | |
32 | - componentType: 'instrument-component-1', | |
33 | - }, | |
34 | - component: DashBoardComponent, | |
35 | - value: { id: buildUUID() }, | |
36 | - }, | |
37 | - { | |
38 | - id: 'instrument-component-2', | |
39 | - layout: { | |
40 | - chartOption: instrumentComponent2(Instrument2DefaultConfig), | |
41 | - componentType: 'instrument-component-2', | |
42 | - }, | |
43 | - component: DashBoardComponent, | |
44 | - value: { id: buildUUID() }, | |
45 | - }, | |
46 | - { | |
47 | - id: 'digital-dashboard-component', | |
48 | - layout: {}, | |
49 | - component: DigitalDashBoard, | |
50 | - value: {}, | |
51 | - }, | |
52 | -]; | ... | ... |
1 | 1 | import PictureComponent from './PictureComponent.vue'; |
2 | 2 | |
3 | -import { PictureComponentType } from './pictureComponent.config'; | |
4 | -import { Component } from 'vue'; | |
5 | - | |
6 | -interface PictureComponentList { | |
7 | - id: PictureComponentType; | |
8 | - component: Component; | |
9 | -} | |
10 | - | |
11 | -const pictureComponentList: PictureComponentList[] = [ | |
12 | - { | |
13 | - id: 'picture-component-1', | |
14 | - component: PictureComponent, | |
15 | - }, | |
16 | -]; | |
17 | - | |
18 | -export { PictureComponent, pictureComponentList }; | |
3 | +export { PictureComponent }; | ... | ... |
... | ... | @@ -20,7 +20,6 @@ export interface TextComponentValue { |
20 | 20 | |
21 | 21 | export type TextComponentType = |
22 | 22 | | 'text-component-1' |
23 | - | 'text-component-2' | |
24 | 23 | | 'text-component-3' |
25 | 24 | | 'text-component-4' |
26 | 25 | | 'text-component-5'; |
... | ... | @@ -32,10 +31,6 @@ export const TextComponent1Config: TextComponentDefault = { |
32 | 31 | base: true, |
33 | 32 | }; |
34 | 33 | |
35 | -export const TextComponent2Config: TextComponentDefault = { | |
36 | - id: 'text-component-2', | |
37 | - base: false, | |
38 | -}; | |
39 | 34 | export const TextComponent3Config: TextComponentDefault = { |
40 | 35 | id: 'text-component-3', |
41 | 36 | base: false, |
... | ... | @@ -62,17 +57,9 @@ export const TextComponentDefaultConfig: Partial<ComponentInfo> = { |
62 | 57 | icon: 'shuiwen', |
63 | 58 | }; |
64 | 59 | |
65 | -export const textComponentConfig: TextComponentDefault[] = [ | |
66 | - TextComponent1Config, | |
67 | - // TextComponent2Config, | |
68 | - TextComponent3Config, | |
69 | - TextComponent4Config, | |
70 | - TextComponent5Config, | |
71 | -]; | |
72 | - | |
73 | 60 | export const transformTextComponentConfig = ( |
74 | 61 | config: TextComponentDefault, |
75 | - record: DataComponentRecord, | |
62 | + _record: DataComponentRecord, | |
76 | 63 | dataSourceRecord: DataSource |
77 | 64 | ) => { |
78 | 65 | return { | ... | ... |
src/views/visual/board/config/componentMap.ts
deleted
100644 → 0
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { Tabs, List } from 'ant-design-vue'; |
3 | 3 | import VisualWidgetSelect from './VisualWidgetSelect.vue'; |
4 | - import TextComponent from '../../components/TextComponent/TextComponent.vue'; | |
5 | - import { textComponentConfig } from '../../components/TextComponent/config'; | |
6 | - import { instrumentComponentConfig } from '../../components/InstrumentComponent'; | |
7 | - import { pictureComponentList } from '../../components/PictureComponent'; | |
8 | - import { getComponentDefaultConfig } from '../config/help'; | |
4 | + import { | |
5 | + FrontComponentCategory, | |
6 | + FrontComponentCategoryName, | |
7 | + getComponentDefaultConfig, | |
8 | + } from '../config/help'; | |
9 | 9 | import { WidgetComponentType } from '../config/visualOptions'; |
10 | + import { frontComponentMap } from '../config/help'; | |
11 | + import { computed } from 'vue'; | |
12 | + | |
13 | + interface DataSource { | |
14 | + category: string; | |
15 | + categoryName: string; | |
16 | + list: Recordable[]; | |
17 | + } | |
10 | 18 | const props = defineProps<{ |
11 | 19 | value: string; |
12 | 20 | }>(); |
... | ... | @@ -14,6 +22,24 @@ |
14 | 22 | |
15 | 23 | const grid = { gutter: 10, column: 1, xs: 1, sm: 2, md: 2, lg: 3, xl: 3, xxl: 4 }; |
16 | 24 | |
25 | + const getDataSource = computed(() => { | |
26 | + const _dataSource = Array.from(frontComponentMap.values()); | |
27 | + const category = new Map<FrontComponentCategory, DataSource>(); | |
28 | + for (const item of _dataSource) { | |
29 | + if (category.has(item.ComponentCategory)) { | |
30 | + const value = category.get(item.ComponentCategory)!; | |
31 | + value.list.push(item); | |
32 | + continue; | |
33 | + } | |
34 | + category.set(item.ComponentCategory, { | |
35 | + category: item.ComponentCategory, | |
36 | + categoryName: FrontComponentCategoryName[item.ComponentCategory], | |
37 | + list: [item], | |
38 | + }); | |
39 | + } | |
40 | + return Array.from(category.values()); | |
41 | + }); | |
42 | + | |
17 | 43 | const handleCheck = (checked: WidgetComponentType) => { |
18 | 44 | const defaultConfig = getComponentDefaultConfig(checked); |
19 | 45 | emit('update:value', checked); |
... | ... | @@ -24,51 +50,20 @@ |
24 | 50 | <template> |
25 | 51 | <section> |
26 | 52 | <Tabs> |
27 | - <Tabs.TabPane key="1" tab="文本组件"> | |
28 | - <List :grid="grid" :data-source="textComponentConfig"> | |
29 | - <template #renderItem="{ item }"> | |
30 | - <List.Item class="!flex !justify-center"> | |
31 | - <VisualWidgetSelect | |
32 | - :checked-id="props.value" | |
33 | - :control-id="item.id" | |
34 | - @change="handleCheck" | |
35 | - > | |
36 | - <TextComponent :layout="item" :value="item.value" /> | |
37 | - </VisualWidgetSelect> | |
38 | - </List.Item> | |
39 | - </template> | |
40 | - </List> | |
41 | - </Tabs.TabPane> | |
42 | - <Tabs.TabPane key="2" tab="图片组件"> | |
43 | - <List :grid="grid" :data-source="pictureComponentList"> | |
44 | - <template #renderItem="{ item }"> | |
45 | - <List.Item class="!flex !justify-center"> | |
46 | - <VisualWidgetSelect | |
47 | - :checked-id="props.value" | |
48 | - :control-id="item.id" | |
49 | - @change="handleCheck" | |
50 | - > | |
51 | - <component :is="item.component" /> | |
52 | - </VisualWidgetSelect> | |
53 | - </List.Item> | |
54 | - </template> | |
55 | - </List> | |
56 | - </Tabs.TabPane> | |
57 | - <Tabs.TabPane key="3" tab="仪表组件"> | |
58 | - <List :grid="grid" :data-source="instrumentComponentConfig"> | |
53 | + <Tabs.TabPane | |
54 | + v-for="category in getDataSource" | |
55 | + :key="category.category" | |
56 | + :tab="category.categoryName" | |
57 | + > | |
58 | + <List :grid="grid" :data-source="category.list"> | |
59 | 59 | <template #renderItem="{ item }"> |
60 | 60 | <List.Item class="!flex !justify-center"> |
61 | 61 | <VisualWidgetSelect |
62 | 62 | :checked-id="props.value" |
63 | - :control-id="item.id" | |
63 | + :control-id="item.ComponentKey" | |
64 | 64 | @change="handleCheck" |
65 | 65 | > |
66 | - <component | |
67 | - :is="item.component" | |
68 | - :random="true" | |
69 | - :layout="item.layout" | |
70 | - :value="item.value" | |
71 | - /> | |
66 | + <component :is="item.Component" :random="true" :layout="item.ComponentConfig" /> | |
72 | 67 | </VisualWidgetSelect> |
73 | 68 | </List.Item> |
74 | 69 | </template> | ... | ... |
... | ... | @@ -2,7 +2,6 @@ import { Component } from 'vue'; |
2 | 2 | import TextComponent from '../../components/TextComponent/TextComponent.vue'; |
3 | 3 | import { |
4 | 4 | TextComponent1Config, |
5 | - TextComponent2Config, | |
6 | 5 | TextComponent3Config, |
7 | 6 | TextComponent4Config, |
8 | 7 | TextComponent5Config, |
... | ... | @@ -24,6 +23,23 @@ import { |
24 | 23 | } from '../../components/InstrumentComponent/dashBoardComponent.config'; |
25 | 24 | import DigitalDashBoard from '../../components/InstrumentComponent/DigitalDashBoard.vue'; |
26 | 25 | import { DigitalComponentDefaultConfig } from '../../components/InstrumentComponent/digitalDashBoard.config'; |
26 | + | |
27 | +export enum FrontComponentCategory { | |
28 | + TEXT = 'text', | |
29 | + PICTURE = 'picture', | |
30 | + INSTRUMENT = 'instrument', | |
31 | + CONTROL = 'control', | |
32 | + MAP = 'map', | |
33 | +} | |
34 | + | |
35 | +export enum FrontComponentCategoryName { | |
36 | + text = '文本组件', | |
37 | + picture = '图片组件', | |
38 | + instrument = '仪表组件', | |
39 | + control = '控制组件', | |
40 | + map = '地图组件', | |
41 | +} | |
42 | + | |
27 | 43 | export enum FrontComponent { |
28 | 44 | TEXT_COMPONENT_1 = 'text-component-1', |
29 | 45 | TEXT_COMPONENT_2 = 'text-component-2', |
... | ... | @@ -38,7 +54,9 @@ export enum FrontComponent { |
38 | 54 | |
39 | 55 | export interface ComponentConfig { |
40 | 56 | Component: Component; |
41 | - ComponentConfig: Recordable; | |
57 | + ComponentKey: FrontComponent; | |
58 | + ComponentConfig?: Recordable; | |
59 | + ComponentCategory: FrontComponentCategory; | |
42 | 60 | transformConfig: ( |
43 | 61 | ComponentConfig: Recordable, |
44 | 62 | record: DataComponentRecord, |
... | ... | @@ -55,66 +73,73 @@ export const frontComponentMap = new Map<WidgetComponentType, ComponentConfig>() |
55 | 73 | |
56 | 74 | frontComponentMap.set(FrontComponent.TEXT_COMPONENT_1, { |
57 | 75 | Component: TextComponent, |
76 | + ComponentKey: FrontComponent.TEXT_COMPONENT_1, | |
58 | 77 | ComponentConfig: TextComponent1Config, |
59 | - transformConfig: transformTextComponentConfig, | |
60 | -}); | |
61 | - | |
62 | -frontComponentMap.set(FrontComponent.TEXT_COMPONENT_2, { | |
63 | - Component: TextComponent, | |
64 | - ComponentConfig: TextComponent2Config, | |
78 | + ComponentCategory: FrontComponentCategory.TEXT, | |
65 | 79 | transformConfig: transformTextComponentConfig, |
66 | 80 | }); |
67 | 81 | |
68 | 82 | frontComponentMap.set(FrontComponent.TEXT_COMPONENT_3, { |
69 | 83 | Component: TextComponent, |
84 | + ComponentKey: FrontComponent.TEXT_COMPONENT_3, | |
70 | 85 | ComponentConfig: TextComponent3Config, |
86 | + ComponentCategory: FrontComponentCategory.TEXT, | |
71 | 87 | transformConfig: transformTextComponentConfig, |
72 | 88 | }); |
73 | 89 | |
74 | 90 | frontComponentMap.set(FrontComponent.TEXT_COMPONENT_4, { |
75 | 91 | Component: TextComponent, |
92 | + ComponentKey: FrontComponent.TEXT_COMPONENT_4, | |
76 | 93 | ComponentConfig: TextComponent4Config, |
94 | + ComponentCategory: FrontComponentCategory.TEXT, | |
77 | 95 | transformConfig: transformTextComponentConfig, |
78 | 96 | }); |
79 | 97 | |
80 | 98 | frontComponentMap.set(FrontComponent.TEXT_COMPONENT_5, { |
81 | 99 | Component: TextComponent, |
100 | + ComponentKey: FrontComponent.TEXT_COMPONENT_5, | |
82 | 101 | ComponentConfig: TextComponent5Config, |
102 | + ComponentCategory: FrontComponentCategory.TEXT, | |
83 | 103 | transformConfig: transformTextComponentConfig, |
84 | 104 | }); |
85 | 105 | |
86 | 106 | frontComponentMap.set(FrontComponent.INSTRUMENT_COMPONENT_1, { |
87 | 107 | Component: DashBoardComponent, |
108 | + ComponentKey: FrontComponent.INSTRUMENT_COMPONENT_1, | |
88 | 109 | ComponentConfig: { |
89 | - chartOption: instrumentComponent1(), | |
110 | + chartOption: instrumentComponent1(Instrument1DefaultConfig), | |
90 | 111 | componentType: FrontComponent.INSTRUMENT_COMPONENT_1, |
91 | 112 | } as DashboardComponentLayout, |
113 | + ComponentCategory: FrontComponentCategory.INSTRUMENT, | |
92 | 114 | transformConfig: transformDashboardComponentConfig, |
93 | 115 | }); |
94 | 116 | |
95 | 117 | frontComponentMap.set(FrontComponent.INSTRUMENT_COMPONENT_2, { |
96 | 118 | Component: DashBoardComponent, |
119 | + ComponentKey: FrontComponent.INSTRUMENT_COMPONENT_2, | |
97 | 120 | ComponentConfig: { |
98 | - chartOption: instrumentComponent2(), | |
121 | + chartOption: instrumentComponent2(Instrument2DefaultConfig), | |
99 | 122 | componentType: FrontComponent.INSTRUMENT_COMPONENT_2, |
100 | 123 | } as DashboardComponentLayout, |
124 | + ComponentCategory: FrontComponentCategory.INSTRUMENT, | |
101 | 125 | transformConfig: transformDashboardComponentConfig, |
102 | 126 | }); |
103 | 127 | |
104 | 128 | frontComponentMap.set(FrontComponent.DIGITAL_DASHBOARD_COMPONENT, { |
105 | 129 | Component: DigitalDashBoard, |
106 | - ComponentConfig: {}, | |
130 | + ComponentKey: FrontComponent.DIGITAL_DASHBOARD_COMPONENT, | |
131 | + ComponentCategory: FrontComponentCategory.INSTRUMENT, | |
107 | 132 | transformConfig: transformDashboardComponentConfig, |
108 | 133 | }); |
109 | 134 | |
110 | 135 | frontComponentMap.set(FrontComponent.PICTURE_COMPONENT_1, { |
111 | 136 | Component: PictureComponent, |
112 | - ComponentConfig: {}, | |
137 | + ComponentKey: FrontComponent.PICTURE_COMPONENT_1, | |
138 | + ComponentCategory: FrontComponentCategory.PICTURE, | |
113 | 139 | transformConfig: transformPictureConfig, |
114 | 140 | }); |
115 | 141 | |
116 | 142 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_1, TextComponentDefaultConfig); |
117 | -frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_2, TextComponentDefaultConfig); | |
118 | 143 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_3, TextComponentDefaultConfig); |
119 | 144 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_4, TextComponentDefaultConfig); |
120 | 145 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_5, TextComponentDefaultConfig); | ... | ... |
... | ... | @@ -309,7 +309,7 @@ |
309 | 309 | ) => { |
310 | 310 | const frontComponent = record.frontId; |
311 | 311 | const component = frontComponentMap.get(frontComponent as WidgetComponentType); |
312 | - return component?.transformConfig(component.ComponentConfig, record, dataSourceRecord); | |
312 | + return component?.transformConfig(component.ComponentConfig || {}, record, dataSourceRecord); | |
313 | 313 | }; |
314 | 314 | |
315 | 315 | const handleUpdate = async (id: string) => { | ... | ... |