Commit 3ed9be764e7475433ed2386654df1e6c316522b6

Authored by ww
1 parent 295b2782

perf: adjust modal width && link visual options and component config

1 1 <script lang="ts" setup>
2   - import { computed } from 'vue';
  2 + import { computed, unref } from 'vue';
3 3 import { Space, Tooltip } from 'ant-design-vue';
4   - import type { DigitalDashBoardLayout, DigitalDashBoardValue } from './digitalDashBoard.config';
  4 + import {
  5 + DigitalComponentDefaultConfig,
  6 + DigitalDashBoardLayout,
  7 + DigitalDashBoardValue,
  8 + } from './digitalDashBoard.config';
5 9 import { dateUtil } from '/@/utils/dateUtil';
6 10 import {
7 11 fontSize,
... ... @@ -9,6 +13,7 @@
9 13 DEFAULT_DATE_FORMAT,
10 14 DEFAULT_RADIO_RECORD,
11 15 } from '../../detail/config/util';
  16 + import { isNaN } from 'lodash';
12 17
13 18 const props = defineProps<{
14 19 layout: DigitalDashBoardLayout;
... ... @@ -16,8 +21,12 @@
16 21 radio?: RadioRecord;
17 22 }>();
18 23
  24 + const getPropsValue = computed(() => {
  25 + return { ...DigitalComponentDefaultConfig, ...props.value };
  26 + });
  27 +
19 28 const integerPart = computed(() => {
20   - let { value = 0 } = props.value;
  29 + let { value = 0 } = unref(getPropsValue);
21 30 const { max = 5 } = props.layout;
22 31 if (isNaN(value)) value = 0;
23 32 let _value = Number(value).toFixed(2).split('.')[0];
... ... @@ -28,7 +37,7 @@
28 37 });
29 38
30 39 const decimalPart = computed(() => {
31   - let { value = 0 } = props.value;
  40 + let { value = 0 } = unref(getPropsValue);
32 41 const { keepNumber = 2 } = props.layout;
33 42 if (isNaN(value)) value = 0;
34 43 let _value = Number(value)?.toFixed(2).split('.')[1];
... ... @@ -56,7 +65,7 @@
56 65 :key="number"
57 66 class="border border-gray-400 p-2"
58 67 :style="{
59   - color: props.value.fontColor,
  68 + color: getPropsValue.fontColor,
60 69 fontSize: fontSize({ radio: getRadio, basic: 20 }),
61 70 }"
62 71 >
... ... @@ -69,7 +78,7 @@
69 78 :key="number"
70 79 class="border border-gray-400 p-1"
71 80 :style="{
72   - color: props.value.fontColor,
  81 + color: getPropsValue.fontColor,
73 82 fontSize: fontSize({ radio: getRadio, basic: 18 }),
74 83 }"
75 84 >
... ... @@ -84,7 +93,7 @@
84 93 :style="{ fontSize: fontSize({ radio: getRadio, basic: 18 }) }"
85 94 >
86 95 <span>{{ props.value.name || '电表' }}</span>
87   - <span class="px-1">({{ 'kw/h' }})</span>
  96 + <span class="px-1">({{ getPropsValue.unit }})</span>
88 97 </div>
89 98 <div
90 99 class="text-center mt-1 text-gray-400 text-xs truncate"
... ...
1 1 import { EChartsOption } from 'echarts';
2 2 import { fontSize } from '../../detail/config/util';
3 3 import { Gradient, visualOptionField } from '../../detail/config/visualOptions';
4   -import { DataComponentRecord, DataSource, GradientInfo } from '/@/api/dataBoard/model';
  4 +import {
  5 + ComponentInfo,
  6 + DataComponentRecord,
  7 + DataSource,
  8 + GradientInfo,
  9 +} from '/@/api/dataBoard/model';
