feat: 电子签全场景集成+场景筛选+设置开关

- ESignRecord 模型新增 scene 字段(CONTRACT/RESIGNATION/POLICY/PAYSLIP/ONBOARDING)
- Organization 模型新增3个电子签开关:esignPolicyEnabled/esignPayslipEnabled/esignOnboardingEnabled
- 设置页面企业信息新增电子签署设置区域,3个开关各自独立,缺省关闭
- 规章制度签收:开启电子签后,员工阅读确认时自动创建POLICY场景签署记录
- 工资条确认:开启电子签后,员工确认工资条时自动创建PAYSLIP场景签署记录
- 入职文件签署:开启电子签后,HR审批通过入职流程时自动创建ONBOARDING场景签署记录
- 电子签署列表增加场景筛选下拉(全部场景/劳动合同/离职协议/规章制度/工资条/入职文件)
- 管理端和员工端列表均展示场景标签(基于scene字段,替代硬编码判断)
- 合同和离职流程的esign调用已加scene参数
This commit is contained in:
freedakgmail
2026-08-05 07:47:00 +08:00
parent e8cd0f472b
commit 9512b555ee
11 changed files with 153 additions and 16 deletions
+4
View File
@@ -132,6 +132,9 @@ model Organization {
contactPhone String?
payrollFrequency Int @default(1) // 每月发薪次数(1=一次一批)
retirementReminderEnabled Boolean @default(false) // 退休提醒开关
esignPolicyEnabled Boolean @default(false) // 规章制度电子签
esignPayslipEnabled Boolean @default(false) // 工资条电子签
esignOnboardingEnabled Boolean @default(false) // 入职文件电子签
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -1465,6 +1468,7 @@ model ESignRecord {
contractId String? // 关联 LaborContract
employeeId String
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
scene String @default("CONTRACT") // CONTRACT | RESIGNATION | POLICY | PAYSLIP | ONBOARDING
flowId String? // 易签宝流程ID
documentTitle String // 文件标题
documentContent String? // 文件内容(HTML/PDF base64
+4
View File
@@ -12,16 +12,19 @@ const createSignSchema = z.object({
documentTitle: z.string().min(1),
documentContent: z.string().optional(),
remark: z.string().optional(),
scene: z.string().optional(),
})
// 签署记录列表
router.get('/', async (req: AuthRequest, res: Response, next: NextFunction) => {
try {
const status = req.query.status as string | undefined
const scene = req.query.scene as string | undefined
const records = await prisma.eSignRecord.findMany({
where: {
orgId: req.user!.orgId,
...(status && { status }),
...(scene && { scene }),
},
include: {
employee: { select: { id: true, name: true, department: true, phone: true } },
@@ -56,6 +59,7 @@ router.post('/create', async (req: AuthRequest, res: Response, next: NextFunctio
orgId: req.user!.orgId,
contractId: data.contractId || null,
employeeId: data.employeeId,
scene: data.scene || 'CONTRACT',
documentTitle: data.documentTitle,
documentContent: data.documentContent || null,
// flowId: esignResult.flowId, // TODO: 易签宝对接后启用
+40
View File
@@ -171,6 +171,25 @@ router.post('/payslip/:id/confirm', portalAuth, async (req: any, res, next) => {
events: [{ action: '工资条确认', timestamp: new Date().toISOString(), ip: req.ip, userAgent: req.headers['user-agent'] }],
createdBy: req.employee.id,
}).catch(() => {})
// 如果开启了工资条电子签,创建电子签记录
const org = await prisma.organization.findUnique({ where: { id: req.employee.orgId }, select: { esignPayslipEnabled: true } })
if (org?.esignPayslipEnabled) {
await prisma.eSignRecord.create({
data: {
orgId: req.employee.orgId,
employeeId: req.employee.id,
scene: 'PAYSLIP',
documentTitle: `工资条确认:${payslip.month}`,
status: 'PENDING',
initiatedBy: req.employee.id,
createdBy: req.employee.id,
remark: '工资条确认时自动发起',
expiredAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
},
})
}
res.json({ success: true })
} catch (err) {
next(err)
@@ -544,6 +563,27 @@ router.post('/policies/:id/read', portalAuth, async (req: Request, res: Response
userAgent: req.headers['user-agent'] || null,
},
})
// 如果开启了制度电子签,创建电子签记录
const org = await prisma.organization.findUnique({ where: { id: orgId }, select: { esignPolicyEnabled: true } })
if (org?.esignPolicyEnabled) {
const policyDoc = await prisma.policyDocument.findUnique({ where: { id: req.params.id }, select: { title: true, content: true } })
await prisma.eSignRecord.create({
data: {
orgId,
employeeId,
scene: 'POLICY',
documentTitle: `制度签收:${policyDoc?.title || '未知'}`,
documentContent: policyDoc?.content || null,
status: 'PENDING',
initiatedBy: employeeId,
createdBy: employeeId,
remark: '制度阅读确认后自动发起',
expiredAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
},
})
}
res.json({ success: true, data: { readAt: record.readAt.toISOString() } })
} catch (err) {
next(err)
+6 -3
View File
@@ -28,7 +28,7 @@ router.get('/org', async (req: AuthRequest, res, next) => {
try {
const org = await prisma.organization.findUnique({
where: { id: req.user!.orgId },
select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true, createdAt: true },
select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true, esignPolicyEnabled: true, esignPayslipEnabled: true, esignOnboardingEnabled: true, createdAt: true },
})
res.json({ success: true, data: org })
} catch (err) {
@@ -39,7 +39,7 @@ router.get('/org', async (req: AuthRequest, res, next) => {
// 更新企业信息
router.put('/org', requireAdmin, async (req: AuthRequest, res, next) => {
try {
const { name, payrollFrequency, city, contactName, contactPhone, retirementReminderEnabled } = req.body as { name?: string; payrollFrequency?: number; city?: string; contactName?: string; contactPhone?: string; retirementReminderEnabled?: boolean }
const { name, payrollFrequency, city, contactName, contactPhone, retirementReminderEnabled, esignPolicyEnabled, esignPayslipEnabled, esignOnboardingEnabled } = req.body as { name?: string; payrollFrequency?: number; city?: string; contactName?: string; contactPhone?: string; retirementReminderEnabled?: boolean; esignPolicyEnabled?: boolean; esignPayslipEnabled?: boolean; esignOnboardingEnabled?: boolean }
const updateData: any = {}
if (name) updateData.name = name
if (payrollFrequency !== undefined) updateData.payrollFrequency = payrollFrequency
@@ -47,10 +47,13 @@ router.put('/org', requireAdmin, async (req: AuthRequest, res, next) => {
if (contactName !== undefined) updateData.contactName = contactName
if (contactPhone !== undefined) updateData.contactPhone = contactPhone
if (retirementReminderEnabled !== undefined) updateData.retirementReminderEnabled = retirementReminderEnabled
if (esignPolicyEnabled !== undefined) updateData.esignPolicyEnabled = esignPolicyEnabled
if (esignPayslipEnabled !== undefined) updateData.esignPayslipEnabled = esignPayslipEnabled
if (esignOnboardingEnabled !== undefined) updateData.esignOnboardingEnabled = esignOnboardingEnabled
const org = await prisma.organization.update({
where: { id: req.user!.orgId },
data: updateData,
select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true },
select: { id: true, name: true, plan: true, maxEmployees: true, city: true, contactName: true, contactPhone: true, payrollFrequency: true, retirementReminderEnabled: true, esignPolicyEnabled: true, esignPayslipEnabled: true, esignOnboardingEnabled: true },
})
res.json({ success: true, data: org })
} catch (err) {
+21
View File
@@ -164,6 +164,27 @@ router.post('/:id/approve', authMiddleware, async (req: AuthRequest, res: Respon
...(execResult.employeeId && !process.employeeId && { employeeId: execResult.employeeId }),
},
})
// 入职审批通过且开启了入职文件电子签,创建电子签记录
if (execResult.employeeId && process.type === 'ONBOARDING') {
const orgSettings = await prisma.organization.findUnique({ where: { id: req.user!.orgId }, select: { esignOnboardingEnabled: true } })
if (orgSettings?.esignOnboardingEnabled) {
await prisma.eSignRecord.create({
data: {
orgId: req.user!.orgId,
employeeId: execResult.employeeId,
scene: 'ONBOARDING',
documentTitle: '入职文件签署',
status: 'PENDING',
initiatedBy: req.user!.id,
createdBy: req.user!.id,
remark: '入职审批通过后自动发起',
expiredAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
},
})
}
}
res.json({ success: true, data: updated })
} catch (err) {
next(err)
+3 -3
View File
@@ -603,9 +603,9 @@ export const benefitApi = {
// ========== 电子签署(易签宝) ==========
export const esignApi = {
list: (status?: string) =>
get('/esign', { params: status ? { status } : {} }).then(unwrap<any[]>()),
create: (data: { contractId?: string; employeeId: string; documentTitle: string; documentContent?: string; remark?: string }) =>
list: (params?: { status?: string; scene?: string }) =>
get('/esign', { params: params || {} }).then(unwrap<any[]>()),
create: (data: { contractId?: string; employeeId: string; documentTitle: string; documentContent?: string; remark?: string; scene?: string }) =>
post('/esign/create', data),
status: (id: string) =>
get(`/esign/${id}/status`).then(unwrap<any>()),
+21 -7
View File
@@ -19,9 +19,18 @@ const STATUS_CONFIG: Record<string, { label: string; color: string }> = {
CANCELLED: { label: '已取消', color: 'bg-gray-100 text-gray-500' },
}
const SCENE_CONFIG: Record<string, { label: string; color: string }> = {
CONTRACT: { label: '劳动合同', color: 'bg-blue-50 text-blue-600 border border-blue-200' },
RESIGNATION: { label: '离职协议', color: 'bg-orange-50 text-orange-600 border border-orange-200' },
POLICY: { label: '规章制度', color: 'bg-amber-50 text-amber-600 border border-amber-200' },
PAYSLIP: { label: '工资条', color: 'bg-emerald-50 text-emerald-600 border border-emerald-200' },
ONBOARDING: { label: '入职文件', color: 'bg-purple-50 text-purple-600 border border-purple-200' },
}
export default function ESign() {
const queryClient = useQueryClient()
const [filterStatus, setFilterStatus] = useState('')
const [filterScene, setFilterScene] = useState('')
const [showCreate, setShowCreate] = useState(false)
const [formData, setFormData] = useState({
employeeId: '',
@@ -30,9 +39,9 @@ export default function ESign() {
})
const { data: records = [], isLoading } = useQuery<any[]>({
queryKey: ['esign-records', filterStatus],
queryKey: ['esign-records', filterStatus, filterScene],
queryFn: async () => {
return await esignApi.list(filterStatus || undefined)
return await esignApi.list({ status: filterStatus || undefined, scene: filterScene || undefined })
},
})
@@ -114,6 +123,14 @@ export default function ESign() {
<option value=""></option>
{Object.entries(STATUS_CONFIG).map(([k, v]) => <option key={k} value={k}>{v.label}</option>)}
</select>
<select
value={filterScene}
onChange={(e) => setFilterScene(e.target.value)}
className="h-9 rounded-md border border-gray-200 bg-white px-3 text-sm text-gray-700 shadow-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/10"
>
<option value=""></option>
{Object.entries(SCENE_CONFIG).map(([k, v]) => <option key={k} value={k}>{v.label}</option>)}
</select>
</div>
<Button size="sm" onClick={() => setShowCreate(true)}>
<Plus className="w-4 h-4 mr-1" />
@@ -149,11 +166,8 @@ export default function ESign() {
<div className="flex items-center gap-1.5">
<FileText className="w-3.5 h-3.5 text-gray-400 shrink-0" />
<span className="font-medium truncate max-w-[200px]">{r.documentTitle}</span>
{r.contractId && (
<span className="px-1.5 py-0.5 rounded text-xs bg-blue-50 text-blue-600 border border-blue-200 shrink-0"></span>
)}
{!r.contractId && r.documentTitle?.includes('离职') && (
<span className="px-1.5 py-0.5 rounded text-xs bg-orange-50 text-orange-600 border border-orange-200 shrink-0"></span>
{r.scene && SCENE_CONFIG[r.scene] && (
<span className={`px-1.5 py-0.5 rounded text-xs shrink-0 ${SCENE_CONFIG[r.scene].color}`}>{SCENE_CONFIG[r.scene].label}</span>
)}
</div>
{r.remark && <div className="text-xs text-gray-400 mt-0.5">{r.remark}</div>}
+37 -1
View File
@@ -1,7 +1,7 @@
import { useState, useEffect } from 'react'
import { toast } from 'sonner'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { Building2, Users, CreditCard, Plus, Bell, Download, Upload, FileSpreadsheet, Clock, CheckCircle, AlertCircle, ClipboardList, LayoutGrid } from 'lucide-react'
import { Building2, Users, CreditCard, Plus, Bell, Download, Upload, FileSpreadsheet, Clock, CheckCircle, AlertCircle, ClipboardList, LayoutGrid, PenTool } from 'lucide-react'
import { settingsApi, notificationsApi } from '../lib/api-services'
import { useAuthStore } from '../store/authStore'
import { getPageSize, setPageSize as setGlobalPageSize } from '../lib/pageSize'
@@ -93,6 +93,9 @@ function OrgSettings({ orgData, onSave, saving }: { orgData: any; onSave: (data:
contactPhone: '',
payrollFrequency: 1,
retirementReminderEnabled: false,
esignPolicyEnabled: false,
esignPayslipEnabled: false,
esignOnboardingEnabled: false,
})
useEffect(() => {
@@ -103,6 +106,9 @@ function OrgSettings({ orgData, onSave, saving }: { orgData: any; onSave: (data:
contactPhone: orgData.contactPhone || '',
payrollFrequency: orgData.payrollFrequency || 1,
retirementReminderEnabled: orgData.retirementReminderEnabled || false,
esignPolicyEnabled: orgData.esignPolicyEnabled || false,
esignPayslipEnabled: orgData.esignPayslipEnabled || false,
esignOnboardingEnabled: orgData.esignOnboardingEnabled || false,
})
}
}, [orgData])
@@ -139,6 +145,36 @@ function OrgSettings({ orgData, onSave, saving }: { orgData: any; onSave: (data:
</div>
<RetirementSection enabled={form.retirementReminderEnabled} onToggle={(v) => { setForm({ ...form, retirementReminderEnabled: v }); onSave({ ...form, retirementReminderEnabled: v }) }} />
{/* 电子签设置 */}
<div className="mt-6 pt-6 border-t">
<div className="flex items-center gap-2 mb-4">
<PenTool className="w-5 h-5 text-primary" />
<h3 className="font-medium"></h3>
</div>
<p className="text-xs text-gray-500 mb-3">使/</p>
<div className="space-y-3">
{[
{ key: 'esignPolicyEnabled', label: '规章制度电子签', desc: '开启后制度签收升级为电子签署,缺省为阅读确认' },
{ key: 'esignPayslipEnabled', label: '工资条电子签', desc: '开启后工资条确认升级为电子签署,缺省为点击确认' },
{ key: 'esignOnboardingEnabled', label: '入职文件电子签', desc: '开启后入职填报时签署入职相关文件,缺省不签' },
].map(item => (
<div key={item.key} className="flex items-center justify-between p-3 rounded-lg bg-gray-50">
<div>
<div className="text-sm font-medium">{item.label}</div>
<div className="text-xs text-gray-500 mt-0.5">{item.desc}</div>
</div>
<button
type="button"
onClick={() => { const v = !form[item.key as keyof typeof form]; setForm({ ...form, [item.key]: v }); onSave({ ...form, [item.key]: v }) }}
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors shrink-0 ml-4 ${form[item.key as keyof typeof form] ? 'bg-primary' : 'bg-gray-300'}`}
>
<span className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${form[item.key as keyof typeof form] ? 'translate-x-6' : 'translate-x-1'}`} />
</button>
</div>
))}
</div>
</div>
</Card>
)
}
+1
View File
@@ -1559,6 +1559,7 @@ export default function Termination() {
employeeId,
documentTitle: '离职协议',
remark: '离职流程中发起',
scene: 'RESIGNATION',
})
queryClient.invalidateQueries({ queryKey: ['esign-records'] })
toast.success('离职协议电子签署已发起')
+15 -2
View File
@@ -18,6 +18,14 @@ const STATUS_MAP: Record<string, { label: string; color: string; icon: React.Rea
EXPIRED: { label: '已过期', color: 'bg-red-50 text-red-600', icon: <XCircle className="w-3 h-3" /> },
}
const SCENE_LABELS: Record<string, { label: string; color: string }> = {
CONTRACT: { label: '劳动合同', color: 'bg-blue-50 text-blue-600 border border-blue-200' },
RESIGNATION: { label: '离职协议', color: 'bg-orange-50 text-orange-600 border border-orange-200' },
POLICY: { label: '规章制度', color: 'bg-amber-50 text-amber-600 border border-amber-200' },
PAYSLIP: { label: '工资条', color: 'bg-emerald-50 text-emerald-600 border border-emerald-200' },
ONBOARDING: { label: '入职文件', color: 'bg-purple-50 text-purple-600 border border-purple-200' },
}
export default function MyEsign() {
const queryClient = useQueryClient()
const [selectedId, setSelectedId] = useState<string | null>(null)
@@ -101,6 +109,11 @@ export default function MyEsign() {
<FileText className="w-3.5 h-3.5" />
</div>
)}
{detail.scene && SCENE_LABELS[detail.scene] && (
<div className="mb-4">
<span className={`px-2 py-0.5 rounded text-xs ${SCENE_LABELS[detail.scene].color}`}>{SCENE_LABELS[detail.scene].label}</span>
</div>
)}
{/* 签署操作 */}
<div className="border-t pt-4">
@@ -169,8 +182,8 @@ export default function MyEsign() {
<div className="flex-1 min-w-0">
<div className="flex items-center gap-1.5">
<span className="text-sm font-medium truncate min-w-0">{r.documentTitle}</span>
{r.contractId && (
<span className="px-1.5 py-0.5 rounded text-xs bg-blue-50 text-blue-600 border border-blue-200 flex-shrink-0"></span>
{r.scene && SCENE_LABELS[r.scene] && (
<span className={`px-1.5 py-0.5 rounded text-xs flex-shrink-0 ${SCENE_LABELS[r.scene].color}`}>{SCENE_LABELS[r.scene].label}</span>
)}
</div>
<div className="text-xs text-gray-500 mt-1">
@@ -27,6 +27,7 @@ export default function ContractInfo({ employeeId, contracts, hireDate }: { empl
employeeId,
documentTitle: `${data.contractType === 'UNFIXED' ? '无固定期限' : '固定期限'}劳动合同`,
remark: '合同创建时自动发起',
scene: 'CONTRACT',
})
toast.success('合同已保存,电子签署记录已创建')
} catch {