feat: 增加机器位置手动编辑功能及公开查看界面

This commit is contained in:
2026-07-11 15:43:17 +08:00
parent becd8f0e20
commit 84dbdf58c4
13 changed files with 316 additions and 51 deletions
+9 -1
View File
@@ -95,6 +95,9 @@ const DataService = {
if (configs.length > 0) cache.config = normalizeConfig(configs[0].v);
else await conn.query('INSERT INTO kv_store (k, v) VALUES (?, ?)', ['config', JSON.stringify(cache.config)]);
const [machLocs] = await conn.query('SELECT v FROM kv_store WHERE k = ?', ['machine_locations']);
if (machLocs.length > 0) cache.machineLocations = machLocs[0].v || {};
const [stations] = await conn.query('SELECT data FROM stations');
cache.stations = stations.map(r => r.data);
@@ -526,11 +529,16 @@ const DataService = {
},
getMachineLocations: () => cache.machineLocations,
updateMachineLocation: (deviceId, data) => {
updateMachineLocation: async (deviceId, data) => {
cache.machineLocations[deviceId] = {
...cache.machineLocations[deviceId],
...data,
last_update_ts: Date.now()
};
try {
await pool.query('INSERT INTO kv_store (k, v) VALUES (?, ?) ON DUPLICATE KEY UPDATE v = VALUES(v)',
['machine_locations', JSON.stringify(cache.machineLocations)]);
} catch(e) { console.error('updateMachineLocation error', e); }
}
};