微信小程序页面迁移校验之前 P5任务处理之前

This commit is contained in:
Neo
2026-03-09 01:19:21 +08:00
parent 263bf96035
commit 6e20987d2f
1112 changed files with 153824 additions and 219694 deletions

View File

@@ -0,0 +1,49 @@
/**
* 对话工具函数
* simulateStreamOutput 为异步函数(使用 setTimeout
* simulateStreamOutputSync 为同步纯函数(用于测试)
*/
/**
* 模拟流式输出:逐字追加调用 callback
* @param text 完整文本
* @param callback 每次追加后的回调,参数为当前已输出的子串
* @returns Promise输出完成后 resolve
*/
export function simulateStreamOutput(
text: string,
callback: (partial: string) => void
): Promise<void> {
return new Promise((resolve) => {
if (text.length === 0) {
callback('')
resolve()
return
}
let index = 0
const tick = () => {
index++
callback(text.slice(0, index))
if (index < text.length) {
setTimeout(tick, 50)
} else {
resolve()
}
}
setTimeout(tick, 50)
})
}
/**
* 同步版流式输出:返回逐字追加的子串数组(用于测试)
* @param text 完整文本
* @returns 逐步增长的子串数组,如 "abc" → ["a", "ab", "abc"]
*/
export function simulateStreamOutputSync(text: string): string[] {
const result: string[] = []
for (let i = 1; i <= text.length; i++) {
result.push(text.slice(0, i))
}
return result
}