From 7e72bbeae5373a163604f32a7747d70f68dc123b Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Wed, 29 Jul 2026 12:29:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=BF=BD=E8=B8=AA=E4=B8=8E=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 升级程序版本至 v1.5.25 - 新增对比度文本颜色计算与垂直滚动条绘制工具函数,优化选择界面滚动显示 - 网页端新增问题记录管理页面,配套完整的表格与详情展示样式 - 实现issue记录标准化处理、实时事件推送接收与按时间倒序排序展示 - 重构原有选择界面的滚动逻辑,替换为通用滚动条绘制函数 --- gate.lua | 50 +++++++++++++++-- ticketmachine.lua | 82 ++++++++++++++++++++++----- web/index.html | 35 +++++++++--- web/index.js | 138 +++++++++++++++++++++++++++++++++++++++++++++- web/style.css | 117 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 394 insertions(+), 28 deletions(-) diff --git a/gate.lua b/gate.lua index bd55d66..67c2834 100644 --- a/gate.lua +++ b/gate.lua @@ -1,7 +1,7 @@ local DEFAULT_SERVER_BASE = "https://ticket.fse-media.group" local DEFAULT_SERVER_PATH = "/api/tickets/check" local GATE_OPEN_SECONDS = 2 -local VERSION = "v1.5.26" +local VERSION = "v1.5.27" local VERSION_CHECK_INTERVAL = 5 local serverURL = nil @@ -86,9 +86,11 @@ local function stationSetFromList(list) return set end +local nativeTerm = (term and type(term.current) == "function" and term.current()) or term local monitor = peripheral.find("monitor") local speaker = peripheral.find("speaker") local inspection = peripheral.find("ticket_inspection_machine") +local monitorSide = nil local serverConnected = nil local isUpdating = false @@ -168,13 +170,49 @@ local function setServerConnected(ok) serverLastChangeTs = os.epoch("utc") end -local termDev = term -if monitor then - pcall(monitor.setTextScale, 0.5) - termDev = monitor +local termDev = nativeTerm +if peripheral and type(peripheral.getName) == "function" and monitor then + pcall(function() monitorSide = peripheral.getName(monitor) end) +end + +local function refreshDisplayTarget() + local nextMonitor = nil + local nextMonitorSide = monitorSide + if peripheral then + if nextMonitorSide and type(peripheral.isPresent) == "function" and peripheral.isPresent(nextMonitorSide) and type(peripheral.wrap) == "function" then + local okWrap, wrapped = pcall(peripheral.wrap, nextMonitorSide) + if okWrap and wrapped then + nextMonitor = wrapped + end + end + if not nextMonitor and type(peripheral.find) == "function" then + local foundName = nil + local found = peripheral.find("monitor", function(name, wrapped) + foundName = name + nextMonitor = wrapped + return true + end) + if found then + nextMonitor = found + nextMonitorSide = foundName + else + nextMonitorSide = nil + end + end + end + monitor = nextMonitor + monitorSide = nextMonitorSide + if monitor then + pcall(monitor.setTextScale, 0.5) + termDev = monitor + else + termDev = nativeTerm or term + end + return termDev end local function clear() + refreshDisplayTarget() termDev.setBackgroundColor(colors.black) termDev.setTextColor(colors.white) termDev.clear() @@ -1479,6 +1517,8 @@ local function mainLoop() processInspectionEvent(ev[1], ev) os.sleep(0.35) drawReadyScreen() + elseif ev[1] == "peripheral" or ev[1] == "peripheral_detach" or ev[1] == "monitor_resize" or ev[1] == "config_updated" then + pcall(drawReadyScreen) end end end diff --git a/ticketmachine.lua b/ticketmachine.lua index 2696569..6a48f61 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -1,6 +1,6 @@ local CURRENT_STATION_CODE = 'Ticket-Machine' local API_BASE = 'https://ticket.fse-media.group/api' -local VERSION = 'v1.5.24' +local VERSION = 'v1.5.25' local UPDATE_CHECK_INTERVAL = 5 -- ########################### @@ -1081,6 +1081,16 @@ local function nearestCCColor(val) return colors.gray end +local function contrastTextColor(bg) + for _, c in ipairs(CC_PALETTE) do + if c.val == bg then + local yiq = (c.rgb[1] * 299 + c.rgb[2] * 587 + c.rgb[3] * 114) / 1000 + return yiq >= 140 and colors.black or colors.white + end + end + return colors.white +end + local function clear() termDev.setBackgroundColor(colors.black) termDev.clear() @@ -1115,6 +1125,31 @@ local function addButton(x, y, label, wBtn, hBtn, colorsPair, onClick) termDev.write(label) end +local function drawVerticalScrollbar(sbX, startY, endY, offset, maxOffset, step, onUp, onDown) + addButton(sbX, startY - 1, '^', 3, 1, {colors.black, colors.white}, onUp) + addButton(sbX, endY + 1, 'v', 3, 1, {colors.black, colors.white}, onDown) + for py = startY, endY do + termDev.setBackgroundColor(colors.black) + termDev.setCursorPos(sbX, py) + termDev.write(' ') + termDev.setBackgroundColor(colors.gray) + termDev.setCursorPos(sbX, py) + termDev.write(' ') + end + if maxOffset <= 0 then + return + end + local railH = endY - startY + 1 + local thumbH = math.max(2, math.floor((railH * railH) / (railH + maxOffset))) + if thumbH > railH then thumbH = railH end + local thumbY = startY + math.floor((railH - thumbH) * (offset / maxOffset)) + for py = thumbY, thumbY + thumbH - 1 do + termDev.setBackgroundColor(colors.lightGray) + termDev.setCursorPos(sbX, py) + termDev.write(' ') + end +end + local function inRect(btn, px, py) return px >= btn.x and px <= (btn.x + btn.w - 1) and py >= btn.y and py <= (btn.y + btn.h - 1) end @@ -1381,8 +1416,12 @@ local function showSingleSegmentSelection() local startIdx = singleSegmentScroll * itemsPerPage + 1 local endIdx = math.min(startIdx + itemsPerPage - 1, #singleSegments) - local bw = math.floor((w - 6) / 2) - local bx1, bx2 = 2, w - bw - 1 + local sbX = w - 3 + local contentRight = sbX - 2 + local colGap = 2 + local bw = math.floor((contentRight - 1 - colGap) / 2) + if bw < 8 then bw = 8 end + local bx1, bx2 = 2, 2 + bw + colGap local by = 5 for i = startIdx, endIdx do local seg = singleSegments[i] @@ -1391,20 +1430,27 @@ local function showSingleSegmentSelection() local x = colIdx == 0 and bx1 or bx2 local y = by + rowIdx * 4 - local label = seg.lineName .. ' cogs:' .. tostring(seg.cost) - if #label > bw then label = label:sub(1, bw) end + local lineColor = nearestCCColor(seg.color) + local textColor = contrastTextColor(lineColor) local isSelected = (state.singleSegment == seg) - addButton(x, y, label, bw, 3, {isSelected and colors.green or colors.blue, colors.white}, function() + local label = seg.lineName .. ' ' .. tostring(seg.cost) .. 'c' + if isSelected then label = '>' .. label end + if #label > bw then label = label:sub(1, bw) end + addButton(x, y, label, bw, 3, {lineColor, textColor}, function() state.singleSegment = seg end) end - if singleSegmentScroll > 0 then - addButton(w-8, 2, 'UP', 6, 1, {colors.gray, colors.white}, function() singleSegmentScroll = singleSegmentScroll - 1 end) - end - if singleSegmentScroll < maxScroll then - addButton(w-8, h-5, 'DN', 6, 1, {colors.gray, colors.white}, function() singleSegmentScroll = singleSegmentScroll + 1 end) - end + drawVerticalScrollbar( + sbX, + by, + h - 6, + singleSegmentScroll * itemsPerPage, + maxScroll * itemsPerPage, + itemsPerPage, + function() singleSegmentScroll = math.max(0, singleSegmentScroll - 1) end, + function() singleSegmentScroll = math.min(maxScroll, singleSegmentScroll + 1) end + ) addCancelButton() addButton(2, h-3, '<-back', 8, 3, {colors.black, colors.red}, function() state.page = 'home' end) @@ -1801,8 +1847,16 @@ local function renderLinesSelection(title, selectedCode, backPage, nextPage, inf local ch = computeHeight(); local maxO = math.max(0, ch - (endY-startY+1)) ui_scroll_offset = math.min(ui_scroll_offset, maxO) - addButton(sbX, startY-1, '^', 3, 1, {colors.black, colors.white}, function() ui_scroll_offset = math.max(0, ui_scroll_offset-4) end) - addButton(sbX, endY+1, 'v', 3, 1, {colors.black, colors.white}, function() ui_scroll_offset = math.min(maxO, ui_scroll_offset+4) end) + drawVerticalScrollbar( + sbX, + startY, + endY, + ui_scroll_offset, + maxO, + 4, + function() ui_scroll_offset = math.max(0, ui_scroll_offset-4) end, + function() ui_scroll_offset = math.min(maxO, ui_scroll_offset+4) end + ) local y = startY for _, l in ipairs(CFG.lines) do diff --git a/web/index.html b/web/index.html index ba93d05..c5dbb1e 100644 --- a/web/index.html +++ b/web/index.html @@ -961,7 +961,7 @@ -
| 时间 | @@ -974,14 +974,33 @@|||||||
|---|---|---|---|---|---|---|---|
| {{ formatTime(issue.ts) }} | -{{ issue.device || issue.machine_id }} | -{{ issue.station_code }} | -{{ issue.error_msg }} |
-
-
+ 查看详情-{{ issue.detail }}
- {{ issue.displayDevice }}
+ {{ issue.machine_id }}
+ |
+
+ {{ issue.displayStation }}
+ {{ issue.station_code }}
+ |
+
+ {{ issue.displayError }}
+ |
+
+
+
+
+
+
+ {{ entry.label }}
+ {{ entry.value }}
+
+
+
+ 查看原始内容+{{ issue.detailRaw }}
+
+
无
{{ issue.detailRaw }}
+ |