import { DEFAULT_LEAVE_WORK_HOURS } from '@/utils/oa-leave-hours' /** 与 FormCreate 官方 unique 同类 */ let _uidSeq = 0 function uniqueId() { const num = 370 + ++_uidSeq return ( 'F' + Math.random().toString(36).slice(3, 6) + Number(`${Date.now()}`).toString(36) + num.toString(36) + 'k' ) } export const LEAVE_TYPE_OPTIONS = [ { label: '事假', value: '事假' }, { label: '调休', value: '调休' }, { label: '病假', value: '病假' }, { label: '年假', value: '年假' }, { label: '产假', value: '产假' }, { label: '陪产假', value: '陪产假' }, { label: '婚假', value: '婚假' }, { label: '例假', value: '例假' }, { label: '丧假', value: '丧假' }, { label: '哺乳假', value: '哺乳假' } ] function buildLeaveKitChildren() { const typeField = uniqueId() const startField = uniqueId() const endField = uniqueId() const durationField = uniqueId() return { startField, endField, durationField, typeField, children: [ { type: 'select', field: typeField, title: '请假类型', info: '', $required: true, options: LEAVE_TYPE_OPTIONS.map((o) => ({ ...o })), props: { placeholder: '请选择请假类型', clearable: true } }, { type: 'datePicker', field: startField, title: '开始时间', info: '', $required: true, props: { type: 'datetime', format: 'YYYY-MM-DD HH:mm', valueFormat: 'YYYY-MM-DD HH:mm', placeholder: '请选择开始时间' } }, { type: 'datePicker', field: endField, title: '结束时间', info: '', $required: true, props: { type: 'datetime', format: 'YYYY-MM-DD HH:mm', valueFormat: 'YYYY-MM-DD HH:mm', placeholder: '请选择结束时间' } }, { type: 'inputNumber', field: durationField, title: '时长(h)', info: '可按工时自动计算;手改后不再自动联动', $required: true, props: { precision: 1, min: 0, controlsPosition: 'right', align: 'left' }, class: 'oa-leave-duration' } ] } } /** FormCreate Designer DragRule:请假套件 */ export const leaveKitDragRule = { menu: 'kit' as const, icon: 'icon-askforleave', label: '请假', name: 'leaveKit', input: false, drag: true, dragBtn: true, mask: false, inside: true, rule() { const built = buildLeaveKitChildren() return { type: 'leaveKit', props: { ...DEFAULT_LEAVE_WORK_HOURS, startField: built.startField, endField: built.endField, durationField: built.durationField, typeField: built.typeField }, children: built.children } }, props() { return [ { type: 'input', field: 'morningStart', title: '上午开始', value: DEFAULT_LEAVE_WORK_HOURS.morningStart, props: { placeholder: 'HH:mm' } }, { type: 'input', field: 'morningEnd', title: '上午结束', value: DEFAULT_LEAVE_WORK_HOURS.morningEnd, props: { placeholder: 'HH:mm' } }, { type: 'input', field: 'afternoonStart', title: '下午开始', value: DEFAULT_LEAVE_WORK_HOURS.afternoonStart, props: { placeholder: 'HH:mm' } }, { type: 'input', field: 'afternoonEnd', title: '下午结束', value: DEFAULT_LEAVE_WORK_HOURS.afternoonEnd, props: { placeholder: 'HH:mm' } } ] } }