feat: 20260815 系统优化 - 全部31项问题修复(P0×6+P1×14+P2×9+P3×2)

P0紧急修复(6项):
- 草稿保存完整恢复所有字段(含socialAvgWage)
- 补偿金批次从compensationBreakdown读取
- 违法解除风险确认UI
- 合同结束日期前后校验(前后端双保险)

P1高优先级(14项):
- 离职日期联动社保/公积金截止月(15号规则)
- 合规检查+工作交接改为软阻断(生成待办)
- 补偿月数(N/N+1/2N/自定义)+计算基数(近12月/合同/自定义)
- 解聘并入花名册操作栏(类型选择跳转向导)
- 合同续签开始日期自动推导(原合同结束日+1天)
- 年龄合规筛查(童工阻断/未成年工/退休警告)
- 编辑入职日期后状态联动(待入职↔在职)
- 转正移植到花名册操作栏+薪资回写
- 男职工无法选择三期

P2体验优化(9项):
- "劳动合同"调整为"用工关系"
- 费用结算新增剩余年假折算(300%日工资)
- 身份证号全域改为"证件号码"(前后端18个文件)
- 手机号查重
- 开具证明+合同续签移植到花名册操作栏
- 批量转正+批量开具证明
- 去掉用工办理模块

P3规划(2项):
- 组织架构+审批流(Department/Position/ApprovalFlow/ApprovalInstance)
- 客服工作台(Ticket/ChatSession+SUPPORT角色)

