feat: 添加货币和汇率管理功能
refactor: 重构前端路由和登录逻辑 docs: 更新业务闭环、任务和架构文档 style: 调整代码格式和文件结构 chore: 更新依赖项和配置文件
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
* @created 2026-03-19
|
||||
*/
|
||||
|
||||
import { setupWorker, rest } from 'msw';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { setupWorker } from 'msw/browser';
|
||||
import {
|
||||
mockCertificates,
|
||||
getMockCertificates,
|
||||
@@ -26,12 +27,13 @@ export const handlers = [
|
||||
// ============================================
|
||||
// 证书列表查询
|
||||
// ============================================
|
||||
rest.get('/api/v1/certificate/certificates', (req, res, ctx) => {
|
||||
const status = req.url.searchParams.get('status');
|
||||
const type = req.url.searchParams.get('type');
|
||||
const keyword = req.url.searchParams.get('keyword');
|
||||
const page = parseInt(req.url.searchParams.get('page') || '1');
|
||||
const pageSize = parseInt(req.url.searchParams.get('pageSize') || '10');
|
||||
http.get('/api/v1/certificate/certificates', ({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
const status = url.searchParams.get('status');
|
||||
const type = url.searchParams.get('type');
|
||||
const keyword = url.searchParams.get('keyword');
|
||||
const page = parseInt(url.searchParams.get('page') || '1');
|
||||
const pageSize = parseInt(url.searchParams.get('pageSize') || '10');
|
||||
|
||||
console.log('[MSW] GET /api/v1/certificate/certificates', { status, type, keyword, page, pageSize });
|
||||
|
||||
@@ -42,95 +44,86 @@ export const handlers = [
|
||||
const end = start + pageSize;
|
||||
const paginatedData = data.slice(start, end);
|
||||
|
||||
return res(
|
||||
ctx.delay(300),
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
success: true,
|
||||
data: paginatedData,
|
||||
total: data.length,
|
||||
page,
|
||||
pageSize,
|
||||
})
|
||||
);
|
||||
return HttpResponse.json({
|
||||
success: true,
|
||||
data: paginatedData,
|
||||
total: data.length,
|
||||
page,
|
||||
pageSize,
|
||||
}, { status: 200 });
|
||||
}),
|
||||
|
||||
// ============================================
|
||||
// 证书详情
|
||||
// ============================================
|
||||
rest.get('/api/v1/certificate/certificates/:id', (req, res, ctx) => {
|
||||
const { id } = req.params;
|
||||
http.get('/api/v1/certificate/certificates/:id', ({ params }) => {
|
||||
const { id } = params;
|
||||
const cert = getMockCertificateById(id as string);
|
||||
|
||||
console.log('[MSW] GET /api/v1/certificate/certificates/:id', { id });
|
||||
|
||||
if (!cert) {
|
||||
return res(
|
||||
ctx.delay(200),
|
||||
ctx.status(404),
|
||||
ctx.json({ success: false, error: '证书不存在' })
|
||||
return HttpResponse.json(
|
||||
{ success: false, error: '证书不存在' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return res(
|
||||
ctx.delay(200),
|
||||
ctx.status(200),
|
||||
ctx.json({ success: true, data: cert })
|
||||
return HttpResponse.json(
|
||||
{ success: true, data: cert },
|
||||
{ status: 200 }
|
||||
);
|
||||
}),
|
||||
|
||||
// ============================================
|
||||
// 创建证书
|
||||
// ============================================
|
||||
rest.post('/api/v1/certificate/certificates', async (req, res, ctx) => {
|
||||
const body = await req.json();
|
||||
http.post('/api/v1/certificate/certificates', async ({ request }) => {
|
||||
const body = await request.json();
|
||||
|
||||
console.log('[MSW] POST /api/v1/certificate/certificates', body);
|
||||
|
||||
const newCert = createMockCertificate(body);
|
||||
|
||||
return res(
|
||||
ctx.delay(500),
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
return HttpResponse.json(
|
||||
{
|
||||
success: true,
|
||||
data: { id: newCert.id },
|
||||
})
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
}),
|
||||
|
||||
// ============================================
|
||||
// 更新证书
|
||||
// ============================================
|
||||
rest.put('/api/v1/certificate/certificates/:id', async (req, res, ctx) => {
|
||||
const { id } = req.params;
|
||||
const body = await req.json();
|
||||
http.put('/api/v1/certificate/certificates/:id', async ({ params, request }) => {
|
||||
const { id } = params;
|
||||
const body = await request.json();
|
||||
|
||||
console.log('[MSW] PUT /api/v1/certificate/certificates/:id', { id, body });
|
||||
|
||||
const updated = updateMockCertificate(id as string, body);
|
||||
|
||||
if (!updated) {
|
||||
return res(
|
||||
ctx.delay(200),
|
||||
ctx.status(404),
|
||||
ctx.json({ success: false, error: '证书不存在' })
|
||||
return HttpResponse.json(
|
||||
{ success: false, error: '证书不存在' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return res(
|
||||
ctx.delay(300),
|
||||
ctx.status(200),
|
||||
ctx.json({ success: true, data: updated })
|
||||
return HttpResponse.json(
|
||||
{ success: true, data: updated },
|
||||
{ status: 200 }
|
||||
);
|
||||
}),
|
||||
|
||||
// ============================================
|
||||
// 更新证书状态(审核)
|
||||
// ============================================
|
||||
rest.put('/api/v1/certificate/certificates/:id/status', async (req, res, ctx) => {
|
||||
const { id } = req.params;
|
||||
const { status, approvedBy } = await req.json();
|
||||
http.put('/api/v1/certificate/certificates/:id/status', async ({ params, request }) => {
|
||||
const { id } = params;
|
||||
const { status, approvedBy } = await request.json();
|
||||
|
||||
console.log('[MSW] PUT /api/v1/certificate/certificates/:id/status', { id, status, approvedBy });
|
||||
|
||||
@@ -143,42 +136,38 @@ export const handlers = [
|
||||
const updated = updateMockCertificate(id as string, updates);
|
||||
|
||||
if (!updated) {
|
||||
return res(
|
||||
ctx.delay(200),
|
||||
ctx.status(404),
|
||||
ctx.json({ success: false, error: '证书不存在' })
|
||||
return HttpResponse.json(
|
||||
{ success: false, error: '证书不存在' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return res(
|
||||
ctx.delay(300),
|
||||
ctx.status(200),
|
||||
ctx.json({ success: true })
|
||||
return HttpResponse.json(
|
||||
{ success: true },
|
||||
{ status: 200 }
|
||||
);
|
||||
}),
|
||||
|
||||
// ============================================
|
||||
// 删除证书
|
||||
// ============================================
|
||||
rest.delete('/api/v1/certificate/certificates/:id', (req, res, ctx) => {
|
||||
const { id } = req.params;
|
||||
http.delete('/api/v1/certificate/certificates/:id', ({ params }) => {
|
||||
const { id } = params;
|
||||
|
||||
console.log('[MSW] DELETE /api/v1/certificate/certificates/:id', { id });
|
||||
|
||||
const deleted = deleteMockCertificate(id as string);
|
||||
|
||||
if (!deleted) {
|
||||
return res(
|
||||
ctx.delay(200),
|
||||
ctx.status(404),
|
||||
ctx.json({ success: false, error: '证书不存在' })
|
||||
return HttpResponse.json(
|
||||
{ success: false, error: '证书不存在' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return res(
|
||||
ctx.delay(200),
|
||||
ctx.status(200),
|
||||
ctx.json({ success: true })
|
||||
return HttpResponse.json(
|
||||
{ success: true },
|
||||
{ status: 200 }
|
||||
);
|
||||
}),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user