重构: P0-4 IdeaRecord.status union类型化(试点·类型安全)
- types.ts: 新增 IdeaStatus union(draft|pending_review|approved|rejected|promoted|archived, 对齐后端df-types IdeaStatus serde snake_case) + IdeaRecord.status string→IdeaStatus - Ideas.vue/IdeaDetail.vue/IdeasPanel.vue: statusOptions/statusLabelKey/onStatusChange/emit收窄 类型IdeaStatus(编译期校验拼写错) - stores/project.ts/state.ts: 比较 IdeaStatus 后端契约: union 6值=df-types IdeaStatus serde, IPC/DB不变零行为变更 P0-4试点跑通: 推广路径验证(union+父子类型传递+emit收窄); 剩余TaskRecord/AiToolCallInfo/WorkflowRecord/ProjectRecord status待推广
This commit is contained in:
@@ -130,7 +130,7 @@ import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { parseTags } from '../../stores/knowledge'
|
||||
import { useRendered } from '../../composables/useMarkdown'
|
||||
import type { IdeaRecord } from '../../api/types'
|
||||
import type { IdeaRecord, IdeaStatus } from '../../api/types'
|
||||
|
||||
const props = defineProps<{
|
||||
idea: IdeaRecord
|
||||
@@ -138,20 +138,20 @@ const props = defineProps<{
|
||||
evalError: string
|
||||
promoting: boolean
|
||||
deleting: boolean
|
||||
statusOptions: { value: string; labelKey: string }[]
|
||||
statusOptions: { value: IdeaStatus; labelKey: string }[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'evaluate'): void
|
||||
(e: 'promote'): void
|
||||
(e: 'delete'): void
|
||||
(e: 'status-change', value: string): void
|
||||
(e: 'status-change', value: IdeaStatus): void
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
// 任意 status 字符串 → 对应 i18n key;未知状态回退到原值显示
|
||||
function statusLabelKey(status: string): string {
|
||||
function statusLabelKey(status: IdeaStatus): string {
|
||||
return props.statusOptions.find(s => s.value === status)?.labelKey ?? status
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ function sentimentClass(sentiment: number) {
|
||||
}
|
||||
|
||||
function onStatusChange(e: Event) {
|
||||
emit('status-change', (e.target as HTMLSelectElement).value)
|
||||
emit('status-change', (e.target as HTMLSelectElement).value as IdeaStatus)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user