修复: 前端UX一致性(Dashboard状态映射/状态徽章全局/Knowledge下一条与失败反馈/Ideas筛选与错误条/ConfirmDialog安全/快捷菜单状态机/分页越界) + 后端校验(queue/count-list一致/软删拒改/父聚合/promote CAS/MCP状态机收口/update白名单剔除id/created_at) + 销账
This commit is contained in:
@@ -12,8 +12,11 @@ export function createIdeasStore() {
|
||||
* F-260621-02:status/keyword/order_by 下沉后端 WHERE,取代前端 computed filter。
|
||||
* - 传 `query` → 多条件查询(状态/关键词/排序/分页)。
|
||||
* - 不传 → 全量(created_at DESC,等价旧行为)。
|
||||
*
|
||||
* WK-7:成功时清 state.error(load 后不残留旧错误),失败由 runWithCatch 置 error。
|
||||
*/
|
||||
async function loadIdeas(query?: IdeaQuery) {
|
||||
state.error = null
|
||||
await runWithCatch(state, t('ideas.err.loadFailed'), async () => {
|
||||
state.ideas = await ideaApi.list(query)
|
||||
})
|
||||
@@ -36,11 +39,14 @@ export function createIdeasStore() {
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteIdea(id: string) {
|
||||
await runWithCatch(state, t('ideas.err.deleteFailed'), async () => {
|
||||
async function deleteIdea(id: string): Promise<boolean> {
|
||||
// WK-7:返成功布尔(失败时 runWithCatch 已置 state.error),调用方据此保留选中态
|
||||
const ok = await runWithCatch(state, t('ideas.err.deleteFailed'), async () => {
|
||||
await ideaApi.delete(id)
|
||||
state.ideas = state.ideas.filter(i => i.id !== id)
|
||||
return true
|
||||
})
|
||||
return ok === true
|
||||
}
|
||||
|
||||
async function evaluateIdea(id: string) {
|
||||
@@ -51,15 +57,16 @@ export function createIdeasStore() {
|
||||
}
|
||||
|
||||
async function promoteIdea(id: string) {
|
||||
const res = await ideaApi.promote(id)
|
||||
await loadIdeas() // 后端已回写 status=promoted/promoted_to,刷新列表
|
||||
return res
|
||||
// WK-4:不再内部全量 loadIdeas(会把 store.ideas 冲成全集、冲掉当前筛选视图)。
|
||||
// 由视图(Ideas.vue promoteToProject)操作后按当前 buildIdeaQuery() 主动重载。
|
||||
return await ideaApi.promote(id)
|
||||
}
|
||||
|
||||
async function relateIdeas(subjectId: string, targetIds: string[]) {
|
||||
await runWithCatch(state, t('ideas.err.relateFailed'), async () => {
|
||||
await ideaApi.relateIdeas(subjectId, targetIds)
|
||||
await loadIdeas() // 后端已原子更新全部受影响灵感,刷新列表保持 store 一致
|
||||
// WK-4:后端原子更新受影响灵感,原全量 loadIdeas 会冲掉当前筛选视图;
|
||||
// 改由视图(Ideas.vue onUpdateRelated)按当前 query 重载。
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { taskApi } from '@/api'
|
||||
import type { TaskQuery, ProjectId } from '@/api/types'
|
||||
import { t } from '@/i18n/i18n-helpers'
|
||||
import { runWithCatch } from '@/composables/useStoreAction'
|
||||
import { runWithCatch, runWithCatchGuarded } from '@/composables/useStoreAction'
|
||||
import { state } from './state'
|
||||
|
||||
/** 任务 CRUD 子 store(共享全局 state) */
|
||||
export function createTasksStore() {
|
||||
// WK-10:并发 loadTasks 竞态守卫(快速切筛选/搜索防旧响应晚到覆盖新结果,
|
||||
// 对齐 knowledge store 的 _itemsSeq 模式)。旧请求的失败也不污染当前视图。
|
||||
let _tasksSeq = 0
|
||||
|
||||
/**
|
||||
* 加载任务列表。
|
||||
*
|
||||
@@ -17,8 +21,10 @@ export function createTasksStore() {
|
||||
* status/keyword 下沉后端 WHERE(P1/P2),取代 Tasks.vue 旧的前端内存 filter。
|
||||
*/
|
||||
async function loadTasks(queryOrProjectId?: TaskQuery | string) {
|
||||
await runWithCatch(state, t('tasks.err.loadFailed'), async () => {
|
||||
state.tasks = await taskApi.list(queryOrProjectId)
|
||||
const seq = ++_tasksSeq
|
||||
await runWithCatchGuarded(state, t('tasks.err.loadFailed'), () => seq === _tasksSeq, async () => {
|
||||
const result = await taskApi.list(queryOrProjectId)
|
||||
if (seq === _tasksSeq) state.tasks = result
|
||||
})
|
||||
}
|
||||
|
||||
@@ -51,13 +57,16 @@ export function createTasksStore() {
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteTask(id: string) {
|
||||
await runWithCatch(state, t('tasks.err.deleteFailed'), async () => {
|
||||
async function deleteTask(id: string): Promise<boolean> {
|
||||
// WK-13:返成功布尔(失败时 runWithCatch 已置 state.error),快捷删除据此 toast 反馈
|
||||
const ok = await runWithCatch(state, t('tasks.err.deleteFailed'), async () => {
|
||||
// 后端已级联软删子任务(delete_task 返回 { ok, cascaded });
|
||||
// 本地同步移除父任务 + 其直接子任务(1 级嵌套,防悬挂 parent_id)
|
||||
await taskApi.delete(id)
|
||||
state.tasks = state.tasks.filter(t => t.id !== id && t.parent_id !== id)
|
||||
return true
|
||||
})
|
||||
return ok === true
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user