Commit 3cc75b98c824183a65364fdf13c1b7b78e38c500

Authored by fengwotao
1 parent 9c49f515

perf: 脚本管理修改测试用例默认内容

@@ -51,11 +51,20 @@ @@ -51,11 +51,20 @@
51 <template #extra> 51 <template #extra>
52 <Button 52 <Button
53 v-show="ifAdd && !view" 53 v-show="ifAdd && !view"
  54 + @click="onHandleTestExampleGateway(scriptForm.scriptType)"
  55 + style="position: relative; top: -4rem; right: -6.6rem"
  56 + type="primary"
  57 + >
  58 + 直连/子设备用例</Button
  59 + >
  60 + <Button
  61 + class="ml-2"
  62 + v-show="ifAdd && !view"
54 @click="onHandleTestExample(scriptForm.scriptType)" 63 @click="onHandleTestExample(scriptForm.scriptType)"
55 style="position: relative; top: -4rem; right: -6.6rem" 64 style="position: relative; top: -4rem; right: -6.6rem"
56 type="primary" 65 type="primary"
57 > 66 >
58 - 测试用例</Button 67 + 网关用例</Button
59 > 68 >
60 <a-button @click="handleFormat" size="small">格式化</a-button> 69 <a-button @click="handleFormat" size="small">格式化</a-button>
61 <Tooltip 70 <Tooltip
@@ -120,6 +129,7 @@ @@ -120,6 +129,7 @@
120 defaultScriptTypeContent, 129 defaultScriptTypeContent,
121 defaultTestUpExample, 130 defaultTestUpExample,
122 defaultTestAuthExample, 131 defaultTestAuthExample,
  132 + defaultTestSubGatewayUpExample,
123 } from './config.data'; 133 } from './config.data';
124 import { useAppStore } from '/@/store/modules/app'; 134 import { useAppStore } from '/@/store/modules/app';
125 import TestScriptModal from './TestScriptModal.vue'; 135 import TestScriptModal from './TestScriptModal.vue';
@@ -220,6 +230,14 @@ @@ -220,6 +230,14 @@
220 handleFormat(); 230 handleFormat();
221 }; 231 };
222 232
  233 + const onHandleTestExampleGateway = (example) => {
  234 + if (example === 'TRANSPORT_TCP_UP') {
  235 + aceEditor.value?.setValue(defaultTestSubGatewayUpExample);
  236 + } else {
  237 + aceEditor.value?.setValue(defaultTestAuthExample);
  238 + }
  239 + handleFormat();
  240 + };
