From 4af238bdd902c6dedd6ca1f7c831a75153cc1842 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Tue, 1 Sep 2026 07:26:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(admin):=20tokenize=20=E8=AF=AD?= =?UTF-8?q?=E4=B9=89=E8=89=B2=E5=B9=B6=E8=A1=A5=E6=9A=97=E9=BB=91=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=8F=98=E9=87=8F=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 admin 8 文件 ~50 处 raw red/green/yellow/amber/blue 类替换为语义 token (error/success/warning/info),使其错误/成功/警告框在暗黑模式正确反色。 - tailwind.config.js: error 补 text 子键(原缺,text-error 暗黑底仅 3.3:1 不达 AA) - globals.css: 新增 --color-error-text;html[data-theme='dark'] 补四语义色的 *-bg(深色底)与 *-text(浅色,暗底达 AA)覆盖,原暗黑块完全漏掉这些变量 - 映射纪律:语义框 bg--bg border border-border-secondary text--text; 危险按钮 bg-error/bg-success hover:bg-*-hover text-white;字段校验 border-error 验证:type-check 0 errors;lint 0 errors;单测 1624 passed;视觉回归 22 passed; Playwright 实测 8 变量 light/dark 翻转 + 真实登录错误框背景反色确认。 Co-Authored-By: 阿睿 --- .../content/[modelCode]/[itemId]/page.tsx | 48 +++++++++---------- src/app/admin/content/[modelCode]/page.tsx | 10 ++-- src/app/admin/login/page.tsx | 2 +- src/app/admin/media/page.tsx | 6 +-- src/app/admin/notifications/page.tsx | 22 ++++----- src/app/admin/page.tsx | 28 +++++------ src/app/admin/roles/page.tsx | 2 +- src/app/admin/users/page.tsx | 18 +++---- src/app/globals.css | 14 ++++++ tailwind.config.js | 3 ++ 10 files changed, 85 insertions(+), 68 deletions(-) diff --git a/src/app/admin/content/[modelCode]/[itemId]/page.tsx b/src/app/admin/content/[modelCode]/[itemId]/page.tsx index d5a38e8..f3ff7ec 100644 --- a/src/app/admin/content/[modelCode]/[itemId]/page.tsx +++ b/src/app/admin/content/[modelCode]/[itemId]/page.tsx @@ -106,12 +106,12 @@ function JsonEditor({ placeholder={placeholder || '输入 JSON 数据'} rows={10} className={`w-full px-3 py-2 border rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-border-dark focus:border-transparent resize-y ${ - error || parseError ? 'border-red-300 bg-red-50' : 'border-border-secondary' + error || parseError ? 'border-error bg-error-bg' : 'border-border-secondary' }`} spellCheck={false} /> - {parseError &&

{parseError}

} - {error && !parseError &&

{error}

} + {parseError &&

{parseError}

} + {error && !parseError &&

{error}

} ); } @@ -119,7 +119,7 @@ function JsonEditor({ function FieldError({ error }: { error?: string }) { if (!error) return null; return ( -

+

{error}

@@ -422,7 +422,7 @@ export default function ContentEditorPage() {
{field.description && (

{field.description}

@@ -435,7 +435,7 @@ export default function ContentEditorPage() { onBlur={() => handleFieldBlur(field.name)} placeholder={field.placeholder} className={`w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-border-dark focus:border-transparent ${ - error ? 'border-red-300 bg-red-50' : 'border-border-secondary' + error ? 'border-error bg-error-bg' : 'border-border-secondary' }`} /> @@ -447,7 +447,7 @@ export default function ContentEditorPage() {
{field.description && (

{field.description}

@@ -460,7 +460,7 @@ export default function ContentEditorPage() { placeholder={field.placeholder} rows={4} className={`w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-border-dark focus:border-transparent resize-y ${ - error ? 'border-red-300 bg-red-50' : 'border-border-secondary' + error ? 'border-error bg-error-bg' : 'border-border-secondary' }`} /> @@ -472,7 +472,7 @@ export default function ContentEditorPage() {
handleFieldChange(field.name, parseFloat(e.target.value) || 0)} className={`w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-border-dark focus:border-transparent ${ - error ? 'border-red-300 bg-red-50' : 'border-border-secondary' + error ? 'border-error bg-error-bg' : 'border-border-secondary' }`} /> @@ -532,7 +532,7 @@ export default function ContentEditorPage() {
{field.description && (

{field.description}

@@ -636,13 +636,13 @@ export default function ContentEditorPage() { {!isNew && (
{autoSaveStatus === 'saving' && ( - + 保存中... )} {autoSaveStatus === 'saved' && ( - + 已保存 {lastSaved && ( @@ -653,7 +653,7 @@ export default function ContentEditorPage() { )} {autoSaveStatus === 'unsaved' && ( - + 未保存 @@ -683,7 +683,7 @@ export default function ContentEditorPage() {
{error && ( -
+
{error}
)} {/* 验证错误汇总 */} {Object.keys(validationErrors).length > 0 && ( -
-
+
+
请修正以下错误
-
    +
      {Object.entries(validationErrors).map(([field, msg]) => (
    • {msg}
    • ))} @@ -732,7 +732,7 @@ export default function ContentEditorPage() { {/* 标题 */}
      @@ -784,7 +784,7 @@ export default function ContentEditorPage() { }} placeholder="URL 友好标识(留空自动生成)" className={`w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-border-dark focus:border-transparent ${ - validationErrors.slug ? 'border-red-300 bg-red-50' : 'border-border-secondary' + validationErrors.slug ? 'border-error bg-error-bg' : 'border-border-secondary' }`} /> @@ -850,7 +850,7 @@ export default function ContentEditorPage() { {Object.keys(validationErrors).length > 0 && ( -
      +
      注意:表单中存在 {Object.keys(validationErrors).length} 个错误,发布可能会失败。
      )} @@ -858,7 +858,7 @@ export default function ContentEditorPage() { 取消 确认发布 diff --git a/src/app/admin/content/[modelCode]/page.tsx b/src/app/admin/content/[modelCode]/page.tsx index 3d0e1e7..cea89ab 100644 --- a/src/app/admin/content/[modelCode]/page.tsx +++ b/src/app/admin/content/[modelCode]/page.tsx @@ -147,7 +147,7 @@ export default function ContentListPage() { {/* Error */} {error && ( -
      +
      {error}
      )} @@ -195,9 +195,9 @@ export default function ContentListPage() { @@ -218,7 +218,7 @@ export default function ContentListPage() {
      {error && ( -
      +
      {error}
      )} @@ -223,12 +223,12 @@ export default function NotificationsPage() { className={`relative flex items-start gap-4 p-4 rounded-lg border transition-colors ${ item.read ? 'bg-bg-primary border-border-light' - : NOTIFICATION_TYPE_COLORS[item.type] || 'bg-blue-50 border-blue-200' + : NOTIFICATION_TYPE_COLORS[item.type] || 'bg-info-bg border-border-secondary' }`} > {/* Unread indicator */} {!item.read && ( -
      +
      )} {/* Type icon */} @@ -278,7 +278,7 @@ export default function NotificationsPage() { {item.relatedItemId && item.relatedModelCode && ( @@ -230,7 +230,7 @@ export default function AdminDashboardPage() { {new Date(n.createdAt).toLocaleDateString('zh-CN')}

      - {!n.read &&
      } + {!n.read &&
      }
      ))}
      diff --git a/src/app/admin/roles/page.tsx b/src/app/admin/roles/page.tsx index 14dc0e7..31dd21d 100644 --- a/src/app/admin/roles/page.tsx +++ b/src/app/admin/roles/page.tsx @@ -154,7 +154,7 @@ export default function RolesPage() { {/* Alerts */} {error && ( -
      +
      {error}
      )} diff --git a/src/app/admin/users/page.tsx b/src/app/admin/users/page.tsx index 428514e..5a4b07a 100644 --- a/src/app/admin/users/page.tsx +++ b/src/app/admin/users/page.tsx @@ -45,10 +45,10 @@ const ROLE_LABELS: Record = { }; const ROLE_COLORS: Record = { - super_admin: 'bg-red-100 text-red-700', - content_admin: 'bg-blue-100 text-blue-700', - content_editor: 'bg-green-100 text-green-700', - reviewer: 'bg-amber-100 text-amber-700', + super_admin: 'bg-error-bg text-error-text', + content_admin: 'bg-info-bg text-info-text', + content_editor: 'bg-success-bg text-success-text', + reviewer: 'bg-warning-bg text-warning-text', readonly: 'bg-bg-hover text-text-secondary', }; @@ -266,7 +266,7 @@ export default function UsersPage() {
      {error && ( -
      +
      {error}
      )} @@ -344,8 +344,8 @@ export default function UsersPage() { {u.status === 1 ? '启用' : '禁用'} @@ -368,7 +368,7 @@ export default function UsersPage() {