Compare commits

...

28 Commits

Author SHA1 Message Date
xiaoshi
6e1c745a47 Update xiaoshi-pad-card.js 2026-01-03 22:08:35 +08:00
xiaoshi
e4e2a218c1 Update xiaoshi-pad-card.js 2026-01-03 22:08:27 +08:00
xiaoshi
2aeca95db9 Update xiaoshi-pad-card.js 2026-01-01 15:45:28 +08:00
xiaoshi
bf6c7d9a1a Update xiaoshi-device-todo-button.js 2026-01-01 15:45:11 +08:00
xiaoshi
b5dfe6ac0a Update xiaoshi-device-ha-info-button.js 2026-01-01 15:44:59 +08:00
xiaoshi
e4c9bcfe32 Update xiaoshi-device-consumables-button.js 2026-01-01 15:44:49 +08:00
xiaoshi
c30a918614 Update xiaoshi-device-balance-button.js 2026-01-01 15:44:35 +08:00
xiaoshi
e15cdfccaa Update xiaoshi-pad-card.js 2026-01-01 15:12:37 +08:00
xiaoshi
c0f45717d4 Update xiaoshi-pad-grid-card.js 2026-01-01 15:11:40 +08:00
xiaoshi
d57f69d4b9 Update xiaoshi-device-ha-info-card.js 2026-01-01 15:11:03 +08:00
xiaoshi
1ba54782c0 Update xiaoshi-device-ha-info-button.js 2026-01-01 15:10:42 +08:00
xiaoshi
240ce4e4ef Update xiaoshi-pad-card.js 2025-12-27 14:01:30 +08:00
xiaoshi
9d0fbaead4 Update xiaoshi-device-todo-button.js 2025-12-27 14:01:17 +08:00
xiaoshi
b357b69fa5 Update xiaoshi-device-consumables-button.js 2025-12-27 14:00:40 +08:00
xiaoshi
0d61619f8d Update xiaoshi-device-balance-button.js 2025-12-27 14:00:21 +08:00
xiaoshi
953e414a61 Update xiaoshi-device-ha-info-button.js 2025-12-27 14:00:00 +08:00
xiaoshi
8974f122b6 Update xiaoshi-device-ha-info-button.js 2025-12-27 13:59:27 +08:00
xiaoshi
6060663a24 Update xiaoshi-device-consumables-button.js 2025-12-27 13:59:08 +08:00
xiaoshi
22e7325a06 Update xiaoshi-device-balance-button.js 2025-12-27 13:58:47 +08:00
xiaoshi
67f13a23ca Update xiaoshi-pad-card.js 2025-12-27 13:08:52 +08:00
xiaoshi
56e85c834f Update xiaoshi-device-todo-button.js 2025-12-27 13:08:15 +08:00
xiaoshi
367a47d33b Update xiaoshi-device-ha-info-button.js 2025-12-27 13:07:54 +08:00
xiaoshi
6501aeead7 Update xiaoshi-device-consumables-button.js 2025-12-27 13:07:29 +08:00
xiaoshi
c93735be82 Update xiaoshi-device-balance-button.js 2025-12-27 13:06:56 +08:00
xiaoshi
740bac1c63 Update xiaoshi-device-todo-button.js 2025-12-20 01:48:48 +08:00
xiaoshi
85d413baa1 Update data refresh interval to 3 seconds
Changed the data refresh interval from 300 seconds to 3 seconds.
2025-12-20 01:48:21 +08:00
xiaoshi
128d24328b Update xiaoshi-device-consumables-button.js 2025-12-20 01:47:57 +08:00
xiaoshi
de64a44599 Update xiaoshi-device-balance-button.js 2025-12-20 01:47:29 +08:00
7 changed files with 160 additions and 332 deletions

View File

