fix(home): 修复按钮处理函数返回类型和空值检查
- 更新 BtnItem 接口中的 handle 函数返回类型定义 - 添加对 btnObj.handle 的空值检查避免执行未定义方法 - 修复响应消息数组处理逻辑确保类型安全
This commit is contained in:
@@ -20,7 +20,7 @@ interface messageItem {
|
||||
interface BtnItem {
|
||||
id: number
|
||||
title: string
|
||||
handle?: () => Promise<never>
|
||||
handle?: () => Promise<{ code: number, message: Array<never> }>
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
@@ -54,7 +54,8 @@ const handleClick = async (btnObj: BtnItem) => {
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await btnObj.handle?.()
|
||||
if (btnObj.handle == undefined) return
|
||||
const res = await btnObj.handle()
|
||||
const res_msg = Array.isArray(res.message) ? res.message : [res.message]
|
||||
messages.value = res_msg.map((msg: string, index: number) => ({
|
||||
id: Date.now() + index, // 简单生成唯一 ID,生产环境建议使用更可靠的 ID 生成器
|
||||
|
||||
Reference in New Issue
Block a user