223 const handleCopy = () => { 241 const handleCopy = () => {
224 const valueRef = aceEditor.value.getValue(); 242 const valueRef = aceEditor.value.getValue();
225 const value = unref(valueRef); 243 const value = unref(valueRef);
@@ -86,88 +86,51 @@ export const defaultUpTitle = h('div', { style: 'background:#404040' }, [ @@ -86,88 +86,51 @@ export const defaultUpTitle = h('div', { style: 'background:#404040' }, [
86 86
87 // TRANSPORT_TCP_DOWN: 'out.datas = "";out.deviceName = "sensor";', 87 // TRANSPORT_TCP_DOWN: 'out.datas = "";out.deviceName = "sensor";',
88 export const defaultScriptTypeContent = { 88 export const defaultScriptTypeContent = {
89 - TRANSPORT_TCP_UP: `var teleData = {};  
90 -/*  
91 -物模型数据(可选):原始数据  
92 -*/  
93 -teleData.source= params;  
94 -/*  
95 -直连/网关子设备设备:temperature是产品物模型中所定义属性的标识符  
96 -*/  
97 -tempVal = params;  
98 -teleData.temperature= tempVal;  
99 -/*  
100 -网关设备:变量slaveDevice是网关子设备的“设备标识”  
101 -*/  
102 -slaveDevice = params.substr(0,2);  
103 -teleData[slaveDevice]= params; 89 + TRANSPORT_TCP_UP: `/*网关上行脚本*/
  90 +var teleData = {};
  91 +/*物模型数据(可选):原始数据*/
  92 +teleData.source = params;
  93 +/*网关设备:slaveDevice是网关子设备的“设备标识”*/
  94 +slaveDevice = params.substr(0, 2);
  95 +teleData[slaveDevice] = params;
104 out.datas = teleData; 96 out.datas = teleData;
105 -/*  
106 -必填:true表示设备上报的遥测数据,false表示命令下发的响应数据  
107 -*/  
108 out.telemetry = true; 97 out.telemetry = true;
109 -/*  
110 -必填:设备或命令下发的唯一标识,设备的唯一标识必须与设备信息的“设备名称”一致  
111 -*/  
112 -out.identifier = "01";  
113 -/*  
114 -可选:服务端收到设备数据后,响应的消息内容  
115 -*/  
116 -out.ackMsg = params;  
117 -/*  
118 -可选:默认使用服务器时间,可以使用数据内的时间  
119 -*/  
120 -out.ts = Date.now();`,  
121 - TRANSPORT_TCP_AUTH: `/*  
122 - 必填:设备的访问令牌  
123 - */  
124 - out.password = params;  
125 - /*  
126 - 选填:设备鉴权成功后响应给设备的信息  
127 - */  
128 - out.success = params; 98 +/*必填:true表示设备上报的遥测数据,false表示命令下发的响应数据*/
  99 + `,
  100 + TRANSPORT_TCP_AUTH: `/*必填:设备的访问令牌*/
  101 +out.password = params;
  102 +/*选填:设备鉴权成功后响应给设备的信息*/
  103 +out.success = params;
129 `, 104 `,
130 }; 105 };
131 106
132 -export const defaultTestUpExample = `var teleData = {};  
133 -/*  
134 -物模型数据(可选):原始数据  
135 -*/ 107 +export const defaultTestUpExample = `/*网关上行脚本*/
  108 +var teleData = {};
  109 +/*物模型数据(可选):原始数据*/
136 teleData.source= params; 110 teleData.source= params;
137 -/*  
138 -直连/网关子设备设备:temperature是产品物模型中所定义属性的标识符  
139 -*/  
140 -tempVal = params;  
141 -teleData.temperature= tempVal;  
142 -/*  
143 -网关设备:变量slaveDevice是网关子设备的“设备标识”  
144 -*/ 111 +/*网关设备:slaveDevice是网关子设备的“设备标识”*/
145 slaveDevice = params.substr(0,2); 112 slaveDevice = params.substr(0,2);
146 teleData[slaveDevice]= params; 113 teleData[slaveDevice]= params;
147 out.datas = teleData; 114 out.datas = teleData;
148 -/*  
149 -必填:true表示设备上报的遥测数据,false表示命令下发的响应数据  
150 -*/  
151 -out.telemetry = true;  
152 -/*  
153 -必填:设备或命令下发的唯一标识,设备的唯一标识必须与设备信息的“设备名称”一致  
154 -*/  
155 -out.identifier = "01";  
156 -/*  
157 -可选:服务端收到设备数据后,响应的消息内容  
158 -*/  
159 -out.ackMsg = params;  
160 -/*  
161 -可选:默认使用服务器时间,可以使用数据内的时间  
162 -*/  
163 -out.ts = Date.now();`; 115 +out.telemetry = true;/*必填:true表示设备上报的遥测数据,false表示命令下发的响应数据*/`;
164 116
165 -export const defaultTestAuthExample = `/*  
166 - 必填:设备的访问令牌  
167 - */ 117 +export const defaultTestAuthExample = `/*必填:设备的访问令牌*/
168 out.password = params; 118 out.password = params;
169 -/*  
170 - 选填:设备鉴权成功后响应给设备的信息  
171 - */ 119 +/*选填:设备鉴权成功后响应给设备的信息*/
172 out.success = params; 120 out.success = params;
173 `; 121 `;
  122 +
  123 +export const defaultTestSubGatewayUpExample = `/*params为TCP上报的标准ModBus数据,实际使用或测试时请删除*/
  124 +var params = "010304026C00883BF0"
  125 +var teleData = {};
  126 +/*物模型数据(可选):原始数据*/
  127 +teleData.source = params;
  128 +/*直连设备:tempVal是产品物模型中所定义属性的标识符*/
  129 +tempVal = params;
  130 +/*物模型温度标识符*/
  131 +teleData.temperature = (parseInt('0x'+tempVal.substr(10, 4))*0.1).toFixed(2);
  132 +/*物模型湿度标识符*/
  133 +teleData.humidity = (parseInt('0x'+tempVal.substr(6, 4))*0.1).toFixed(2);
  134 +out.datas = teleData;
  135 +/*必填:true表示设备上报的遥测数据,false表示命令下发的响应数据*/
  136 +out.telemetry = true;`;