From 974dd523675e18219d77f904631b9d33b3f0c5cf Mon Sep 17 00:00:00 2001 From: laoyang Date: Tue, 3 Nov 2026 20:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=BD=AF=E4=BB=B6=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E7=9A=84=E6=8F=8F=E8=BE=B9=EF=BC=9B=E4=BF=AE=E3=80=8C?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E9=97=AE=E9=A2=98=E3=80=8D=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=A0=87=E7=AD=BE=E6=B8=B2=E6=9F=93=E6=88=90?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两个问题: 一、两个标签中间那道「线」 不是 CSS 分隔符 —— 是 .badge.sw(软件徽章)带 border:1px solid var(--swc-line), 而 .badge.cat / .badge.st 都没有边框。并排显示时那道描边看起来 就像凭空插了一条分隔线。去掉边框,三个标签统一为无边框胶囊。 二、反馈类型(Bug / 功能建议)在后台「全部问题」列表里不显示 🔴 根因:fb_category_label() 参数是**数字 id**,内部会 (int) 化。 而全部问题列表传的是 $t["category"](老 slug 字段,值为 bug), (int)bug === 0 → 函数返回空串 → 渲染出一个**空的** badge: 标签框在、里面什么都没有,看起来就像「类型没了」。 修法: - 新增 fb_category_label_by_slug($softwareId, $slug) 给老数据兜底 (slug 在不同软件下可能重名,必须带 software_id) - 全部问题列表改用 category_id 优先、slug 兜底 - 前台列表同样处理,并且**取不到名字就不渲染这个标签**, 绝不再输出空胶囊 - 在 fb_category_label() 的注释里写明「必须传数字 id」, 避免下次再踩 验证: 函数对照跑通:#4 category_id=6 → Bug;#5 category_id=7 → 功能建议; 旧写法 fb_category_label("bug") → (空),确认这就是根因。 浏览器实测详情页三个标签 border-top-width 全部 0px / style none, 圆角都是 999px,描边已消除。 前台列表两个条目分类标签分别渲染出 Bug / 功能建议,不再是空。 7 个路由全 200。 --- admin.php | 12 +++++++++++- assets/style.css | 5 ++++- index.php | 10 +++++++++- lib/bootstrap.php | 2 +- lib/util.php | 24 +++++++++++++++++++++++- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/admin.php b/admin.php index 1527b06..b01f961 100644 --- a/admin.php +++ b/admin.php @@ -766,7 +766,17 @@ fb_layout_head('管理后台', ['robots' => 'noindex,nofollow']); diff --git a/assets/style.css b/assets/style.css index c61a55e..9a766b0 100644 --- a/assets/style.css +++ b/assets/style.css @@ -599,7 +599,10 @@ main.wrap{padding-top:24px; padding-bottom:40px; min-height:60vh} .badge.sw{ display:inline-flex; align-items:center; gap:5px; background:var(--swc-soft, #eef2f8); color:var(--swc, #2b4a74); - border:1px solid var(--swc-line, #cfdcee); font-weight:600; + /* ⚠️ 不要加 border —— 用户 2026-11-03 指出「两个标签中间加个线干嘛」。 + * 分类/状态标签都没有边框,只有软件标签有,并排显示时那道描边 + * 看起来就像凭空插了一条分隔线。统一成无边框的胶囊。 */ + font-weight:600; padding:1px 9px 1px 6px; } .badge.sw .badge-sw-ic{ diff --git a/index.php b/index.php index cd15cab..0f511da 100644 --- a/index.php +++ b/index.php @@ -166,7 +166,15 @@ if (!$sw): #
diff --git a/lib/bootstrap.php b/lib/bootstrap.php index 8e0f27d..8a03a64 100644 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -8,7 +8,7 @@ if (!defined('FB_ROOT')) { define('FB_ROOT', dirname(__DIR__)); // 静态资源版本号:改 assets/ 下的 css/js 后把这个数字 +1, // 让浏览器与 CDN 缓存失效。全站只此一处,别再往页面里写死数字。 - if (!defined('FB_ASSET_V')) { define('FB_ASSET_V', 37); } + if (!defined('FB_ASSET_V')) { define('FB_ASSET_V', 38); } } /* ------------------------------------------------------------------ diff --git a/lib/util.php b/lib/util.php index cacbdfa..bb47338 100644 --- a/lib/util.php +++ b/lib/util.php @@ -486,7 +486,11 @@ function fb_category_by_slug($softwareId, $slug) { return $r ? $r : null; } -/** 分类显示名:只给 id 就能拿到名字(列表渲染用) */ +/** 分类显示名:只给 id 就能拿到名字(列表渲染用) + * + * ⚠️ 参数必须是**数字 id**。传字符串 slug(如 'bug')会被 (int) 成 0 而返回空串, + * 调用方如果不判空就会渲染出一个空标签 —— 这个坑踩过(见 admin.php 全部问题列表)。 + * 需要按 slug 取名字请用 fb_category_label_by_slug()。 */ function fb_category_label($id) { if (!$id) { return ''; } static $cache = []; @@ -498,6 +502,24 @@ function fb_category_label($id) { return $cache[$id]; } +/** + * 按「软件 + slug」取分类显示名 —— 给只存了老 slug 字段的历史数据兜底。 + * slug 在不同软件下可能重名,所以必须带上 software_id 才能定位。 + */ +function fb_category_label_by_slug($softwareId, $slug) { + $slug = trim((string)$slug); + if ($slug === '') { return ''; } + if ((int)$softwareId > 0) { + $c = fb_category_by_slug((int)$softwareId, $slug); + if ($c) { return (string)$c['name']; } + } + // 实在定不到软件(老数据 software_id 为空)时,按 slug 全局找一个 + $st = fb_db()->prepare('SELECT name FROM categories WHERE slug = ? LIMIT 1'); + $st->execute([$slug]); + $nm = $st->fetchColumn(); + return $nm !== false ? (string)$nm : ''; +} + /** 全部状态(按排序) */ function fb_statuses($onlyEnabled = true) { $sql = 'SELECT * FROM statuses';