完善白名单异常处理与消息提示

This commit is contained in:
2025-04-30 15:19:57 +08:00
parent 5ef673bacb
commit 0ac5679988
4 changed files with 48 additions and 39 deletions

View File

@@ -52,18 +52,18 @@ export default function WhitelistPage(props: WhitelistPageProps) {
setWait(true)
try {
const resp = await listWhitelist({page, size})
if (resp && resp.success) {
setStatus('done')
setData(resp.data)
}
else {
setStatus('fail')
toast.error('加载数据失败')
if (!resp.success) {
throw new Error(resp.message)
}
setStatus('done')
setData(resp.data)
}
catch (error) {
catch (e) {
setStatus('fail')
toast.error('加载数据失败')
toast.error('加载数据失败', {
description: e instanceof Error ? e.message : String(e),
})
}
finally {
setWait(false)
@@ -171,37 +171,37 @@ export default function WhitelistPage(props: WhitelistPageProps) {
const onSubmit = async (value: SchemaType) => {
setWait(true)
try {
// 添加白名单
if (dialogType === 'add') {
// 添加白名单
const resp = await createWhitelist(value)
if (resp && resp.success) {
await refresh(1, data.size)
toggleDialog(false)
toast.success('添加成功')
}
else {
toast.error('添加失败')
if (!resp.success) {
throw new Error(resp.message)
}
await refresh(1, data.size)
toggleDialog(false)
toast.success('添加成功')
}
// 编辑白名单
else {
// 编辑白名单
if (!dialogData) {
toast.error('编辑失败')
return
throw new Error('编辑数据出错')
}
const resp = await updateWhitelist({...value, id: dialogData.id})
if (resp && resp.success) {
await refresh(1, data.size)
toggleDialog(false)
toast.success('编辑成功')
}
else {
toast.error('编辑失败')
if (!resp.success) {
throw new Error(resp.message)
}
await refresh(1, data.size)
toggleDialog(false)
toast.success('编辑成功')
}
}
catch (error) {
toast.error(dialogType === 'add' ? '添加失败' : '编辑失败')
catch (e) {
toast.error(dialogType === 'add' ? '添加失败' : '编辑失败', {
description: e instanceof Error ? e.message : String(e),
})
}
finally {
setWait(false)
@@ -254,11 +254,14 @@ export default function WhitelistPage(props: WhitelistPageProps) {
columns={[
{
accessorKey: 'host', header: `IP 地址`,
}, {
accessorKey: 'createdAt', header: `添加时间`,
}, {
},
{
accessorKey: 'remark', header: `备注`,
}, {
},
{
accessorKey: 'createdAt', header: `添加时间`,
},
{
id: 'actions',
header: `操作`,
cell: ({row}) => (