重构+优化: CR-04+06 AiChat 流式渲染改进 + CR-10 useRendered DRY 抽
- CR-04: splitBlocks 正则切块改 marked.lexer() tokens 遍历(type=code 的 .raw 整块,其余按双换行切),正确处理行首空格/4+反引号嵌套/未闭合围栏——lexer 与 parse 同 marked 实例同 gfm 规则,切块边界与渲染边界一致。 - CR-06: watch(mdReady) 翻 true 时主动 scheduleStreamParse 重算,修首屏 marked 慢+暂无 delta 致末段停留 escapeFallback 纯文本。 - CR-10: useMarkdown 抽 useRendered(computed 读 mdReady+renderMd + ensureLoaded 幂等预热),4 view(TaskDetail/ProjectDetail/Ideas/Knowledge)删手写 renderedDesc computed + onMounted loadMarkdown 重复,loadMarkdown 提模块级。DRY 行为零变化。 批4 wlnazlvdc,vue-tsc 0 err
This commit is contained in:
@@ -99,7 +99,7 @@ import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { taskApi, projectApi } from '../api'
|
||||
import { formatDate } from '../utils/time'
|
||||
import { useMarkdown } from '../composables/useMarkdown'
|
||||
import { useRendered } from '../composables/useMarkdown'
|
||||
import {
|
||||
taskStatusLabel,
|
||||
taskStatusClass,
|
||||
@@ -108,16 +108,6 @@ import {
|
||||
} from '../constants/project'
|
||||
import type { TaskRecord, ProjectRecord } from '../api/types'
|
||||
|
||||
// B-24:任务描述 Markdown 渲染(复用 AiChat 同款渲染器,模块级单例)
|
||||
const { renderMd, loadMarkdown, mdReady } = useMarkdown()
|
||||
|
||||
// 描述渲染依赖 mdReady 响应式:loadMarkdown 完成前 escapeFallback 纯文本,完成后 mdReady 翻转
|
||||
// 触发 computed 重算(B-24 漏响应式致 v-html=renderMd 首次纯文本后不重算,代码块不渲染)
|
||||
const renderedDescription = computed(() => {
|
||||
void mdReady.value
|
||||
return renderMd(task.value?.description ?? '')
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const loading = ref(true)
|
||||
@@ -127,6 +117,12 @@ const projects = ref<ProjectRecord[]>([])
|
||||
|
||||
const taskId = computed(() => route.params.id as string)
|
||||
|
||||
// B-24:任务描述 Markdown 渲染(复用 AiChat 同款渲染器,模块级单例),useRendered 封装
|
||||
// computed(读 mdReady 触发响应式 + renderMd)+ ensureLoaded(幂等预热)
|
||||
const { rendered: renderedDescription, ensureLoaded } = useRendered(
|
||||
() => task.value?.description ?? '',
|
||||
)
|
||||
|
||||
const projectName = computed(() => {
|
||||
const p = projects.value.find(p => p.id === task.value?.project_id)
|
||||
return p?.name ?? task.value?.project_id ?? '—'
|
||||
@@ -159,7 +155,7 @@ function refresh() {
|
||||
watch(taskId, () => { load() })
|
||||
|
||||
onMounted(() => {
|
||||
loadMarkdown() // 后台预热 Markdown 渲染器(模块单例,与 AiChat 共享),不阻塞 load
|
||||
ensureLoaded() // 后台预热 Markdown 渲染器(模块单例,与 AiChat 共享),不阻塞 load
|
||||
load()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user