fix: 修复帮助内容加载、搜索滚动和账户同步的问题

- 完善帮助内容接口的响应校验,增加数据格式和范围验证
- 优化搜索页面的滚动位置管理,避免H5页面激活时的组件重建问题
- 增加账户切换时的定时器清理,防止内存泄漏和重复请求
This commit is contained in:
hujun
2026-10-08 17:43:53 +08:00
parent 71b3c25695
commit 25cb06b71c
9 changed files with 1317 additions and 39 deletions
+12 -8
View File
@@ -4,15 +4,19 @@ export type HelpQuestion = { id: string, category: string, question: string, ans
export const helpCategories: string[] = ['账户使用', '融资评估', '资料与隐私']
export async function fetchHelpQuestions(): Promise<HelpQuestion[]> {
const response = await requestJson('/help/faqs', 'GET', {})
const items = response['items'] as UTSJSONObject[] | null
if (items == null) throw new Error('帮助内容加载失败')
const items = response['items']
if (items == null || !Array.isArray(items)) throw new Error('帮助内容响应不完整,请重试')
const results: HelpQuestion[] = []
items.forEach((item) => {
const id = item['id'] as string ?? ''; const category = item['category'] as string ?? ''
const question = item['question'] as string ?? ''; const answer = item['answer'] as string ?? ''
if (id.length > 0 && helpCategories.includes(category) && question.length > 0 && answer.length > 0 && !results.some((entry: HelpQuestion): boolean => entry.id == id)) {
const result: HelpQuestion = { id, category, question, answer }; results.push(result)
}
;(items as any[]).forEach((value: any) => {
if (value == null || typeof value != 'object' || Array.isArray(value)) throw new Error('帮助内容响应不完整,请重试')
const item = value as UTSJSONObject
const id = item.getString('id'); const category = item.getString('category')
const question = item.getString('question'); const answer = item.getString('answer')
if (id == null || !/^[1-9][0-9]{0,9}$/.test(id) || parseFloat(id) > 2147483647
|| category == null || !helpCategories.includes(category) || question == null || question.trim().length == 0
|| answer == null || answer.trim().length == 0 || results.some((entry: HelpQuestion): boolean => entry.id == id))
throw new Error('帮助内容响应不完整,请重试')
const result: HelpQuestion = { id, category, question, answer }; results.push(result)
})
return results
}