优化: 大文件拆分+代码分割+按需加载+console清理+any类型替换
- Money.tsx (2260行→54行): 拆分为 money/ 子目录4个组件, React.lazy二级分割 - AIAssistant.tsx (2038行→63行): 拆分为 ai-assistant/ 子目录6个组件, React.lazy二级分割 - xlsx改为动态导入, OvertimeTab从345KB降至12.7KB - api-services.ts: 请求参数 any→Record<string,unknown> - 移除前端3处console.log残留 - 后端console替换为pino logger - 前后端未使用import/变量清理 - Zod schema验证: termination/platform/special-status/work-process - 新增 leave.routes.ts, acceptance-test.routes.ts - UI组件: PageGuide, QueryError, Stepper
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
import { Router } from 'express'
|
||||
import prisma from '../lib/prisma'
|
||||
import { AuthRequest, authMiddleware, platformAdminMiddleware } from '../middleware/auth'
|
||||
import { loginLimiter } from '../middleware/rateLimit'
|
||||
import { parsePagination } from '../lib/pagination'
|
||||
import { createOrgSchema, updateOrgSchema, updateOrgAdminSchema, createPlatformAdminSchema } from '../schemas/platform.schema'
|
||||
|
||||
const router = Router()
|
||||
|
||||
@@ -88,8 +89,7 @@ router.get('/dashboard', async (_req: AuthRequest, res, next) => {
|
||||
*/
|
||||
router.get('/orgs', async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const page = parseInt(req.query.page as string) || 1
|
||||
const pageSize = parseInt(req.query.pageSize as string) || 20
|
||||
const { page, pageSize } = parsePagination(req.query)
|
||||
const search = (req.query.search as string) || ''
|
||||
const planFilter = (req.query.plan as string) || ''
|
||||
|
||||
@@ -154,19 +154,7 @@ router.post('/orgs', async (req: AuthRequest, res, next) => {
|
||||
const {
|
||||
name, plan, maxEmployees, city, contactName, contactPhone,
|
||||
adminName, adminPhone, adminPassword,
|
||||
} = req.body as {
|
||||
name: string; plan?: string; maxEmployees?: number
|
||||
city?: string; contactName?: string; contactPhone?: string
|
||||
adminName?: string; adminPhone: string; adminPassword: string
|
||||
}
|
||||
|
||||
if (!name || !adminPhone || !adminPassword) {
|
||||
return res.status(400).json({ success: false, error: { code: 'VALIDATION', message: '企业名称、管理员手机号、密码不能为空' } })
|
||||
}
|
||||
|
||||
if (adminPassword.length < 8) {
|
||||
return res.status(400).json({ success: false, error: { code: 'VALIDATION', message: '密码至少8位' } })
|
||||
}
|
||||
} = createOrgSchema.parse(req.body)
|
||||
|
||||
const existing = await prisma.user.findUnique({ where: { phone: adminPhone } })
|
||||
if (existing) {
|
||||
@@ -244,10 +232,7 @@ router.get('/orgs/:id', async (req: AuthRequest, res, next) => {
|
||||
*/
|
||||
router.put('/orgs/:id', async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const { name, plan, maxEmployees, city, contactName, contactPhone } = req.body as {
|
||||
name?: string; plan?: string; maxEmployees?: number;
|
||||
city?: string; contactName?: string; contactPhone?: string
|
||||
}
|
||||
const { name, plan, maxEmployees, city, contactName, contactPhone } = updateOrgSchema.parse(req.body)
|
||||
|
||||
const updateData: any = {}
|
||||
if (name) updateData.name = name
|
||||
@@ -274,9 +259,7 @@ router.put('/orgs/:id', async (req: AuthRequest, res, next) => {
|
||||
*/
|
||||
router.put('/orgs/:id/admin', async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const { adminName, adminPhone, adminPassword } = req.body as {
|
||||
adminName?: string; adminPhone?: string; adminPassword?: string
|
||||
}
|
||||
const { adminName, adminPhone, adminPassword } = updateOrgAdminSchema.parse(req.body)
|
||||
|
||||
// 找到该企业的 ADMIN 角色用户(第一个管理员)
|
||||
const admin = await prisma.user.findFirst({
|
||||
@@ -335,8 +318,7 @@ router.delete('/orgs/:id', async (req: AuthRequest, res, next) => {
|
||||
*/
|
||||
router.get('/users', async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const page = parseInt(req.query.page as string) || 1
|
||||
const pageSize = parseInt(req.query.pageSize as string) || 20
|
||||
const { page, pageSize } = parsePagination(req.query)
|
||||
const search = (req.query.search as string) || ''
|
||||
const orgId = (req.query.orgId as string) || ''
|
||||
|
||||
@@ -432,11 +414,7 @@ router.get('/admins', async (_req: AuthRequest, res, next) => {
|
||||
*/
|
||||
router.post('/admins', async (req: AuthRequest, res, next) => {
|
||||
try {
|
||||
const { name, phone, password } = req.body as { name: string; phone: string; password: string }
|
||||
|
||||
if (!name || !phone || !password) {
|
||||
return res.status(400).json({ success: false, error: { code: 'VALIDATION', message: '姓名、手机号、密码不能为空' } })
|
||||
}
|
||||
const { name, phone, password } = createPlatformAdminSchema.parse(req.body)
|
||||
|
||||
const existing = await prisma.user.findUnique({ where: { phone } })
|
||||
if (existing) {
|
||||
|
||||
Reference in New Issue
Block a user