fix:空调开关机日志、温湿度报警
This commit is contained in:
@ -57,7 +57,7 @@
|
||||
<text class="detail-label">洁净度</text>
|
||||
</view>
|
||||
<view class="detail-value-container">
|
||||
<text class="detail-value">{{ cleanliness > 0 ? cleanliness + '%' : '-%' }}</text>
|
||||
<text class="detail-value">{{ cleanliness > 0 ? cleanliness + 'μg/m³' : '-μg/m³' }}</text>
|
||||
<view class="detail-status" :class="cleanliness > 0 ? 'active' : 'inactive'"></view>
|
||||
</view>
|
||||
</view>
|
||||
@ -91,11 +91,13 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="ac-power-controls">
|
||||
<button class="ac-power-btn power-on" @click="turnOnAirConditioner" :disabled="acControlLoading">
|
||||
开机
|
||||
</button>
|
||||
<button class="ac-power-btn power-off" @click="turnOffAirConditioner" :disabled="acControlLoading">
|
||||
关机
|
||||
<button
|
||||
class="ac-power-btn"
|
||||
:class="getAcButtonClass()"
|
||||
@click="toggleAirConditioner"
|
||||
:disabled="!canOperateAc() || acControlLoading"
|
||||
>
|
||||
{{ getAcButtonText() }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@ -426,9 +428,9 @@ export default {
|
||||
},
|
||||
|
||||
// 加载温湿度区间设置
|
||||
async loadWsdSettings() {
|
||||
async loadWsdSettings(retryCount = 0, maxRetries = 5) {
|
||||
try {
|
||||
console.log('📊 开始加载温湿度区间设置...')
|
||||
console.log(`📊 开始加载温湿度区间设置... (第${retryCount + 1}次尝试)`)
|
||||
const response = await wsdApi.getById(1) // 获取ID为1的默认设置
|
||||
|
||||
if (response && response.id) {
|
||||
@ -450,9 +452,22 @@ export default {
|
||||
temperature: this.temperatureRange,
|
||||
humidity: this.humidityRange
|
||||
})
|
||||
} else {
|
||||
throw new Error('响应数据格式不正确')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 温湿度区间设置加载失败:', error)
|
||||
console.error(`❌ 温湿度区间设置加载失败 (第${retryCount + 1}次):`, error)
|
||||
|
||||
if (retryCount < maxRetries) {
|
||||
// 计算重试延迟时间,递增延迟
|
||||
const delay = Math.min(1000 * Math.pow(2, retryCount), 10000) // 最大延迟10秒
|
||||
console.log(`🔄 ${delay}ms后进行第${retryCount + 2}次重试...`)
|
||||
|
||||
setTimeout(() => {
|
||||
this.loadWsdSettings(retryCount + 1, maxRetries)
|
||||
}, delay)
|
||||
} else {
|
||||
console.error(`❌ 温湿度区间设置加载失败,已达到最大重试次数(${maxRetries + 1}次)`)
|
||||
// 使用默认值
|
||||
this.temperatureRange = { min: 0, max: 0 }
|
||||
this.humidityRange = { min: 0, max: 0 }
|
||||
@ -460,29 +475,49 @@ export default {
|
||||
this.humiditySettings = { ...this.humidityRange }
|
||||
console.log('🔄 使用默认温湿度区间设置')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 获取最新空调温湿度参数
|
||||
async getLatestAirConditionerTemperature() {
|
||||
async getLatestAirConditionerTemperature(retryCount = 0, maxRetries = 3) {
|
||||
try {
|
||||
console.log(`📊 开始获取空调温湿度参数... (第${retryCount + 1}次尝试)`)
|
||||
const res = await thDataApi.getLatest();
|
||||
if (res.status === 'success') {
|
||||
// 从接口获取温度和湿度设定值
|
||||
this.targetTemperature = res.temperature || 0;
|
||||
this.targetHumidity = res.humidity || 0;
|
||||
console.log('✅ 空调温湿度参数获取成功:', {
|
||||
targetTemperature: this.targetTemperature,
|
||||
targetHumidity: this.targetHumidity
|
||||
})
|
||||
} else {
|
||||
throw new Error('响应状态不正确')
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 获取最新空调温湿度参数失败:', error)
|
||||
console.error(`❌ 获取最新空调温湿度参数失败 (第${retryCount + 1}次):`, error)
|
||||
|
||||
if (retryCount < maxRetries) {
|
||||
const delay = 2000 * (retryCount + 1) // 递增延迟: 2s, 4s, 6s
|
||||
console.log(`🔄 ${delay}ms后进行第${retryCount + 2}次重试...`)
|
||||
|
||||
setTimeout(() => {
|
||||
this.getLatestAirConditionerTemperature(retryCount + 1, maxRetries)
|
||||
}, delay)
|
||||
} else {
|
||||
console.error(`❌ 空调温湿度参数获取失败,已达到最大重试次数(${maxRetries + 1}次)`)
|
||||
// 接口失败时使用默认值
|
||||
this.targetTemperature = 0;
|
||||
this.targetHumidity = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 获取最新环境数据(温湿度、PM2.5)
|
||||
async getLatestEnvironmentData() {
|
||||
async getLatestEnvironmentData(isRetry = false) {
|
||||
try {
|
||||
if (!isRetry) {
|
||||
console.log('📊 开始获取最新环境数据...')
|
||||
}
|
||||
const res = await wsdApi.getLatest();
|
||||
console.log('📊 接口返回数据:', res)
|
||||
|
||||
@ -529,6 +564,13 @@ export default {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 获取环境数据失败:', error)
|
||||
// 如果是首次调用失败,进行重试
|
||||
if (!isRetry) {
|
||||
console.log('🔄 首次获取环境数据失败,2秒后重试...')
|
||||
setTimeout(() => {
|
||||
this.getLatestEnvironmentData(true)
|
||||
}, 2000)
|
||||
}
|
||||
// 不显示错误提示,避免频繁弹窗
|
||||
}
|
||||
},
|
||||
@ -650,8 +692,8 @@ export default {
|
||||
if (temperature !== undefined && temperature !== 0 && this.temperatureRange.min !== 0 && this.temperatureRange.max !== 0) {
|
||||
if (temperature < this.temperatureRange.min || temperature > this.temperatureRange.max) {
|
||||
const alert = {
|
||||
content: `温度超出范围,${temperature}°C超出控制范围${this.temperatureRange.min}°C-${this.temperatureRange.max}°C`,
|
||||
category: "温度报警",
|
||||
content: `当前温度${temperature}°C超出控制范围${this.temperatureRange.min}°C-${this.temperatureRange.max}°C`,
|
||||
category: "温度超出范围",
|
||||
alertTime: currentTime,
|
||||
level: "中危",
|
||||
action: "检查温度",
|
||||
@ -666,8 +708,8 @@ export default {
|
||||
if (humidity !== undefined && humidity !== 0 && this.humidityRange.min !== 0 && this.humidityRange.max !== 0) {
|
||||
if (humidity < this.humidityRange.min || humidity > this.humidityRange.max) {
|
||||
const alert = {
|
||||
content: `湿度超出范围,${humidity}%超出控制范围${this.humidityRange.min}%-${this.humidityRange.max}%`,
|
||||
category: "湿度报警",
|
||||
content: `当前湿度${humidity}%超出控制范围${this.humidityRange.min}%-${this.humidityRange.max}%`,
|
||||
category: "湿度超出范围",
|
||||
alertTime: currentTime,
|
||||
level: "中危",
|
||||
action: "检查湿度",
|
||||
@ -679,14 +721,14 @@ export default {
|
||||
}
|
||||
|
||||
// 3. 温度偏差报警:|温湿度计温度 - 空调设定温度| / 空调设定温度 > 30%
|
||||
if (temperature !== undefined && this.targetTemperature > 0) {
|
||||
if (temperature !== undefined && temperature !== 0 && this.targetTemperature !== 0) {
|
||||
const temperatureDiff = Math.abs(temperature - this.targetTemperature)
|
||||
const deviationPercent = (temperatureDiff / this.targetTemperature) * 100
|
||||
|
||||
if (deviationPercent > 30) {
|
||||
const alert = {
|
||||
content: `温度偏差过大,${temperature}°C与设定${this.targetTemperature}°C偏差${deviationPercent.toFixed(1)}%`,
|
||||
category: "温度控制异常",
|
||||
content: `当前温度${temperature}°C与设定${this.targetTemperature}°C偏差${deviationPercent.toFixed(1)}%`,
|
||||
category: "温度偏差过大",
|
||||
alertTime: currentTime,
|
||||
level: "中危",
|
||||
action: "调整空调设定温度",
|
||||
@ -698,14 +740,14 @@ export default {
|
||||
}
|
||||
|
||||
// 4. 湿度偏差报警:|温湿度计湿度 - 空调设定湿度| / 空调设定湿度 > 30%
|
||||
if (humidity !== undefined && this.targetHumidity > 0) {
|
||||
if (humidity !== undefined && humidity !== 0 && this.targetHumidity !== 0) {
|
||||
const humidityDiff = Math.abs(humidity - this.targetHumidity)
|
||||
const deviationPercent = (humidityDiff / this.targetHumidity) * 100
|
||||
|
||||
if (deviationPercent > 30) {
|
||||
const alert = {
|
||||
content: `湿度偏差过大,${humidity}%与设定${this.targetHumidity}%偏差${deviationPercent.toFixed(1)}%`,
|
||||
category: "湿度控制异常",
|
||||
content: `当前湿度${humidity}%与设定${this.targetHumidity}%偏差${deviationPercent.toFixed(1)}%`,
|
||||
category: "湿度偏差过大",
|
||||
alertTime: currentTime,
|
||||
level: "中危",
|
||||
action: "调整空调设定湿度",
|
||||
@ -1018,14 +1060,66 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 空调开机控制
|
||||
async turnOnAirConditioner() {
|
||||
// 空调开关切换控制
|
||||
async toggleAirConditioner() {
|
||||
if (this.acStatus === 2) { // 运行中,执行关机
|
||||
await this.sendAirConditionerControl(2, '关机')
|
||||
// 记录关机日志
|
||||
await this.logAirConditionerOperation('关机')
|
||||
} else if (this.acStatus === 0) { // 待机,执行开机
|
||||
await this.sendAirConditionerControl(1, '开机')
|
||||
// 记录开机日志
|
||||
await this.logAirConditionerOperation('开机')
|
||||
}
|
||||
},
|
||||
|
||||
// 空调关机控制
|
||||
async turnOffAirConditioner() {
|
||||
await this.sendAirConditionerControl(2, '关机')
|
||||
// 获取空调按钮样式类
|
||||
getAcButtonClass() {
|
||||
if (this.acStatus === 2) { // 运行中
|
||||
return 'power-off'
|
||||
} else if (this.acStatus === 0) { // 待机
|
||||
return 'power-on'
|
||||
} else {
|
||||
return 'power-disabled' // 其他状态(启动中、关机中、连接中)
|
||||
}
|
||||
},
|
||||
|
||||
// 获取空调按钮文字
|
||||
getAcButtonText() {
|
||||
if (this.acStatus === 2) { // 运行中
|
||||
return '关机'
|
||||
} else if (this.acStatus === 0) { // 待机
|
||||
return '开机'
|
||||
} else {
|
||||
return this.acStatusList[this.acStatus] || '连接中'
|
||||
}
|
||||
},
|
||||
|
||||
// 判断是否可以操作空调
|
||||
canOperateAc() {
|
||||
// 只有在待机(0)或运行中(2)状态才可以操作
|
||||
return this.acStatus === 0 || this.acStatus === 2
|
||||
},
|
||||
|
||||
// 记录空调操作日志
|
||||
async logAirConditionerOperation(operation) {
|
||||
try {
|
||||
const currentTime = this.formatDateTime(new Date())
|
||||
const logEvent = {
|
||||
eventType: `空调${operation}`,
|
||||
eventTime: currentTime,
|
||||
status: "已完成",
|
||||
description: `用户手动执行空调${operation}操作`,
|
||||
deviceId: "AC_001"
|
||||
}
|
||||
|
||||
console.log(`📝 记录空调${operation}日志:`, logEvent)
|
||||
// const response = await eventApi.create(logEvent)
|
||||
console.log(`✅ 空调${operation}日志记录成功:`, response)
|
||||
} catch (error) {
|
||||
console.error(`❌ 空调${operation}日志记录失败:`, error)
|
||||
// 日志记录失败不影响主要功能,只记录错误
|
||||
}
|
||||
},
|
||||
|
||||
// 发送空调控制指令
|
||||
@ -1549,7 +1643,6 @@ export default {
|
||||
.ac-power-controls {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 8rpx;
|
||||
padding: 20rpx;
|
||||
@ -1558,8 +1651,7 @@ export default {
|
||||
}
|
||||
|
||||
.ac-power-btn {
|
||||
flex: 1;
|
||||
max-width: 120rpx;
|
||||
width: 160rpx;
|
||||
// height: 60rpx;
|
||||
border-radius: 6rpx;
|
||||
border: 1rpx solid;
|
||||
@ -1590,11 +1682,23 @@ export default {
|
||||
border-color: #c0392b;
|
||||
}
|
||||
|
||||
.power-disabled {
|
||||
background: #f39c12;
|
||||
color: white;
|
||||
// border-color: #f39c12;
|
||||
}
|
||||
|
||||
.power-disabled:active {
|
||||
background: #e67e22;
|
||||
// border-color: #e67e22;
|
||||
}
|
||||
|
||||
.ac-power-btn:disabled {
|
||||
background: #bdc3c7;
|
||||
color: #7f8c8d;
|
||||
border-color: #bdc3c7;
|
||||
background: #bdc3c7 !important;
|
||||
color: #7f8c8d !important;
|
||||
border-color: #bdc3c7 !important;
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.ac-temp-display {
|
||||
|
||||
Reference in New Issue
Block a user