feat:测试平台2.1更新(测试指令-语音播报)
All checks were successful
iot-test-platform CI/CD / build-and-deploy (push) Successful in 17s
All checks were successful
iot-test-platform CI/CD / build-and-deploy (push) Successful in 17s
This commit is contained in:
@@ -143,6 +143,9 @@
|
||||
<li class="nav-item">
|
||||
<button class="nav-link py-2 small" @click="mode='custom'" :class="{active: mode==='custom'}">自定义</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link py-2 small" @click="mode='command'" :class="{active: mode==='command'}">指令下发</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="mode === 'badge'">
|
||||
@@ -195,6 +198,24 @@
|
||||
</div>
|
||||
<button @click="sendCustomJson" class="btn btn-secondary btn-sm w-100">发送自定义数据</button>
|
||||
</div>
|
||||
|
||||
<div v-if="mode === 'command'">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small text-muted">接口类型</label>
|
||||
<select v-model="commandForm.apiType" class="form-select form-select-sm" @change="updateJsonTemplate">
|
||||
<option value="location">位置查询 (8201)</option>
|
||||
<option value="text">文本下发 (8300)</option>
|
||||
<option value="general">通用指令 (API)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small text-muted">请求参数 (JSON)</label>
|
||||
<textarea v-model="commandForm.jsonBody" class="form-control font-monospace form-control-sm" rows="8"></textarea>
|
||||
</div>
|
||||
<button @click="sendCommand" class="btn btn-primary btn-sm w-100">
|
||||
<i class="fas fa-terminal me-2"></i>发送指令
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -380,6 +401,11 @@
|
||||
},
|
||||
customJson: '{\n "deviceType": "sensor",\n "temp": 24.5\n}',
|
||||
|
||||
commandForm: {
|
||||
apiType: 'location',
|
||||
jsonBody: '{\n "phone": "09207455611"\n}'
|
||||
},
|
||||
|
||||
// 实时数据存储
|
||||
badges: {}, // Map: id -> badge data
|
||||
counters: {}, // Map: id -> counter data
|
||||
@@ -493,6 +519,75 @@
|
||||
alert('JSON 格式错误');
|
||||
}
|
||||
},
|
||||
|
||||
updateJsonTemplate() {
|
||||
const type = this.commandForm.apiType;
|
||||
if (type === 'location') {
|
||||
this.commandForm.jsonBody = '{\n "phone": "09207455611"\n}';
|
||||
} else if (type === 'text') {
|
||||
this.commandForm.jsonBody = '{\n "phone": "09207455611",\n "content": "#2014*SET*R:#",\n "flag": 1\n}';
|
||||
} else if (type === 'general') {
|
||||
this.commandForm.jsonBody = '{\n "imei": "09207455611",\n "cmd": "workmode",\n "params": ["2", "300"]\n}';
|
||||
}
|
||||
},
|
||||
|
||||
async sendCommand() {
|
||||
let payload;
|
||||
try {
|
||||
payload = JSON.parse(this.commandForm.jsonBody);
|
||||
} catch (e) {
|
||||
alert('JSON 格式错误');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.commandForm.apiType === 'location') {
|
||||
// 调用 /api/v1/device/command/location
|
||||
const formData = new FormData();
|
||||
if (!payload.phone) { alert('缺少 phone 字段'); return; }
|
||||
formData.append('phone', payload.phone);
|
||||
|
||||
const res = await fetch('/api/v1/device/command/location', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.code === 200) alert('指令已发送');
|
||||
else alert('失败: ' + result.message);
|
||||
|
||||
} else if (this.commandForm.apiType === 'text') {
|
||||
// 调用 /api/v1/device/command/text
|
||||
const formData = new FormData();
|
||||
if (!payload.phone || !payload.content) { alert('缺少 phone 或 content 字段'); return; }
|
||||
formData.append('phone', payload.phone);
|
||||
formData.append('content', payload.content);
|
||||
formData.append('flag', payload.flag || 1);
|
||||
|
||||
const res = await fetch('/api/v1/device/command/text', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.code === 200) alert('指令已发送');
|
||||
else alert('失败: ' + result.message);
|
||||
|
||||
} else {
|
||||
// 通用指令接口 /api/v1/device/command/send
|
||||
if (!payload.imei || !payload.cmd) { alert('缺少 imei 或 cmd 字段'); return; }
|
||||
|
||||
const res = await fetch('/api/v1/device/command/send', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const result = await res.json();
|
||||
if (result.code === 200) alert('指令已发送');
|
||||
else alert('失败: ' + result.message);
|
||||
}
|
||||
} catch (e) {
|
||||
alert('发送异常: ' + e.message);
|
||||
}
|
||||
},
|
||||
|
||||
// 辅助函数
|
||||
formatTime(date) {
|
||||
|
||||
Reference in New Issue
Block a user