refactor(feeder): remove batch set-unit from platform config
Batch equipment-unit assignment is now handled via the "选择设备" modal in app-config. Remove the batch toolbar, checkbox selection, and related JS/state from the equipment panel in platform config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3a9b52864b
commit
6b9e396044
|
|
@ -1,17 +0,0 @@
|
||||||
<section class="panel top-left">
|
|
||||||
<div class="panel-head">
|
|
||||||
<h2>设备</h2>
|
|
||||||
<button type="button" id="newEquipmentBtn">+ 新增</button>
|
|
||||||
</div>
|
|
||||||
<div class="toolbar equipment-toolbar">
|
|
||||||
<input id="equipmentKeyword" placeholder="搜索编码或名称" />
|
|
||||||
<button type="button" class="secondary" id="refreshEquipmentBtn">刷新</button>
|
|
||||||
</div>
|
|
||||||
<div class="toolbar equipment-batch-toolbar">
|
|
||||||
<div class="muted" id="selectedEquipmentSummary">已选 0 台设备</div>
|
|
||||||
<select id="equipmentBatchUnitId"></select>
|
|
||||||
<button type="button" class="secondary" id="clearEquipmentSelectionBtn">清空选择</button>
|
|
||||||
<button type="button" id="applyEquipmentUnitBtn">批量设单元</button>
|
|
||||||
</div>
|
|
||||||
<div class="list equipment-list" id="equipmentList"></div>
|
|
||||||
</section>
|
|
||||||
|
|
@ -4,9 +4,7 @@ import { dom } from "./dom.js";
|
||||||
import { closeApiDocDrawer, openApiDocDrawer, openReadmeDrawer } from "./docs.js";
|
import { closeApiDocDrawer, openApiDocDrawer, openReadmeDrawer } from "./docs.js";
|
||||||
import { loadEvents } from "./events.js";
|
import { loadEvents } from "./events.js";
|
||||||
import {
|
import {
|
||||||
applyBatchEquipmentUnit,
|
|
||||||
clearPointBinding,
|
clearPointBinding,
|
||||||
clearSelectedEquipments,
|
|
||||||
closeEquipmentModal,
|
closeEquipmentModal,
|
||||||
loadEquipments,
|
loadEquipments,
|
||||||
openCreateEquipmentModal,
|
openCreateEquipmentModal,
|
||||||
|
|
@ -105,9 +103,6 @@ function bindEvents() {
|
||||||
dom.refreshEquipmentBtn.addEventListener("click", () => withStatus(loadEquipments()));
|
dom.refreshEquipmentBtn.addEventListener("click", () => withStatus(loadEquipments()));
|
||||||
dom.newEquipmentBtn.addEventListener("click", openCreateEquipmentModal);
|
dom.newEquipmentBtn.addEventListener("click", openCreateEquipmentModal);
|
||||||
dom.closeEquipmentModalBtn.addEventListener("click", closeEquipmentModal);
|
dom.closeEquipmentModalBtn.addEventListener("click", closeEquipmentModal);
|
||||||
dom.applyEquipmentUnitBtn.addEventListener("click", () => withStatus(applyBatchEquipmentUnit()));
|
|
||||||
dom.clearEquipmentSelectionBtn.addEventListener("click", clearSelectedEquipments);
|
|
||||||
|
|
||||||
dom.openPointModalBtn.addEventListener("click", openPointCreateModal);
|
dom.openPointModalBtn.addEventListener("click", openPointCreateModal);
|
||||||
dom.pointSourceSelect.addEventListener("change", () => {
|
dom.pointSourceSelect.addEventListener("change", () => {
|
||||||
dom.nodeTree.innerHTML = '<div class="muted">Click "Load Nodes" to fetch node tree</div>';
|
dom.nodeTree.innerHTML = '<div class="muted">Click "Load Nodes" to fetch node tree</div>';
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,6 @@ export const dom = {
|
||||||
equipmentDescription: byId("equipmentDescription"),
|
equipmentDescription: byId("equipmentDescription"),
|
||||||
equipmentResetBtn: byId("equipmentReset"),
|
equipmentResetBtn: byId("equipmentReset"),
|
||||||
equipmentKeyword: byId("equipmentKeyword"),
|
equipmentKeyword: byId("equipmentKeyword"),
|
||||||
equipmentBatchUnitId: byId("equipmentBatchUnitId"),
|
|
||||||
selectedEquipmentSummary: byId("selectedEquipmentSummary"),
|
|
||||||
equipmentList: byId("equipmentList"),
|
equipmentList: byId("equipmentList"),
|
||||||
refreshUnitBtn: byId("refreshUnitBtn"),
|
refreshUnitBtn: byId("refreshUnitBtn"),
|
||||||
newUnitBtn: byId("newUnitBtn"),
|
newUnitBtn: byId("newUnitBtn"),
|
||||||
|
|
@ -77,8 +75,6 @@ export const dom = {
|
||||||
closeUnitModalBtn: byId("closeUnitModal"),
|
closeUnitModalBtn: byId("closeUnitModal"),
|
||||||
closeEquipmentModalBtn: byId("closeEquipmentModal"),
|
closeEquipmentModalBtn: byId("closeEquipmentModal"),
|
||||||
refreshEventBtn: byId("refreshEventBtn"),
|
refreshEventBtn: byId("refreshEventBtn"),
|
||||||
applyEquipmentUnitBtn: byId("applyEquipmentUnitBtn"),
|
|
||||||
clearEquipmentSelectionBtn: byId("clearEquipmentSelectionBtn"),
|
|
||||||
pointBindingForm: byId("pointBindingForm"),
|
pointBindingForm: byId("pointBindingForm"),
|
||||||
bindingPointId: byId("bindingPointId"),
|
bindingPointId: byId("bindingPointId"),
|
||||||
bindingPointName: byId("bindingPointName"),
|
bindingPointName: byId("bindingPointName"),
|
||||||
|
|
|
||||||
|
|
@ -40,26 +40,6 @@ function renderEquipmentUnitOptions(selected = "", target = dom.equipmentUnitId)
|
||||||
target.innerHTML = options.join("");
|
target.innerHTML = options.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderBatchUnitOptions(selected = "") {
|
|
||||||
if (!dom.equipmentBatchUnitId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = ['<option value="">批量绑定到单元...</option>'];
|
|
||||||
state.units.forEach((unit) => {
|
|
||||||
const isSelected = unit.id === selected ? "selected" : "";
|
|
||||||
options.push(`<option value="${unit.id}" ${isSelected}>${unit.code} / ${unit.name}</option>`);
|
|
||||||
});
|
|
||||||
dom.equipmentBatchUnitId.innerHTML = options.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSelectedEquipmentSummary() {
|
|
||||||
if (!dom.selectedEquipmentSummary) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dom.selectedEquipmentSummary.textContent = `已选 ${state.selectedEquipmentIds.size} 台设备`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function renderBindingEquipmentOptions(selected = "", target = dom.bindingEquipmentId) {
|
export function renderBindingEquipmentOptions(selected = "", target = dom.bindingEquipmentId) {
|
||||||
const options = ['<option value="">Unbound</option>'];
|
const options = ['<option value="">Unbound</option>'];
|
||||||
filteredEquipments().forEach((item) => {
|
filteredEquipments().forEach((item) => {
|
||||||
|
|
@ -119,21 +99,6 @@ async function selectEquipment(equipmentId) {
|
||||||
await loadPoints();
|
await loadPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleEquipmentSelection(equipmentId, checked) {
|
|
||||||
if (checked) {
|
|
||||||
state.selectedEquipmentIds.add(equipmentId);
|
|
||||||
} else {
|
|
||||||
state.selectedEquipmentIds.delete(equipmentId);
|
|
||||||
}
|
|
||||||
updateSelectedEquipmentSummary();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearSelectedEquipments() {
|
|
||||||
state.selectedEquipmentIds.clear();
|
|
||||||
renderEquipments();
|
|
||||||
updateSelectedEquipmentSummary();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearEquipmentFilter() {
|
export function clearEquipmentFilter() {
|
||||||
state.selectedEquipmentId = null;
|
state.selectedEquipmentId = null;
|
||||||
state.pointsPage = 1;
|
state.pointsPage = 1;
|
||||||
|
|
@ -144,7 +109,6 @@ export function clearEquipmentFilter() {
|
||||||
|
|
||||||
export function renderEquipments() {
|
export function renderEquipments() {
|
||||||
dom.equipmentList.innerHTML = "";
|
dom.equipmentList.innerHTML = "";
|
||||||
updateSelectedEquipmentSummary();
|
|
||||||
|
|
||||||
const items = filteredEquipments();
|
const items = filteredEquipments();
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
|
|
@ -157,10 +121,6 @@ export function renderEquipments() {
|
||||||
const box = document.createElement("div");
|
const box = document.createElement("div");
|
||||||
box.className = `list-item equipment-card ${state.selectedEquipmentId === equipment.id ? "selected" : ""}`;
|
box.className = `list-item equipment-card ${state.selectedEquipmentId === equipment.id ? "selected" : ""}`;
|
||||||
box.innerHTML = `
|
box.innerHTML = `
|
||||||
<label class="equipment-select-row">
|
|
||||||
<input type="checkbox" data-equipment-select="true" ${state.selectedEquipmentIds.has(equipment.id) ? "checked" : ""} />
|
|
||||||
<span class="muted">批量选择</span>
|
|
||||||
</label>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<strong>${equipment.code}</strong>
|
<strong>${equipment.code}</strong>
|
||||||
<span class="badge">${item.point_count ?? 0} pts</span>
|
<span class="badge">${item.point_count ?? 0} pts</span>
|
||||||
|
|
@ -177,14 +137,6 @@ export function renderEquipments() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkbox = box.querySelector('input[data-equipment-select="true"]');
|
|
||||||
checkbox.addEventListener("click", (event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
});
|
|
||||||
checkbox.addEventListener("change", (event) => {
|
|
||||||
toggleEquipmentSelection(equipment.id, event.target.checked);
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionRow = box.querySelector(".equipment-card-actions");
|
const actionRow = box.querySelector(".equipment-card-actions");
|
||||||
|
|
||||||
const editBtn = document.createElement("button");
|
const editBtn = document.createElement("button");
|
||||||
|
|
@ -254,14 +206,7 @@ export async function loadEquipments() {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
state.selectedEquipmentIds.forEach((id) => {
|
|
||||||
if (!state.equipmentMap.has(id)) {
|
|
||||||
state.selectedEquipmentIds.delete(id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
renderEquipmentUnitOptions(dom.equipmentUnitId?.value || "");
|
renderEquipmentUnitOptions(dom.equipmentUnitId?.value || "");
|
||||||
renderBatchUnitOptions(dom.equipmentBatchUnitId?.value || "");
|
|
||||||
dom.equipmentKind.innerHTML = renderEquipmentKindOptions(dom.equipmentKind?.value || "");
|
dom.equipmentKind.innerHTML = renderEquipmentKindOptions(dom.equipmentKind?.value || "");
|
||||||
renderBindingEquipmentOptions();
|
renderBindingEquipmentOptions();
|
||||||
renderBatchBindingDefaults();
|
renderBatchBindingDefaults();
|
||||||
|
|
@ -301,25 +246,6 @@ export async function saveEquipment(event) {
|
||||||
await loadPoints();
|
await loadPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function applyBatchEquipmentUnit() {
|
|
||||||
if (!state.selectedEquipmentIds.size) {
|
|
||||||
throw new Error("请先选择设备");
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = dom.equipmentBatchUnitId.value;
|
|
||||||
await apiFetch("/api/equipment/batch/set-unit", {
|
|
||||||
method: "PUT",
|
|
||||||
body: JSON.stringify({
|
|
||||||
equipment_ids: Array.from(state.selectedEquipmentIds),
|
|
||||||
unit_id: value || null,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
clearSelectedEquipments();
|
|
||||||
renderBatchUnitOptions("");
|
|
||||||
await loadEquipments();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteEquipment(equipmentId) {
|
export async function deleteEquipment(equipmentId) {
|
||||||
if (!window.confirm("Delete this equipment?")) {
|
if (!window.confirm("Delete this equipment?")) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -329,7 +255,6 @@ export async function deleteEquipment(equipmentId) {
|
||||||
if (state.selectedEquipmentId === equipmentId) {
|
if (state.selectedEquipmentId === equipmentId) {
|
||||||
state.selectedEquipmentId = null;
|
state.selectedEquipmentId = null;
|
||||||
}
|
}
|
||||||
state.selectedEquipmentIds.delete(equipmentId);
|
|
||||||
resetEquipmentForm();
|
resetEquipmentForm();
|
||||||
closeEquipmentModal();
|
closeEquipmentModal();
|
||||||
clearSelectedPoints();
|
clearSelectedPoints();
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ export const state = {
|
||||||
equipments: [],
|
equipments: [],
|
||||||
equipmentMap: new Map(),
|
equipmentMap: new Map(),
|
||||||
selectedEquipmentId: null,
|
selectedEquipmentId: null,
|
||||||
selectedEquipmentIds: new Set(),
|
|
||||||
selectedSourceId: null,
|
selectedSourceId: null,
|
||||||
selectedNodeIds: new Set(),
|
selectedNodeIds: new Set(),
|
||||||
selectedPointIds: new Set(),
|
selectedPointIds: new Set(),
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,6 @@ export async function loadUnits() {
|
||||||
|
|
||||||
renderUnits();
|
renderUnits();
|
||||||
renderUnitOptions(dom.equipmentUnitId?.value || "", dom.equipmentUnitId);
|
renderUnitOptions(dom.equipmentUnitId?.value || "", dom.equipmentUnitId);
|
||||||
renderUnitOptions(dom.equipmentBatchUnitId?.value || "", dom.equipmentBatchUnitId);
|
|
||||||
document.dispatchEvent(new Event("units-loaded"));
|
document.dispatchEvent(new Event("units-loaded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue