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