新增模型: Department/Position/ApprovalFlow/ApprovalInstance/Ticket/TicketMessage/ChatSession/ChatMessage
新增字段: Employee.departmentId/supervisorId
新增角色: SUPPORT

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
selfrelease
2026-08-15 12:37:27 +08:00
parent 8cfdd566af
commit e1b5ae9aab
46 changed files with 3455 additions and 206 deletions
+252 -26
View File
@@ -1,4 +1,5 @@
import { useState, useMemo, useEffect } from 'react'
import { useSearchParams } from 'react-router-dom'
import { usePageSize } from '../hooks/usePageSize'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
@@ -162,12 +163,26 @@ interface EmployeeProfile {
export default function Termination() {
const queryClient = useQueryClient()
const confirm = useConfirm()
const [searchParams] = useSearchParams()
const [view, setView] = useState<'list' | 'wizard' | 'detail'>('list')
const [draftId, setDraftId] = useState<string | null>(null)
const [step, setStep] = useState(0)
const [reason, setReason] = useState('')
const [employeeId, setEmployeeId] = useState('')
const [terminationDate, setTerminationDate] = useState('')
// 从 URL 参数预填员工和解聘类型(从花名册操作栏跳转)
useEffect(() => {
const urlEmployeeId = searchParams.get('employeeId')
const urlReason = searchParams.get('reason')
if (urlEmployeeId) {
setEmployeeId(urlEmployeeId)
setView('wizard')
}
if (urlReason) {
setReason(urlReason)
}
}, [searchParams])
const [socialInsEndMonth, setSocialInsEndMonth] = useState('')
const [housingFundEndMonth, setHousingFundEndMonth] = useState('')
const [checklist, setChecklist] = useState<Record<string, boolean>>({})
@@ -181,6 +196,18 @@ export default function Termination() {
const [editCompValue, setEditCompValue] = useState<number>(0)
const [editCompReason, setEditCompReason] = useState('')
const [approvalComment, setApprovalComment] = useState('')
/** 违法解除且实际补偿金低于法定2N时需确认风险 */
const [illegalRiskAcknowledged, setIllegalRiskAcknowledged] = useState(false)
/** 补偿月数模式:N/N+1/2N/自定义 */
const [compMonthMode, setCompMonthMode] = useState<'N' | 'N+1' | '2N' | 'CUSTOM'>('N')
const [customCompMonths, setCustomCompMonths] = useState<number>(0)
const [customCompReason, setCustomCompReason] = useState('')
/** 计算基数来源:近12月平均/合同工资/自定义 */
const [wageBaseType, setWageBaseType] = useState<'AVG_12' | 'CONTRACT' | 'CUSTOM'>('AVG_12')
const [customWageBase, setCustomWageBase] = useState<number>(0)
const [customWageReason, setCustomWageReason] = useState('')
/** 剩余年假天数及折算金额 */
const [annualLeaveDays, setAnnualLeaveDays] = useState<number>(0)
const [savedItems, setSavedItems] = useState<Array<{
id: string
employeeId: string
@@ -479,6 +506,28 @@ export default function Termination() {
capped = true
}
// 支持自定义计算基数(近12月平均/合同工资/自定义)
let effectiveWageBase = cappedWage
if (wageBaseType === 'CONTRACT') {
effectiveWageBase = selectedEmployee.latestContract?.monthlySalary || wage
} else if (wageBaseType === 'CUSTOM' && customWageBase > 0) {
effectiveWageBase = customWageBase
// 自定义基数时提示三倍社平封顶但不强制
if (socialAvgWage > 0 && customWageBase > socialAvgWage * 3) {
capped = true // 仅标记提示
}
}
// 支持自定义补偿月数(N/N+1/2N/其他)
let effectiveMonths = cappedMonths
if (compMonthMode === 'N+1') {
effectiveMonths = compMonths + 1
} else if (compMonthMode === '2N') {
effectiveMonths = compMonths * 2
} else if (compMonthMode === 'CUSTOM' && customCompMonths > 0) {
effectiveMonths = customCompMonths
}
const reasonMap: Record<string, { multiplier: number; notice: boolean }> = {
NEGOTIATED: { multiplier: 1, notice: false },
FAULT: { multiplier: 0, notice: false },
@@ -488,9 +537,9 @@ export default function Termination() {
ILLEGAL: { multiplier: 2, notice: false },
}
const r = reasonMap[reason] || { multiplier: 1, notice: false }
const basePay = cappedWage * cappedMonths
const basePay = effectiveWageBase * effectiveMonths
const severancePay = basePay * r.multiplier
const noticePay = r.notice ? cappedWage : 0
const noticePay = r.notice ? effectiveWageBase : 0
const totalSeverance = severancePay + noticePay
// 双倍工资计算(未签合同)
@@ -525,35 +574,45 @@ export default function Termination() {
isIllegal: r.multiplier === 2,
grandTotal: totalSeverance + doublePay,
}
}, [selectedEmployee, terminationDate, socialAvgWage, reason])
}, [selectedEmployee, terminationDate, socialAvgWage, reason, compMonthMode, customCompMonths, wageBaseType, customWageBase])
// 计算调整后的实际补偿金(系统预估 + 手动调整差额
// 年假折算金额:日工资 × 剩余年假天数 × 3(未休年假按300%支付
const annualLeavePay = useMemo(() => {
if (!costResult || annualLeaveDays <= 0) return 0
const dailyWage = (costResult.cappedWage || 0) / 21.75
return Math.round(dailyWage * annualLeaveDays * 3 * 100) / 100
}, [costResult, annualLeaveDays])
// 计算调整后的实际补偿金(系统预估 + 手动调整差额 + 年假折算)
const adjustedTotal = useMemo(() => {
if (!costResult) return 0
let total = costResult.grandTotal
compAdjustments.forEach(adj => {
total += (adj.to - adj.from)
})
total += annualLeavePay
return total
}, [costResult, compAdjustments])
}, [costResult, compAdjustments, annualLeavePay])
const canProceed = () => {
if (step === 0) return !!employeeId && (!!draftId || !selectedEmployee?.hasTermination || selectedEmployee?.latestTerminationStatus === 'CANCELLED' || selectedEmployee?.latestTerminationStatus === 'COMPLETED')
if (step === 1) return !!reason && !!terminationDate && (!riskAssessment?.warnings.length || acknowledgeRisk)
// step 2: 合规检查 — required 项必须勾选
// step 2: 合规检查 — 改为软阻断,未勾选 required 项可下一步但会生成待办
if (step === 2) {
if (!checklistItems) return true
const requiredItems = checklistItems.filter(item => item.suggestionType === 'required')
if (requiredItems.length === 0) return true
return requiredItems.every(item => checklist[item.key] === true)
// 法定禁止情形(孕期/工伤/医疗期)仍硬阻断
if (riskAssessment?.warnings.length && !acknowledgeRisk) return false
return true
}
// step 3: 费用结算 — 有补偿金时需确认
if (step === 3) return true
// step 4: 工作交接 — 关键项需完成
// step 3: 费用结算 — 违法解除且实际补偿金低于法定2N时需确认风险
if (step === 3) {
if (reason === 'ILLEGAL' && costResult && adjustedTotal < costResult.grandTotal) {
return illegalRiskAcknowledged
}
return true
}
// step 4: 工作交接 — 改为软阻断,未完成可下一步但会生成待办
if (step === 4) {
const keyItems = handoverItems.filter(item => item.key === 'work_handover' || item.key === 'equipment_return' || item.key === 'access_revoke')
if (keyItems.length === 0) return true
return keyItems.every(item => item.done)
return true
}
return false
}
@@ -568,6 +627,13 @@ export default function Termination() {
total: adjustedTotal,
systemTotal: costResult.grandTotal,
adjustments: compAdjustments,
riskAcknowledged: reason === 'ILLEGAL' && adjustedTotal < costResult.grandTotal ? {
acknowledged: illegalRiskAcknowledged,
legalAmount: costResult.grandTotal,
actualAmount: adjustedTotal,
difference: costResult.grandTotal - adjustedTotal,
timestamp: new Date().toISOString(),
} : null,
} : null
saveDraftMutation.mutate({
@@ -583,18 +649,53 @@ export default function Termination() {
compensationBreakdown: breakdown,
handoverItems,
checklistOverrides,
compMonthMode,
customCompMonths: compMonthMode === 'CUSTOM' ? customCompMonths : undefined,
customCompReason: compMonthMode === 'CUSTOM' ? customCompReason : undefined,
wageBaseType,
customWageBase: wageBaseType === 'CUSTOM' ? customWageBase : undefined,
customWageReason: wageBaseType === 'CUSTOM' ? customWageReason : undefined,
annualLeaveDays: annualLeaveDays > 0 ? annualLeaveDays : undefined,
annualLeavePay: annualLeavePay > 0 ? annualLeavePay : undefined,
socialAvgWage: socialAvgWage > 0 ? socialAvgWage : undefined,
remark: '',
})
}
/** 编辑已有草稿 */
const handleEditDraft = (item: any) => {
/** 编辑已有草稿(拉取完整详情后恢复所有字段) */
const handleEditDraft = async (item: any) => {
setDraftId(item.id)
setEmployeeId(item.employeeId)
setReason(item.reason)
setTerminationDate(item.terminationDate)
setStep(item.currentStep || 0)
setView('wizard')
// 恢复所有已保存的字段
if (item.socialInsEndMonth) setSocialInsEndMonth(item.socialInsEndMonth)
if (item.housingFundEndMonth) setHousingFundEndMonth(item.housingFundEndMonth)
if (item.checklist) setChecklist(item.checklist)
if (item.compensationBreakdown) {
setCompBreakdown(item.compensationBreakdown)
if (item.compensationBreakdown.adjustments) {
setCompAdjustments(item.compensationBreakdown.adjustments)
}
// 恢复违法解除风险确认状态
if (item.compensationBreakdown.riskAcknowledged?.acknowledged) {
setIllegalRiskAcknowledged(true)
}
}
if (item.handoverItems) setHandoverItems(item.handoverItems)
if (item.checklistOverrides) setChecklistOverrides(item.checklistOverrides)
// 恢复补偿月数和计算基数设置
if (item.compMonthMode) setCompMonthMode(item.compMonthMode)
if (item.customCompMonths) setCustomCompMonths(item.customCompMonths)
if (item.customCompReason) setCustomCompReason(item.customCompReason)
if (item.wageBaseType) setWageBaseType(item.wageBaseType)
if (item.customWageBase) setCustomWageBase(item.customWageBase)
if (item.customWageReason) setCustomWageReason(item.customWageReason)
if (item.annualLeaveDays) setAnnualLeaveDays(item.annualLeaveDays)
// 恢复社平工资
if (item.socialAvgWage) setSocialAvgWage(item.socialAvgWage)
}
/** 查看详情 */
@@ -675,6 +776,14 @@ export default function Termination() {
setChecklistOverrides({})
setEditingCompField(null)
setApprovalComment('')
setIllegalRiskAcknowledged(false)
setCompMonthMode('N')
setCustomCompMonths(0)
setCustomCompReason('')
setWageBaseType('AVG_12')
setCustomWageBase(0)
setCustomWageReason('')
setAnnualLeaveDays(0)
}
const handleReset = resetWizard
@@ -1079,7 +1188,7 @@ body { font-family: SimSun, serif; font-size: 14pt; line-height: 2; text-align:
</style></head>
<body>
<div class="title">解除/终止劳动合同证明书</div>
<div class="body">兹证明 ${draftDetail.employeeName}身份证号${draftDetail.idCardNumber || '—'}),原系我公司 ${draftDetail.department || '—'} 部门员工,于 ${draftDetail.terminationDate}${reasonLabel} 原因,正式解除/终止劳动合同。</div>
<div class="body">兹证明 ${draftDetail.employeeName}证件号码${draftDetail.idCardNumber || '—'}),原系我公司 ${draftDetail.department || '—'} 部门员工,于 ${draftDetail.terminationDate}${reasonLabel} 原因,正式解除/终止劳动合同。</div>
<div class="body">经济补偿金已结清:¥${fmt(draftDetail.compensation)}。社保截止月份:${draftDetail.socialInsEndMonth || '—'},公积金截止月份:${draftDetail.housingFundEndMonth || '—'}。</div>
<div class="body">特此证明。</div>
<div class="sign">公司(盖章)<br/>${new Date().toISOString().slice(0, 10)}</div>
@@ -1275,7 +1384,26 @@ ${items}
})()}
<div>
<Label></Label>
<Input type="date" value={terminationDate} onChange={(e) => setTerminationDate(e.target.value)} />
<Input type="date" value={terminationDate} onChange={(e) => {
const date = e.target.value
setTerminationDate(date)
// 自动推导社保/公积金截止月:15号前(含)截止上月,15号后截止当月
if (date) {
const d = new Date(date)
const day = d.getDate()
const monthStr = date.slice(0, 7)
if (day <= 15) {
// 上月
const prev = new Date(d.getFullYear(), d.getMonth() - 1, 1)
const prevMonth = `${prev.getFullYear()}-${String(prev.getMonth() + 1).padStart(2, '0')}`
setSocialInsEndMonth(prevMonth)
setHousingFundEndMonth(prevMonth)
} else {
setSocialInsEndMonth(monthStr)
setHousingFundEndMonth(monthStr)
}
}
}} />
</div>
{/* 实时费用预览 - 当有足够数据时在解聘方式下方显示 */}
{step === 1 && costResult && (
@@ -1428,6 +1556,57 @@ ${items}
)}
</div>
{/* 补偿月数和计算基数选择 */}
{!costResult.noComp && (
<div className="border rounded-md p-3 space-y-3 bg-blue-50/30">
<div className="text-xs font-medium text-gray-700"></div>
{/* 补偿月数模式 */}
<div>
<Label></Label>
<div className="flex gap-2 flex-wrap">
{(['N', 'N+1', '2N', 'CUSTOM'] as const).map(mode => (
<button
key={mode}
type="button"
onClick={() => setCompMonthMode(mode)}
className={`px-3 py-1 rounded text-xs border ${compMonthMode === mode ? 'bg-primary text-white border-primary' : 'bg-white text-gray-600 border-gray-300 hover:border-primary'}`}
>
{mode === 'N' ? 'N(法定)' : mode === 'N+1' ? 'N+1(含代通知)' : mode === '2N' ? '2N(违法解除)' : '自定义'}
</button>
))}
</div>
{compMonthMode === 'CUSTOM' && (
<div className="mt-2 space-y-1">
<Input type="number" value={customCompMonths || ''} onChange={(e) => setCustomCompMonths(Number(e.target.value) || 0)} placeholder="自定义补偿月数" />
<Input value={customCompReason} onChange={(e) => setCustomCompReason(e.target.value)} placeholder="自定义原因(必填)" />
</div>
)}
</div>
{/* 计算基数来源 */}
<div>
<Label></Label>
<div className="flex gap-2 flex-wrap">
{(['AVG_12', 'CONTRACT', 'CUSTOM'] as const).map(bt => (
<button
key={bt}
type="button"
onClick={() => setWageBaseType(bt)}
className={`px-3 py-1 rounded text-xs border ${wageBaseType === bt ? 'bg-primary text-white border-primary' : 'bg-white text-gray-600 border-gray-300 hover:border-primary'}`}
>
{bt === 'AVG_12' ? '近12月平均工资' : bt === 'CONTRACT' ? '合同约定工资' : '自定义基数'}
</button>
))}
</div>
{wageBaseType === 'CUSTOM' && (
<div className="mt-2 space-y-1">
<Input type="number" value={customWageBase || ''} onChange={(e) => setCustomWageBase(Number(e.target.value) || 0)} placeholder="自定义月工资基数" />
<Input value={customWageReason} onChange={(e) => setCustomWageReason(e.target.value)} placeholder="自定义原因(必填)" />
</div>
)}
</div>
</div>
)}
{/* 经济补偿金 / 赔偿金 */}
{costResult.noComp ? (
<div className="px-3 py-2 rounded-md bg-gray-50 text-gray-700 text-xs">
@@ -1496,8 +1675,55 @@ ${items}
{/* 合计 */}
<div className="border-t pt-3">
<div className="flex items-center justify-between">
<span className="font-medium"></span>
<span className="text-lg font-bold text-danger">¥{fmt(costResult.grandTotal)}</span>
<span className="font-medium"></span>
<span className="text-lg font-bold text-gray-700">¥{fmt(costResult.grandTotal)}</span>
</div>
{compAdjustments.length > 0 && (
<div className="flex items-center justify-between mt-1">
<span className="font-medium text-primary"></span>
<span className="text-lg font-bold text-danger">¥{fmt(adjustedTotal)}</span>
</div>
)}
</div>
{/* 违法解除风险提醒:实际补偿金低于法定2N时需确认 */}
{reason === 'ILLEGAL' && costResult && adjustedTotal < costResult.grandTotal && (
<div className="border border-danger rounded-md p-3 space-y-2 bg-red-50">
<div className="text-xs font-medium text-danger flex items-center gap-1.5">
<AlertTriangle className="w-4 h-4" />
</div>
<p className="text-xs text-danger">
287 ¥{fmt(adjustedTotal)} ¥{fmt(costResult.grandTotal)} ¥{fmt(costResult.grandTotal - adjustedTotal)}
</p>
<p className="text-xs text-danger"></p>
<label className="flex items-center gap-2 text-xs text-danger cursor-pointer">
<input
type="checkbox"
checked={illegalRiskAcknowledged}
onChange={(e) => setIllegalRiskAcknowledged(e.target.checked)}
/>
<span></span>
</label>
</div>
)}
{/* 剩余年假折算 */}
<div className="border rounded-md p-3 space-y-2 bg-green-50/30">
<div className="text-xs font-medium flex items-center gap-1.5">
<Calculator className="w-3.5 h-3.5" />
</div>
<div className="text-xs text-gray-500">300%5</div>
<div className="flex items-center gap-3">
<div className="flex-1">
<Label></Label>
<Input type="number" min="0" step="0.5" value={annualLeaveDays || ''} onChange={(e) => setAnnualLeaveDays(Number(e.target.value) || 0)} placeholder="0" />
</div>
{annualLeaveDays > 0 && costResult && (
<div className="text-xs text-gray-600">
<div>¥{fmt((costResult.cappedWage || 0) / 21.75)}/</div>
<div className="font-medium text-danger">¥{fmt(annualLeavePay)}</div>
</div>
)}
</div>
</div>
@@ -1884,11 +2110,11 @@ ${items}
</Button>
{step < 4 ? (
<div className="flex items-center gap-2">
{!canProceed() && step === 2 && checklistItems?.some(item => item.suggestionType === 'required' && !checklist[item.key]) && (
<span className="text-xs text-danger"></span>
{step === 2 && checklistItems?.some(item => item.suggestionType === 'required' && !checklist[item.key]) && (
<span className="text-xs text-amber-600"></span>
)}
{!canProceed() && step === 4 && handoverItems.some(item => (item.key === 'work_handover' || item.key === 'equipment_return' || item.key === 'access_revoke') && !item.done) && (
<span className="text-xs text-danger"></span>
{step === 4 && handoverItems.some(item => (item.key === 'work_handover' || item.key === 'equipment_return' || item.key === 'access_revoke') && !item.done) && (
<span className="text-xs text-amber-600"></span>
)}
<Button onClick={() => setStep(step + 1)} disabled={!canProceed()}>
<ChevronRight className="w-4 h-4 ml-1" />