feat(monitor): 作品标签 —— 词表在设置里维护,作品上贴
和「作品备注」刻意并存,不是一回事:备注是一句话的自由文字,标签是**从一份固定
词表里选的分类**。分类必须封闭,否则「重点 / 重要 / 优先」各写各的,筛就没法用了。
* `monitor_tag`:词表,全局一套(不按平台分)—— 「重点」是给人自己用的心智,不该在
小红书和抖音各定义一遍。颜色存的是**调色板里的名字**,不是色值:Tailwind 的类名是
静态提取的,拼出来的 `text-${color}` 它看不见,线上会静默变无色。
* `monitor_note_tag`:作品↔标签,**多对多**。一条作品可以既是重点又是竞品;只能贴一个
的话人就会跑去备注里写自由文字,这份词表就白建了。全部替换式提交,不是逐个增删。
* 删除标签时**显式删关联**,不靠外键级联 —— 测试跑 SQLite,它默认不开外键约束。
* 组头上的筛选做成平铺开关片,多选是「或」。
顺带:/monitor/notes 现在支持按 tag_id 筛。
This commit is contained in:
@@ -104,16 +104,82 @@ export function useTaskRuns(taskId: number | null) {
|
||||
* 最该显示的一类。所以服务端单独给一份 `creators`,两者必须来自同一次请求,否则
|
||||
* 组头和组里的作品会对不上(比如刚删掉一个任务)。
|
||||
*/
|
||||
export function useMonitorNotes(taskId: number | null, onlyNew: boolean) {
|
||||
export function useMonitorNotes(
|
||||
taskId: number | null,
|
||||
onlyNew: boolean,
|
||||
tagIds: number[] = [],
|
||||
) {
|
||||
const platform = usePlatformParam()
|
||||
return useQuery({
|
||||
queryKey: ['monitorNotes', platform, taskId, onlyNew],
|
||||
queryKey: ['monitorNotes', platform, taskId, onlyNew, tagIds],
|
||||
queryFn: async () =>
|
||||
(await monitorApi.getNotes(taskId ?? undefined, onlyNew, 200, platform)).data,
|
||||
(await monitorApi.getNotes(taskId ?? undefined, onlyNew, 200, platform, tagIds)).data,
|
||||
refetchInterval: POLL_MS,
|
||||
})
|
||||
}
|
||||
|
||||
// --- 标签 ------------------------------------------------------------------
|
||||
|
||||
export function useMonitorTags() {
|
||||
return useQuery({
|
||||
queryKey: ['monitorTags'],
|
||||
queryFn: async () => (await monitorApi.listTags()).data.tags,
|
||||
// 词表是人手工维护的,没有别的写入方,不用频繁刷。
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
|
||||
/** 标签变了要让作品列表重取 —— 标签是画在作品行上的。 */
|
||||
function useTagMutation<TArgs>(
|
||||
mutationFn: (args: TArgs) => Promise<unknown>,
|
||||
successMessage: string,
|
||||
) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn,
|
||||
onSuccess: () => {
|
||||
toast.success(successMessage)
|
||||
queryClient.invalidateQueries({ queryKey: ['monitorTags'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['monitorNotes'] })
|
||||
},
|
||||
onError: (error: Error) => toast.error(`操作失败:${error.message}`),
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateTag() {
|
||||
return useTagMutation(
|
||||
({ name, color }: { name: string; color: string }) => monitorApi.createTag(name, color),
|
||||
'标签已创建',
|
||||
)
|
||||
}
|
||||
|
||||
export function useUpdateTag() {
|
||||
return useTagMutation(
|
||||
({ id, name, color }: { id: number; name: string; color: string }) =>
|
||||
monitorApi.updateTag(id, name, color),
|
||||
'标签已保存',
|
||||
)
|
||||
}
|
||||
|
||||
export function useDeleteTag() {
|
||||
return useTagMutation((id: number) => monitorApi.deleteTag(id), '标签已删除')
|
||||
}
|
||||
|
||||
export function useSetNoteTags() {
|
||||
const queryClient = useQueryClient()
|
||||
const platform = usePlatformParam()
|
||||
return useMutation({
|
||||
mutationFn: ({ noteId, tagIds }: { noteId: string; tagIds: number[] }) =>
|
||||
monitorApi.setNoteTags(noteId, tagIds, platform),
|
||||
onSuccess: () => {
|
||||
// 不打 toast:贴标签是个连着点好几次的动作,每次都弹一条会把屏幕刷满。
|
||||
queryClient.invalidateQueries({ queryKey: ['monitorNotes'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['monitorTags'] })
|
||||
},
|
||||
onError: (error: Error) => toast.error(`标签保存失败:${error.message}`),
|
||||
})
|
||||
}
|
||||
|
||||
export function useNoteSeries(noteId: string | null, taskId: number | null) {
|
||||
return useQuery({
|
||||
queryKey: ['monitorNoteSeries', noteId, taskId],
|
||||
|
||||
Reference in New Issue
Block a user