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

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 ## TODO
- 表格页筛选日期,范围筛选需要联动
- 购买套餐页的冗余组件
- 确认各个页面操作列的内容
- 验证码读秒用 store 保存到本地,(全局共享读秒时间) - 验证码读秒用 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)) ].some(item => item.test(pathname))
if (match && !resp.success && resp.status === 401) { if (match && !resp.success && resp.status === 401) {
console.log("!!!!!!!!!redirect", resp.message) console.log('!!!!!!!!!redirect', '"', pathname, '"', resp.message)
redirect(pathname === '/' ? '/login' : `/login?redirect=${pathname}`) redirect(pathname === '/' ? '/login' : `/login?redirect=${pathname}`)
} }

View File

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

View File

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