From 8318c45fd111d8e4769a9455bcde14d6b5a3927a Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Fri, 10 Jul 2026 10:25:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(ticketmachine):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=AB=99=E7=82=B9=E7=BC=93=E5=AD=98=E4=B8=8E=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 配置更新时清空singleSegments缓存,确保UI重新渲染 - 支持stations、stops、站点列表、站点四种站点列表键名 - 为站点与票价代码添加标准化处理,提升跨格式匹配准确性 - 同步更新线路选择渲染的站点列表提取逻辑 - 新增test-db.js测试脚本用于数据服务验证 - 新增空的data.json文件作为数据存储占位 --- data.json | 0 test-db.js | 16 ++++++++++++++++ ticketmachine.lua | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 data.json create mode 100644 test-db.js diff --git a/data.json b/data.json new file mode 100644 index 0000000..e69de29 diff --git a/test-db.js b/test-db.js new file mode 100644 index 0000000..8992f00 --- /dev/null +++ b/test-db.js @@ -0,0 +1,16 @@ +const DataService = require('./server/services/data'); +async function run() { + try { + await DataService.init(); + const lines = DataService.getLines(); + console.log("Line 0 stops:", lines[0]?.stops, lines[0]?.['站序'], lines[0]?.['站点列表']); + console.log("Line 0 name:", lines[0]?.name, lines[0]?.['线路名称']); + const fares = DataService.getFares(); + console.log("Fare 0:", fares[0]); + } catch(e) { + console.error(e); + } finally { + process.exit(0); + } +} +run(); \ No newline at end of file diff --git a/ticketmachine.lua b/ticketmachine.lua index 0694c3c..aa1924e 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -963,6 +963,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 end @@ -1175,13 +1176,20 @@ local function buildSingleSegments() local segments = {} local fares = CFG.fares or {} for _, line in ipairs(CFG.lines or {}) do - local stops = line.stops or line['站点列表'] or {} + local stops = {} + if type(line.stops) == 'table' then stops = line.stops + elseif type(line['站点列表']) == 'table' then stops = line['站点列表'] + elseif type(line.stations) == 'table' then stops = line.stations + elseif type(line['站点']) == 'table' then stops = line['站点'] + end local lineFares = {} for i = 1, #stops - 1 do - local a, b = stops[i], stops[i+1] + local a, b = normalizeCode(stops[i]), normalizeCode(stops[i+1]) local f = nil for _, fx in ipairs(fares) do - if (fx.from == a and fx.to == b) or (fx.from == b and fx.to == a) then + local from = normalizeCode(fx.from) + local to = normalizeCode(fx.to) + if (from == a and to == b) or (from == b and to == a) then f = fx break end @@ -1203,10 +1211,10 @@ local function buildSingleSegments() end local function showSingleSegmentSelection() - if not singleSegments then - singleSegments = buildSingleSegments() - end 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 @@ -1566,7 +1574,15 @@ local function renderLinesSelection(title, selectedCode, backPage, nextPage, inf local y = startY for _, l in ipairs(CFG.lines) do y = y + 2; local x = 2 - for _, sc in ipairs((type(l) == 'table' and type(l.stations) == 'table' and l.stations) or {}) do + local stopsList = {} + if type(l) == 'table' then + if type(l.stations) == 'table' then stopsList = l.stations + elseif type(l.stops) == 'table' then stopsList = l.stops + elseif type(l['站点列表']) == 'table' then stopsList = l['站点列表'] + elseif type(l['站点']) == 'table' then stopsList = l['站点'] + end + end + for _, sc in ipairs(stopsList) do local c = normalizeCode(sc) local st = stationByCode[c] local label = (st and (st.en_name or st.name)) or c @@ -1598,7 +1614,15 @@ local function renderLinesSelection(title, selectedCode, backPage, nextPage, inf termDev.setBackgroundColor(colors.black) end y = y + 1; local x = 2 - for _, sc in ipairs((type(l) == 'table' and type(l.stations) == 'table' and l.stations) or {}) do + local stopsList = {} + if type(l) == 'table' then + if type(l.stations) == 'table' then stopsList = l.stations + elseif type(l.stops) == 'table' then stopsList = l.stops + elseif type(l['站点列表']) == 'table' then stopsList = l['站点列表'] + elseif type(l['站点']) == 'table' then stopsList = l['站点'] + end + end + for _, sc in ipairs(stopsList) do local c = normalizeCode(sc) local st = stationByCode[c] local label = (st and (st.en_name or st.name)) or c