From 8a78034ad384725aed2c06b09e448ba9d4a00306 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 10 Jul 2026 23:38:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0Lua=E8=84=9A=E6=9C=AC=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=B9=B6=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增配置API的force_update字段返回与保存支持,更新终端Lua脚本逻辑以支持强制更新标记,同时简化前端更新按钮,移除模拟进度条并动态切换按钮状态与显示文本。 --- gate.lua | 6 +++--- server/routes/api.js | 6 +++++- server/routes/public.js | 3 ++- ticketmachine.lua | 2 +- web/index.html | 12 ++++-------- web/index.js | 12 +----------- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/gate.lua b/gate.lua index 9de49e2..deb7efa 100644 --- a/gate.lua +++ b/gate.lua @@ -89,10 +89,9 @@ local speaker = peripheral.find("speaker") local inspection = peripheral.find("ticket_inspection_machine") local serverConnected = nil -local serverLastChangeTs = 0 -local expectedGateVersion = nil local versionMismatch = nil local pendingGateUpdate = false +local remoteForceUpdate = false local isUpdating = false local gateBusyUntilTs = 0 @@ -395,6 +394,7 @@ local function refreshRemoteLuaVersion(serverBase) local ok, parsed = getJSON(url) if not ok or type(parsed) ~= "table" then return false end local remote = normalizeVersionTag(type(parsed.lua_versions) == "table" and parsed.lua_versions.gate or nil) + remoteForceUpdate = (parsed.force_update == true) if #remote == 0 then expectedGateVersion = nil versionMismatch = nil @@ -1427,7 +1427,7 @@ while true do pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end) - if type(cfg) == "table" and type(cfg.force_update) == "boolean" and cfg.force_update == true and versionMismatch == true then + if remoteForceUpdate and versionMismatch == true then pendingGateUpdate = true end diff --git a/server/routes/api.js b/server/routes/api.js index dae9567..1c8a25d 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -162,7 +162,8 @@ router.get('/config', (req, res) => { fares: DataService.getFares(), transfers: cfg.transfers || [], promotion: cfg.promotion || { name: '', discount: 1 }, - lua_versions: cfg.lua_versions || {} + lua_versions: cfg.lua_versions || {}, + force_update: cfg.force_update === true }); }); @@ -185,6 +186,9 @@ router.put('/config', async (req, res) => { ...(incoming.lua_versions || {}) }; } + if (typeof incoming.force_update === 'boolean') { + cfg.force_update = incoming.force_update; + } await DataService.saveConfig(cfg); appendReqLog(req, { category: 'admin', type: 'update_config_generic', detail: incoming }); io.emit('config:updated', cfg); diff --git a/server/routes/public.js b/server/routes/public.js index ec2457a..5e2b759 100644 --- a/server/routes/public.js +++ b/server/routes/public.js @@ -228,7 +228,8 @@ router.get('/config', (req, res) => { const cfg = DataService.getConfig(); res.json({ promotion: { name: cfg.promotion?.name || '', discount: cfg.promotion?.discount ?? 1 }, - lua_versions: cfg.lua_versions || {} + lua_versions: cfg.lua_versions || {}, + force_update: cfg.force_update === true }); }); diff --git a/ticketmachine.lua b/ticketmachine.lua index 298805f..b7bf5ac 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -681,7 +681,7 @@ local function backgroundSyncTask() sleep(UPDATE_CHECK_INTERVAL) pcall(refreshConfigOnce) - if type(cfg) == 'table' and type(cfg.force_update) == 'boolean' and cfg.force_update == true and versionMismatch == true then + if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then pendingMachineUpdate = true end end diff --git a/web/index.html b/web/index.html index f61d163..4c5b4fe 100644 --- a/web/index.html +++ b/web/index.html @@ -815,14 +815,10 @@
-
- -
-
-
推送中... {{ updateProgress }}%
-
-
-
+
+
点击按钮后,将向全服所有终端发送更新指令,并在 5 秒内生效。
终端将在业务空闲时静默下载更新并重启,未加载的机器在加载后也会第一时间更新。 diff --git a/web/index.js b/web/index.js index 76c47dd..9283253 100644 --- a/web/index.js +++ b/web/index.js @@ -1477,13 +1477,11 @@ createApp({ }; const isPushingUpdate = ref(false); - const updateProgress = ref(0); const pushLuaUpdate = async () => { if (!confirm('确定要向所有机器推送更新指令吗?这将会使空闲机器静默更新并重启。')) return; isPushingUpdate.value = true; - updateProgress.value = 0; // 自动提升版本号 & 开启 force_update if (!config.lua_versions.ticketmachine) config.lua_versions.ticketmachine = 'v1.0.0'; @@ -1494,20 +1492,12 @@ createApp({ try { await requestJson('/api/config', { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(config) }, { expectOk: true }); - - // 模拟进度条,持续约 5 秒 (设备5秒轮询一次) - for (let i = 0; i <= 100; i += 2) { - updateProgress.value = i; - await new Promise(resolve => setTimeout(resolve, 100)); // 100ms * 50 = 5000ms - } - toast('推送指令发送完毕,终端将陆续更新', 'success'); } catch (err) { console.error(err); toast('推送更新失败', 'error'); } finally { isPushingUpdate.value = false; - updateProgress.value = 100; } }; @@ -1762,7 +1752,7 @@ createApp({ saveCurrentFare, deleteCurrentFare, closeFareModal, - saveConfig, isPushingUpdate, updateProgress, pushLuaUpdate, exportData, exportFareMap, + saveConfig, isPushingUpdate, pushLuaUpdate, exportData, exportFareMap, formatTime, formatLogDetail, getStationName, getStationInfo, loadFareMap, fetchData, refreshData: fetchData, fareMapScale, fareMapLoading, fareMapError, zoomFareMapIn, zoomFareMapOut, zoomFareMapReset, isTransferStation, getTransferTitleSuffix, getTransferLineBadges