diff --git a/.env.development b/.env.development
index 6b1e1da..05e0632 100644
--- a/.env.development
+++ b/.env.development
@@ -14,7 +14,7 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true
VUE_APP_SERVER_API_URL = 'http://localhost:8080/'
# Mqtt消息服务器连接地址
-VUE_APP_MQTT_SERVER_URL = 'ws://localhost:8083/mqtt'
+VUE_APP_MQTT_SERVER_URL = 'ws://192.168.1.188:8083/mqtt'
# 百度地图AK
VUE_APP_BAI_DU_AK = 'nAtaBg9FYzav6c8P9rF9qzsWZfT8O0PD'
diff --git a/.env.staging b/.env.staging
index 906e855..dd9f082 100644
--- a/.env.staging
+++ b/.env.staging
@@ -10,7 +10,7 @@ ENV = 'staging'
VUE_APP_BASE_API = '/stage-api'
# Mqtt消息服务器连接地址
-VUE_APP_MQTT_SERVER_URL = 'ws://localhost:8083/mqtt'
+VUE_APP_MQTT_SERVER_URL = 'ws://192.168.1.188:8083/mqtt'
# 百度地图AK
VUE_APP_BAI_DU_AK = 'nAtaBg9FYzav6c8P9rF9qzsWZXXXXXX'
diff --git a/README.md b/README.md
index a4a6e05..45d3987 100644
--- a/README.md
+++ b/README.md
@@ -39,3 +39,8 @@ npm run build:prod
- 若使用 vscode 开发代码,则可以安装一下插件辅助开发
- Prettier 统一代码格式,避免冲突
- i18n Ally 提高开发者翻译多语言的效率、简单出错率
+
+
+
+sql需要扩大logvalue字段
+ALTER TABLE iot_device_log MODIFY COLUMN log_value VARCHAR(1024);
\ No newline at end of file
diff --git a/dist.zip b/dist.zip
index 839962c..e9b444c 100644
Binary files a/dist.zip and b/dist.zip differ
diff --git a/src/views/iot/device/voicecard.vue b/src/views/iot/device/voicecard.vue
index ae1fe58..811ba12 100644
--- a/src/views/iot/device/voicecard.vue
+++ b/src/views/iot/device/voicecard.vue
@@ -75,6 +75,11 @@
+
+
+
+
+
@@ -116,6 +121,11 @@
+
+
+
+
+
@@ -449,37 +459,8 @@ export default {
volume: 50,
audioEnabled: true
},
- audioList: [
- { id: 1, name: '音频1' },
- { 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: '禁用'
- }
- ],
+ audioList: [],
+ defaultList: [],
// 录音相关数据
isRecording: false,
recordingTime: 0,
@@ -716,6 +697,38 @@ export default {
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() {
@@ -1298,61 +1311,86 @@ export default {
submitPlaylistForm() {
this.$refs.playlistForm.validate((valid) => {
if (valid) {
- const selectedAudio = this.audioList.find(audio => audio.id === this.newPlaylist.audioId);
- this.defaultList.push({
- id: this.defaultList.length + 1,
- name: selectedAudio ? selectedAudio.name : '',
- type: this.newPlaylist.type,
- status: this.newPlaylist.status,
- playTime: `${this.formatTime(this.newPlaylist.playTimeStart)} - ${this.formatTime(this.newPlaylist.playTimeEnd)}`,
- weekdays: this.formatWeekdays(this.newPlaylist.weekdays),
- radarEnabled: this.newPlaylist.radarEnabled,
- radarSpeed: this.newPlaylist.radarEnabled ?
- `${this.newPlaylist.radarSpeedMin}-${this.newPlaylist.radarSpeedMax}km/h` : ''
- });
- this.addPlaylistDialogVisible = false;
- this.$message.success('添加成功');
+ // 找到play_list物模型
+ const playListModel = this.deviceInfo.thingsModels.find(model => model.id === 'play_list');
+ if (playListModel) {
+ try {
+ // 解析当前JSON
+ const jsonStr = playListModel.shadow.replace('JSON=', '');
+ const data = JSON.parse(jsonStr);
+
+ // 获取选中的音频信息
+ const selectedAudio = this.audioList.find(audio => audio.id === this.newPlaylist.audioId);
+ if (!selectedAudio) {
+ this.$message.error('未找到选中的音频');
+ return;
+ }
+
+ // 构建新的播放项
+ 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 '';
- const hours = time.getHours().toString().padStart(2, '0');
- const minutes = time.getMinutes().toString().padStart(2, '0');
- return `${hours}:${minutes}`;
+ // 将时间转换为秒数
+ convertTimeToSeconds(time) {
+ if (!time) return 0;
+ return time.getHours() * 3600 + time.getMinutes() * 60;
},
- formatWeekdays(weekdays) {
- const weekMap = {
- '0': '周日',
- '1': '周一',
- '2': '周二',
- '3': '周三',
- '4': '周四',
- '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(() => { });
+ // 将星期数组转换为位值
+ convertWeekArrayToValue(weekdays) {
+ let value = 0;
+ weekdays.forEach(day => {
+ value |= (1 << parseInt(day));
+ });
+ return value;
},
formatSpeed(val) {
@@ -1366,6 +1404,106 @@ export default {
formatVolume(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(() => {});
+ },
},
};