From 3738b0b092283a7fbfc787f8cc5a0033c0201259 Mon Sep 17 00:00:00 2001
From: xiaoshi <115949669+xiaoshi930@users.noreply.github.com>
Date: Tue, 25 Nov 2025 19:51:37 +0800
Subject: [PATCH] Update xiaoshi-device-consumables-card.js
---
xiaoshi-device-consumables-card.js | 221 ++++++++++++++++++++---------
1 file changed, 155 insertions(+), 66 deletions(-)
diff --git a/xiaoshi-device-consumables-card.js b/xiaoshi-device-consumables-card.js
index 11643d7..42c04ef 100644
--- a/xiaoshi-device-consumables-card.js
+++ b/xiaoshi-device-consumables-card.js
@@ -251,6 +251,18 @@ class XiaoshiConsumablesCardEditor extends LitElement {
+
+
+
+
+
-
- ${this._loading ?
- html`
加载中...
` :
-
- this._oilPriceData.length === 0 ?
- html`
请配置耗材实体
` :
- html`
- ${this._oilPriceData.map(consumablesData => {
- // 明细预警优先级最高
- let isWarning = false;
-
- // 首先检查明细预警,如果存在且满足条件,直接设为预警状态
- if (consumablesData.warning_threshold && consumablesData.warning_threshold.trim() !== '') {
- isWarning = this._evaluateWarningCondition(consumablesData.value, consumablesData.warning_threshold);
- console.log(`明细预警 - 实体: ${consumablesData.friendly_name}, 值: "${consumablesData.value}", 条件: "${consumablesData.warning_threshold}", 预警: ${isWarning}`);
- } else {
- // 只有在没有明细预警时才检查全局预警
- if (this.config.global_warning && this.config.global_warning.trim() !== '') {
- isWarning = this._evaluateWarningCondition(consumablesData.value, this.config.global_warning);
- console.log(`全局预警 - 实体: ${consumablesData.friendly_name}, 值: "${consumablesData.value}", 条件: "${this.config.global_warning}", 预警: ${isWarning}`);
- }
- }
-
- return html`
-
this._handleEntityClick(consumablesData)}>
-
-
-
${consumablesData.friendly_name}
-
-
- ${consumablesData.value}
- ${consumablesData.unit}
-
-
- `;
- })}
- `
- }
-
+ ${this._loading ?
+ html`加载中...
` :
+
+ this._oilPriceData.length === 0 ?
+ html`请配置耗材实体
` :
+ this.config.columns === '1' ? html`
+
+ ${this._oilPriceData.map(consumablesData => this._renderDeviceItem(consumablesData))}
+
+ ` : html`
+
+ ${this._oilPriceData.map(consumablesData => this._renderDeviceItem(consumablesData))}
+
+ `
+ }
`;
}
@@ -1094,19 +1186,16 @@ class XiaoshiConsumablesCard extends LitElement {
setConfig(config) {
this.config = config;
- // 设置CSS变量来控制卡片的宽度和高度
if (config.width) {
this.style.setProperty('--card-width', config.width);
}
- // 设置主题
if (config.theme) {
this.setAttribute('theme', config.theme);
}
}
getCardSize() {
- // 根据设备耗材实体数量动态计算卡片大小
const baseSize = 3;
const entitySize = Math.max(0, Math.min(this._oilPriceData.length * 2, 10));
return baseSize + entitySize;