diff --git a/perler-lab/src/ChibiPage.css b/perler-lab/src/ChibiPage.css index 133e3e0..31a4e54 100644 --- a/perler-lab/src/ChibiPage.css +++ b/perler-lab/src/ChibiPage.css @@ -174,6 +174,28 @@ background: var(--success); } +.chibi-nav-btn { + display: inline-flex; + align-items: center; + height: 24px; + padding: 0 10px; + margin-left: 8px; + font-size: var(--text-xs); + color: var(--text-secondary); + background: transparent; + border: 1px solid var(--border); + border-radius: var(--radius-full); + white-space: nowrap; + cursor: pointer; + transition: color .15s ease, border-color .15s ease, background .15s ease; +} + +.chibi-nav-btn:hover { + color: var(--text-primary); + border-color: var(--border-strong); + background: var(--bg-hover); +} + .chibi-nav-lang { display: inline-flex; align-items: center; @@ -1150,6 +1172,93 @@ width: 100%; } +/* ═══════════════════════ 历史记录弹窗 (P1-8) ═══════════════════════ */ + +.chibi-history-modal { + max-width: 480px; +} + +.chibi-history-body { + max-height: 60vh; + overflow-y: auto; +} + +.chibi-history-status { + padding: var(--space-6) 0; + text-align: center; + font-size: var(--text-sm); + color: var(--text-tertiary); +} + +.chibi-history-list { + display: flex; + flex-direction: column; + gap: var(--space-2); +} + +.chibi-history-item { + display: flex; + align-items: center; + gap: var(--space-3); + padding: var(--space-2); + border: 1px solid var(--border); + border-radius: var(--radius-md); + background: var(--bg-card); +} + +.chibi-history-thumb-wrap { + flex-shrink: 0; +} + +.chibi-history-thumb { + display: block; + width: 48px; + height: 48px; + object-fit: cover; + border-radius: var(--radius-sm); + border: 1px solid var(--border); + background: var(--bg-subtle); +} + +.chibi-history-thumb-empty { + background: var(--bg-subtle); +} + +.chibi-history-meta { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 2px; +} + +.chibi-history-category { + font-size: var(--text-sm); + font-weight: 600; + color: var(--text-primary); +} + +.chibi-history-time { + font-size: var(--text-xs); + color: var(--text-tertiary); +} + +.chibi-history-dl { + flex-shrink: 0; + padding: 6px 12px; + font-size: var(--text-xs); + font-weight: 600; + color: var(--text-on-dark); + background: var(--accent); + border-radius: var(--radius-full); + text-decoration: none; + transition: background .15s ease; +} + +.chibi-history-dl:hover { + background: var(--accent-hover); +} + /* ═══════════════════════ 移动端底部 CTA 条 ═══════════════════════ */ .chibi-mobile-bar { diff --git a/perler-lab/src/ChibiPage.tsx b/perler-lab/src/ChibiPage.tsx index 55dcea5..304ad54 100644 --- a/perler-lab/src/ChibiPage.tsx +++ b/perler-lab/src/ChibiPage.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef, useState } from "react"; import "./ChibiPage.css"; -import { generateChibi, publishShowcaseWork, redeemCode } from "./lib/api"; +import { generateChibi, publishShowcaseWork, redeemCode, getChibiHistory } from "./lib/api"; +import type { ChibiHistoryItem } from "./lib/api"; import { CHIBI_CATEGORY_TO_TAG } from "./lib/showcase"; import { useT, type MessageKey } from "./i18n"; import LangSwitcher from "./components/LangSwitcher"; @@ -392,6 +393,12 @@ export function ChibiPage() { const [publishError, setPublishError] = useState(null); const [publishedId, setPublishedId] = useState(null); + // 历史记录状态(P1-8) + const [historyOpen, setHistoryOpen] = useState(false); + const [historyItems, setHistoryItems] = useState([]); + const [historyLoading, setHistoryLoading] = useState(false); + const [historyError, setHistoryError] = useState(null); + const hasCode = redeemedCode !== null; const category = CATEGORIES.find((c) => c.id === categoryId) ?? CATEGORIES[0]; @@ -546,6 +553,19 @@ export function ChibiPage() { {t("chibi.nav.badge")} + {hasCode && ( + + )} @@ -985,6 +1005,66 @@ export function ChibiPage() { )} + + {/* ── 历史记录弹窗 ── */} + {historyOpen && ( +
{ + if (e.target === e.currentTarget) setHistoryOpen(false); + }} + > +
+
+

{t("chibi.history.title")}

