feat(chibi+beads): 历史抽屉弹窗+换色库存角标+缺货置灰 三语言
This commit is contained in:
1 parent
b33d5c466d
commit
a28fa1e775
8 files changed
+272
-13
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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<string | null>(null);
|
||||
const [publishedId, setPublishedId] = useState<string | null>(null);
|
||||
|
||||
// 历史记录状态(P1-8)
|
||||
const [historyOpen, setHistoryOpen] = useState(false);
|
||||
const [historyItems, setHistoryItems] = useState<ChibiHistoryItem[]>([]);
|
||||
const [historyLoading, setHistoryLoading] = useState(false);
|
||||
const [historyError, setHistoryError] = useState<string | null>(null);
|
||||
|
||||
const hasCode = redeemedCode !== null;
|
||||
|
||||
const category = CATEGORIES.find((c) => c.id === categoryId) ?? CATEGORIES[0];
|
||||
@@ -546,6 +553,19 @@ export function ChibiPage() {
|
||||
<span className="chibi-nav-badge-dot" />
|
||||
{t("chibi.nav.badge")}
|
||||
</span>
|
||||
{hasCode && (
|
||||
<button type="button" className="chibi-nav-btn" onClick={() => {
|
||||
setHistoryOpen(true);
|
||||
setHistoryLoading(true);
|
||||
setHistoryError(null);
|
||||
getChibiHistory(redeemedCode!).then(
|
||||
(res) => setHistoryItems(res.items),
|
||||
(err) => setHistoryError(err instanceof Error ? err.message : t("chibi.history.fail")),
|
||||
).finally(() => setHistoryLoading(false));
|
||||
}}>
|
||||
{t("chibi.history.btn")}
|
||||
</button>
|
||||
)}
|
||||
<LangSwitcher base="chibi-nav-lang" />
|
||||
</div>
|
||||
</nav>
|
||||
@@ -985,6 +1005,66 @@ export function ChibiPage() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── 历史记录弹窗 ── */}
|
||||
{historyOpen && (
|
||||
<div
|
||||
className="chibi-modal-mask"
|
||||
role="presentation"
|
||||
onMouseDown={(e) => {
|
||||
if (e.target === e.currentTarget) setHistoryOpen(false);
|
||||
}}
|
||||
>
|
||||
<div className="chibi-modal chibi-history-modal" role="dialog" aria-modal="true" aria-label={t("chibi.history.title")}>
|
||||
<div className="chibi-modal-head">
|
||||
<h3 className="chibi-modal-title">{t("chibi.history.title")}</h3>
|
||||
<button type="button" className="chibi-modal-close" aria-label={t("modal.close")} onClick={() => setHistoryOpen(false)}>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<div className="chibi-history-body">
|
||||
{historyLoading ? (
|
||||
<p className="chibi-history-status">{t("chibi.modal.processing")}</p>
|
||||
) : historyError ? (
|
||||
<p className="chibi-modal-error">{historyError}</p>
|
||||
) : historyItems.length === 0 ? (
|
||||
<p className="chibi-history-status">{t("chibi.history.empty")}</p>
|
||||
) : (
|
||||
<div className="chibi-history-list">
|
||||
{historyItems.map((item) => (
|
||||
<div key={item.id} className="chibi-history-item">
|
||||
<div className="chibi-history-thumb-wrap">
|
||||
{item.image ? (
|
||||
<img className="chibi-history-thumb" src={item.image} alt="" />
|
||||
) : (
|
||||
<div className="chibi-history-thumb chibi-history-thumb-empty" />
|
||||
)}
|
||||
</div>
|
||||
<div className="chibi-history-meta">
|
||||
<span className="chibi-history-category">
|
||||
{t(`chibi.cat.${item.category === "person" ? "people" : item.category}.name` as MessageKey)}
|
||||
</span>
|
||||
<span className="chibi-history-time">
|
||||
{item.createdAt?.slice(0, 16).replace("T", " ")}
|
||||
</span>
|
||||
</div>
|
||||
{item.image && (
|
||||
<a
|
||||
className="chibi-history-dl"
|
||||
href={item.image}
|
||||
download={`chibi-${item.id}.png`}
|
||||
>
|
||||
{t("chibi.history.download")}
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
</button>
|
||||
</div>
|
||||
<div className="bd-replace-grid">
|
||||
{replacePalette.map((c) => (
|
||||
<button
|
||||
key={c.code}
|
||||
type="button"
|
||||
className="bd-replace-color"
|
||||
onClick={() => handleReplacePick(c.code)}
|
||||
>
|
||||
<span className="bd-replace-swatch" style={{ background: c.hex }} />
|
||||
<span className="bd-replace-code">{c.code}</span>
|
||||
</button>
|
||||
))}
|
||||
{replacePalette.map((c) => {
|
||||
const stock = getBeadCount(inventory, c.code);
|
||||
const out = stock === 0;
|
||||
return (
|
||||
<button
|
||||
key={c.code}
|
||||
type="button"
|
||||
className={`bd-replace-color${out ? " is-out" : ""}`}
|
||||
onClick={() => {
|
||||
if (out) return;
|
||||
handleReplacePick(c.code);
|
||||
}}
|
||||
>
|
||||
<span className="bd-replace-swatch" style={{ background: c.hex }} />
|
||||
<span className="bd-replace-code">
|
||||
{c.code}
|
||||
<span className="bd-bead-stock">
|
||||
{out ? t("beads.bottle.outOfStock") : stock}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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': '山川、城市和旅行纪念',
|
||||
|
||||
@@ -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': '山川、城市和旅行紀念',
|
||||
|
||||
@@ -167,6 +167,25 @@ export function generateChibi(params: GenerateChibiParams): Promise<GenerateChib
|
||||
});
|
||||
}
|
||||
|
||||
/** 历史记录单条。 */
|
||||
export interface ChibiHistoryItem {
|
||||
id: number;
|
||||
category: string;
|
||||
subtype: string;
|
||||
gridSize: number;
|
||||
colorCount: number;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
image: string | null;
|
||||
}
|
||||
|
||||
/** GET /api/chibi/history?code=XXX — 查询生成历史(最近 7 天,最多 50 条)。 */
|
||||
export function getChibiHistory(code: string): Promise<{ items: ChibiHistoryItem[] }> {
|
||||
return request<{ items: ChibiHistoryItem[] }>(
|
||||
`/api/chibi/history?code=${encodeURIComponent(code)}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* T-102:POST /api/showcase/works — 把 AI 专区生成的作品发布到作品展示。
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/* ═══════════════════════ 添加豆子全屏弹窗 ═══════════════════════ */
|
||||
|
||||
Reference in new issue
Block a user