mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-14 14:08:19 +08:00
在后台增加6个开关重命名功能,名称将同步到ha mqtt设备中
This commit is contained in:
@@ -147,7 +147,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-1
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-1</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -159,7 +166,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-2
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-2</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -171,7 +185,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-3
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-3</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -183,7 +204,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-4
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-4</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -195,7 +223,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-5
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-5</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -207,7 +242,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-6
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-6</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -544,6 +586,10 @@
|
||||
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
</g>
|
||||
<g id="icon-edit">
|
||||
<path d="M5,3C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19H5V5H12V3H5M17.78,4C17.61,4 17.43,4.07 17.3,4.2L16.08,5.41L18.58,7.91L19.8,6.7C20.06,6.44 20.06,6 19.8,5.75L18.25,4.2C18.12,4.07 17.95,4 17.78,4M15.37,6.12L8,13.5V16H10.5L17.87,8.62L15.37,6.12Z" />
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
</g>
|
||||
<g id="icon-translate">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"/>
|
||||
@@ -731,12 +777,18 @@
|
||||
HttpGet("/status", function (re) {
|
||||
var status = JSON.parse(re);
|
||||
var status_arr = status.sockets.split(",");
|
||||
var names_arr = status.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
for (var i = 0; i < status_arr.length; i++) {
|
||||
var langSpan = switchTexts[i+2].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+2].querySelector('.socket-index');
|
||||
if (langSpan) langSpan.textContent = names_arr[i]; // 修改插座名称
|
||||
if (indexSpan) indexSpan.textContent = ""; // 修改序号,可自定义起始数字
|
||||
//checkboxs[i].checked = status_arr[i] == "1";
|
||||
if (status_arr[i] == "1") {
|
||||
switch_lables[i].MaterialSwitch.on();
|
||||
switch_lables[i+2].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[i].MaterialSwitch.off();
|
||||
switch_lables[i+2].MaterialSwitch.off();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,6 +866,38 @@
|
||||
}, checkboxs[0].checked ? "1" : "0");
|
||||
|
||||
});
|
||||
|
||||
$(".edit-socket-name").on("click", function () {
|
||||
// 获取当前按钮所在的 li 元素
|
||||
var $li = $(this).closest(".mdl-list__item");
|
||||
|
||||
// 获取当前索引
|
||||
var index = $(".edit-socket-name").index(this);
|
||||
|
||||
// 获取 lang 名称和 socket-index 元素
|
||||
var $lang = $li.find(".lang");
|
||||
var $index = $li.find(".socket-index");
|
||||
|
||||
// 原名称
|
||||
var oldName = $lang.text().trim();
|
||||
|
||||
// 弹窗编辑
|
||||
var newName = prompt("请输入新的插座名称", oldName);
|
||||
if (newName && newName.trim() !== "") {
|
||||
$lang.text(newName.trim());
|
||||
// 可选:更新序号
|
||||
$index.text("");
|
||||
// 🔸 编辑完成后,获取所有名称并拼接
|
||||
var allNames = [];
|
||||
$(".mdl-list__item .lang").each(function () {
|
||||
allNames.push('"' + $(this).text().trim() + '"');
|
||||
});
|
||||
var nameString = allNames.join(',');
|
||||
HttpPost("/socketNames", function (re) {
|
||||
}, nameString);});
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("list-switch-all").addEventListener("click", function() {
|
||||
HttpPost("/socketAll", function (re) {
|
||||
}, checkboxs[1].checked ? "1" : "0");});
|
||||
@@ -979,8 +1063,14 @@
|
||||
switch_lables[1].MaterialSwitch.off();
|
||||
}
|
||||
var status_arr = power.sockets.split(",");
|
||||
var names_arr = power.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
for (var i = 0; i < status_arr.length; i++) {
|
||||
//checkboxs[i].checked = status_arr[i] == "1";
|
||||
var langSpan = switchTexts[i+2].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+2].querySelector('.socket-index');
|
||||
if (langSpan) langSpan.textContent = names_arr[i]; // 修改插座名称
|
||||
if (indexSpan) indexSpan.textContent = ""; // 修改序号,可自定义起始数字
|
||||
if (status_arr[i] == "1") {
|
||||
switch_lables[i+2].MaterialSwitch.on();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user