A8多套打包+M4归档+R5多图:存量功能备份

A8 多套交付包(packaging_task.py):
- 修复交付包只打第1条混乱note的bug,按ImageCandidate.strategy分A/B/C组
- 每组生独立note_0N夹(6图+文案.txt),同seq留最新去重,老数据兼容
- task74端到端验:3套各6图,独立agent7项交叉验证全过

M4 归档(tasks.py/exports.py/前端):
- list_tasks加date_from/date_to/product_id筛选+product_name批量填(防N+1)
- 新增exports.py:产品JSON导出+标杆CSV导出(UTF-8 BOM)
- 前端HistoryFilters日期/产品筛选+产品列+打回原因红banner
- response.py加raise_param_error;独立agent验A1/A2/A9通过

R5 产品多图(product_images.py/020迁移/前端):
- product_images表+5端点(上传/列/改场景/设主图/删图)
- 生图按ROLE_SCENE_PREFERENCE选对应场景图,回落primary
- 前端ProductImageManager多图画廊

R6 账号config拆页(settings/):
- 配置页按角色拆/settings(运营+组长+admin)+/config(仅admin)
- Key只显末4位不显余额(守红线)

核销表对齐真实代码状态:D1改稿框/M7裂变/E12评图分纠偏为已完成(曾漏回写)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
yangqianqian
2026-06-18 17:32:49 +08:00
parent 285791c12f
commit 4bed7425a8
41 changed files with 1211 additions and 236 deletions

View File

