Commit 16472ea5756d9018f5c7219a1906641771b7bfd0

Authored by fengwotao
2 parents 6af2edbf a4c0aff7

Merge branch 'main_dev' into ft

... ... @@ -46,11 +46,8 @@
46 46 const value = target.checked;
47 47 const { option } = props.config || {};
48 48
49   - const { values, isModbusCommand, sendValue } = await getSendValues(
50   - option,
51   - unref(getDesign),
52   - value
53   - );
  49 + const { values, isModbusCommand, sendValue } =
  50 + (await getSendValues(option, unref(getDesign), value)) || {};
54 51
55 52 const flag = await sendCommand(values, isModbusCommand ? sendValue : value, isModbusCommand);
56 53 if (flag) currentValue.value = value;
... ...
... ... @@ -51,51 +51,8 @@
51 51 const handleChange = async () => {
52 52 const { option } = props.config || {};
53 53
54   - const { values, isModbusCommand, sendValue } = await getSendValues(
55   - option,
56   - unref(getDesign),
57   - unref(checked)
58   - );
59   -
60   - // const { values, sendValue, isModbusCommand } = getSendValues(
61   - // values,
62   - // unref(getDesign),
63   - // unref(checked)
64   - // );
65   - // const isModbusCommand = ref<boolean>(false); //判断是否是TCP设备-> 且设备标识符是modeBUs,切选择是下发命令类型是属性
66   - // const { extensionDesc, commandType, codeType, deviceCode, customCommand } =
67   - // unref(getDesign) || {};
68   - // const { registerAddress, actionType } = extensionDesc || {};
69   - // const { openCommand, closeCommand, transportType } = customCommand || {};
70   - // const modBUS = ref<any>({});
71   - // const sendValue = ref();
72   - // console.log(transportType, 'transportType', codeType, 'codeType');
73   - // //判断是不是TCP类型设备
74   - // if (transportType === TransportTypeEnum.TCP) {
75   - // if (
76   - // //判断TCP下发类型是否是自定义还是服务
77   - // commandType === CommandTypeEnum.CUSTOM.toString() ||
78   - // commandType == CommandTypeEnum.SERVICE.toString()
79   - // ) {
80   - // values.customCommand.command = unref(checked) ? openCommand : closeCommand;
81   - // }
82   - // if (
83   - // //判断命令下发类型是不是属性
84   - // commandType === CommandTypeEnum.ATTRIBUTE.toString() &&
85   - // codeType === TaskTypeEnum.MODBUS_RTU
86   - // ) {
87   - // isModbusCommand.value = true;
88   - // modBUS.value = {
89   - // crc: 'CRC_16_LOWER',
90   - // deviceCode: deviceCode,
91   - // method: actionType == '16' ? '10' : actionType,
92   - // registerAddress,
93   - // registerNumber: 1,
94   - // registerValues: [Number(unref(checked))],
95   - // };
96   - // sendValue.value = await genModbusCommand(unref(modBUS));
97   - // }
98   - // }
  54 + const { values, isModbusCommand, sendValue } =
  55 + (await getSendValues(option, unref(getDesign), unref(checked))) || {};
99 56
100 57 const flag = await sendCommand(
101 58 values,
... ...
... ... @@ -46,11 +46,8 @@
46 46 const value = target.checked;
47 47 const { option } = props.config || {};
48 48
49   - const { values, isModbusCommand, sendValue } = await getSendValues(
50   - option,
51   - unref(getDesign),
52   - value
53   - );
  49 + const { values, isModbusCommand, sendValue } =
  50 + (await getSendValues(option, unref(getDesign), value)) || {};
54 51
55 52 const flag = await sendCommand(values, isModbusCommand ? sendValue : value, isModbusCommand);
56 53 flag ? (currentValue.value = value) : (target.checked = !value);
... ...
... ... @@ -32,6 +32,10 @@
32 32 transportType: value.transportType,
33 33 service: value.service,
34 34 command: value.command,
  35 + openService: value.openService,
  36 + closeService: value.closeService,
  37 + openCommand: value.openCommand,
  38 + closeCommand: value.closeCommand,
35 39 commandType: value.commandType,
36 40 },
37 41 };
... ... @@ -44,6 +48,10 @@
44 48 ...record,
45 49 transportType: customCommand?.transportType || (record as Recordable).transportType,
46 50 service: customCommand?.service || (record as Recordable).service,
  51 + openService: customCommand?.openService || (record as Recordable).openService,
  52 + closeService: customCommand?.closeService || (record as Recordable).closeService,
  53 + openCommand: customCommand?.openCommand || (record as Recordable).openCommand,
  54 + closeCommand: customCommand?.closeCommand || (record as Recordable).closeCommand,
