useCommon.ts
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import useParitalValid from './useParitalValid';
import { findDictItemByCode } from '/@/api/system/dict';
import { buildUUID } from '/@/utils/uuid';
///根据不同数据类型得到不同表单数据(模拟的阿里云数据结构)
type TForm = {
dataType: string;
max?: string;
min?: string;
step?: string;
unit?: string;
boolClose?: string;
boolOpen?: string;
length?: string;
valueRange?: {
min: string;
max: string;
};
};
export default () => {
const { validateValueRangeAndStep, validateValueBool } = useParitalValid();
const useChangeTypeGetTypeForm = (type, options: TForm) => {
switch (type) {
//INT和DOUBLE收集表单一样
case 'INT':
validateValueRangeAndStep(
Number(options?.valueRange?.min),
Number(options?.step),
Number(options?.valueRange?.max)
);
return {
dataType: options?.dataType,
max: options?.valueRange?.max,
min: options?.valueRange?.min,
step: options?.step,
unit: options?.unit,
};
case 'DOUBLE':
validateValueRangeAndStep(
Number(options?.valueRange?.min),
Number(options?.step),
Number(options?.valueRange?.max)
);
return {
dataType: options?.dataType,
max: options?.valueRange?.max,
min: options?.valueRange?.min,
step: options?.step,
unit: options?.unit,
};
case 'BOOL':
validateValueBool(Number(options?.boolClose), Number(options?.boolOpen));
return [
{
dataType: options?.dataType,
name: options?.boolClose,
value: 0,
},
{
dataType: options?.dataType,
name: options?.boolOpen,
value: 1,
},
];
case 'TEXT':
return {
dataType: options?.dataType,
length: Number(options?.length),
};
}
};
//是否排除结构体
const useUpdateFormExcludeStruct = async (F, U) => {
const res: any = await findDictItemByCode({ dictCode: 'data_type' });
const optionTrue = res
.map((m) => {
if (F) {
if (m.itemValue !== 'STRUCT') {
return {
value: m.itemValue,
label: m.itemText,
};
}
} else {
return {
value: m.itemValue,
label: m.itemText,
};
}
})
.filter(Boolean);
U({
field: 'dataType',
componentProps: {
options: optionTrue,
},
});
};
//获取输入参数或者输出参数弹窗数据
const useGetInOrOutData = (d, f, inputData, outputData) => {
if (f == 'input') {
if (d.id !== null) {
const findIndex = inputData.findIndex((f) => f.id == d.id);
if (findIndex !== -1) inputData.splice(findIndex, 1, d);
} else {
inputData.push({ ...d, id: buildUUID() });
}
} else {
if (d.id !== null) {
const findIndex = outputData.findIndex((f) => f.id == d.id);
if (findIndex !== -1) outputData.splice(findIndex, 1, d);
} else {
outputData.push({ ...d, id: buildUUID() });
}
}
};
const useBlockContent = `物模型是对设备在云端的功能描述,包括设备的属性、服务和事件。物联网平台通过定义一种物的描述语言来描述物模型,称之为 TSL(即 Thing
Specification Language),采用 JSON 格式,您可以根据 TSL 组装上报设备的数据。您可以导出完整物模型,用于云端应用开发;您也可以只导出
精简物模型,配合设备端 SDK 实现设备开发。`;
const useBlockPhysicalContent = `属性一般是设备的运行状态,如当前温度等;服务是设备可被调用的方法,支持定义参数,如执行某项任务;事件则是设备上报的
通知,如告警,需要被及时处理。`;
return {
useChangeTypeGetTypeForm,
useUpdateFormExcludeStruct,
useGetInOrOutData,
useBlockContent,
useBlockPhysicalContent,
};
};