@@ -0,0 +1,77 @@
'use client';
/**
* HistoryFilters — 历史归档页筛选条(日期区间 + 产品下拉 + 导出按钮)
* 按文件约束从 page.tsx 拆出,避免 page 超行。
*/
import { useEffect, useState } from 'react';
import { api } from '@/lib/api';
interface ProductOpt { id: number; name: string }
interface Props {
dateFrom: string;
dateTo: string;
productId: string;
onChange: (patch: { dateFrom?: string; dateTo?: string; productId?: string }) => void;
}
// 通用导出getBlob 下载,带 Authorization header复用 DownloadButton 同款 blob 方案)
async function exportData(path: string, filename: string) {
const blob = await api.getBlob(path);
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
export function HistoryFilters({ dateFrom, dateTo, productId, onChange }: Props) {
const [products, setProducts] = useState<ProductOpt[]>([]);
const [exporting, setExporting] = useState(false);
useEffect(() => {
api.get<{ items: ProductOpt[] }>('/api/v1/products?page_size=100')
.then((d) => setProducts(d.items || []))
.catch(() => setProducts([]));
}, []);
async function handleExport() {
setExporting(true);
try {
await exportData('/api/v1/products/export', 'products.json');
} catch { /* 失败静默,按钮恢复可重试 */ }
finally { setExporting(false); }
}
const inputCls = 'rounded-lg border border-border-default px-3 py-1.5 text-sm text-text-primary focus:border-brand-orange outline-none';
return (
<div className="flex flex-wrap items-center gap-3">
<label className="flex items-center gap-1.5 text-sm text-text-secondary">
<input type="date" value={dateFrom} max={dateTo || undefined}
onChange={(e) => onChange({ dateFrom: e.target.value })} className={inputCls} />
</label>
<label className="flex items-center gap-1.5 text-sm text-text-secondary">
<input type="date" value={dateTo} min={dateFrom || undefined}
onChange={(e) => onChange({ dateTo: e.target.value })} className={inputCls} />
</label>
<select value={productId} onChange={(e) => onChange({ productId: e.target.value })} className={inputCls}>
<option value=""></option>
{products.map((p) => <option key={p.id} value={String(p.id)}>{p.name}</option>)}
</select>
{(dateFrom || dateTo || productId) && (
<button onClick={() => onChange({ dateFrom: '', dateTo: '', productId: '' })}
className="text-xs text-text-tertiary hover:text-brand-orange underline"></button>
)}
<button onClick={handleExport} disabled={exporting}
className="ml-auto rounded-lg border border-border-default px-3 py-1.5 text-sm text-text-secondary hover:border-brand-orange disabled:opacity-50">
{exporting ? '导出中…' : '导出产品数据'}
</button>
</div>
);
}

View File

@@ -7,7 +7,7 @@
* window.open 无法附带 Authorization header会 401。
* 改法api.getBlob 拿二进制流 → URL.createObjectURL → a.click → revoke。
*/
import { useState } from 'react';
import { useState, Fragment } from 'react';
import Link from 'next/link';
import { clsx } from 'clsx';
import { TaskListItem } from '@/types';
@@ -76,6 +76,7 @@ export function HistoryTable({ tasks }: { tasks: TaskListItem[] }) {
<thead>
<tr className="bg-surface-secondary text-text-secondary">
<th className="px-4 py-3 text-left font-medium"></th>
<th className="px-4 py-3 text-left font-medium"></th>
<th className="px-4 py-3 text-left font-medium"></th>
<th className="px-4 py-3 text-left font-medium"></th>
<th className="px-4 py-3 text-left font-medium"></th>
@@ -85,8 +86,8 @@ export function HistoryTable({ tasks }: { tasks: TaskListItem[] }) {
</thead>
<tbody>
{tasks.map((task, i) => (
<Fragment key={task.id}>
<tr
key={task.id}
className={clsx(
'border-t border-border-default hover:bg-surface-tertiary transition-colors',
i % 2 === 0 ? 'bg-white' : 'bg-surface-primary'
@@ -95,6 +96,9 @@ export function HistoryTable({ tasks }: { tasks: TaskListItem[] }) {
<td className="px-4 py-3 text-text-primary font-medium max-w-xs truncate">
{task.theme}
</td>
<td className="px-4 py-3 text-text-secondary">
{task.product_name ?? '-'}
</td>
<td className="px-4 py-3">
<span className={clsx(
'px-2 py-0.5 rounded-full text-xs font-medium',
@@ -128,6 +132,17 @@ export function HistoryTable({ tasks }: { tasks: TaskListItem[] }) {
</div>
</td>
</tr>
{/* 被打回任务:原因独占一行展示,运营见"为何被打回"可重做(R8历史复用) */}
{task.status === 'rejected' && task.reject_reason && (
<tr className={i % 2 === 0 ? 'bg-white' : 'bg-surface-primary'}>
<td colSpan={7} className="px-4 pb-3 pt-0">
<div className="rounded-md bg-red-50 border border-red-200 px-3 py-2 text-xs text-red-600">
<span className="font-medium"></span>{task.reject_reason}
</div>
</td>
</tr>
)}
</Fragment>
))}
</tbody>
</table>
@@ -142,6 +157,7 @@ export function HistorySkeleton() {
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="flex gap-4 px-4 py-3 border-t border-border-default first:border-t-0">
<div className="h-4 bg-gray-200 rounded flex-1" />
<div className="h-4 bg-gray-200 rounded w-20" />
<div className="h-4 bg-gray-200 rounded w-16" />
<div className="h-4 bg-gray-200 rounded w-12" />
<div className="h-4 bg-gray-200 rounded w-12" />

View File

@@ -10,6 +10,7 @@ import { TaskListItem, PaginatedResponse } from '@/types';
import { getErrorAction } from '@/types/errors';
import { clsx } from 'clsx';
import { HistoryTable, HistorySkeleton, Pagination } from './components';
import { HistoryFilters } from './HistoryFilters';
const HISTORY_STATUSES = ['approved', 'archived', 'rejected', 'failed'];
const STATUS_LABELS: Record<string, string> = {
@@ -24,14 +25,21 @@ export default function HistoryPage() {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [statusFilter, setStatusFilter] = useState<string>('all');
// M4: 日期区间 + 产品筛选
const [filters, setFilters] = useState({ dateFrom: '', dateTo: '', productId: '' });
const fetchHistory = useCallback(async (p: number, status: string) => {
const fetchHistory = useCallback(async (
p: number, status: string, f: { dateFrom: string; dateTo: string; productId: string },
) => {
setLoading(true);
setError(null);
try {
const params = new URLSearchParams({ page: String(p), page_size: String(PAGE_SIZE) });
if (status !== 'all') params.append('status', status);
else HISTORY_STATUSES.forEach((s) => params.append('status', s));
if (f.dateFrom) params.append('date_from', f.dateFrom);
if (f.dateTo) params.append('date_to', f.dateTo);
if (f.productId) params.append('product_id', f.productId);
const res = await api.get<PaginatedResponse<TaskListItem>>(`/api/v1/tasks?${params}`);
setTasks(res.items);
setTotal(res.total);
@@ -43,7 +51,7 @@ export default function HistoryPage() {
}
}, []);
useEffect(() => { fetchHistory(page, statusFilter); }, [page, statusFilter, fetchHistory]);
useEffect(() => { fetchHistory(page, statusFilter, filters); }, [page, statusFilter, filters, fetchHistory]);
const totalPages = Math.ceil(total / PAGE_SIZE);
@@ -74,10 +82,18 @@ export default function HistoryPage() {
))}
</div>
{/* M4: 日期区间 + 产品筛选 + 导出 */}
<HistoryFilters
dateFrom={filters.dateFrom}
dateTo={filters.dateTo}
productId={filters.productId}
onChange={(patch) => { setFilters((f) => ({ ...f, ...patch })); setPage(1); }}
/>
{error && (
<div className="rounded-lg bg-red-50 border border-red-200 p-4 text-sm text-red-600">
{error}
<button className="ml-4 underline" onClick={() => fetchHistory(page, statusFilter)}>
<button className="ml-4 underline" onClick={() => fetchHistory(page, statusFilter, filters)}>
</button>
</div>