Commit 94898c86733fab84672793517b545a59435ea190

Authored by loveumiko
1 parent 4e42ac99

feat: 新增控制组件和文本组件等

... ... @@ -33,6 +33,7 @@
33 33 service: value.service,
34 34 command: value.command,
35 35 commandType: value.commandType,
  36 + callType: value.callType,
36 37 },
37 38 };
38 39 return value;
... ... @@ -42,10 +43,11 @@
42 43 const { customCommand } = record;
43 44 return setFieldsValue({
44 45 ...record,
45   - transportType: customCommand?.transportType,
46   - service: customCommand?.service,
47   - command: customCommand?.command,
48   - commandType: customCommand?.commandType,
  46 + transportType: customCommand?.transportType || (record as Recordable).transportType,
  47 + service: customCommand?.service || (record as Recordable).service,
  48 + command: customCommand?.command || (record as Recordable).command,
  49 + commandType: customCommand?.commandType || (record as Recordable).commandType,
  50 + callType: customCommand?.callType || (record as Recordable).callType,
49 51 } as unknown as Partial<CommonDataSourceBindValueType>);
50 52 };
51 53
... ...
... ... @@ -10,17 +10,19 @@
10 10 import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
11 11 import { MultipleDataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
12 12 import { useMultipleDataFetch } from '../../../hook/socket/useSocket';
  13 + import { useReceiveMessage } from '../../../hook/useReceiveMessage';
  14 + import { useReceiveValue } from '../../../hook/useReceiveValue';
  15 + import { DataSource } from '/@/views/visual/palette/types';
13 16
14 17 const props = defineProps<{
15 18 config: ComponentPropsConfigType<typeof option>;
16 19 }>();
17 20
18   - const checked = ref(false);
19   -
20 21 const svgList = ref<any>([
21 22 {
22 23 value: 26.2,
23   - name: 'wendu',
  24 + deviceName: '光照设备',
  25 + attributeName: '光照',
24 26 icon: 'zongfushe',
25 27 unit: 'kw',
26 28 iconColor: '#367BFF',
... ... @@ -30,7 +32,8 @@
30 32 },
31 33 {
32 34 value: 53.7,
33   - name: 'shidu',
  35 + deviceName: '风机设备',
  36 + attributeName: '风机',
34 37 icon: 'guangzhaoqiangdu',
35 38 unit: '℃',
36 39 iconColor: '#FFA000',
... ... @@ -41,6 +44,7 @@
41 44 ]);
42 45
43 46 const getDesign = computed(() => {
  47 + console.log(props.config.option, 'option');
44 48 const { persetOption = {}, option } = props.config;
45 49 const { dataSource = [] } = option || {};
46 50 const {
... ... @@ -51,42 +55,65 @@
51 55 } = persetOption || {};
52 56 return {
53 57 dataSource: dataSource.map((item) => {
54   - const { fontColor, icon, iconColor, unit } = item.componentInfo;
55   - const { attribute, attributeRename } = item;
  58 + const { fontColor, icon, iconColor, unit, showDeviceName } = item.componentInfo;
  59 + const { attribute, attributeRename, attributeName, deviceId, deviceName, deviceRename } =
  60 + item;
56 61 return {
57 62 unit: unit ?? persetUnit,
58 63 fontColor: fontColor ?? persetFontColor,
59 64 icon: icon ?? persetIcon,
60 65 iconColor: iconColor ?? persetIconColor,
61   - attribute: attribute || attributeRename,
62   - attributeRename,
  66 + attribute: attribute,
  67 + attributeName: attributeRename ?? attributeName,
  68 + showDeviceName,
  69 + deviceName: deviceRename ?? deviceName,
  70 + id: deviceId,
63 71 };
64 72 }),
65 73 };
66 74 });
67 75
68   - const { sendCommand, loading } = useSendCommand();
69   - const handleChange = async (index: number) => {
70   - const flag = await sendCommand(props.config.option, unref(checked));
71   - if (!flag) svgList[index].checked = !svgList[index].checked;
  76 + const { loading, sendCommand } = useSendCommand();
  77 + const handleChange = async (index: number, checked: Boolean) => {
  78 + console.log(props.config.option);
  79 + const { heightPx, itemHeightRatio, itemWidthRatio, mode, widthPx, dataSource } =
  80 + props.config.option;
  81 +
  82 + const data = {
  83 + ...dataSource?.[index],
  84 + heightPx,
  85 + itemHeightRatio,
  86 + itemWidthRatio,
  87 + mode,
  88 + widthPx,
  89 + } as DataSource;
  90 + console.log(data, 'data', checked);
  91 +
  92 + const flag = await sendCommand(data, checked);
  93 + if (!flag) controlList.value[index].checked = !checked;
72 94 };
73 95
74   - const updateFn: MultipleDataFetchUpdateFn = (message) => {
75   - const { data = {} } = message;
76   - const { dataSource } = unref(getDesign);
77   - svgList.value.length = 0;
78   - svgList.value = dataSource.map((item) => {
79   - const { icon, iconColor, unit, fontColor, attribute } = item || {};
80   - const [latest] = data[attribute] || [];
81   - const [_timespan, value] = latest || [];
82   - return {
83   - value: Number(value),
84   - name: attribute,
85   - icon,
86   - unit,
87   - iconColor,
88   - fontColor,
89   - };
  96 + const { forEachGroupMessage } = useReceiveMessage();
  97 + const { getNumberValue } = useReceiveValue();
  98 +
  99 + const controlList = ref(
  100 + props.config.option.dataSource
  101 + ? unref(getDesign).dataSource.map((item) => {
  102 + return { ...item, checked: false };
  103 + })
  104 + : svgList
  105 + );
  106 +
  107 + const updateFn: MultipleDataFetchUpdateFn = async (message, deviceId, attribute) => {
  108 + console.log(unref(getDesign).dataSource, 'dataSource');
  109 +
  110 + forEachGroupMessage(message, deviceId, attribute, (attribute, value, time) => {
  111 + console.log(attribute, value, time);
  112 + controlList.value.forEach((item) => {
  113 + if (item.id === deviceId && item.attribute === attribute) {
  114 + item.checked = Boolean(getNumberValue(value));
  115 + }
  116 + });
90 117 });
91 118 };
92 119
... ... @@ -99,7 +126,7 @@
99 126 <DeviceName :config="config" />
100 127 <div
101 128 style="width: 86%"
102   - v-for="(item, index) in svgList"
  129 + v-for="(item, index) in controlList"
103 130 :key="item.id"
104 131 class="flex justify-between items-center"
105 132 >
... ... @@ -111,10 +138,18 @@
111 138 :style="{ color: item.iconColor }"
112 139 />
113 140
114   - <div class="text-gray-500 text-lg truncate ml-6">{{ item.attribute || '温度' }}</div>
  141 + <div
  142 + class="text-gray-500 truncate ml-6"
  143 + :style="{ fontSize: getRatio ? '18px' : getRatio * 18 + 'px' }"
  144 + >{{ `${item.deviceName} - ${item.attributeName}` }}</div
  145 + >
115 146 </div>
116 147
117   - <Switch v-model:checked="item.checked" :loading="loading" @change="handleChange(index)" />
  148 + <Switch
  149 + v-model:checked="item.checked"
  150 + :loading="loading"
  151 + @change="handleChange(index, item.checked)"
  152 + />
118 153 </div>
119 154 </main>
120 155 </template>
... ...
... ... @@ -2,12 +2,12 @@ import { ControlComponentSlidingSwitchConfig } from './ControlComponentSlidingSw
2 2 import { ControlComponentSwitchWithIconConfig } from './ControlComponentSwitchWithIcon';
3 3 import { ControlComponentToggleSwitchConfig } from './ControlComponentToggleSwitch';
4 4 import { LateralNumericalControlConfig } from './LateralNumericalControl';
5   -// import { SwitchListConfig } from './SwitchList';
  5 +import { SwitchListConfig } from './SwitchList';
6 6
7 7 export const ControlList = [
8 8 ControlComponentSwitchWithIconConfig,
9 9 ControlComponentSlidingSwitchConfig,
10 10 ControlComponentToggleSwitchConfig,
11 11 LateralNumericalControlConfig,
12   - // SwitchListConfig,
  12 + SwitchListConfig,
13 13 ];
... ...
... ... @@ -63,14 +63,16 @@
63 63 <main :style="getScale" class="w-full h-full flex flex-col justify-center items-center">
64 64 <DeviceName :config="config" class="text-center" />
65 65
66   - <div
67   - :style="{
68   - '--open-color': getDesign.openColor,
69   - '--close-color': getDesign.closeColor,
70   - }"
71   - :class="isOpenClose ? 'switch_open' : 'switch_close'"
72   - ></div>
73   - <div class="text-gray-500 text-sm truncate">{{ getDesign.attribute }}</div>
  66 + <div class="flex-1 flex justify-center items-center flex-col">
  67 + <div
  68 + :style="{
  69 + '--open-color': getDesign.openColor,
  70 + '--close-color': getDesign.closeColor,
  71 + }"
  72 + :class="isOpenClose ? 'switch_open' : 'switch_close'"
  73 + ></div>
  74 + <div class="text-gray-500 text-sm truncate">{{ getDesign.attribute }}</div>
  75 + </div>
74 76 <UpdateTime :time="time" />
75 77 </main>
76 78 </template>
... ...
src/views/visual/packages/components/Other/SwitchStatus/config.ts renamed from src/views/visual/packages/components/Text/SwitchStatus/config.ts
... ... @@ -10,9 +10,9 @@ import { PublicConfigClass, componentInitConfig } from '/@/views/visual/packages
10 10 import { ComponentConfigFieldEnum } from '/@/views/visual/packages/enum';
11 11
12 12 export const option: PublicPresetOptions = {
13   - [ComponentConfigFieldEnum.ICON]: 'shuiwen',
14   - [ComponentConfigFieldEnum.ICON_COLOR]: '#367bff',
15   - [ComponentConfigFieldEnum.ICON_CLOSE]: 'shuiwen',
  13 + [ComponentConfigFieldEnum.ICON]: 'dianyuandianya',
  14 + [ComponentConfigFieldEnum.ICON_COLOR]: '#ffa621',
  15 + [ComponentConfigFieldEnum.ICON_CLOSE]: 'dianyuandianya',
16 16 [ComponentConfigFieldEnum.ICON_COLOR_CLOSE]: '#CCCCCC',
17 17 [ComponentConfigFieldEnum.SHOW_DEVICE_NAME]: false,
18 18 };
... ...
src/views/visual/packages/components/Other/SwitchStatus/config.vue renamed from src/views/visual/packages/components/Text/SwitchStatus/config.vue
src/views/visual/packages/components/Other/SwitchStatus/datasource.vue renamed from src/views/visual/packages/components/Text/SwitchStatus/datasource.vue
src/views/visual/packages/components/Other/SwitchStatus/index.ts renamed from src/views/visual/packages/components/Text/SwitchStatus/index.ts
... ... @@ -5,5 +5,5 @@ const componentKeys = useComponentKeys('SwitchStatus');
5 5 export const SwitchStatusConfig: ConfigType = {
6 6 ...componentKeys,
7 7 title: '开关量状态',
8   - package: PackagesCategoryEnum.TEXT,
  8 + package: PackagesCategoryEnum.OTHER,
9 9 };
... ...
src/views/visual/packages/components/Other/SwitchStatus/index.vue renamed from src/views/visual/packages/components/Text/SwitchStatus/index.vue
... ... @@ -2,52 +2,71 @@
2 2 import { ComponentPropsConfigType } from '/@/views/visual/packages/index.type';
3 3 import { option } from './config';
4 4 import { SvgIcon } from '/@/components/Icon';
5   - import { computed } from 'vue';
  5 + import { computed, ref } from 'vue';
6 6 import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
  7 + import { UpdateTime } from '/@/views/visual/commonComponents/UpdateTime';
7 8 import { useDataFetch } from '../../../hook/socket/useSocket';
8 9 import { DataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
  10 + import { useReceiveValue } from '../../../hook/useReceiveValue';
9 11
10 12 const props = defineProps<{
11 13 config: ComponentPropsConfigType<typeof option>;
12 14 }>();
13 15
  16 + const time = ref<Nullable<number>>(null);
  17 + const isOpenClose = ref<boolean>(true);
  18 +
14 19 const getDesign = computed(() => {
15 20 const { persetOption = {}, option } = props.config;
16   -
17 21 const {
18 22 iconColor: persetIconColor,
19 23 unit: perseUnit,
20 24 icon: persetIcon,
21 25 fontColor: persetFontColor,
  26 + iconClose: persetIconCLose,
  27 + iconColorClose: persetIconColorClose,
22 28 } = persetOption;
23 29
24   - const { componentInfo, attribute, attributeRename } = option;
  30 + const { componentInfo, attributeRename } = option;
25 31
26   - const { icon, iconColor, fontColor, unit } = componentInfo || {};
  32 + const { icon, iconColor, fontColor, unit, iconClose, iconColorClose, attributeName } =
  33 + componentInfo || {};
27 34 return {
28 35 iconColor: iconColor || persetIconColor,
29 36 unit: unit ?? perseUnit,
30 37 icon: icon || persetIcon,
31 38 fontColor: fontColor || persetFontColor,
32   - attribute: attributeRename || attribute,
  39 + attribute: attributeRename || attributeName,
  40 + iconClose: iconClose || persetIconCLose,
  41 + iconColorClose: iconColorClose || persetIconColorClose,
33 42 };
34 43 });
35 44
36   - const updateFn: DataFetchUpdateFn = () => {};
  45 + const { getNumberValue } = useReceiveValue();
  46 +
  47 + const updateFn: DataFetchUpdateFn = (message, attribute) => {
  48 + const { data = {} } = message;
  49 + const [latest] = data[attribute] || [];
  50 + const [timespan, value] = latest;
  51 + time.value = timespan;
  52 + isOpenClose.value = Boolean(getNumberValue(value));
  53 + };
37 54
38 55 useDataFetch(props, updateFn);
39 56 </script>
40 57
41 58 <template>
42   - <main class="w-full h-full flex flex-col justify-evenly items-center">
  59 + <main class="w-full h-full flex flex-col justify-center items-center">
43 60 <DeviceName :config="config" />
44   - <div class="flex justify-center items-center">
  61 + <div class="flex flex-1 flex-col justify-center items-center">
45 62 <SvgIcon
46   - :name="getDesign.icon!"
  63 + :name="isOpenClose ? getDesign.icon : getDesign.iconClose"
47 64 prefix="iconfont"
48 65 :size="60"
49   - :style="{ color: getDesign.iconColor }"
  66 + :style="{ color: isOpenClose ? getDesign.iconColor : getDesign.iconColorClose }"
50 67 />
  68 + <div class="text-gray-500 text-sm truncate m-2">{{ getDesign.attribute || '温度' }}</div>
51 69 </div>
  70 + <UpdateTime :time="time" />
52 71 </main>
53 72 </template>
... ...
1 1 import { MonitorVideoConfig } from './MonitorVideo';
2 2 import { PictureConfig } from './Picture';
3 3 import { SwitchSignalLightConfig } from './SwitchSignalLight';
  4 +import { SwitchStatusConfig } from './SwitchStatus';
4 5
5   -export const OtherList = [MonitorVideoConfig, PictureConfig, SwitchSignalLightConfig];
  6 +export const OtherList = [
  7 + MonitorVideoConfig,
  8 + PictureConfig,
  9 + SwitchSignalLightConfig,
  10 + SwitchStatusConfig,
  11 +];
... ...
... ... @@ -37,8 +37,8 @@
37 37 fontColor: '#377dff',
38 38 backgroundColor: '#377dff',
39 39 unit: '℃',
40   - deviceName: '温度',
41   - attribute: '1',
  40 + deviceName: '温湿度',
  41 + attribute: '温度',
42 42 id: buildUUID(),
43 43 },
44 44 {
... ... @@ -46,8 +46,8 @@
46 46 fontColor: '#1E8667',
47 47 backgroundColor: '#1E8667',
48 48 unit: '℃',
49   - deviceName: '温度',
50   - attribute: '3',
  49 + deviceName: '温湿度',
  50 + attribute: '湿度',
51 51 id: buildUUID(),
52 52 },
53 53 ];
... ...
... ... @@ -29,7 +29,8 @@
29 29 return {
30 30 dataSource: dataSource.map((item) => {
31 31 const { fontColor, icon, iconColor, unit } = item.componentInfo;
32   - const { attribute, attributeRename, deviceName, deviceRename, deviceId } = item;
  32 + const { attribute, attributeRename, deviceName, deviceRename, deviceId, attributeName } =
  33 + item;
33 34
34 35 return {
35 36 unit: unit ?? persetUnit,
... ... @@ -39,6 +40,7 @@
39 40 attribute: attribute || attributeRename,
40 41 attributeRename,
41 42 deviceName,
  43 + attributeName,
42 44 deviceRename,
43 45 id: deviceId,
44 46 };
... ... @@ -48,15 +50,17 @@
48 50 const defaultSvgList = ref<any>([
49 51 {
50 52 value: 26.2,
51   - name: 'wendu',
  53 + deviceRename: '温湿度',
  54 + attributeRename: '温度',
52 55 icon: 'zongfushe',
53   - unit: 'kw',
  56 + unit: '',
54 57 iconColor: '#367BFF',
55 58 fontColor: '#357CFB',
56 59 },
57 60 {
58 61 value: 53.7,
59   - name: 'shidu',
  62 + deviceRename: '温湿度',
  63 + attributeRename: '湿度',
60 64 icon: 'guangzhaoqiangdu',
61 65 unit: '℃',
62 66 iconColor: '#FFA000',
... ... @@ -72,7 +76,6 @@
72 76 );
73 77
74 78 const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
75   - // console.log(unref(getDesign).dataSource, 'dataSource');
76 79 forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
77 80 updateSvgList.value.forEach((item) => {
78 81 if (item.id === deviceId && item.attribute === attribute) {
... ... @@ -93,19 +96,19 @@
93 96 style="width: 86%"
94 97 v-for="item in updateSvgList"
95 98 :key="item.id"
96   - class="flex justify-between items-center"
  99 + class="flex justify-between items-center mt-2"
97 100 >
98 101 <div class="flex items-center">
99 102 <SvgIcon
100 103 :name="item.icon!"
101 104 prefix="iconfont"
102   - :size="45"
  105 + :size="40"
103 106 :style="{ color: item.iconColor }"
104 107 />
105 108
106 109 <div class="text-gray-500 text-lg truncate ml-6">{{
107 110 item.deviceRename ||
108   - item.deviceName + '-' + (item.attributeRename || item.attribute) ||
  111 + item.deviceName + '-' + (item.attributeRename || item.attributeName) ||
109 112 '温度'
110 113 }}</div>
111 114 </div>
... ...
... ... @@ -3,6 +3,7 @@ import { TextComponent2Config } from './TextComponent2';
3 3 import { TextComponent3Config } from './TextComponent3';
4 4 import { TextComponent4Config } from './TextComponent4';
5 5 import { ValueList1Config } from './ValueList1';
  6 +import { ValueList2Config } from './ValueList2';
6 7
7 8 export const TextList = [
8 9 TextComponent1Config,
... ... @@ -10,4 +11,5 @@ export const TextList = [
10 11 TextComponent3Config,
11 12 TextComponent4Config,
12 13 ValueList1Config,
  14 + ValueList2Config,
13 15 ];
... ...
... ... @@ -54,7 +54,10 @@ const isControlComponent = (category?: string) => PackagesCategoryEnum.CONTROL =
54 54
55 55 const isBooleanComponent = (componentKeys: { categoryKey?: string; componentKey?: string }) => {
56 56 const { categoryKey, componentKey } = componentKeys;
57   - return categoryKey == 'OTHER' && componentKey == 'SwitchSignalLight';
  57 + return (
  58 + categoryKey == 'OTHER' &&
  59 + (componentKey == 'SwitchSignalLight' || componentKey == 'SwitchStatus')
  60 + );
58 61 };
59 62
60 63 const getDeviceService = async (deviceProfileId: string) => {
... ...