diff --git a/web/index.html b/web/index.html index f6882f0..f61d163 100644 --- a/web/index.html +++ b/web/index.html @@ -815,21 +815,17 @@
-
- 售票机 - - +
+
-
- 检票机 - - +
+
推送中... {{ updateProgress }}%
+
+
+
- 每次发布新的 Lua 脚本后,在这里手动提升一次版本号;设备检测到不一致时会在左上角版本号旁显示更新标记。 -
-
- + 点击按钮后,将向全服所有终端发送更新指令,并在 5 秒内生效。
终端将在业务空闲时静默下载更新并重启,未加载的机器在加载后也会第一时间更新。
diff --git a/web/index.js b/web/index.js index 5a4f41f..76c47dd 100644 --- a/web/index.js +++ b/web/index.js @@ -1476,10 +1476,39 @@ createApp({ }, { successMessage: '保存成功' }); }; - const bumpLuaVersion = async (device) => { - if (!config.lua_versions[device]) config.lua_versions[device] = 'v1.0.0'; - config.lua_versions[device] = bumpPatchVersion(config.lua_versions[device]); - await saveConfig(); + 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'; + if (!config.lua_versions.gate) config.lua_versions.gate = 'v1.0.0'; + config.lua_versions.ticketmachine = bumpPatchVersion(config.lua_versions.ticketmachine); + config.lua_versions.gate = bumpPatchVersion(config.lua_versions.gate); + config.force_update = true; + + 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; + } }; const exportData = () => { @@ -1733,7 +1762,7 @@ createApp({ saveCurrentFare, deleteCurrentFare, closeFareModal, - saveConfig, bumpLuaVersion, exportData, exportFareMap, + saveConfig, isPushingUpdate, updateProgress, pushLuaUpdate, exportData, exportFareMap, formatTime, formatLogDetail, getStationName, getStationInfo, loadFareMap, fetchData, refreshData: fetchData, fareMapScale, fareMapLoading, fareMapError, zoomFareMapIn, zoomFareMapOut, zoomFareMapReset, isTransferStation, getTransferTitleSuffix, getTransferLineBadges