声卡部分功能完善

This commit is contained in:
1 2025-06-10 17:22:29 +08:00
parent ddc740eab2
commit f877f5f9a2
5 changed files with 225 additions and 82 deletions

View File

@ -14,7 +14,7 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true
VUE_APP_SERVER_API_URL = 'http://localhost:8080/' VUE_APP_SERVER_API_URL = 'http://localhost:8080/'
# Mqtt消息服务器连接地址 # Mqtt消息服务器连接地址
VUE_APP_MQTT_SERVER_URL = 'ws://localhost:8083/mqtt' VUE_APP_MQTT_SERVER_URL = 'ws://192.168.1.188:8083/mqtt'
# 百度地图AK # 百度地图AK
VUE_APP_BAI_DU_AK = 'nAtaBg9FYzav6c8P9rF9qzsWZfT8O0PD' VUE_APP_BAI_DU_AK = 'nAtaBg9FYzav6c8P9rF9qzsWZfT8O0PD'

View File

@ -10,7 +10,7 @@ ENV = 'staging'
VUE_APP_BASE_API = '/stage-api' VUE_APP_BASE_API = '/stage-api'
# Mqtt消息服务器连接地址 # Mqtt消息服务器连接地址
VUE_APP_MQTT_SERVER_URL = 'ws://localhost:8083/mqtt' VUE_APP_MQTT_SERVER_URL = 'ws://192.168.1.188:8083/mqtt'
# 百度地图AK # 百度地图AK
VUE_APP_BAI_DU_AK = 'nAtaBg9FYzav6c8P9rF9qzsWZXXXXXX' VUE_APP_BAI_DU_AK = 'nAtaBg9FYzav6c8P9rF9qzsWZXXXXXX'

View File

@ -39,3 +39,8 @@ npm run build:prod
- 若使用 vscode 开发代码,则可以安装一下插件辅助开发 - 若使用 vscode 开发代码,则可以安装一下插件辅助开发
- Prettier 统一代码格式,避免冲突 - Prettier 统一代码格式,避免冲突
- i18n Ally 提高开发者翻译多语言的效率、简单出错率 - i18n Ally 提高开发者翻译多语言的效率、简单出错率
sql需要扩大logvalue字段
ALTER TABLE iot_device_log MODIFY COLUMN log_value VARCHAR(1024);

BIN
dist.zip

Binary file not shown.

View File