@@ -1217,7 +1217,6 @@ class XiaoshiBalanceButton extends LitElement {
super();
this._oilPriceData = [];
this._loading = false;
this._dataLoaded = false; //button新元素
this._refreshInterval = null;
this.theme = 'on';
}
@@ -1233,12 +1232,6 @@ class XiaoshiBalanceButton extends LitElement {
// 设置主题属性
this.setAttribute('theme', this._evaluateTheme());
//button新元素 开始
setTimeout(() => {
this._loadOilPriceData();
}, 50);
//button新元素 结束
// 每300秒刷新一次数据减少频繁刷新
this._refreshInterval = setInterval(() => {
this._loadOilPriceData();
@@ -1336,11 +1329,9 @@ class XiaoshiBalanceButton extends LitElement {
}
this._oilPriceData = balanceData;
this._dataLoaded = true; //button新元素
} catch (error) {
console.error('加载设备余额数据失败:', error);
this._oilPriceData = [];
this._dataLoaded = true; //button新元素
}
this._loading = false;
@@ -1662,7 +1653,7 @@ class XiaoshiBalanceButton extends LitElement {
const buttonIcon = this.config.button_icon || 'mdi:cellphone';
// 设置背景颜色
const buttonBgColor = transparentBg ? 'transparent' : bgColor;
const buttonBgColor = transparentBg ? 'transparent' : theme === 'on' ? 'rgb(255, 255, 255, 0.6)' : 'rgb(83, 83, 83, 0.6)';
// 获取显示模式
const displayMode = this.config.display_mode || 'min_value';
@@ -1674,15 +1665,7 @@ class XiaoshiBalanceButton extends LitElement {
let displayUnit = '元';
let isWarning = false; // 是否处于预警状态
if (!this._dataLoaded) {
// 数据加载中
displayValue = '加载中';
displayUnit = '';
} else if (this._oilPriceData.length === 0) {
// 无数据
displayValue = '无数据';
displayUnit = '';
} else if (displayMode === 'min_value') {
if (displayMode === 'min_value') {
// 显示最小值模式
const numericValues = this._oilPriceData
.map(item => {

View File

@@ -1286,7 +1286,6 @@ class XiaoshiConsumablesButton extends LitElement {
super();
this._oilPriceData = [];
this._loading = false;
this._dataLoaded = false; //button新元素
this._refreshInterval = null;
this.theme = 'on';
}
@@ -1301,12 +1300,6 @@ class XiaoshiConsumablesButton extends LitElement {
// 设置主题属性
this.setAttribute('theme', this._evaluateTheme());
//button新元素 开始
setTimeout(() => {
this._loadOilPriceData();
}, 50);
//button新元素 结束
// 每300秒刷新一次数据减少频繁刷新
this._refreshInterval = setInterval(() => {
@@ -1438,11 +1431,9 @@ class XiaoshiConsumablesButton extends LitElement {
}
this._oilPriceData = consumablesData;
this._dataLoaded = true; //button新元素
} catch (error) {
console.error('加载设备耗材数据失败:', error);
this._oilPriceData = [];
this._dataLoaded = true; //button新元素
}
this._loading = false;
@@ -1869,10 +1860,10 @@ class XiaoshiConsumablesButton extends LitElement {
const buttonIcon = this.config.button_icon || 'mdi:battery-sync';
// 设置背景颜色
const buttonBgColor = transparentBg ? 'transparent' : bgColor;
const buttonBgColor = transparentBg ? 'transparent' : theme === 'on' ? 'rgb(255, 255, 255, 0.6)' : 'rgb(83, 83, 83, 0.6)';
// 检查是否需要自动隐藏只有数据加载完成且数量为0时才考虑隐藏
const shouldAutoHide = this._dataLoaded && autoHide && warningCount === 0;
const shouldAutoHide = autoHide && warningCount === 0;
// 如果需要自动隐藏返回空div
if (shouldAutoHide) {
@@ -1881,95 +1872,53 @@ class XiaoshiConsumablesButton extends LitElement {
// 渲染按钮
let buttonHtml;
if (!this._dataLoaded) {
if (badgeMode) {
// 角标模式只显示图标数量为0时不显示角标
buttonHtml = html`
<div class="consumables-status badge-mode" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
</div>
`;
} else {
// 普通模式
// 应用锁定白色功能
const iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
const textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数决定是否显示0值
if (!hideZero) {
displayText += ' 0';
} else {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
}
buttonHtml = html`
<div class="consumables-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
}
if (badgeMode) {
// 角标模式:只显示图标,根据数量显示角标
const hasWarning = warningCount > 0;
buttonHtml = html`
<div class="consumables-status badge-mode ${hasWarning ? 'has-warning' : ''}" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
${hasWarning ? html`<div class="badge-number">${warningCount}</div>` : ''}
</div>
`;
} else {
// 数据加载完成后
if (badgeMode) {
// 角标模式:只显示图标,根据数量显示角标
const hasWarning = warningCount > 0;
buttonHtml = html`
<div class="consumables-status badge-mode ${hasWarning ? 'has-warning' : ''}" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
${hasWarning ? html`<div class="badge-number">${warningCount}</div>` : ''}
</div>
`;
// 普通模式:显示文本和数量
// 应用锁定白色功能,但预警颜色(红色)不受影响
let textColor, iconColor;
if (warningCount === 0) {
// 非预警状态:根据锁定白色设置决定颜色
textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
} else {
// 普通模式:显示文本和数量
// 应用锁定白色功能,但预警颜色(红色)不受影响
let textColor, iconColor;
if (warningCount === 0) {
// 非预警状态:根据锁定白色设置决定颜色
textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
} else {
// 预警状态:始终使用红色,不受锁定白色影响
textColor = 'rgb(255, 0, 0)';
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
}
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数和实际数量决定是否显示数量
if (hideZero && warningCount === 0) {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
} else {
displayText += ` ${warningCount}`;
}
buttonHtml = html`
<div class="consumables-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
// 预警状态:始终使用红色,不受锁定白色影响
textColor = 'rgb(255, 0, 0)';
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
}
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数和实际数量决定是否显示数量
if (hideZero && warningCount === 0) {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
} else {
displayText += ` ${warningCount}`;
}
buttonHtml = html`
<div class="consumables-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
}
// 返回最终的渲染结果(包括按钮和预览卡片)

View File

@@ -405,7 +405,7 @@ template: 测试模板(最好引用模板,否则大概率会报错)'>
}
customElements.define('xiaoshi-ha-info-button-editor', XiaoshiHaInfoButtonEditor);
export class XiaoshiHaInfoButton extends LitElement {
class XiaoshiHaInfoButton extends LitElement {
static get properties() {
return {
hass: Object,
@@ -416,7 +416,6 @@ export class XiaoshiHaInfoButton extends LitElement {
_offlineEntities: Array,
_loading: Boolean,
_refreshInterval: Number,
_dataLoaded: Boolean, //button新元素
theme: { type: String }
};
}
@@ -785,7 +784,6 @@ export class XiaoshiHaInfoButton extends LitElement {
this._offlineDevices = [];
this._offlineEntities = [];
this._loading = false;
this._dataLoaded = false; //button新元素
this._refreshInterval = null;
this.theme = 'on';
}
@@ -801,14 +799,7 @@ export class XiaoshiHaInfoButton extends LitElement {
// 设置主题属性
this.setAttribute('theme', this._evaluateTheme());
//button新元素 开始
setTimeout(() => {
this._loadUpdateData();
this._loadOfflineDevices();
}, 50);
//button新元素 结束
// 每300秒刷新一次数据减少频繁刷新
this._refreshInterval = setInterval(() => {
this._loadUpdateData();
@@ -990,11 +981,9 @@ export class XiaoshiHaInfoButton extends LitElement {
this._offlineDevices = offlineDevices;
this._offlineEntities = offlineEntities;
this._dataLoaded = true; //button新元素
} catch (error) {
console.error('加载离线设备失败:', error);
this._offlineDevices = [];
this._dataLoaded = true; //button新元素
}
this._loading = false;
@@ -1226,7 +1215,7 @@ export class XiaoshiHaInfoButton extends LitElement {
const regex = new RegExp(`^${regexPattern}$`, 'i'); // 不区分大小写
return regex.test(str);
}
async _loadUpdateData() {
_loadUpdateData() {
if (!this.hass) return;
this._loading = true;
@@ -1551,8 +1540,6 @@ export class XiaoshiHaInfoButton extends LitElement {
return html`${backupElements}`;
}
/*button新元素 开始*/
_handleButtonClick() {
const tapAction = this.config.tap_action;
@@ -1799,10 +1786,10 @@ export class XiaoshiHaInfoButton extends LitElement {
const buttonIcon = this.config.button_icon || 'mdi:home-assistant';
// 设置背景颜色
const buttonBgColor = transparentBg ? 'transparent' : bgColor;
const buttonBgColor = transparentBg ? 'transparent' : theme === 'on' ? 'rgb(255, 255, 255, 0.6)' : 'rgb(83, 83, 83, 0.6)';
// 检查是否需要自动隐藏只有数据加载完成且数量为0时才考虑隐藏
const shouldAutoHide = this._dataLoaded && autoHide && warningCount === 0;
const shouldAutoHide = autoHide && warningCount === 0;
// 如果需要自动隐藏返回空div
if (shouldAutoHide) {
@@ -1811,95 +1798,53 @@ export class XiaoshiHaInfoButton extends LitElement {
// 渲染按钮
let buttonHtml;
if (!this._dataLoaded) {
if (badgeMode) {
// 角标模式只显示图标数量为0时不显示角标
buttonHtml = html`
<div class="ha-info-status badge-mode" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
</div>
`;
} else {
// 普通模式
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数决定是否显示0值
if (!hideZero) {
displayText += ' 0';
} else {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
}
// 应用锁定白色功能
const iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
const textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
buttonHtml = html`
<div class="ha-info-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
}
if (badgeMode) {
// 角标模式:只显示图标,根据数量显示角标
const hasWarning = warningCount > 0;
buttonHtml = html`
<div class="ha-info-status badge-mode ${hasWarning ? 'has-warning' : ''}" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
${hasWarning ? html`<div class="badge-number">${warningCount}</div>` : ''}
</div>
`;
} else {
// 数据加载完成后
if (badgeMode) {
// 角标模式:只显示图标,根据数量显示角标
const hasWarning = warningCount > 0;
buttonHtml = html`
<div class="ha-info-status badge-mode ${hasWarning ? 'has-warning' : ''}" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
${hasWarning ? html`<div class="badge-number">${warningCount}</div>` : ''}
</div>
`;
// 普通模式:显示文本和数量
// 应用锁定白色功能,但预警颜色(红色)不受影响
let textColor, iconColor;
if (warningCount === 0) {
// 非预警状态:根据锁定白色设置决定颜色
textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
} else {
// 普通模式:显示文本和数量
// 应用锁定白色功能,但预警颜色(红色)不受影响
let textColor, iconColor;
if (warningCount === 0) {
// 非预警状态:根据锁定白色设置决定颜色
textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
} else {
// 预警状态:始终使用红色,不受锁定白色影响
textColor = 'rgb(255, 0, 0)';
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
}
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数和实际数量决定是否显示数量
if (hideZero && warningCount === 0) {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
} else {
displayText += ` ${warningCount}`;
}
buttonHtml = html`
<div class="ha-info-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
// 预警状态:始终使用红色,不受锁定白色影响
textColor = 'rgb(255, 0, 0)';
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
}
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数和实际数量决定是否显示数量
if (hideZero && warningCount === 0) {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
} else {
displayText += ` ${warningCount}`;
}
buttonHtml = html`
<div class="ha-info-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
}
return html`

View File

@@ -153,7 +153,7 @@ class XiaoshiHaInfoCardEditor extends LitElement {
}
customElements.define('xiaoshi-ha-info-card-editor', XiaoshiHaInfoCardEditor);
export class XiaoshiHaInfoCard extends LitElement {
class XiaoshiHaInfoCard extends LitElement {
static get properties() {
return {
hass: Object,

View File

@@ -1107,7 +1107,6 @@ class XiaoshiTodoButton extends LitElement {
super();
this._todoData = [];
this._loading = false;
this._dataLoaded = false; //button新元素
this._refreshInterval = null;
this.theme = 'on';
this._editingItem = null;
@@ -1122,19 +1121,13 @@ class XiaoshiTodoButton extends LitElement {
super.connectedCallback();
this._loadTodoData();
//button新元素 开始
setTimeout(() => {
this._loadTodoData();
}, 50);
//button新元素 结束
// 设置主题属性
this.setAttribute('theme', this._evaluateTheme());
// 每300秒刷新一次数据减少频繁刷新
this._refreshInterval = setInterval(() => {
this._loadTodoData();
}, 300000);
}, 3000);
}
_evaluateTheme() {
@@ -1272,11 +1265,9 @@ class XiaoshiTodoButton extends LitElement {
}
this._todoData = todoData;
this._dataLoaded = true; //button新元素
} catch (error) {
console.error('加载待办事项数据失败:', error);
this._todoData = [];
this._dataLoaded = true; //button新元素
}
this._loading = false;
@@ -1636,10 +1627,10 @@ class XiaoshiTodoButton extends LitElement {
const buttonIcon = this.config.button_icon || 'mdi:clipboard-list';
// 设置背景颜色
const buttonBgColor = transparentBg ? 'transparent' : bgColor;
const buttonBgColor = transparentBg ? 'transparent' : theme === 'on' ? 'rgb(255, 255, 255, 0.6)' : 'rgb(83, 83, 83, 0.6)';
// 检查是否需要自动隐藏只有数据加载完成且数量为0时才考虑隐藏
const shouldAutoHide = this._dataLoaded && autoHide && totalIncompleteCount === 0;
const shouldAutoHide = autoHide && totalIncompleteCount === 0;
// 如果需要自动隐藏返回空div
if (shouldAutoHide) {
@@ -1648,95 +1639,55 @@ class XiaoshiTodoButton extends LitElement {
// 渲染按钮
let buttonHtml;
if (!this._dataLoaded) {
if (badgeMode) {
// 角标模式只显示图标数量为0时不显示角标
buttonHtml = html`
<div class="todo-status badge-mode" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
</div>
`;
} else {
// 普通模式
// 应用锁定白色功能
const iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
const textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数决定是否显示0值
if (!hideZero) {
displayText += ' 0';
} else {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
}
buttonHtml = html`
<div class="todo-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
}
// 数据加载完成后
if (badgeMode) {
// 角标模式:只显示图标,根据数量显示角标
const hasWarning = totalIncompleteCount > 0;
buttonHtml = html`
<div class="todo-status badge-mode ${hasWarning ? 'has-warning' : ''}" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
${hasWarning ? html`<div class="badge-number">${totalIncompleteCount}</div>` : ''}
</div>
`;
} else {
// 数据加载完成后
if (badgeMode) {
// 角标模式:只显示图标,根据数量显示角标
const hasWarning = totalIncompleteCount > 0;
buttonHtml = html`
<div class="todo-status badge-mode ${hasWarning ? 'has-warning' : ''}" style="--bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
<ha-icon class="status-icon" icon="${buttonIcon}"></ha-icon>
${hasWarning ? html`<div class="badge-number">${totalIncompleteCount}</div>` : ''}
</div>
`;
// 普通模式:显示文本和数量
// 应用锁定白色功能,但预警颜色(红色)不受影响
let textColor, iconColor;
if (totalIncompleteCount === 0) {
// 非预警状态:根据锁定白色设置决定颜色
textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
} else {
// 普通模式:显示文本和数量
// 应用锁定白色功能,但预警颜色(红色)不受影响
let textColor, iconColor;
if (totalIncompleteCount === 0) {
// 非预警状态:根据锁定白色设置决定颜色
textColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
} else {
// 预警状态:始终使用红色,不受锁定白色影响
textColor = 'rgb(255, 0, 0)';
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
}
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数和实际数量决定是否显示数量
if (hideZero && totalIncompleteCount === 0) {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
} else {
displayText += ` ${totalIncompleteCount}`;
}
buttonHtml = html`
<div class="todo-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
// 预警状态:始终使用红色,不受锁定白色影响
textColor = 'rgb(255, 0, 0)';
iconColor = lockWhiteFg ? 'rgb(255, 255, 255)' : fgColor;
}
// 构建显示文本
let displayText = buttonText;
// 根据hide_colon参数决定是否显示冒号
if (!hideColon) {
displayText += ':';
} else {
displayText += ' ';
}
// 根据hide_zero参数和实际数量决定是否显示数量
if (hideZero && totalIncompleteCount === 0) {
// 隐藏0值时使用CSS空格占位符保持布局稳定
displayText += '\u2002'; // 两个en空格大约等于数字"0"的宽度
} else {
displayText += ` ${totalIncompleteCount}`;
}
buttonHtml = html`
<div class="todo-status" style="--fg-color: ${textColor}; --bg-color: ${buttonBgColor};" @click=${this._handleButtonClick}>
${!hideIcon ? html`<ha-icon class="status-icon" style="color: ${iconColor};" icon="${buttonIcon}"></ha-icon>` : ''}
${displayText}
</div>
`;
}
// 返回最终的渲染结果(包括按钮和预览卡片)

View File

@@ -1,15 +1,15 @@
console.info("%c 消逝卡-平板端 \n%c v 0.2.1 ", "color: red; font-weight: bold; background: black", "color: white; font-weight: bold; background: black");
console.info("%c 消逝卡-平板端 \n%c v 0.2.7 ", "color: red; font-weight: bold; background: black", "color: white; font-weight: bold; background: black");
const loadCards = async () => {
await import('./xiaoshi-pad-grid-card.js');
await import('./xiaoshi-device-balance-card.js');
await import('./xiaoshi-device-balance-button.js');
await import('./xiaoshi-device-todo-card.js');
await import('./xiaoshi-device-todo-button.js');
await import('./xiaoshi-device-consumables-card.js');
await import('./xiaoshi-device-consumables-button.js');
await import('./xiaoshi-device-ha-info-card.js');
await import('./xiaoshi-device-ha-info-button.js');
const loadCards = () => {
import('./xiaoshi-device-balance-button.js');
import('./xiaoshi-device-ha-info-button.js');
import('./xiaoshi-device-todo-button.js');
import('./xiaoshi-device-consumables-button.js');
import('./xiaoshi-device-balance-card.js');
import('./xiaoshi-device-ha-info-card.js');
import('./xiaoshi-device-todo-card.js');
import('./xiaoshi-device-consumables-card.js');
import('./xiaoshi-pad-grid-card.js');
window.customCards = window.customCards || [];
window.customCards.push(...cardConfigs);

View File

@@ -1,6 +1,6 @@
import { LitElement, html, css } from "https://unpkg.com/lit-element@2.4.0/lit-element.js?module";
export class XiaoshiPadGridCard extends LitElement {
class XiaoshiPadGridCard extends LitElement {
static get properties() {
return {
hass: Object,