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

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

@@ -1,5 +1,8 @@
## TODO
- 表格页筛选日期,范围筛选需要联动
- 购买套餐页的冗余组件
- 确认各个页面操作列的内容
- 验证码读秒用 store 保存到本地,(全局共享读秒时间)
- 网页标题根据实际页面变化
- 检查时间范围选择,限定到一定范围内
@@ -15,9 +18,10 @@
- 总览
- 提取记录
- 使用记录
- 检查页面请求异常处理
- 实现完整的客户端 ip 有效性检查
### 长期
检查扩大服务端组件边界
检查 Card 替换 section 或 div
- 检查扩大服务端组件边界
- 检查 Card 替换 section 或 div

View File

@@ -163,7 +163,7 @@ async function postCall<R = undefined>(rawResp: Promise<ApiResponse<R>>) {
].some(item => item.test(pathname))
if (match && !resp.success && resp.status === 401) {
console.log("!!!!!!!!!redirect", resp.message)
console.log('!!!!!!!!!redirect', '"', pathname, '"', resp.message)
redirect(pathname === '/' ? '/login' : `/login?redirect=${pathname}`)
}

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}) => (

View File

@@ -18,11 +18,13 @@ export async function middleware(request: NextRequest) {
RegExp(`^/admin.*`),
].some(item => item.test(request.nextUrl.pathname))
console.log('🔧 match', match, request.nextUrl.pathname)
if (match) {
try {
const accessToken = request.cookies.get('auth_token')
const refreshToken = request.cookies.get('auth_refresh')
if (!accessToken && refreshToken) {
console.log('🔧 token', !accessToken && !!refreshToken, !!accessToken, !!refreshToken)
if (!accessToken && !!refreshToken) {
console.log('💡 refresh token')
const token = await refreshAuth()
request.cookies.set('auth_token', token.access_token)
@@ -31,7 +33,7 @@ export async function middleware(request: NextRequest) {
}
catch (error) {
console.log(error)
console.log("redirect!!!!!!!!!")
console.log('redirect!!!!!!!!!')
return NextResponse.redirect(`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`)
}
}