@ -75,6 +75,11 @@
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
<template slot="empty">
<div style="padding: 20px 0;">
<el-empty description="暂无音频数据"></el-empty>
</div>
</template>
</el-table> </el-table>
</el-card> </el-card>
@ -116,6 +121,11 @@
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
<template slot="empty">
<div style="padding: 20px 0;">
<el-empty description="暂无播放列表数据"></el-empty>
</div>
</template>
</el-table> </el-table>
</el-card> </el-card>
</el-col> </el-col>
@ -449,37 +459,8 @@ export default {
volume: 50, volume: 50,
audioEnabled: true audioEnabled: true
}, },
audioList: [ audioList: [],
{ id: 1, name: '音频1' }, defaultList: [],
{ id: 2, name: '音频2' },
{ id: 3, name: '音频3' }
],
defaultList: [
{
id: 1,
name: '默认音频1',
playTime: '08:00',
weekdays: '周一, 周三, 周五',
radarEnabled: true,
status: '启用'
},
{
id: 2,
name: '默认音频2',
playTime: '12:30',
weekdays: '周二, 周四',
radarEnabled: false,
status: '启用'
},
{
id: 3,
name: '默认音频3',
playTime: '18:00',
weekdays: '周六, 周日',
radarEnabled: true,
status: '禁用'
}
],
// //
isRecording: false, isRecording: false,
recordingTime: 0, recordingTime: 0,
@ -716,6 +697,38 @@ export default {
console.error('解析音频列表失败:', error); console.error('解析音频列表失败:', error);
} }
} }
//
const playListModel = this.deviceInfo.thingsModels.find(model => model.id === 'play_list');
if (playListModel && playListModel.shadow) {
try {
const jsonStr = playListModel.shadow.replace('JSON=', '');
const data = JSON.parse(jsonStr);
if (data.sound_card && data.sound_card.play_list) {
this.defaultList = data.sound_card.play_list.map((item, index) => {
//
const beginTime = this.formatSecondsToTime(item.time.begin);
const endTime = this.formatSecondsToTime(item.time.end);
//
const weekdays = this.convertWeekToArray(item.time.week);
return {
id: index + 1,
name: item.play.filename,
playTime: `${beginTime} - ${endTime}`,
weekdays: weekdays.join(', '),
radarEnabled: item.speed.en === 1,
status: item.play.en === 1 ? '启用' : '禁用',
radarSpeed: item.speed.en === 1 ? `${item.speed.min}-${item.speed.max}km/h` : ''
};
});
}
} catch (error) {
console.error('解析播放列表失败:', error);
}
}
}, },
printThingsModels() { printThingsModels() {
@ -1298,61 +1311,86 @@ export default {
submitPlaylistForm() { submitPlaylistForm() {
this.$refs.playlistForm.validate((valid) => { this.$refs.playlistForm.validate((valid) => {
if (valid) { if (valid) {
const selectedAudio = this.audioList.find(audio => audio.id === this.newPlaylist.audioId); // play_list
this.defaultList.push({ const playListModel = this.deviceInfo.thingsModels.find(model => model.id === 'play_list');
id: this.defaultList.length + 1, if (playListModel) {
name: selectedAudio ? selectedAudio.name : '', try {
type: this.newPlaylist.type, // JSON
status: this.newPlaylist.status, const jsonStr = playListModel.shadow.replace('JSON=', '');
playTime: `${this.formatTime(this.newPlaylist.playTimeStart)} - ${this.formatTime(this.newPlaylist.playTimeEnd)}`, const data = JSON.parse(jsonStr);
weekdays: this.formatWeekdays(this.newPlaylist.weekdays),
radarEnabled: this.newPlaylist.radarEnabled, //
radarSpeed: this.newPlaylist.radarEnabled ? const selectedAudio = this.audioList.find(audio => audio.id === this.newPlaylist.audioId);
`${this.newPlaylist.radarSpeedMin}-${this.newPlaylist.radarSpeedMax}km/h` : '' if (!selectedAudio) {
}); this.$message.error('未找到选中的音频');
this.addPlaylistDialogVisible = false; return;
this.$message.success('添加成功'); }
//
const newPlayItem = {
play: {
en: 1,
num: this.defaultList.length + 1,
sou: 0,
filename: `${selectedAudio.id}_${selectedAudio.name}`,
play_time: 1,
pause_time: 0
},
time: {
en: 1,
begin: this.convertTimeToSeconds(this.newPlaylist.playTimeStart),
end: this.convertTimeToSeconds(this.newPlaylist.playTimeEnd),
week: this.convertWeekArrayToValue(this.newPlaylist.weekdays)
},
speed: {
en: this.newPlaylist.radarEnabled ? 1 : 0,
min: this.newPlaylist.radarEnabled ? this.newPlaylist.radarSpeedMin : 0,
max: this.newPlaylist.radarEnabled ? this.newPlaylist.radarSpeedMax : 0
}
};
//
if (!data.sound_card) {
data.sound_card = {};
}
if (!data.sound_card.play_list) {
data.sound_card.play_list = [];
}
data.sound_card.play_list.push(newPlayItem);
// shadow
playListModel.shadow = 'JSON=' + JSON.stringify(data);
//
this.mqttPublish(this.deviceInfo, playListModel).then(() => {
this.addPlaylistDialogVisible = false;
this.$message.success('添加成功');
}).catch(error => {
console.error('发送播放列表更新失败:', error);
this.$message.error('添加失败');
});
} catch (error) {
console.error('解析或更新播放列表失败:', error);
this.$message.error('添加失败');
}
}
} }
}); });
}, },
formatTime(time) { //
if (!time) return ''; convertTimeToSeconds(time) {
const hours = time.getHours().toString().padStart(2, '0'); if (!time) return 0;
const minutes = time.getMinutes().toString().padStart(2, '0'); return time.getHours() * 3600 + time.getMinutes() * 60;
return `${hours}:${minutes}`;
}, },
formatWeekdays(weekdays) { //
const weekMap = { convertWeekArrayToValue(weekdays) {
'0': '周日', let value = 0;
'1': '周一', weekdays.forEach(day => {
'2': '周二', value |= (1 << parseInt(day));
'3': '周三', });
'4': '周四', return value;
'5': '周五',
'6': '周六'
};
return weekdays.map(day => weekMap[day]).join(', ');
},
handleStatusChange(row) {
// TODO: API
console.log('状态变更:', row);
},
handleDeletePlaylist(row) {
this.$confirm('确认删除该音频吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const index = this.defaultList.findIndex(item => item.id === row.id);
if (index > -1) {
this.defaultList.splice(index, 1);
}
this.$message.success('删除成功');
}).catch(() => { });
}, },
formatSpeed(val) { formatSpeed(val) {
@ -1366,6 +1404,106 @@ export default {
formatVolume(val) { formatVolume(val) {
return val; return val;
}, },
//
formatSecondsToTime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
},
//
convertWeekToArray(week) {
const weekMap = {
1: '周一',
2: '周二',
3: '周三',
4: '周四',
5: '周五',
6: '周六',
0: '周日'
};
const result = [];
for (let i = 0; i < 7; i++) {
if (week & (1 << i)) {
result.push(weekMap[i]);
}
}
return result;
},
handleStatusChange(row) {
const playListModel = this.deviceInfo.thingsModels.find(model => model.id === 'play_list');
if (playListModel) {
try {
const jsonStr = playListModel.shadow.replace('JSON=', '');
const data = JSON.parse(jsonStr);
if (data.sound_card && data.sound_card.play_list) {
//
const playItem = data.sound_card.play_list[row.id - 1];
if (playItem) {
//
playItem.play.en = row.status === '启用' ? 1 : 0;
// shadow
playListModel.shadow = 'JSON=' + JSON.stringify(data);
//
this.mqttPublish(this.deviceInfo, playListModel).then(() => {
this.$message.success('状态更新成功');
}).catch(error => {
console.error('发送状态更新失败:', error);
this.$message.error('状态更新失败');
});
}
}
} catch (error) {
console.error('解析或更新播放列表状态失败:', error);
this.$message.error('状态更新失败');
}
}
},
handleDeletePlaylist(row) {
this.$confirm('确认删除该播放项吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const playListModel = this.deviceInfo.thingsModels.find(model => model.id === 'play_list');
if (playListModel) {
try {
const jsonStr = playListModel.shadow.replace('JSON=', '');
const data = JSON.parse(jsonStr);
if (data.sound_card && data.sound_card.play_list) {
//
data.sound_card.play_list.splice(row.id - 1, 1);
//
data.sound_card.play_list.forEach((item, index) => {
item.play.num = index + 1;
});
// shadow
playListModel.shadow = 'JSON=' + JSON.stringify(data);
//
this.mqttPublish(this.deviceInfo, playListModel).then(() => {
this.$message.success('删除成功');
}).catch(error => {
console.error('发送删除命令失败:', error);
this.$message.error('删除失败');
});
}
} catch (error) {
console.error('解析或更新播放列表失败:', error);
this.$message.error('删除失败');
}
}
}).catch(() => {});
},
}, },
}; };
</script> </script>