From d2809c4d6d6f361d89c90c35dd30b4aa30aed9ab Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 10 Jul 2026 11:33:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E4=B8=9C=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- ticketmachine.lua | 22 +++------- update-db.js | 35 ++++++++++++++++ web/ic-card-admin.js | 6 ++- web/ic-card-search.js | 6 ++- web/index.js | 12 +++++- web/ticket-board.html | 30 +++++++++++-- web/ticket-route.js | 6 ++- web/ticket-search.js | 97 ++++++++++++++++++++++++++++++++----------- 9 files changed, 166 insertions(+), 50 deletions(-) create mode 100644 update-db.js diff --git a/package.json b/package.json index 1abebd7..55db365 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ticketmachine", - "version": "1.0.14", + "version": "1.0.15", "main": "server/index.js", "scripts": { "start": "node server/index.js", diff --git a/ticketmachine.lua b/ticketmachine.lua index e0390ca..6c5d31c 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -1,6 +1,6 @@ local CURRENT_STATION_CODE = 'Ticket-Machine' local API_BASE = 'http://ticket.fse-media.group/api' -local VERSION = 'v1.5.11' +local VERSION = 'v1.5.12' -- ########################### -- Core HTTP & JSON Utilities @@ -239,10 +239,7 @@ local function firstNumber(...) end local function currentDeviceId() - local dev = nil - if os.getComputerLabel then dev = os.getComputerLabel() end - if not dev and os.getComputerID then dev = tostring(os.getComputerID()) end - return tostring(dev or 'unknown') + return 'ticket_machine' end local function normalizeTrainTypeLabel(v) @@ -658,10 +655,6 @@ local function backgroundSyncTask() sleep(5) pcall(refreshConfigOnce) if versionMismatch == true then - pcall(function() - clear() - centerText(math.floor(h/2), "Auto Updating...", colors.yellow) - end) pcall(function() if shell and type(shell.run) == "function" then shell.run("update_machine.lua") @@ -669,7 +662,7 @@ local function backgroundSyncTask() os.run(getfenv and getfenv() or _ENV, "update_machine.lua") end end) - os.reboot() + -- Removed os.reboot() to prevent interrupting user unexpectedly end end end @@ -963,9 +956,7 @@ local function waitButtons() end end elseif ev == 'config_updated' then - singleSegments = nil - -- If config was updated in background, return to force UI re-render - return + -- Ignore config_updated while waiting for buttons, to prevent interrupting user's selection end end end @@ -1211,10 +1202,9 @@ local function buildSingleSegments() end local function showSingleSegmentSelection() + singleSegments = buildSingleSegments() + singleSegmentScroll = 0 while state.page == 'single_segment' do - if not singleSegments or #singleSegments == 0 then - singleSegments = buildSingleSegments() - end drawHeader('Select Single Segment', 'Select a line and fare') Buttons = {} local itemsPerPage = math.floor((h - 10) / 4) * 2 diff --git a/update-db.js b/update-db.js new file mode 100644 index 0000000..5ee525c --- /dev/null +++ b/update-db.js @@ -0,0 +1,35 @@ +/* + * @Author: HenryDu8133 813367384@qq.com + * @Date: 2026-07-10 11:05:43 + * @LastEditors: HenryDu8133 813367384@qq.com + * @LastEditTime: 2026-07-10 11:23:30 + * @FilePath: \TicketMachine\update-db.js + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +const mysql = require('mysql2/promise'); +async function run() { + const pool = mysql.createPool({ + host: '127.0.0.1', + port: 3306, + user: 'cc-ticket-machine', + password: 'cc-ticket-machine', + database: 'cc-ticket-machine', + }); + try { + const [rows] = await pool.query('SELECT data FROM config LIMIT 1'); + if (rows.length > 0) { + let data = rows[0].data; + if (typeof data === 'string') data = JSON.parse(data); + data.lua_versions = data.lua_versions || {}; + data.lua_versions.ticketmachine = 'v1.5.12'; + data.lua_versions.gate = 'v1.5.9'; + await pool.query('UPDATE config SET data = ?', [JSON.stringify(data)]); + console.log('Updated DB config to v1.5.12'); + } + } catch(e) { + console.error(e); + } finally { + await pool.end(); + } +} +run(); \ No newline at end of file diff --git a/web/ic-card-admin.js b/web/ic-card-admin.js index 5c10a7d..835971e 100644 --- a/web/ic-card-admin.js +++ b/web/ic-card-admin.js @@ -191,7 +191,11 @@ const formatIcCardEventUnified = (ev) => { const type = String(ev?.type || '').toLowerCase(); const action = String(ev?.action || '').toLowerCase(); - const deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + let deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + if (/^\d+$/.test(deviceId)) deviceId = 'ticket_machine'; + if (deviceId === 'ticket_machine') deviceId = '售票机'; + if (deviceId === 'gate') deviceId = '闸机'; + if (deviceId === 'refill_machine') deviceId = '充值机'; const timeStr = formatTime(ev?.ts); const balance = ev?.balance ?? ev?.["余额"] ?? 0; diff --git a/web/ic-card-search.js b/web/ic-card-search.js index f63ca17..6c5e5ca 100644 --- a/web/ic-card-search.js +++ b/web/ic-card-search.js @@ -90,7 +90,11 @@ const formatIcCardEventUnified = (ev) => { const type = String(ev?.type || '').toLowerCase(); const action = String(ev?.action || '').toLowerCase(); - const deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + let deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + if (/^\d+$/.test(deviceId)) deviceId = 'ticket_machine'; + if (deviceId === 'ticket_machine') deviceId = '售票机'; + if (deviceId === 'gate') deviceId = '闸机'; + if (deviceId === 'refill_machine') deviceId = '充值机'; const timeStr = formatTime(ev?.ts); const balance = ev?.balance ?? ev?.["余额"] ?? 0; diff --git a/web/index.js b/web/index.js index cc1d6d6..1a531fd 100644 --- a/web/index.js +++ b/web/index.js @@ -348,7 +348,11 @@ createApp({ const formatTicketEventUnified = (ev) => { const type = getTicketEventType(ev); const action = getTicketEventAction(ev); - const deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + let deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + if (/^\d+$/.test(deviceId)) deviceId = 'ticket_machine'; + if (deviceId === 'ticket_machine') deviceId = '售票机'; + if (deviceId === 'gate') deviceId = '闸机'; + if (deviceId === 'refill_machine') deviceId = '充值机'; const timeStr = formatTime(ev?.ts || ev?.["时间戳"]); if (type === 'sale' || type === '售票') { @@ -451,7 +455,11 @@ createApp({ const formatIcEventDetail = (ev) => { const type = String(ev?.type || '').toLowerCase(); const action = String(ev?.action || '').toLowerCase(); - const deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + let deviceId = ev?.device || ev?.device_id || ev?.["设备编号"] || ev?.["机器ID"] || '---'; + if (/^\d+$/.test(deviceId)) deviceId = 'ticket_machine'; + if (deviceId === 'ticket_machine') deviceId = '售票机'; + if (deviceId === 'gate') deviceId = '闸机'; + if (deviceId === 'refill_machine') deviceId = '充值机'; const timeStr = formatTime(ev?.ts); const balance = ev?.balance ?? ev?.["余额"] ?? 0; diff --git a/web/ticket-board.html b/web/ticket-board.html index 528017c..eb40c12 100644 --- a/web/ticket-board.html +++ b/web/ticket-board.html @@ -96,7 +96,15 @@ {{ statusInfo.text }} -