fix(ticketmachine): 修复站点缓存与匹配问题,优化数据处理逻辑
- 配置更新时清空singleSegments缓存,确保UI重新渲染 - 支持stations、stops、站点列表、站点四种站点列表键名 - 为站点与票价代码添加标准化处理,提升跨格式匹配准确性 - 同步更新线路选择渲染的站点列表提取逻辑 - 新增test-db.js测试脚本用于数据服务验证 - 新增空的data.json文件作为数据存储占位
This commit is contained in:
+16
@@ -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();
|
||||
+32
-8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user