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 }} -
+
+
+
+ {{ ticket.overview.start_name }} +
+
单程单区间
+
+
+
{{ ticket.overview.start_name }} @@ -113,7 +121,18 @@
{{ ticket.overview.terminal_en }}
-
+ +
+
+ 票价 + ¥ {{ ticket.overview.amount || 0 }} +
+
+ 更新时间 + {{ formatTime(ticket.overview.last_update_ts) }} +
+
+
车型 {{ formatTrainType(ticket.overview.train_type) }} @@ -298,7 +317,12 @@ } const stationEn = event.station_en || event['站点英文'] || ''; - const deviceId = event.device_id || event['设备编号'] || ''; + let deviceId = event.device || event.device_id || event['设备编号'] || event['机器ID'] || ''; + if (/^\d+$/.test(deviceId)) deviceId = 'ticket_machine'; + if (deviceId === 'ticket_machine') deviceId = '售票机'; + if (deviceId === 'gate') deviceId = '闸机'; + if (deviceId === 'refill_machine') deviceId = '充值机'; + if (stationEn && deviceId) return `${stationEn} (${deviceId})`; if (deviceId) return `设备:${deviceId}`; return stationEn; diff --git a/web/ticket-route.js b/web/ticket-route.js index 950a576..562bc25 100644 --- a/web/ticket-route.js +++ b/web/ticket-route.js @@ -228,7 +228,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 === '售票') { diff --git a/web/ticket-search.js b/web/ticket-search.js index 3e00135..599343c 100644 --- a/web/ticket-search.js +++ b/web/ticket-search.js @@ -110,7 +110,11 @@ const formatTicketEventUnified = (ev) => { const type = getEventType(ev); const action = String(ev.action || ev["动作"] || '').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 || ev["时间戳"]); if (type === 'sale' || type === '售票') { @@ -151,6 +155,9 @@ const overview = it.overview || it["概览"] || null; const startName = overview ? (overview.start_name || overview["起点"]) : (it.start_name || it["起点"] || '---'); const terminalName = overview ? (overview.terminal_name || overview["终点"]) : (it.terminal_name || it["终点"] || '---'); + const trainType = overview ? (overview.train_type || overview["车型"]) : (it.train_type || it["车型"]); + const isSingle = String(trainType || '').toLowerCase() === 'single'; + const updateTime = formatTime( (overview && (overview.last_update_ts || overview["上次更新时间"])) || it.last_update_ts || @@ -158,13 +165,20 @@ '' ); + let routeHtml = ''; + if (isSingle) { + routeHtml = `${escapeHtml(startName)} 单程单区间`; + } else { + routeHtml = `${escapeHtml(startName)} → ${escapeHtml(terminalName)}`; + } + row.innerHTML = `
${escapeHtml(id)} ${escapeHtml(statusText)}
- ${escapeHtml(startName)} → ${escapeHtml(terminalName)} + ${routeHtml}
最近更新 ${escapeHtml(updateTime)}
`; @@ -192,6 +206,60 @@ const stRaw = ov.status || ov["状态"] || d.status || d["状态"] || ''; const statusText = formatStatusText(stRaw); const statusClass = isValidStatus(stRaw) ? 'jr-status-valid' : (statusText === '已使用' ? 'jr-status-used' : 'jr-status-expired'); + const isSingle = String(ov.train_type || ov["车型"] || '').toLowerCase() === 'single'; + + let routeBoardHtml = ''; + if (isSingle) { + routeBoardHtml = ` +
+
+
+ ${escapeHtml(ov.start_name || ov["起点"] || '---')} +
+
单程单区间
+
+
+ `; + } else { + routeBoardHtml = ` +
+
+
+ ${escapeHtml(ov.start_name || ov["起点"] || '---')} + ${escapeHtml(ov.start_code || ov["起点编号"] || '')} +
+
${escapeHtml(ov.start_en || ov["起点英文"] || '')}
+
+
+
+
+ ${escapeHtml(ov.terminal_name || ov["终点"] || '---')} + ${escapeHtml(ov.terminal_code || ov["终点编号"] || '')} +
+
${escapeHtml(ov.terminal_en || ov["终点英文"] || '')}
+
+
+ `; + } + + let metaGridHtml = ''; + if (isSingle) { + metaGridHtml = ` +
+
票价${escapeHtml(ov.amount ?? ov["金额"] ?? 0)}
+
更新${escapeHtml(formatTime(ov.last_update_ts ?? ov["上次更新时间"]))}
+
+ `; + } else { + metaGridHtml = ` +
+
车型${escapeHtml(formatTrainType(ov.train_type || ov["车型"]))}
+
乘次${escapeHtml(ov.trips_total ?? ov["总乘次"] ?? 0)}
+
票价${escapeHtml(ov.amount ?? ov["金额"] ?? 0)}
+
更新${escapeHtml(formatTime(ov.last_update_ts ?? ov["上次更新时间"]))}
+
+ `; + } detailEl.innerHTML = `
@@ -199,29 +267,8 @@ ${id} ${statusText}
-
-
-
- ${ov.start_name || ov["起点"] || '---'} - ${ov.start_code || ov["起点编号"] || ''} -
-
${ov.start_en || ov["起点英文"] || ''}
-
-
-
-
- ${ov.terminal_name || ov["终点"] || '---'} - ${ov.terminal_code || ov["终点编号"] || ''} -
-
${ov.terminal_en || ov["终点英文"] || ''}
-
-
-
-
车型${formatTrainType(ov.train_type || ov["车型"])}
-
乘次${ov.trips_total ?? ov["总乘次"] ?? 0}
-
票价${ov.amount ?? ov["金额"] ?? 0}
-
更新${formatTime(ov.last_update_ts ?? ov["上次更新时间"])}
-
+ ${routeBoardHtml} + ${metaGridHtml}