fix: 签署日期不能晚于当前日期

后端 /sign-date 和 /paper-sign 均增加校验,签署日期晚于今天则报错。
前端日期选择器增加 max 属性限制为今天。
This commit is contained in:
selfrelease
2026-08-17 12:48:07 +08:00
parent e824cd1629
commit c66ea290eb
2 changed files with 16 additions and 1 deletions
+14
View File
@@ -221,6 +221,12 @@ router.post('/sign-date', async (req: AuthRequest, res: Response, next: NextFunc
if (isNaN(parsedDate.getTime())) { if (isNaN(parsedDate.getTime())) {
return res.status(400).json({ success: false, error: { code: 'VALIDATION_ERROR', message: '签署日期格式无效' } }) return res.status(400).json({ success: false, error: { code: 'VALIDATION_ERROR', message: '签署日期格式无效' } })
} }
// 签署日期不能晚于当前日期
const today = new Date()
today.setHours(23, 59, 59, 999)
if (parsedDate > today) {
return res.status(400).json({ success: false, error: { code: 'VALIDATION_ERROR', message: '签署日期不能晚于当前日期' } })
}
// 更新合同签署日期 // 更新合同签署日期
await prisma.laborContract.update({ await prisma.laborContract.update({
where: { id: contractId }, where: { id: contractId },
@@ -623,6 +629,14 @@ router.post('/paper-sign', authMiddleware, async (req: AuthRequest, res: Respons
return res.status(404).json({ success: false, error: { code: 'NOT_FOUND', message: '员工不存在' } }) return res.status(404).json({ success: false, error: { code: 'NOT_FOUND', message: '员工不存在' } })
} }
// 签署日期不能晚于当前日期
const signDate = new Date(data.signedAt)
const todayEnd = new Date()
todayEnd.setHours(23, 59, 59, 999)
if (signDate > todayEnd) {
return res.status(400).json({ success: false, error: { code: 'VALIDATION_ERROR', message: '签署日期不能晚于当前日期' } })
}
// 创建签署记录(线下手签直接为 COMPLETED 状态) // 创建签署记录(线下手签直接为 COMPLETED 状态)
const record = await prisma.eSignRecord.create({ const record = await prisma.eSignRecord.create({
data: { data: {
+2 -1
View File
@@ -528,7 +528,7 @@ function PaperSignModal({ onClose, onSuccess, initialEmployeeId, initialScene, i
<div className="grid grid-cols-2 gap-2"> <div className="grid grid-cols-2 gap-2">
<div> <div>
<Label> *</Label> <Label> *</Label>
<Input type="date" value={form.signedAt} onChange={(e) => setForm({ ...form, signedAt: e.target.value })} /> <Input type="date" max={new Date().toISOString().slice(0, 10)} value={form.signedAt} onChange={(e) => setForm({ ...form, signedAt: e.target.value })} />
</div> </div>
<div> <div>
<Label></Label> <Label></Label>
@@ -935,6 +935,7 @@ function PendingTab({ pendingList, loading, onRemind, remindLoading, remindData,
<> <>
<input <input
type="date" type="date"
max={new Date().toISOString().slice(0, 10)}
value={signDateValue} value={signDateValue}
onChange={(e) => setSignDateValue(e.target.value)} onChange={(e) => setSignDateValue(e.target.value)}
className="h-7 px-2 text-xs border rounded" className="h-7 px-2 text-xs border rounded"