diff --git a/admin/config/index.js b/admin/config/index.js index 85b8313..ff14a7b 100644 --- a/admin/config/index.js +++ b/admin/config/index.js @@ -26,11 +26,11 @@ const baseConfig = { // 开发环境配置 const developmentConfig = { ...baseConfig, - apiUrl: 'http://localhost:9097/admin_api/', - uploadUrl: 'http://localhost:9097/admin_api/upload', + // apiUrl: 'http://localhost:9097/admin_api/', + // uploadUrl: 'http://localhost:9097/admin_api/upload', - // apiUrl: 'http://work.light120.com/admin_api/', - // uploadUrl: 'http://work.light120.com/admin_api/upload', + apiUrl: 'http://work.light120.com/admin_api/', + uploadUrl: 'http://work.light120.com/admin_api/upload', // 开发环境显示更多调试信息 debug: true } diff --git a/admin/src/views/home/index.vue b/admin/src/views/home/index.vue index 8b6360c..bf26f67 100644 --- a/admin/src/views/home/index.vue +++ b/admin/src/views/home/index.vue @@ -753,11 +753,11 @@ export default { } } - // 确保布尔值字段正确初始化 - accountData.is_enabled = accountData.is_enabled !== undefined ? accountData.is_enabled : 1 - accountData.auto_deliver = accountData.auto_deliver !== undefined ? accountData.auto_deliver : 0 - accountData.auto_chat = accountData.auto_chat !== undefined ? accountData.auto_chat : 0 - accountData.auto_active = accountData.auto_active !== undefined ? accountData.auto_active : 0 + // 确保布尔值字段正确初始化,转换为数字类型(0 或 1) + accountData.is_enabled = accountData.is_enabled !== undefined ? Number(accountData.is_enabled) : 1 + accountData.auto_deliver = accountData.auto_deliver !== undefined ? Number(accountData.auto_deliver) : 0 + accountData.auto_chat = accountData.auto_chat !== undefined ? Number(accountData.auto_chat) : 0 + accountData.auto_active = accountData.auto_active !== undefined ? Number(accountData.auto_active) : 0 this.accountInfo = accountData console.log('设置账户信息:', this.accountInfo) @@ -798,8 +798,8 @@ export default { this.switchLoading[field] = true try { - // 确保 value 是数字类型(0 或 1) - const numericValue = value ? 1 : 0 + // i-switch 的 on-change 事件已经返回了正确的值(1 或 0),直接使用 + const numericValue = Number(value) // 构建更新数据,确保是纯对象,只包含基本类型 const updateData = { @@ -819,19 +819,8 @@ export default { const errorMsg = error.response?.data?.message || error.message || '请稍后重试' this.$Message.error('更新失败:' + errorMsg) - // 恢复原值 - this.$nextTick(() => { - const oldValue = this.accountInfo[field] - if (field === 'is_enabled') { - this.accountInfo.is_enabled = oldValue === 1 ? 0 : 1 - } else if (field === 'auto_deliver') { - this.accountInfo.auto_deliver = oldValue === 1 ? 0 : 1 - } else if (field === 'auto_chat') { - this.accountInfo.auto_chat = oldValue === 1 ? 0 : 1 - } else if (field === 'auto_active') { - this.accountInfo.auto_active = oldValue === 1 ? 0 : 1 - } - }) + // 恢复原值(从数据库重新加载) + await this.loadAccountInfo() } finally { this.switchLoading[field] = false } diff --git a/api/middleware/mqtt/mqttDispatcher.js b/api/middleware/mqtt/mqttDispatcher.js index 7da79b4..a85428e 100644 --- a/api/middleware/mqtt/mqttDispatcher.js +++ b/api/middleware/mqtt/mqttDispatcher.js @@ -267,21 +267,7 @@ class MqttDispatcher { if (device) { await device_status.update(updateData, { where: { sn_code } }); console.log(`[MQTT心跳] 设备 ${sn_code} 状态已更新 - 在线: true, 登录: ${updateData.isLoggedIn}`); - } else { - // 创建新设备记录 - await device_status.create({ - sn_code, - device_id: clientId, - deviceName: `设备_${sn_code}`, - deviceType: 'node_mqtt_client', - ...updateData, - isRunning: false, - taskStatus: 'idle', - healthStatus: 'unknown', - healthScore: 0 - }); - console.log(`[MQTT心跳] 设备 ${sn_code} 记录已创建 - 在线: true, 登录: ${updateData.isLoggedIn}`); - } + } // 记录心跳到设备管理器 await deviceManager.recordHeartbeat(sn_code, heartbeatData);