feat(monitor): 作品标签 —— 词表在设置里维护,作品上贴
和「作品备注」刻意并存,不是一回事:备注是一句话的自由文字,标签是**从一份固定
词表里选的分类**。分类必须封闭,否则「重点 / 重要 / 优先」各写各的,筛就没法用了。
* `monitor_tag`:词表,全局一套(不按平台分)—— 「重点」是给人自己用的心智,不该在
小红书和抖音各定义一遍。颜色存的是**调色板里的名字**,不是色值:Tailwind 的类名是
静态提取的,拼出来的 `text-${color}` 它看不见,线上会静默变无色。
* `monitor_note_tag`:作品↔标签,**多对多**。一条作品可以既是重点又是竞品;只能贴一个
的话人就会跑去备注里写自由文字,这份词表就白建了。全部替换式提交,不是逐个增删。
* 删除标签时**显式删关联**,不靠外键级联 —— 测试跑 SQLite,它默认不开外键约束。
* 组头上的筛选做成平铺开关片,多选是「或」。
顺带:/monitor/notes 现在支持按 tag_id 筛。
This commit is contained in:
+27
-2
@@ -10,6 +10,7 @@ import type {
|
||||
MonitorNote,
|
||||
MonitorOverview,
|
||||
MonitorRun,
|
||||
MonitorTag,
|
||||
MonitorTask,
|
||||
LoginState,
|
||||
PlatformCapability,
|
||||
@@ -186,9 +187,16 @@ export const monitorApi = {
|
||||
getRuns: (id: number, limit = 50) =>
|
||||
api.get<{ runs: MonitorRun[] }>(`/monitor/tasks/${id}/runs`, { params: { limit } }),
|
||||
|
||||
getNotes: (taskId?: number, onlyNew = false, limit = 200, platform?: string) =>
|
||||
getNotes: (
|
||||
taskId?: number,
|
||||
onlyNew = false,
|
||||
limit = 200,
|
||||
platform?: string,
|
||||
tagIds?: number[],
|
||||
) =>
|
||||
api.get<{ notes: MonitorNote[]; creators: MonitorCreator[] }>('/monitor/notes', {
|
||||
params: { task_id: taskId, only_new: onlyNew, limit, platform },
|
||||
// tag_id 可重复传 —— axios 会把数组序列化成 tag_id=1&tag_id=2,正是后端要的形状。
|
||||
params: { task_id: taskId, only_new: onlyNew, limit, platform, tag_id: tagIds },
|
||||
}),
|
||||
// Metric time series for one note; the chart reads this.
|
||||
getNoteSeries: (noteId: string, taskId?: number) =>
|
||||
@@ -291,6 +299,23 @@ export const monitorApi = {
|
||||
{ alias },
|
||||
{ params: { platform } },
|
||||
),
|
||||
// --- 标签 ---------------------------------------------------------------
|
||||
|
||||
/** 标签词表(设置页维护),带各自被用在多少条作品上。 */
|
||||
listTags: () => api.get<{ tags: MonitorTag[] }>('/monitor/tags'),
|
||||
createTag: (name: string, color = '') =>
|
||||
api.post<MonitorTag>('/monitor/tags', { name, color }),
|
||||
updateTag: (id: number, name: string, color = '') =>
|
||||
api.put<MonitorTag>(`/monitor/tags/${id}`, { name, color }),
|
||||
deleteTag: (id: number) => api.delete<{ removed: number }>(`/monitor/tags/${id}`),
|
||||
/** 把一条作品的标签**整体替换**成这一组。空数组 = 全摘掉。 */
|
||||
setNoteTags: (noteId: string, tagIds: number[], platform?: string) =>
|
||||
api.put(
|
||||
`/monitor/notes/${encodeURIComponent(noteId)}/tags`,
|
||||
{ tag_ids: tagIds },
|
||||
{ params: { platform } },
|
||||
),
|
||||
|
||||
/** 给作品起备注(空串 = 清掉)。键是 note_id —— 和博主备注是两回事。 */
|
||||
setNoteAlias: (noteId: string, alias: string, platform?: string) =>
|
||||
api.put(
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 标签颜色:调色板名字 → Tailwind 类名。
|
||||
*
|
||||
* **必须写死。** Tailwind 是在构建时静态扫描源码找类名的,`text-cyber-neon-${color}`
|
||||
* 这种拼出来的字符串它看不见 —— 而且不会报错,只是线上那些标签全变成无色。所以这里
|
||||
* 是一张查表,后端存的是键(cyan / pink / …)。
|
||||
*/
|
||||
const TAG_COLOR_CLASSES: Record<string, string> = {
|
||||
cyan: 'border-cyber-neon-cyan/40 text-cyber-neon-cyan',
|
||||
pink: 'border-cyber-neon-pink/40 text-cyber-neon-pink',
|
||||
green: 'border-cyber-neon-green/40 text-cyber-neon-green',
|
||||
orange: 'border-cyber-neon-orange/40 text-cyber-neon-orange',
|
||||
muted: 'border-cyber-border-DEFAULT text-cyber-text-secondary',
|
||||
}
|
||||
|
||||
/** 设置页里让用户选的那几个。键要和后端 `service.TAG_COLORS` 一致。 */
|
||||
export const TAG_COLOR_CHOICES = ['cyan', 'pink', 'green', 'orange', 'muted'] as const
|
||||
|
||||
const COLOR_LABELS: Record<string, string> = {
|
||||
cyan: '青',
|
||||
pink: '粉',
|
||||
green: '绿',
|
||||
orange: '橙',
|
||||
muted: '灰',
|
||||
}
|
||||
|
||||
export function tagColorClass(color: string): string {
|
||||
// 认不出来的颜色回落到默认色,而不是整块没有样式 —— 后端也会这么回落,两边一致。
|
||||
return TAG_COLOR_CLASSES[color] ?? TAG_COLOR_CLASSES.cyan
|
||||
}
|
||||
|
||||
export function tagColorLabel(color: string): string {
|
||||
return COLOR_LABELS[color] ?? COLOR_LABELS.cyan
|
||||
}
|
||||
Reference in New Issue
Block a user