声卡音频上传接口修改
This commit is contained in:
parent
70b0895bf6
commit
7d23747811
@ -254,17 +254,17 @@
|
|||||||
$t('device.running-status.866086-12') }}</el-link>
|
$t('device.running-status.866086-12') }}</el-link>
|
||||||
</template>
|
</template>
|
||||||
<el-descriptions-item :label="$t('device.running-status.866086-13')">{{ firmware.firmwareName
|
<el-descriptions-item :label="$t('device.running-status.866086-13')">{{ firmware.firmwareName
|
||||||
}}</el-descriptions-item>
|
}}</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('device.device-edit.148398-4')">{{ firmware.productName
|
<el-descriptions-item :label="$t('device.device-edit.148398-4')">{{ firmware.productName
|
||||||
}}</el-descriptions-item>
|
}}</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('device.device-edit.148398-12')">Version {{ firmware.version
|
<el-descriptions-item :label="$t('device.device-edit.148398-12')">Version {{ firmware.version
|
||||||
}}</el-descriptions-item>
|
}}</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('device.running-status.866086-16')">
|
<el-descriptions-item :label="$t('device.running-status.866086-16')">
|
||||||
<el-link :href="getDownloadUrl(firmware.filePath)" :underline="false" type="primary">{{
|
<el-link :href="getDownloadUrl(firmware.filePath)" :underline="false" type="primary">{{
|
||||||
getDownloadUrl(firmware.filePath) }}</el-link>
|
getDownloadUrl(firmware.filePath) }}</el-link>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('device.running-status.866086-17')">{{ firmware.remark
|
<el-descriptions-item :label="$t('device.running-status.866086-17')">{{ firmware.remark
|
||||||
}}</el-descriptions-item>
|
}}</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button type="success" @click="otaUpgrade"
|
<el-button type="success" @click="otaUpgrade"
|
||||||
@ -1238,19 +1238,62 @@ export default {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', audioBlob, `recording_${Date.now()}.mp3`);
|
formData.append('file', audioBlob, `recording_${Date.now()}.mp3`);
|
||||||
|
|
||||||
// TODO: 替换为实际的上传API
|
// 强制使用 HTTP 协议,因为接口只支持 HTTP
|
||||||
// const response = await uploadFile(formData);
|
const uploadUrl = 'https://iot-xcwl.cn/common/upload/audio';
|
||||||
|
// const uploadUrl = 'http://1.94.62.14:8080/common/upload/audio';
|
||||||
|
|
||||||
this.$message.success('上传成功');
|
// 调用上传接口
|
||||||
this.recordings.unshift({
|
const response = await fetch(uploadUrl, {
|
||||||
name: `录音_${this.formatTime(this.recordingTime)}`,
|
method: 'POST',
|
||||||
time: new Date().toLocaleString()
|
headers: {
|
||||||
|
'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImU3MWM2OTg4LTNlMzMtNDYyMy05M2M3LWE4YzZmMTNlMjZkZSJ9.wgsL8b3WDmyuesG8JTA3LcNFp2FigkB90h6Inwxt7OFadH6rc5np5TjAyU1pzU2_b5cmG8BYXMEdAqEdJzoDcA'
|
||||||
|
},
|
||||||
|
body: formData
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重置录音状态
|
if (response.ok) {
|
||||||
this.reRecord();
|
const result = await response.json();
|
||||||
|
if (result.code === 200) {
|
||||||
|
this.$message.success('上传成功');
|
||||||
|
this.recordings.unshift({
|
||||||
|
name: `录音_${this.formatTime(this.recordingTime)}`,
|
||||||
|
time: new Date().toLocaleString()
|
||||||
|
});
|
||||||
|
|
||||||
|
// 提取返回的 URL 并通过 MQTT 下发到 103#onlinePlay
|
||||||
|
if (result.url) {
|
||||||
|
const onlinePlayModel = this.deviceInfo.thingsModels.find(model => model.id === '103#onlinePlay');
|
||||||
|
if (onlinePlayModel) {
|
||||||
|
// 构建包含 interrupt 参数的 JSON 数据
|
||||||
|
const playData = {
|
||||||
|
"online_play": {
|
||||||
|
url: "http://1.94.62.14:8080" + result.resourcePath,
|
||||||
|
},
|
||||||
|
interrupt: 98
|
||||||
|
};
|
||||||
|
onlinePlayModel.shadow = JSON.stringify(playData);
|
||||||
|
await this.mqttPublish(this.deviceInfo, onlinePlayModel);
|
||||||
|
this.$message.success('音频已下发到设备');
|
||||||
|
} else {
|
||||||
|
this.$message.warning('未找到 103#onlinePlay 物模型');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置录音状态
|
||||||
|
this.reRecord();
|
||||||
|
} else {
|
||||||
|
this.$message.error(result.msg || '上传失败');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$message.error('上传失败,请检查网络连接');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('上传失败');
|
// 处理混合内容错误
|
||||||
|
if (error.message && error.message.includes('Mixed Content')) {
|
||||||
|
this.$message.error('由于安全策略,无法在 HTTPS 页面访问 HTTP 接口。请联系管理员配置接口支持 HTTPS。');
|
||||||
|
} else {
|
||||||
|
this.$message.error('上传失败');
|
||||||
|
}
|
||||||
console.error('上传错误:', error);
|
console.error('上传错误:', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1330,7 +1373,8 @@ export default {
|
|||||||
vol: this.newAudio.vol,
|
vol: this.newAudio.vol,
|
||||||
tex_utf8: this.newAudio.tex_utf8,
|
tex_utf8: this.newAudio.tex_utf8,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
}
|
},
|
||||||
|
"interrupt": 99
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user