47 55 command: customCommand?.command || (record as Recordable).command,
48 56 commandType: customCommand?.commandType || (record as Recordable).command,
49 57 } as unknown as Partial<CommonDataSourceBindValueType>);
... ...
... ... @@ -9,6 +9,10 @@
9 9 import { useReceiveValue } from '../../../hook/useReceiveValue';
10 10 import { DataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
11 11 import { useDataFetch } from '../../../hook/socket/useSocket';
  12 + import { TaskTypeEnum } from '/@/views/task/center/config';
  13 + import { useMessage } from '/@/hooks/web/useMessage';
  14 + import { SingleToHex } from '/@/views/device/list/cpns/tabs/ObjectModelCommandDeliveryModal/config';
  15 + import { genModbusCommand } from '/@/api/task';
12 16
13 17 const props = defineProps<{
14 18 config: ComponentPropsConfigType<typeof option>;
... ... @@ -23,7 +27,17 @@
23 27
24 28 const getDesign = computed(() => {
25 29 const { option, persetOption } = props.config;
26   - const { componentInfo, attribute, attributeRename, attributeName } = option;
  30 + const {
  31 + componentInfo,
  32 + attribute,
  33 + attributeRename,
  34 + attributeName,
  35 + commandType,
  36 + extensionDesc,
  37 + codeType,
  38 + deviceCode,
  39 + customCommand,
  40 + } = option;
27 41 const {
28 42 controlBarColor: persetControlBarColor,
29 43 fonColor: persetFontColor,
... ... @@ -37,6 +51,11 @@
37 51 fontColor: fontColor ?? persetFontColor,
38 52 minNumber: minNumber ?? persetMinNumber,
39 53 maxNumber: maxNumber ?? persetMaxNumber,
  54 + extensionDesc: extensionDesc ? JSON.parse(extensionDesc) : {},
  55 + commandType,
  56 + codeType,
  57 + deviceCode,
  58 + customCommand,
40 59 };
41 60 });
42 61
... ... @@ -59,9 +78,98 @@
59 78 sliderValue.value = afterValue.value; //这一步是因为当我们是点击不是拖动时候,会让值更新不了,所以需要赋值一次
60 79 };
61 80
  81 + const { createMessage } = useMessage();
  82 +
  83 + // 获取小数
  84 + const getFloatPart = (number: string | number) => {
  85 + const isLessZero = Number(number) < 0;
  86 + number = number.toString();
  87 + const floatPartStartIndex = number.indexOf('.');
  88 + const value = ~floatPartStartIndex
  89 + ? `${isLessZero ? '-' : ''}0.${number.substring(floatPartStartIndex + 1)}`
  90 + : '0';
  91 + return Number(value);
  92 + };
  93 +
  94 + const getArray = (values) => {
  95 + const str = values.replace(/\s+/g, '');
  96 + const array: any = [];
  97 +
  98 + for (let i = 0; i < str.length; i += 4) {
  99 + const chunk = parseInt(str.substring(i, i + 4), 16);
  100 + array.push(chunk);
  101 + }
  102 + return array;
  103 + };
  104 +
  105 + const getSendValue = async (value: number) => {
  106 + const { extensionDesc, codeType, deviceCode, customCommand } = unref(getDesign) || {};
  107 + const { transportType } = customCommand || {};
  108 + const { registerAddress, actionType, zoomFactor } = extensionDesc || {};
  109 + const newZoomValue = zoomFactor ? Number(zoomFactor) : 1;
  110 + if (transportType == 'TCP' && codeType == TaskTypeEnum.MODBUS_RTU) {
  111 + if (!deviceCode) {
  112 + createMessage.warning('当前设备没有设置地址码');
  113 + return;
  114 + }
  115 + const modbusForm = ref({
  116 + crc: 'CRC_16_LOWER',
  117 + deviceCode: deviceCode,
  118 + method: actionType == '16' ? '10' : actionType,
  119 + registerAddress,
  120 + registerNumber: 1,
  121 + registerValues: [value],
  122 + }) as any;
  123 + if (!actionType) {
  124 + createMessage.warning('当前物模型扩展描述没有填写');
  125 + return;
  126 + }
  127 + if (actionType == '06') {
  128 + const newValue = Math.trunc(value) * newZoomValue + getFloatPart(value) * newZoomValue;
  129 + if (newValue % 1 != 0) {
  130 + createMessage.warning(`值必须是整数,缩放因子为${unref(newZoomValue)}`);
  131 + return;
  132 + }
  133 +
  134 + if (newValue > 65535) {
  135 + createMessage.warning(`值不能超过65535,缩放因子是${unref(newZoomValue)}`);
  136 + return;
  137 + }
  138 + modbusForm.value.registerValues = [newValue];
  139 + }
  140 + if (actionType == '05') {
  141 + if (Number(value) != 0 || Number(value) != 1) {
  142 + createMessage.warning(`当前物模型仅支持值为0和1`);
  143 + return;
  144 + }
  145 + }
  146 + if (actionType == '16' || actionType == '10') {
  147 + const regex = /^-?\d+(\.\d{0,2})?$/;
  148 + const values =
  149 + Math.trunc(value) * unref(newZoomValue) + getFloatPart(value) * unref(newZoomValue);
  150 + if (!regex.test(values as any)) {
  151 + createMessage.warning(`值精确到两位小数,缩放因子是${unref(newZoomValue)}`);
  152 + return;
  153 + }
  154 + const newValue = values == 0 ? [0, 0] : getArray(SingleToHex(values));
  155 + modbusForm.value.registerValues = newValue;
  156 + modbusForm.value.registerNumber = 2;
  157 + modbusForm.value.method = '10';
  158 + }
  159 + const sendValue = await genModbusCommand(unref(modbusForm));
  160 + return sendValue;
  161 + }
  162 + };
  163 +
62 164 const handleBlur = async () => {
63 165 if (unref(oldSliderValue) !== unref(sliderValue)) {
64   - const flag = await sendCommand(props.config.option, unref(sliderValue));
  166 + const { codeType, customCommand } = unref(getDesign) || {};
  167 + const { transportType } = customCommand || {};
  168 + const sendValue = ref<any>(unref(sliderValue));
  169 + if (transportType == 'TCP' && codeType == TaskTypeEnum.MODBUS_RTU) {
  170 + sendValue.value = await getSendValue(unref(sliderValue));
  171 + }
  172 + const flag = await sendCommand(props.config.option, unref(sendValue), true);
65 173 flag
66 174 ? ((sliderValue.value = unref(sliderValue)),
67 175 (oldSliderValue.value = sliderValue.value),
... ...
... ... @@ -101,11 +101,8 @@
101 101 mode,
102 102 widthPx,
103 103 } as DataSource;
104   - const { values, isModbusCommand, sendValue } = await getSendValues(
105   - data,
106   - unref(getDesign).dataSource[index],
107   - checked
108   - );
  104 + const { values, isModbusCommand, sendValue } =
  105 + (await getSendValues(data, unref(getDesign).dataSource[index], checked)) || {};
109 106
110 107 const flag = await sendCommand(values, isModbusCommand ? sendValue : checked, isModbusCommand);
111 108 if (!flag) controlList.value[index].checked = !checked;
... ...
... ... @@ -3,6 +3,19 @@ import { TransportTypeEnum } from '/@/views/device/profiles/components/Transport
3 3 import { CommandTypeEnum } from '/@/views/rule/linkedge/config/config.data';
4 4 import { TaskTypeEnum } from '/@/views/task/center/config';
5 5 import { genModbusCommand } from '/@/api/task';
  6 +import { useMessage } from '/@/hooks/web/useMessage';
  7 +import { SingleToHex } from '/@/views/device/list/cpns/tabs/ObjectModelCommandDeliveryModal/config';
  8 +
  9 +const getArray = (values) => {
  10 + const str = values.replace(/\s+/g, '');
  11 + const array: any = [];
  12 +
  13 + for (let i = 0; i < str.length; i += 4) {
  14 + const chunk = parseInt(str.substring(i, i + 4), 16);
  15 + array.push(chunk);
  16 + }
  17 + return array;
  18 +};
6 19
7 20 export const getSendValues = async (option, getDesign, checked) => {
8 21 const values: any = option;
... ... @@ -12,6 +25,8 @@ export const getSendValues = async (option, getDesign, checked) => {
12 25 const { openCommand, closeCommand, transportType } = customCommand || {};
13 26 const modBUS = ref<any>({});
14 27 const sendValue = ref();
  28 +
  29 + const { createMessage } = useMessage();
15 30 //判断是不是TCP类型设备
16 31 if (transportType === TransportTypeEnum.TCP) {
17 32 if (
... ... @@ -22,10 +37,18 @@ export const getSendValues = async (option, getDesign, checked) => {
22 37 values.customCommand.command = checked ? openCommand : closeCommand;
23 38 }
24 39 if (
25   - //判断命令下发类型是不是属性
  40 + //判断命令下发类型是不是属性 且是modbus
26 41 commandType === CommandTypeEnum.ATTRIBUTE.toString() &&
27 42 codeType === TaskTypeEnum.MODBUS_RTU
28 43 ) {
  44 + if (!deviceCode) {
  45 + createMessage.warning('当前设备没有设置地址码');
  46 + return;
  47 + }
  48 + if (!actionType) {
  49 + createMessage.warning('当前物模型扩展描述没有填写');
  50 + return;
  51 + }
29 52 isModbusCommand.value = true;
30 53 modBUS.value = {
31 54 crc: 'CRC_16_LOWER',
... ... @@ -35,6 +58,14 @@ export const getSendValues = async (option, getDesign, checked) => {
35 58 registerNumber: 1,
36 59 registerValues: [Number(checked)],
37 60 };
  61 +
  62 + if (actionType == '16' || actionType == '10') {
  63 + const newValue = Number(checked) == 0 ? [0, 0] : getArray(SingleToHex(Number(checked)));
  64 + modBUS.value.registerValues = newValue;
  65 + modBUS.value.registerNumber = 2;
  66 + modBUS.value.method = '10';
  67 + }
  68 +
38 69 sendValue.value = await genModbusCommand(unref(modBUS));
39 70 }
40 71 }
... ...
... ... @@ -364,9 +364,10 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
364 364 });
365 365 }
366 366
  367 + // 选择控制组件4的时候只能选择属性且是(int double类型)
367 368 if (unref(selectWidgetKeys).componentKey == 'LateralNumericalControl') {
368 369 setFieldsValue({
369   - [DataSourceField.COMMAND_TYPE]: 2,
  370 + [DataSourceField.COMMAND_TYPE]: CommandTypeEnum.ATTRIBUTE.toString(),
370 371 });
371 372 return option.filter(
372 373 (item) =>
... ...