From 3c80f4a2f75ed385d77e385d3500bdef39b0ef16 Mon Sep 17 00:00:00 2001 From: JayJiaJun Date: Fri, 14 Mar 2025 09:37:40 +0800 Subject: [PATCH] 3.14 --- src/views/CarControl.vue | 2 +- src/views/ConeControl.vue | 522 +++++++++++++++++++-------- src/views/gateway/GatewaySetting.vue | 14 +- 3 files changed, 378 insertions(+), 160 deletions(-) diff --git a/src/views/CarControl.vue b/src/views/CarControl.vue index 35998cc..0053e9d 100644 --- a/src/views/CarControl.vue +++ b/src/views/CarControl.vue @@ -140,7 +140,7 @@ export default { // 启动定时发送数据 this.sendInterval = setInterval(() => { this.sendControlData(); - }, 1000); // 每100ms发送一次 + }, 400); // 每100ms发送一次 // 初始化音频处理器 this.audioHandler = { diff --git a/src/views/ConeControl.vue b/src/views/ConeControl.vue index 1554501..62c48c7 100644 --- a/src/views/ConeControl.vue +++ b/src/views/ConeControl.vue @@ -1,114 +1,106 @@ @@ -135,6 +127,15 @@ export default { const channelPickerVisible = ref(false); const speedRatePickerVisible = ref(false); const powerPickerVisible = ref(false); + const alarmStatus = ref('报警'); + const lightStatus = ref('白灯亮'); + const defenseEnabled = ref(false); + const lightStatusPickerVisible = ref(false); + const refreshing = ref(false); + const firmwareVersion = ref(''); + const macAddress = ref(''); + const modePickerVisible = ref(false); + const currentMode = ref(''); // 选项数据 const freqBandOptions = [ @@ -170,6 +171,24 @@ export default { { text: '2dbm', value: 7 } ]; + // 灯光状态选项 + const lightStatusOptions = [ + { text: '白光亮(高)', value: 0 }, + { text: '白光亮(中)', value: 1 }, + { text: '白光亮(低)', value: 2 }, + { text: '红蓝快闪', value: 3 }, + { text: '红蓝慢闪', value: 4 }, + { text: '投射灯亮', value: 5 }, + { text: '关闭', value: 6 } + ]; + + const modeOptions = [ + { text: '通道一', value: 0, networkId: '6A6A00' }, + { text: '通道二', value: 1, networkId: '6A6A01' }, + { text: '通道三', value: 2, networkId: '6A6A02' }, + { text: '通道四', value: 3, networkId: '6A6A03' } + ]; + const onClickLeft = () => { router.back(); }; @@ -190,6 +209,14 @@ export default { powerPickerVisible.value = true; }; + const showLightStatusPicker = () => { + lightStatusPickerVisible.value = true; + }; + + const showModePopup = () => { + modePickerVisible.value = true; + }; + const onFreqBandConfirm = (value) => { freqBand.value = value.selectedOptions[0].text; freqBandPickerVisible.value = false; @@ -210,6 +237,68 @@ export default { powerPickerVisible.value = false; }; + const onLightStatusConfirm = (value) => { + lightStatus.value = value.selectedOptions[0].text; + lightStatusPickerVisible.value = false; + sendLightStatusCommand(value.selectedOptions[0].value); + }; + + const sendLightStatusCommand = (value) => { + const lightStatusCommand = { + board_id: 106, + JSON_id: 1, + cones_card: { + traffic_cone: { + lamplight: value + } + }, + error_code: 0 + }; + if (isLocal.value) { + axios.post('/communication', lightStatusCommand, { + headers: { + "content-type": "application/json" + } + }) + .then(response => { + console.log('Light status response:', response.data); + }) + .catch(error => { + console.error('Light status error:', error); + }); + } else { + MQTT_send(lightStatusCommand); + } + }; + + const onDefenseChange = (value) => { + const defenseCommand = { + board_id: 106, + JSON_id: 1, + cones_card: { + traffic_cone: { + mode: value ? 1 : 0 + } + }, + error_code: 0 + }; + if (isLocal.value) { + axios.post('/communication', defenseCommand, { + headers: { + "content-type": "application/json" + } + }) + .then(response => { + console.log('Defense mode response:', response.data); + }) + .catch(error => { + console.error('Defense mode error:', error); + }); + } else { + MQTT_send(defenseCommand); + } + }; + const checkEnvironment = () => { if (window.location.hostname === '192.168.4.1') { console.log('in local'); @@ -291,12 +380,130 @@ export default { }; const sendCommand = (command) => { - // 发送指令逻辑 - showToast(`发送${command}`); + if (command === 'clearAlarm') { + const clearAlarmCommand = { + board_id: 106, + JSON_id: 1, + cones_card: { + traffic_cone: { + alarm: 0 + } + }, + error_code: 0 + }; + if (isLocal.value) { + axios.post('/communication', clearAlarmCommand, { + headers: { + "content-type": "application/json" + } + }) + .then(response => { + console.log('Clear alarm response:', response.data); + alarmStatus.value = '正常'; + }) + .catch(error => { + console.error('Clear alarm error:', error); + }); + } else { + MQTT_send(clearAlarmCommand); + } + } + }; + + const onModeConfirm = (value) => { + currentMode.value = value.selectedOptions[0].text; + networkId.value = value.selectedOptions[0].networkId; + modePickerVisible.value = false; + + // 发送配置更新命令 + const configData = { + board_id: 106, + JSON_id: 1, + cones_card: { + LoRa_cfg: { + mesh_id: [ + parseInt(networkId.value.slice(0, 2), 16), + parseInt(networkId.value.slice(2, 4), 16), + parseInt(networkId.value.slice(4, 6), 16) + ], + fre_band: parseInt(freqBand.value), + channel: parseInt(channel.value), + SF: parseInt(speedRate.value), + power: parseInt(power.value), + mode: value.selectedOptions[0].value + } + }, + error_code: 0 + }; + + if (isLocal.value) { + axios.post('/communication', configData, { + headers: { + "content-type": "application/json" + } + }) + .then(response => { + console.log('Mode update response:', response.data); + }) + .catch(error => { + console.error('Mode update error:', error); + }); + } else { + MQTT_send(configData); + } + }; + + const updateStateFromResponse = (data) => { + firmwareVersion.value = data.versions; + macAddress.value = data.mac_addr.join(':'); + networkId.value = data.mesh_id.map(num => num.toString(16).padStart(2, '0').toUpperCase()).join(''); + freqBand.value = freqBandOptions.find(option => option.value === data.fre_band)?.text || ''; + channel.value = `信道${data.channel + 1}`; + speedRate.value = speedRateOptions.find(option => option.value === data.SF)?.text || ''; + power.value = powerOptions.find(option => option.value === data.power)?.text || ''; + + // 更新当前模式 + const mode = modeOptions.find(option => option.networkId === networkId.value); + if (mode) { + currentMode.value = mode.text; + } + }; + + const onRefresh = () => { + const refreshCommand = { + board_id: 106, + JSON_id: 1, + cones_card: { + get_traffic_cone: 1, + get_LoRa_cfg: 1 + }, + error_code: 0 + }; + if (isLocal.value) { + axios.post('/communication', refreshCommand, { + headers: { + "content-type": "application/json" + } + }) + .then(response => { + console.log('Refresh response:', response.data); + updateStateFromResponse(response.data.cones_card.LoRa_cfg); + refreshing.value = false; + }) + .catch(error => { + console.error('Refresh error:', error); + refreshing.value = false; + }); + } else { + MQTT_send(refreshCommand); + refreshing.value = false; + } }; onMounted(() => { checkEnvironment(); + onRefresh(); + }); return { @@ -326,6 +533,23 @@ export default { channelOptions, speedRateOptions, powerOptions, + alarmStatus, + lightStatus, + defenseEnabled, + lightStatusPickerVisible, + lightStatusOptions, + showLightStatusPicker, + onLightStatusConfirm, + onDefenseChange, + refreshing, + onRefresh, + firmwareVersion, + macAddress, + modePickerVisible, + currentMode, + modeOptions, + showModePopup, + onModeConfirm, }; } }; @@ -358,7 +582,7 @@ export default { gap: 8px; } -.command-container { +.status-container { margin: 16px; background: #ffffff; border-radius: 12px; @@ -366,52 +590,6 @@ export default { overflow: hidden; } -.command-header { - padding: 16px; - font-size: 16px; - font-weight: 500; - color: #323233; - border-bottom: 1px solid #f5f5f5; - display: flex; - align-items: center; - gap: 8px; -} - -.command-grid { - display: grid; - grid-template-columns: repeat(2, 1fr); - gap: 16px; - padding: 16px; -} - -.command-item { - background: #f7f8fa; - border-radius: 8px; - padding: 16px; - text-align: center; - transition: all 0.3s; - cursor: pointer; - display: flex; - flex-direction: column; - align-items: center; - gap: 8px; -} - -.command-item:active { - background: #e8e8e8; - transform: scale(0.98); -} - -.command-icon { - color: #1989fa; - margin-bottom: 4px; -} - -.command-text { - font-size: 14px; - color: #323233; -} - .info-row { display: flex; align-items: center; @@ -459,4 +637,44 @@ export default { .command-item:active::after { opacity: 1; } + +/* 为清除报警按钮添加样式 */ +:deep(.van-button--danger) { + margin-left: 8px; +} + +.mode-container { + margin: 12px -16px; + padding: 12px 16px; + background-color: #f2f7ff; + /* 浅蓝色背景 */ + border-left: 4px solid #1989fa; + /* 左边添加蓝色边框 */ +} + +.mode-row { + margin-bottom: 0; + /* 覆盖原来的 margin */ +} + +.mode-field { + font-weight: 500; + /* 字体加粗 */ + color: #1989fa; + /* 使用主题蓝色 */ +} + +.mode-field :deep(.van-field__value) { + color: #1989fa; +} + +.mode-field :deep(.van-field__placeholder) { + color: #1989fa; + opacity: 0.7; +} + +/* 让其他网络参数稍微淡一点 */ +.info-row:not(.mode-row) { + opacity: 0.85; +} \ No newline at end of file diff --git a/src/views/gateway/GatewaySetting.vue b/src/views/gateway/GatewaySetting.vue index c9f7a8a..1065ce1 100644 --- a/src/views/gateway/GatewaySetting.vue +++ b/src/views/gateway/GatewaySetting.vue @@ -106,8 +106,8 @@ @@ -118,8 +118,8 @@ @@ -468,7 +468,7 @@ export default { pins: [] } : {}), ...(outputType === '其他' ? { - customTarget: '', + customTarget: '0', customData1: '0', customData2: '0', customData3: '0' @@ -495,7 +495,7 @@ export default { const saveEvent = () => { // 检查必填字段 - if (!currentEvent.type || !currentEvent.source || !currentEvent.priority || currentEvent.outputs.length === 0) { + if (!currentEvent.type || !currentEvent.source || !currentEvent.priority || currentEvent.outputs.length === 0) { showToast('请填写所有必填字段并至少添加一个输出'); return; } @@ -1044,7 +1044,7 @@ export default { // 在 setup 中添加上传配置方法 const uploadLoRaConfig = () => { // 检查必填字段是否为空 - if (!networkId.value || !freqBand.value || !channel.value || !speedRate.value || !power.value) { + if (!networkId.value || !freqBand.value || !channel.value || !speedRate.value || !power.value || !customEventType.value || !customEventSource.value) { showToast('请填写所有必填字段'); return; }