5 10 import { isArray } from '/@/utils/is';
6 11 import { buildUUID } from '/@/utils/uuid';
7 12
... ... @@ -36,11 +41,13 @@ export interface DashboardComponentLayout {
36 41 componentType: InstrumentComponentType;
37 42 }
38 43
39   -export const instrumentComponent1 = (params?: {
40   - value: number;
41   - unit: string;
42   - fontColor: string;
43   -}): EChartsOption => {
  44 +export enum GradientColor {
  45 + FIRST = '#67e0e3',
  46 + SECOND = '#37a2da',
  47 + THIRD = '#fd666d',
  48 +}
  49 +
  50 +export const instrumentComponent1 = (params?: Partial<ComponentInfo>): EChartsOption => {
44 51 const { value = 10, unit = '°C' } = params || {};
45 52 return {
46 53 series: [
... ... @@ -108,7 +115,7 @@ export const instrumentComponent1 = (params?: {
108 115 },
109 116 data: [
110 117 {
111   - value: value,
  118 + value: value as number,
112 119 },
113 120 ],
114 121 },
... ... @@ -146,7 +153,7 @@ export const instrumentComponent1 = (params?: {
146 153 },
147 154 data: [
148 155 {
149   - value: value,
  156 + value: value as number,
150 157 },
151 158 ],
152 159 },
... ... @@ -154,16 +161,11 @@ export const instrumentComponent1 = (params?: {
154 161 };
155 162 };
156 163
157   -export const instrumentComponent2 = (params?: {
158   - gradient: GradientInfo[];
159   - value: number;
160   - unit: string;
161   - fontColor: string;
162   -}): EChartsOption => {
163   - const { gradient = [], value = 0, unit = 'km/h' } = params || {};
164   - const firstRecord = getGradient(Gradient.FIRST, gradient);
165   - const secondRecord = getGradient(Gradient.SECOND, gradient);
166   - const thirdRecord = getGradient(Gradient.THIRD, gradient);
  164 +export const instrumentComponent2 = (params?: Partial<ComponentInfo>): EChartsOption => {
  165 + const { gradientInfo = [], value = 0, unit = 'km/h' } = params || {};
  166 + const firstRecord = getGradient(Gradient.FIRST, gradientInfo);
  167 + const secondRecord = getGradient(Gradient.SECOND, gradientInfo);
  168 + const thirdRecord = getGradient(Gradient.THIRD, gradientInfo);
167 169
168 170 let max = thirdRecord?.value || secondRecord?.value || firstRecord?.value || 70;
169 171 max = Number(1 + Array(String(max).length).fill(0).join(''));
... ... @@ -182,9 +184,9 @@ export const instrumentComponent2 = (params?: {
182 184 lineStyle: {
183 185 width: 20,
184 186 color: [
185   - [firstGradient, firstRecord?.color || '#67e0e3'],
186   - [secondGradient, secondRecord?.color || '#37a2da'],
187   - [1, thirdRecord?.color || '#fd666d'],
  187 + [firstGradient, firstRecord?.color || GradientColor.FIRST],
  188 + [secondGradient, secondRecord?.color || GradientColor.SECOND],
  189 + [1, thirdRecord?.color || GradientColor.THIRD],
188 190 ],
189 191 },
190 192 },
... ... @@ -223,7 +225,7 @@ export const instrumentComponent2 = (params?: {
223 225 },
224 226 data: [
225 227 {
226   - value: value,
  228 + value: value as number,
227 229 },
228 230 ],
229 231 },
... ... @@ -293,14 +295,23 @@ export const update_instrument_2_value = (value) => {
293 295
294 296 function setGradientInfo(dataSource: DataSource) {
295 297 const componentInfo = dataSource.componentInfo;
296   - return instrumentComponent2({
297   - unit: componentInfo.unit,
298   - value: 0,
299   - gradient: componentInfo.gradientInfo,
300   - fontColor: componentInfo.fontColor,
301   - });
  298 + return instrumentComponent2(componentInfo);
302 299 }
303 300
  301 +export const Instrument1DefaultConfig: Partial<ComponentInfo> = {
  302 + fontColor: '#FD7347',
  303 +};
  304 +
  305 +export const Instrument2DefaultConfig: Partial<ComponentInfo> = {
  306 + fontColor: GradientColor.FIRST,
  307 + unit: 'km/h',
  308 + gradientInfo: [
  309 + { key: Gradient.FIRST, value: 30, color: GradientColor.FIRST },
  310 + { key: Gradient.SECOND, value: 70, color: GradientColor.SECOND },
  311 + { key: Gradient.THIRD, value: 80, color: GradientColor.THIRD },
  312 + ],
  313 +};
  314 +
304 315 export const transformDashboardComponentConfig = (
305 316 config: DashboardComponentLayout,
306 317 record: DataComponentRecord,
... ...
  1 +import { ComponentInfo } from '/@/api/dataBoard/model';
  2 +
1 3 export type DigitalDashBoardComponentType = 'digital-dashboard-component';
2 4
3 5 export interface DigitalDashBoardLayout {
... ... @@ -12,3 +14,8 @@ export interface DigitalDashBoardValue {
12 14 value?: number;
13 15 fontColor?: string;
14 16 }
  17 +
  18 +export const DigitalComponentDefaultConfig: Partial<ComponentInfo> = {
  19 + fontColor: '#000',
  20 + unit: 'kw/h',
  21 +};
... ...
1 1 import { EChartsOption } from 'echarts';
2 2 import { Component } from 'vue';
3 3 import { WidgetComponentType } from '../../detail/config/visualOptions';
4   -import { instrumentComponent1, instrumentComponent2 } from './dashBoardComponent.config';
  4 +import {
  5 + Instrument1DefaultConfig,
  6 + Instrument2DefaultConfig,
  7 + instrumentComponent1,
  8 + instrumentComponent2,
  9 +} from './dashBoardComponent.config';
5 10 import DashBoardComponent from './DashBoardComponent.vue';
6 11 import DigitalDashBoard from './DigitalDashBoard.vue';
7 12 import { buildUUID } from '/@/utils/uuid';
... ... @@ -20,13 +25,13 @@ interface InstrumentComponentConfig {
20 25 export const instrumentComponentConfig: InstrumentComponentConfig[] = [
21 26 {
22 27 id: 'instrument-component-1',
23   - layout: { chartOption: instrumentComponent1() },
  28 + layout: { chartOption: instrumentComponent1(Instrument1DefaultConfig) },
24 29 component: DashBoardComponent,
25 30 value: { id: buildUUID() },
26 31 },
27 32 {
28 33 id: 'instrument-component-2',
29   - layout: { chartOption: instrumentComponent2() },
  34 + layout: { chartOption: instrumentComponent2(Instrument2DefaultConfig) },
30 35 component: DashBoardComponent,
31 36 value: { id: buildUUID() },
32 37 },
... ...
... ... @@ -7,7 +7,7 @@
7 7 DEFAULT_RADIO_RECORD,
8 8 DEFAULT_DATE_FORMAT,
9 9 } from '../../detail/config/util';
10   - import type { TextComponentLayout, TextComponentValue } from './config';
  10 + import { TextComponentDefaultConfig, TextComponentLayout, TextComponentValue } from './config';
11 11 import { SvgIcon } from '/@/components/Icon';
12 12 import { dateUtil } from '/@/utils/dateUtil';
13 13 const props = defineProps({
... ... @@ -17,7 +17,8 @@
17 17 },
18 18 value: {
19 19 type: Object as PropType<TextComponentValue>,
20   - default: () => ({ name: '温度', value: 123 } as TextComponentValue),
  20 + default: () =>
  21 + ({ ...TextComponentDefaultConfig, name: '温度', value: 123 } as TextComponentValue),
21 22 },
22 23 radio: {
23 24 type: Object as PropType<RadioRecord>,
... ...
1   -import { formatToDateTime } from '/@/utils/dateUtil';
2   -import { DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
  1 +import { ComponentInfo, DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
3 2 export interface TextComponentLayout {
4 3 id: string;
5 4 base?: boolean;
... ... @@ -26,28 +25,21 @@ export type TextComponentType =
26 25 | 'text-component-4'
27 26 | 'text-component-5';
28 27
29   -type TextComponentDefault = TextComponentLayout & { value: TextComponentValue };
  28 +type TextComponentDefault = TextComponentLayout;
30 29
31 30 export const TextComponent1Config: TextComponentDefault = {
32 31 id: 'text-component-1',
33 32 base: true,
34   - value: { value: 123, name: '温度' },
35 33 };
36 34
37 35 export const TextComponent2Config: TextComponentDefault = {
38 36 id: 'text-component-2',
39 37 base: false,
40   - value: { value: 123, name: '温度' },
41 38 };
42 39 export const TextComponent3Config: TextComponentDefault = {
43 40 id: 'text-component-3',
44 41 base: false,
45 42 showUpdate: true,
46   - value: {
47   - value: 123,
48   - name: '温度',
49   - updateTime: formatToDateTime(new Date(), 'YYYY-MM-DD HH:mm:ss'),
50   - },
51 43 };
52 44 export const TextComponent4Config: TextComponentDefault = {
53 45 id: 'text-component-4',
... ... @@ -55,19 +47,19 @@ export const TextComponent4Config: TextComponentDefault = {
55 47 showIcon: true,
56 48 showUpdate: true,
57 49 showUnit: true,
58   - value: {
59   - value: 123,
60   - name: '温度',
61   - updateTime: formatToDateTime(new Date(), 'YYYY-MM-DD HH:mm:ss'),
62   - unit: '℃',
63   - },
64 50 };
65 51 export const TextComponent5Config: TextComponentDefault = {
66 52 id: 'text-component-5',
67 53 base: false,
68 54 showIcon: true,
69 55 showUnit: true,
70   - value: { value: 123, name: '温度', unit: '℃' },
  56 +};
  57 +
  58 +export const TextComponentDefaultConfig: Partial<ComponentInfo> = {
  59 + fontColor: '#000',
  60 + unit: '℃',
  61 + iconColor: '#000',
  62 + icon: 'CO2',
71 63 };
72 64
73 65 export const textComponentConfig: TextComponentDefault[] = [
... ...
... ... @@ -11,8 +11,9 @@
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, getComponentDefaultConfig } from '../config/help';
15 15 import { computed } from '@vue/reactivity';
  16 + import { WidgetComponentType } from '../config/visualOptions';
16 17
17 18 type DataSourceFormEL = { [key: string]: Nullable<FormActionType> };
18 19
... ... @@ -96,9 +97,14 @@
96 97 createMessage.warning('请先选择可视化组件');
97 98 return;
98 99 }
  100 +
  101 + const defaultConfig = getComponentDefaultConfig(props.frontId as WidgetComponentType);
  102 +
  103 + const componentInfo: ComponentInfo = { ...defaultConfig, ...(item.componentInfo || {}) };
  104 +
99 105 openModal(true, {
100 106 recordId: item.id,
101   - componentInfo: item.componentInfo,
  107 + componentInfo,
102 108 });
103 109 };
104 110
... ...
... ... @@ -36,7 +36,6 @@
36 36 componentRecord.value = data.record || ({} as unknown as DataBoardLayoutInfo);
37 37 frontId.value = data.record?.record?.frontId || '';
38 38 isEdit.value = data.isEdit || false;
39   - console.log(unref(isEdit));
40 39 }
41 40 );
42 41
... ...
... ... @@ -87,7 +87,7 @@
87 87 @register="register"
88 88 @ok="handleClose"
89 89 title="选项"
90   - width="60%"
  90 + width="40%"
91 91 >
92 92 <BasicForm class="form" @register="registerForm" :schemas="getSchemas" />
93 93 </BasicModal>
... ...
... ... @@ -23,7 +23,7 @@
23 23 :style="{ borderColor: props.controlId === props.checkedId ? '#1a74e8' : '#f0f0f0' }"
24 24 hoverable
25 25 bordered
26   - class="w-60 h-60 widget-select !bg-light-50"
  26 + class="w-60 h-60 widget-select !bg-light-50 cursor-pointer"
27 27 @click="handleClick"
28 28 >
29 29 <div class="widget-container">
... ...
... ... @@ -6,20 +6,24 @@ import {
6 6 TextComponent3Config,
7 7 TextComponent4Config,
8 8 TextComponent5Config,
  9 + TextComponentDefaultConfig,
9 10 transformTextComponentConfig,
10 11 } from '../../components/TextComponent/config';
11   -import { DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
  12 +import { ComponentInfo, DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
12 13 import DashBoardComponent from '../../components/InstrumentComponent/DashBoardComponent.vue';
13 14 import PictureComponent from '../../components/PictureComponent/PictureComponent.vue';
14 15 import { transformPictureConfig } from '../../components/PictureComponent/pictureComponent.config';
15 16 import { WidgetComponentType } from './visualOptions';
16 17 import {
17 18 DashboardComponentLayout,
  19 + Instrument1DefaultConfig,
  20 + Instrument2DefaultConfig,
18 21 instrumentComponent1,
19 22 instrumentComponent2,
20 23 transformDashboardComponentConfig,
21 24 } from '../../components/InstrumentComponent/dashBoardComponent.config';
22 25 import DigitalDashBoard from '../../components/InstrumentComponent/DigitalDashBoard.vue';
  26 +import { DigitalComponentDefaultConfig } from '../../components/InstrumentComponent/digitalDashBoard.config';
23 27 export enum FrontComponent {
24 28 TEXT_COMPONENT_1 = 'text-component-1',
25 29 TEXT_COMPONENT_2 = 'text-component-2',
... ... @@ -42,6 +46,11 @@ export interface ComponentConfig {
42 46 ) => Recordable;
43 47 }
44 48
  49 +export const frontComponentDefaultConfigMap = new Map<
  50 + WidgetComponentType,
  51 + Partial<ComponentInfo>
  52 +>();
  53 +
45 54 export const frontComponentMap = new Map<WidgetComponentType, ComponentConfig>();
46 55
47 56 frontComponentMap.set(FrontComponent.TEXT_COMPONENT_1, {
... ... @@ -103,3 +112,21 @@ frontComponentMap.set(FrontComponent.PICTURE_COMPONENT_1, {
103 112 ComponentConfig: {},
104 113 transformConfig: transformPictureConfig,
105 114 });
  115 +
  116 +frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_1, TextComponentDefaultConfig);
  117 +frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_2, TextComponentDefaultConfig);
  118 +frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_3, TextComponentDefaultConfig);
  119 +frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_4, TextComponentDefaultConfig);
  120 +frontComponentDefaultConfigMap.set(FrontComponent.TEXT_COMPONENT_5, TextComponentDefaultConfig);
  121 +
  122 +frontComponentDefaultConfigMap.set(FrontComponent.INSTRUMENT_COMPONENT_1, Instrument1DefaultConfig);
  123 +frontComponentDefaultConfigMap.set(FrontComponent.INSTRUMENT_COMPONENT_2, Instrument2DefaultConfig);
  124 +
  125 +frontComponentDefaultConfigMap.set(
  126 + FrontComponent.DIGITAL_DASHBOARD_COMPONENT,
  127 + DigitalComponentDefaultConfig
  128 +);
  129 +
  130 +export const getComponentDefaultConfig = (key: WidgetComponentType) => {
  131 + return frontComponentDefaultConfigMap.get(key) || {};
  132 +};
... ...
... ... @@ -175,7 +175,7 @@ schemasMap.set('text-component-1', modeOne);
175 175 schemasMap.set('text-component-2', modeOne);
176 176 schemasMap.set('text-component-3', modeOne);
177 177 schemasMap.set('text-component-4', modeTwo);
178   -schemasMap.set('text-component-4', modeTwo);
  178 +schemasMap.set('text-component-5', modeTwo);
179 179 schemasMap.set('instrument-component-1', modeOne);
180 180 schemasMap.set('instrument-component-2', modeThree);
181 181 schemasMap.set('digital-dashboard-component', modeFour);
... ...
... ... @@ -88,9 +88,9 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
88 88 throw Error(error as string);
89 89 }
90 90 },
91   - onDisconnected() {
92   - close();
93   - },
  91 + // onDisconnected() {
  92 + // close();
  93 + // },
94 94 });
95 95
96 96 const setCmdId = (cmdId: number, record: CmdMapping) => {
... ...