Commit 7b1bbc8c5f09a972013bc9aad4442c50dfe29b8d
1 parent
9156c53a
refactor: visual board component config
Showing
14 changed files
with
54 additions
and
73 deletions
src/views/visual/board/components/ControlComponent/ToggleSwitch.vue
renamed from
src/views/visual/board/components/Other/ToggleSwitch.vue
1 | 1 | <script lang="ts" setup> |
2 | + import { RadioRecord } from '../../detail/config/util'; | |
3 | + | |
2 | 4 | const props = defineProps<{ |
3 | 5 | value?: boolean; |
6 | + layout?: Recordable; | |
7 | + radio?: RadioRecord; | |
4 | 8 | }>(); |
5 | 9 | |
6 | 10 | const emit = defineEmits(['update:value', 'change']); |
... | ... | @@ -76,12 +80,12 @@ |
76 | 80 | transform-origin: center center -20px; |
77 | 81 | transform: translateZ(20px) rotateX(-25deg); |
78 | 82 | transform-style: preserve-3d; |
79 | - background-color: #9b0621; | |
80 | 83 | width: 100%; |
81 | 84 | height: 100%; |
82 | 85 | position: relative; |
83 | 86 | cursor: pointer; |
84 | 87 | background: linear-gradient(#980000 0%, #6f0000 30%, #6f0000 70%, #980000 100%); |
88 | + background-color: #9b0621; | |
85 | 89 | background-repeat: no-repeat; |
86 | 90 | } |
87 | 91 | |
... | ... | @@ -113,7 +117,7 @@ |
113 | 117 | transform: translateY(30px) rotateX(-90deg); |
114 | 118 | position: absolute; |
115 | 119 | bottom: 0; |
116 | - box-shadow: 0 30px 8px 0px black, 0 60px 20px 0px rgb(0 0 0 / 50%); | |
120 | + box-shadow: 0 30px 8px 0 black, 0 60px 20px 0 rgb(0 0 0 / 50%); | |
117 | 121 | } |
118 | 122 | |
119 | 123 | .switch .light { | ... | ... |
... | ... | @@ -102,11 +102,6 @@ |
102 | 102 | |
103 | 103 | watch(() => props.value, updateChartValue); |
104 | 104 | |
105 | - // watch( | |
106 | - // () => [props.value.gradientInfo, props.value.unit, props.value.valueColor, props.value.name], | |
107 | - // updateChartValue | |
108 | - // ); | |
109 | - | |
110 | 105 | const updateChartFont = useThrottleFn(() => { |
111 | 106 | const option = beforeUpdateFn(props.layout.componentType); |
112 | 107 | setTimeout(() => { |
... | ... | @@ -123,8 +118,6 @@ |
123 | 118 | |
124 | 119 | watch(() => props.layout.componentType, updateChartType); |
125 | 120 | |
126 | - // watch(() => props.value.gradientInfo, updateChartType); | |
127 | - | |
128 | 121 | let timeout: Nullable<number> = null; |
129 | 122 | |
130 | 123 | function handleRandomValue() { | ... | ... |
1 | 1 | import { EChartsOption } from 'echarts'; |
2 | +import { FrontComponent } from '../help'; | |
2 | 3 | import { fontSize, RadioRecord } from '../../detail/config/util'; |
3 | 4 | import { Gradient, visualOptionField } from '../../detail/config/visualOptions'; |
4 | 5 | import { |
... | ... | @@ -10,8 +11,6 @@ import { |
10 | 11 | import { isArray } from '/@/utils/is'; |
11 | 12 | import { buildUUID } from '/@/utils/uuid'; |
12 | 13 | |
13 | -export type InstrumentComponentType = 'instrument-component-1' | 'instrument-component-2'; | |
14 | - | |
15 | 14 | export type GradientKey = |
16 | 15 | | visualOptionField.FIRST_PHASE_COLOR |
17 | 16 | | visualOptionField.FIRST_PHASE_VALUE |
... | ... | @@ -38,7 +37,7 @@ export interface DashBoardValue { |
38 | 37 | |
39 | 38 | export interface DashboardComponentLayout { |
40 | 39 | chartOption: EChartsOption; |
41 | - componentType: InstrumentComponentType; | |
40 | + componentType: FrontComponent; | |
42 | 41 | } |
43 | 42 | |
44 | 43 | export enum GradientColor { | ... | ... |
1 | 1 | import { DataComponentRecord, DataSource } from '/@/api/dataBoard/model'; |
2 | 2 | |
3 | -export type PictureComponentType = 'picture-component-1'; | |
4 | - | |
5 | -export interface PictureComponentLayout {} | |
6 | - | |
7 | 3 | export interface PictureComponentValue { |
8 | 4 | value?: string; |
9 | 5 | updateTime?: string; |
10 | 6 | } |
11 | 7 | |
12 | 8 | export const transformPictureConfig = ( |
13 | - config: PictureComponentLayout, | |
14 | - record: DataComponentRecord, | |
9 | + _config: Recordable, | |
10 | + _record: DataComponentRecord, | |
15 | 11 | dataSourceRecord: DataSource |
16 | 12 | ) => { |
17 | 13 | const componentInfo = dataSourceRecord.componentInfo; | ... | ... |
... | ... | @@ -18,12 +18,6 @@ export interface TextComponentValue { |
18 | 18 | deviceName?: string; |
19 | 19 | } |
20 | 20 | |
21 | -export type TextComponentType = | |
22 | - | 'text-component-1' | |
23 | - | 'text-component-3' | |
24 | - | 'text-component-4' | |
25 | - | 'text-component-5'; | |
26 | - | |
27 | 21 | type TextComponentDefault = TextComponentLayout; |
28 | 22 | |
29 | 23 | export const TextComponent1Config: TextComponentDefault = { | ... | ... |
src/views/visual/board/components/help.ts
renamed from
src/views/visual/board/detail/config/help.ts
1 | 1 | import { Component } from 'vue'; |
2 | -import TextComponent from '../../components/TextComponent/TextComponent.vue'; | |
2 | +import TextComponent from './TextComponent/TextComponent.vue'; | |
3 | 3 | import { |
4 | 4 | TextComponent1Config, |
5 | 5 | TextComponent3Config, |
... | ... | @@ -7,12 +7,11 @@ import { |
7 | 7 | TextComponent5Config, |
8 | 8 | TextComponentDefaultConfig, |
9 | 9 | transformTextComponentConfig, |
10 | -} from '../../components/TextComponent/config'; | |
10 | +} from './TextComponent/config'; | |
11 | 11 | import { ComponentInfo, DataComponentRecord, DataSource } from '/@/api/dataBoard/model'; |
12 | -import DashBoardComponent from '../../components/InstrumentComponent/DashBoardComponent.vue'; | |
13 | -import PictureComponent from '../../components/PictureComponent/PictureComponent.vue'; | |
14 | -import { transformPictureConfig } from '../../components/PictureComponent/pictureComponent.config'; | |
15 | -import { WidgetComponentType } from './visualOptions'; | |
12 | +import DashBoardComponent from './InstrumentComponent/DashBoardComponent.vue'; | |
13 | +import PictureComponent from './PictureComponent/PictureComponent.vue'; | |
14 | +import { transformPictureConfig } from './PictureComponent/pictureComponent.config'; | |
16 | 15 | import { |
17 | 16 | DashboardComponentLayout, |
18 | 17 | Instrument1DefaultConfig, |
... | ... | @@ -20,9 +19,10 @@ import { |
20 | 19 | instrumentComponent1, |
21 | 20 | instrumentComponent2, |
22 | 21 | transformDashboardComponentConfig, |
23 | -} from '../../components/InstrumentComponent/dashBoardComponent.config'; | |
24 | -import DigitalDashBoard from '../../components/InstrumentComponent/DigitalDashBoard.vue'; | |
25 | -import { DigitalComponentDefaultConfig } from '../../components/InstrumentComponent/digitalDashBoard.config'; | |
22 | +} from './InstrumentComponent/dashBoardComponent.config'; | |
23 | +import DigitalDashBoard from './InstrumentComponent/DigitalDashBoard.vue'; | |
24 | +import { DigitalComponentDefaultConfig } from './InstrumentComponent/digitalDashBoard.config'; | |
25 | +import ToggleSwitch from './ControlComponent/ToggleSwitch.vue'; | |
26 | 26 | |
27 | 27 | export enum FrontComponentCategory { |
28 | 28 | TEXT = 'text', |
... | ... | @@ -32,13 +32,13 @@ export enum FrontComponentCategory { |
32 | 32 | MAP = 'map', |
33 | 33 | } |
34 | 34 | |
35 | -export enum FrontComponentCategoryName { | |
36 | - text = '文本组件', | |
37 | - picture = '图片组件', | |
38 | - instrument = '仪表组件', | |
39 | - control = '控制组件', | |
40 | - map = '地图组件', | |
41 | -} | |
35 | +export const FrontComponentCategoryName = { | |
36 | + [FrontComponentCategory.TEXT]: '文本组件', | |
37 | + [FrontComponentCategory.INSTRUMENT]: '仪表组件', | |
38 | + [FrontComponentCategory.CONTROL]: '控制组件', | |
39 | + [FrontComponentCategory.PICTURE]: '图片组件', | |
40 | + [FrontComponentCategory.MAP]: '地图组件', | |
41 | +}; | |
42 | 42 | |
43 | 43 | export enum FrontComponent { |
44 | 44 | TEXT_COMPONENT_1 = 'text-component-1', |
... | ... | @@ -50,6 +50,7 @@ export enum FrontComponent { |
50 | 50 | INSTRUMENT_COMPONENT_2 = 'instrument-component-2', |
51 | 51 | DIGITAL_DASHBOARD_COMPONENT = 'digital-dashboard-component', |
52 | 52 | PICTURE_COMPONENT_1 = 'picture-component-1', |
53 | + CONTROL_COMPONENT_TOGGLE_SWITCH = 'control-component-toggle-switch', | |
53 | 54 | } |
54 | 55 | |
55 | 56 | export interface ComponentConfig { |
... | ... | @@ -64,12 +65,9 @@ export interface ComponentConfig { |
64 | 65 | ) => Recordable; |
65 | 66 | } |
66 | 67 | |
67 | -export const frontComponentDefaultConfigMap = new Map< | |
68 | - WidgetComponentType, | |
69 | - Partial<ComponentInfo> | |
70 | ->(); | |
68 | +export const frontComponentDefaultConfigMap = new Map<FrontComponent, Partial<ComponentInfo>>(); | |
71 | 69 | |
72 | -export const frontComponentMap = new Map<WidgetComponentType, ComponentConfig>(); | |
70 | +export const frontComponentMap = new Map<FrontComponent, ComponentConfig>(); | |
73 | 71 | |
74 | 72 | frontComponentMap.set(FrontComponent.TEXT_COMPONENT_1, { |
75 | 73 | Component: TextComponent, |
... | ... | @@ -139,6 +137,12 @@ frontComponentMap.set(FrontComponent.PICTURE_COMPONENT_1, { |
139 | 137 | transformConfig: transformPictureConfig, |
140 | 138 | }); |
141 | 139 | |
140 | +frontComponentMap.set(FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH, { | |
141 | + Component: ToggleSwitch, | |
142 | + ComponentKey: FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH, | |
143 | + transformConfig: () => {}, | |
144 | +}); | |
145 | + | |
142 | 146 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_1, TextComponentDefaultConfig); |
143 | 147 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_3, TextComponentDefaultConfig); |
144 | 148 | frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_4, TextComponentDefaultConfig); |
... | ... | @@ -152,6 +156,6 @@ frontComponentDefaultConfigMap.set( |
152 | 156 | DigitalComponentDefaultConfig |
153 | 157 | ); |
154 | 158 | |
155 | -export const getComponentDefaultConfig = (key: WidgetComponentType) => { | |
159 | +export const getComponentDefaultConfig = (key: FrontComponent) => { | |
156 | 160 | return frontComponentDefaultConfigMap.get(key) || {}; |
157 | 161 | }; | ... | ... |
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | import type { ComponentInfo, DataSource } from '/@/api/dataBoard/model'; |
12 | 12 | import { useMessage } from '/@/hooks/web/useMessage'; |
13 | 13 | import { DataBoardLayoutInfo } from '../../types/type'; |
14 | - import { FrontComponent } from '../config/help'; | |
14 | + import { FrontComponent } from '../../components/help'; | |
15 | 15 | import { computed } from '@vue/reactivity'; |
16 | 16 | |
17 | 17 | type DataSourceFormEL = { [key: string]: Nullable<FormActionType> }; |
... | ... | @@ -112,8 +112,6 @@ |
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - // const defaultConfig = getComponentDefaultConfig(props.frontId as WidgetComponentType); | |
116 | - | |
117 | 115 | const componentInfo: ComponentInfo = { |
118 | 116 | ...(props.defaultConfig || {}), |
119 | 117 | ...(item.componentInfo || {}), | ... | ... |
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | import { decode } from '../../config/config'; |
13 | 13 | import { ComponentInfo } from '/@/api/dataBoard/model'; |
14 | 14 | import { useCalcGridLayout } from '../../hook/useCalcGridLayout'; |
15 | - import { FrontComponent } from '../config/help'; | |
15 | + import { FrontComponent } from '../../components/help'; | |
16 | 16 | |
17 | 17 | interface DataComponentRouteParams extends RouteParams { |
18 | 18 | id: string; | ... | ... |
... | ... | @@ -2,12 +2,12 @@ |
2 | 2 | import { Tabs, List } from 'ant-design-vue'; |
3 | 3 | import VisualWidgetSelect from './VisualWidgetSelect.vue'; |
4 | 4 | import { |
5 | + FrontComponent, | |
5 | 6 | FrontComponentCategory, |
6 | 7 | FrontComponentCategoryName, |
7 | 8 | getComponentDefaultConfig, |
8 | - } from '../config/help'; | |
9 | - import { WidgetComponentType } from '../config/visualOptions'; | |
10 | - import { frontComponentMap } from '../config/help'; | |
9 | + } from '../../components/help'; | |
10 | + import { frontComponentMap } from '../../components/help'; | |
11 | 11 | import { computed } from 'vue'; |
12 | 12 | |
13 | 13 | interface DataSource { |
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 | return Array.from(category.values()); |
41 | 41 | }); |
42 | 42 | |
43 | - const handleCheck = (checked: WidgetComponentType) => { | |
43 | + const handleCheck = (checked: FrontComponent) => { | |
44 | 44 | const defaultConfig = getComponentDefaultConfig(checked); |
45 | 45 | emit('update:value', checked); |
46 | 46 | emit('change', defaultConfig); | ... | ... |
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { ref, unref } from 'vue'; |
3 | 3 | import { |
4 | - WidgetComponentType, | |
5 | 4 | schemasMap, |
6 | 5 | VisualOptionParams, |
7 | 6 | visualOptionField, |
... | ... | @@ -11,6 +10,7 @@ |
11 | 10 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
12 | 11 | import { ComponentInfo } from '/@/api/dataBoard/model'; |
13 | 12 | import { computed } from '@vue/reactivity'; |
13 | + import { FrontComponent } from '../../components/help'; | |
14 | 14 | |
15 | 15 | const emit = defineEmits(['close', 'register']); |
16 | 16 | |
... | ... | @@ -21,7 +21,7 @@ |
21 | 21 | const recordId = ref(''); |
22 | 22 | |
23 | 23 | const getSchemas = computed(() => { |
24 | - return schemasMap.get((props.value as WidgetComponentType) || 'text-component-1'); | |
24 | + return schemasMap.get((props.value as FrontComponent) || 'text-component-1'); | |
25 | 25 | }); |
26 | 26 | |
27 | 27 | const [registerForm, method] = useForm({ | ... | ... |
1 | -import { InstrumentComponentType } from '../../components/InstrumentComponent/dashBoardComponent.config'; | |
2 | -import { DigitalDashBoardComponentType } from '../../components/InstrumentComponent/digitalDashBoard.config'; | |
3 | -import { PictureComponentType } from '../../components/PictureComponent/pictureComponent.config'; | |
4 | -import { TextComponentType } from '../../components/TextComponent/config'; | |
5 | 1 | import { FormSchema } from '/@/components/Form'; |
6 | 2 | |
7 | -export type WidgetComponentType = | |
8 | - | TextComponentType | |
9 | - | InstrumentComponentType | |
10 | - | DigitalDashBoardComponentType | |
11 | - | PictureComponentType; | |
12 | - | |
13 | 3 | export interface VisualOptionParams { |
14 | 4 | [visualOptionField.FONT_COLOR]: string; |
15 | 5 | [visualOptionField.UNIT]: string; |
... | ... | @@ -198,7 +188,7 @@ export const modeFour: FormSchema[] = [ |
198 | 188 | }, |
199 | 189 | ]; |
200 | 190 | |
201 | -export const schemasMap = new Map<WidgetComponentType, FormSchema[]>(); | |
191 | +export const schemasMap = new Map<string, FormSchema[]>(); | |
202 | 192 | |
203 | 193 | schemasMap.set('text-component-1', modeOne); |
204 | 194 | schemasMap.set('text-component-2', modeOne); | ... | ... |
... | ... | @@ -33,11 +33,10 @@ |
33 | 33 | DataSource, |
34 | 34 | Layout, |
35 | 35 | } from '/@/api/dataBoard/model'; |
36 | - import { frontComponentMap } from './config/help'; | |
36 | + import { frontComponentMap } from '../components/help'; | |
37 | 37 | import { calcScale } from './config/util'; |
38 | 38 | import { useMessage } from '/@/hooks/web/useMessage'; |
39 | 39 | import { DataBoardLayoutInfo } from '../types/type'; |
40 | - import { WidgetComponentType } from './config/visualOptions'; | |
41 | 40 | import Authority from '/@/components/Authority/src/Authority.vue'; |
42 | 41 | import { useSocketConnect } from '../hook/useSocketConnect'; |
43 | 42 | import { buildUUID } from '/@/utils/uuid'; |
... | ... | @@ -45,6 +44,7 @@ |
45 | 44 | import trendIcon from '/@/assets/svg/trend.svg'; |
46 | 45 | import backIcon from '/@/assets/images/back.png'; |
47 | 46 | import { useCalcGridLayout } from '../hook/useCalcGridLayout'; |
47 | + import { FrontComponent } from '../components/help'; | |
48 | 48 | |
49 | 49 | const ROUTE = useRoute(); |
50 | 50 | |
... | ... | @@ -299,7 +299,7 @@ |
299 | 299 | |
300 | 300 | const getComponent = (record: DataComponentRecord) => { |
301 | 301 | const frontComponent = record.frontId; |
302 | - const component = frontComponentMap.get(frontComponent as WidgetComponentType); | |
302 | + const component = frontComponentMap.get(frontComponent as FrontComponent); | |
303 | 303 | return component?.Component; |
304 | 304 | }; |
305 | 305 | |
... | ... | @@ -308,7 +308,7 @@ |
308 | 308 | dataSourceRecord: DataSource |
309 | 309 | ) => { |
310 | 310 | const frontComponent = record.frontId; |
311 | - const component = frontComponentMap.get(frontComponent as WidgetComponentType); | |
311 | + const component = frontComponentMap.get(frontComponent as FrontComponent); | |
312 | 312 | return component?.transformConfig(component.ComponentConfig || {}, record, dataSourceRecord); |
313 | 313 | }; |
314 | 314 | ... | ... |