feat: 在账号资源库中展示导入的标签字段

KOC 资源导入模板新增「标签」列,导入后写入 accounts.tags 并在
账号资源库面板以 badge 形式展示,导出时也带回标签列以保证往返一致。

- lib/resource-import.ts: 新增 tags 字段与 HEADER 别名(标签/账号标签/人设标签),
  新增 normalizeTags/mergeTags 工具,按顿号规整与合并
- 修复 xlsx 解析器对自闭合空 cell (<c r="G6"/>) 的错位 bug,否则
  行内出现空 cell 会让后续 cell 的列引用读到错误 body(如老茄子行标签丢失)
- db/schema.ts + lib/mvp-db.ts: accounts 表新增 tags VARCHAR(500)
- app/api/resources-import/route.ts: SELECT/INSERT/UPDATE/预览全部带上 tags
- app/api/resources-export/route.ts: 导出表加「标签」列
- app/admin-app.tsx + app/globals.css: 资源卡片新增「账号标签」区,
  导入预览行展示标签
- public/KOC资源导入模板.xlsx: 模板补「标签(选填)」列与填写说明
- mysql/0005_account_tags.sql: 线上 MySQL 迁移
- tests/resource-import.test.mjs: 补 tags 解析/合并用例
This commit is contained in:
ABAPPLO
2026-08-18 16:39:38 +08:00
parent ad3dbdcc86
commit 582c26e57e
10 changed files with 145 additions and 8 deletions

View File

@@ -60,6 +60,7 @@ type Account = {
post_count: number;
avg_views: number;
cooperation_source: string;
tags: string;
first_seen_at: string;
last_seen_at: string;
};
@@ -74,6 +75,7 @@ type ResourceImportPreview = {
ipLocation: string;
followers: number;
cooperationSource: string;
tags: string;
action: "create" | "update" | "error";
errors: string[];
}>;
@@ -1991,6 +1993,14 @@ function ResourcesPage({
].filter(Boolean),
),
].sort((left, right) => left.localeCompare(right, "zh-CN")),
tags: [
...new Set(
(account.tags || "")
.split(/[、,;|]/)
.map((item) => item.trim())
.filter(Boolean),
),
],
partnerManagedOnly:
deliveries.some((item) => item.delegation_bundle_id) &&
deliveries.every((item) => item.delegation_bundle_id),
@@ -2203,7 +2213,7 @@ function ResourcesPage({
</div>
</div>
<div className="resource-grid">
{filteredAccounts.map(({ account, sources, partnerManagedOnly }) => (
{filteredAccounts.map(({ account, sources, tags: tagList, partnerManagedOnly }) => (
<article className="resource-card" key={account.id}>
<div className="resource-card-head">
<div className={`avatar xlarge ${avatarColor(account.nickname)}`}>{account.nickname.slice(0, 1)}</div>
@@ -2227,6 +2237,14 @@ function ResourcesPage({
)}
</div>
</div>
{tagList.length > 0 && (
<div className="resource-tags">
<span></span>
<div>
{tagList.map((tag) => <b key={tag}>{tag}</b>)}
</div>
</div>
)}
<div className="resource-card-foot">
<span> {formatDate(account.last_seen_at)}</span>
{account.profile_url && <a href={account.profile_url} target="_blank" rel="noreferrer"> </a>}
@@ -2282,7 +2300,7 @@ function ResourcesPage({
</label>
{!importPreview && (
<div className="import-template-note">
<div><strong></strong><span>IDIP属地</span></div>
<div><strong></strong><span>IDIP属地</span></div>
<a className="ghost-button" download href="/KOC资源导入模板.xlsx"></a>
</div>
)}
@@ -2303,7 +2321,7 @@ function ResourcesPage({
<span>{row.rowNumber}</span>
<span><strong>{row.nickname || "—"}</strong><small>{row.platform || "未填写平台"}</small></span>
<span>{row.publicAccountId || "主页识别"}</span>
<span><strong>{row.ipLocation}</strong><small>{row.cooperationSource || "未填写来源"}</small></span>
<span><strong>{row.ipLocation}</strong><small>{row.cooperationSource || "未填写来源"}</small>{row.tags && <em>{row.tags}</em>}</span>
<span className={`import-result ${row.action}`}>
{row.action === "create" ? "新增" : row.action === "update" ? "更新" : row.errors.join("")}
</span>