+ +
+
+ {historyLoading ? ( +

{t("chibi.modal.processing")}

+ ) : historyError ? ( +

{historyError}

+ ) : historyItems.length === 0 ? ( +

{t("chibi.history.empty")}

+ ) : ( +
+ {historyItems.map((item) => ( +
+
+ {item.image ? ( + + ) : ( +
+ )} +
+
+ + {t(`chibi.cat.${item.category === "person" ? "people" : item.category}.name` as MessageKey)} + + + {item.createdAt?.slice(0, 16).replace("T", " ")} + +
+ {item.image && ( + + {t("chibi.history.download")} + + )} +
+ ))} +
+ )} +
+
+
+ )}
); } diff --git a/perler-lab/src/components/BeadSettlementModal.tsx b/perler-lab/src/components/BeadSettlementModal.tsx index ed7731d..e320f7f 100644 --- a/perler-lab/src/components/BeadSettlementModal.tsx +++ b/perler-lab/src/components/BeadSettlementModal.tsx @@ -9,6 +9,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useT } from '../i18n'; import { useBeadInventory } from '../lib/useBeadInventory'; import { getBrandPalette, BRANDS } from '../lib/brand-palettes'; +import { getBeadCount } from '../lib/bead-inventory'; import type { BeadUsage } from '../lib/bead-inventory'; // ─── 类型 ──────────────────────────────────────────────────────────────── @@ -143,12 +144,14 @@ export default function BeadSettlementModal({ const handleReplacePick = useCallback( (newCode: string) => { if (!replaceCode || !onReplace) return; + // 库存为 0 的色号不可选 + if (getBeadCount(inventory, newCode) === 0) return; onReplace(replaceCode, newCode); setReplaceToast(t('beads.replace.done', { oldCode: replaceCode, newCode })); setReplaceCode(null); window.setTimeout(() => setReplaceToast(null), 2500); }, - [replaceCode, onReplace, t], + [replaceCode, onReplace, t, inventory], ); // 遮罩点击关闭 @@ -299,17 +302,29 @@ export default function BeadSettlementModal({
- {replacePalette.map((c) => ( - - ))} + {replacePalette.map((c) => { + const stock = getBeadCount(inventory, c.code); + const out = stock === 0; + return ( + + ); + })}
diff --git a/perler-lab/src/i18n/messages/en.ts b/perler-lab/src/i18n/messages/en.ts index 829dff3..dea4bb2 100644 --- a/perler-lab/src/i18n/messages/en.ts +++ b/perler-lab/src/i18n/messages/en.ts @@ -270,6 +270,13 @@ export const en: Messages = { 'chibi.error.generateFail': 'Generation failed, please try again later', 'chibi.tags.hint': 'Up to {max} tags', + /* ── ChibiPage history (P1-8) ── */ + 'chibi.history.btn': 'History', + 'chibi.history.title': 'History', + 'chibi.history.empty': 'No history yet', + 'chibi.history.download': 'Download', + 'chibi.history.fail': 'Failed to load history, please try again later', + /* ── ChibiPage data: categories ── */ 'chibi.cat.landscape.name': 'Landscape', 'chibi.cat.landscape.note': 'Mountains, cities and travel memories', diff --git a/perler-lab/src/i18n/messages/zh-CN.ts b/perler-lab/src/i18n/messages/zh-CN.ts index 73b4b9b..cb42cc9 100644 --- a/perler-lab/src/i18n/messages/zh-CN.ts +++ b/perler-lab/src/i18n/messages/zh-CN.ts @@ -258,6 +258,13 @@ export const zhCN = { 'chibi.error.generateFail': '生成失败,请稍后重试', 'chibi.tags.hint': '最多选 {max} 项', + /* ── ChibiPage 历史记录(P1-8) ── */ + 'chibi.history.btn': '历史记录', + 'chibi.history.title': '历史记录', + 'chibi.history.empty': '暂无历史记录', + 'chibi.history.download': '下载', + 'chibi.history.fail': '加载历史记录失败,请稍后重试', + /* ── ChibiPage 数据:五大类 ── */ 'chibi.cat.landscape.name': '风景', 'chibi.cat.landscape.note': '山川、城市和旅行纪念', diff --git a/perler-lab/src/i18n/messages/zh-TW.ts b/perler-lab/src/i18n/messages/zh-TW.ts index eea2075..d281a09 100644 --- a/perler-lab/src/i18n/messages/zh-TW.ts +++ b/perler-lab/src/i18n/messages/zh-TW.ts @@ -258,6 +258,13 @@ export const zhTW: Messages = { 'chibi.error.generateFail': '生成失敗,請稍後重試', 'chibi.tags.hint': '最多選 {max} 項', + /* ── ChibiPage 歷史記錄(P1-8) ── */ + 'chibi.history.btn': '歷史記錄', + 'chibi.history.title': '歷史記錄', + 'chibi.history.empty': '暫無歷史記錄', + 'chibi.history.download': '下載', + 'chibi.history.fail': '載入歷史記錄失敗,請稍後重試', + /* ── ChibiPage 資料:五大類 ── */ 'chibi.cat.landscape.name': '風景', 'chibi.cat.landscape.note': '山川、城市和旅行紀念', diff --git a/perler-lab/src/lib/api.ts b/perler-lab/src/lib/api.ts index 14da45c..0f79a0f 100644 --- a/perler-lab/src/lib/api.ts +++ b/perler-lab/src/lib/api.ts @@ -167,6 +167,25 @@ export function generateChibi(params: GenerateChibiParams): Promise { + return request<{ items: ChibiHistoryItem[] }>( + `/api/chibi/history?code=${encodeURIComponent(code)}`, + ); +} + /** * T-102:POST /api/showcase/works — 把 AI 专区生成的作品发布到作品展示。 * diff --git a/perler-lab/src/pages/beads.css b/perler-lab/src/pages/beads.css index 0ba3616..bc9a952 100644 --- a/perler-lab/src/pages/beads.css +++ b/perler-lab/src/pages/beads.css @@ -775,6 +775,21 @@ font-size: 9px; color: var(--text-tertiary); line-height: 1; + display: flex; + flex-direction: column; + align-items: center; + gap: 1px; +} + +.bd-replace-color.is-out { + opacity: .45; + cursor: not-allowed; +} + +.bd-replace-color .bd-bead-stock { + font-size: 10px; + opacity: .7; + margin-left: 0; } /* ═══════════════════════ 添加豆子全屏弹窗 ═══════════════════════ */