提交
This commit is contained in:
1 parent
80138c6388
commit
693e8a678e
682 files changed
+211375
-5306
No files matched your search
@@ -1,9 +1,17 @@
|
||||
/** 加班套件运行时:时长仅手动填写,补齐数字框左对齐;加班人默认当前登录人 */
|
||||
/** 加班套件运行时:时长可按起止自动计算,支持手改;加班人默认当前登录人 */
|
||||
|
||||
import {
|
||||
buildCurrentOwnerPerson,
|
||||
type OwnerUserSnapshot
|
||||
} from '@/utils/oa-owner-field-defaults'
|
||||
import {
|
||||
calcOvertimeHours,
|
||||
DEFAULT_OVERTIME_WINDOWS,
|
||||
type OvertimeWindows,
|
||||
type RestDayResolver
|
||||
} from '@/utils/oa-overtime-hours'
|
||||
|
||||
export const OVERTIME_MANUAL_PREFIX = '__manual_'
|
||||
|
||||
function asRules(schema: unknown): Record<string, unknown>[] {
|
||||
if (Array.isArray(schema)) return schema.filter((r) => r && typeof r === 'object') as any
|
||||
@@ -29,16 +37,22 @@ function walk(rules: Record<string, unknown>[], out: Record<string, unknown>[])
|
||||
|
||||
export type OvertimeKitBinding = {
|
||||
personField?: string
|
||||
durationField?: string
|
||||
startField: string
|
||||
endField: string
|
||||
durationField: string
|
||||
windows: OvertimeWindows
|
||||
}
|
||||
|
||||
function resolveBinding(kit: Record<string, unknown>): OvertimeKitBinding {
|
||||
function resolveBinding(kit: Record<string, unknown>): OvertimeKitBinding | null {
|
||||
const props = (kit.props && typeof kit.props === 'object' ? kit.props : {}) as Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
let personField = props.personField ? String(props.personField) : undefined
|
||||
let startField = props.startField ? String(props.startField) : undefined
|
||||
let endField = props.endField ? String(props.endField) : undefined
|
||||
let durationField = props.durationField ? String(props.durationField) : undefined
|
||||
|
||||
const children = (
|
||||
Array.isArray(kit.children)
|
||||
? kit.children
|
||||
@@ -46,19 +60,66 @@ function resolveBinding(kit: Record<string, unknown>): OvertimeKitBinding {
|
||||
? props.rule
|
||||
: []
|
||||
) as Record<string, any>[]
|
||||
|
||||
for (const c of children) {
|
||||
if (!c?.field) continue
|
||||
const sem = String(c.props?._fc_kit_field || '')
|
||||
if (sem === 'overtimePerson' && !personField) personField = String(c.field)
|
||||
if (sem === 'overtimeStart' && !startField) startField = String(c.field)
|
||||
if (sem === 'overtimeEnd' && !endField) endField = String(c.field)
|
||||
if (sem === 'overtimeDuration' && !durationField) durationField = String(c.field)
|
||||
}
|
||||
return { personField, durationField }
|
||||
|
||||
if (!startField || !endField || !durationField) {
|
||||
const dateFields: string[] = []
|
||||
let dur: string | undefined
|
||||
for (const c of children) {
|
||||
if (!c?.field) continue
|
||||
const t = String(c.type || '')
|
||||
if (t === 'datePicker' || t === 'date' || t === 'timePicker' || t === 'time') {
|
||||
dateFields.push(String(c.field))
|
||||
} else if (
|
||||
(t === 'inputNumber' || t === 'number') &&
|
||||
(String(c.title || '').includes('时长') || String(c.props?._fc_kit_field || '') === 'overtimeDuration')
|
||||
) {
|
||||
dur = String(c.field)
|
||||
}
|
||||
}
|
||||
startField = startField || dateFields[0]
|
||||
endField = endField || dateFields[1]
|
||||
durationField = durationField || dur
|
||||
}
|
||||
|
||||
if (!startField || !endField || !durationField) return null
|
||||
|
||||
return {
|
||||
personField,
|
||||
startField,
|
||||
endField,
|
||||
durationField,
|
||||
windows: {
|
||||
workdayOvertimeStart: String(
|
||||
props.workdayOvertimeStart || DEFAULT_OVERTIME_WINDOWS.workdayOvertimeStart
|
||||
),
|
||||
workdayOvertimeEnd: String(
|
||||
props.workdayOvertimeEnd || DEFAULT_OVERTIME_WINDOWS.workdayOvertimeEnd
|
||||
),
|
||||
restBreakStart: String(props.restBreakStart || DEFAULT_OVERTIME_WINDOWS.restBreakStart),
|
||||
restBreakEnd: String(props.restBreakEnd || DEFAULT_OVERTIME_WINDOWS.restBreakEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function listOvertimeKitBindings(schema: unknown): OvertimeKitBinding[] {
|
||||
const flat: Record<string, unknown>[] = []
|
||||
walk(asRules(schema), flat)
|
||||
return flat.filter((r) => String(r.type || '') === 'overtimeKit').map(resolveBinding)
|
||||
const out: OvertimeKitBinding[] = []
|
||||
for (const r of flat) {
|
||||
if (String(r.type || '') !== 'overtimeKit') continue
|
||||
const b = resolveBinding(r)
|
||||
if (b) out.push(b)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function isEmptyPersonValue(raw: unknown): boolean {
|
||||
@@ -91,28 +152,57 @@ export function applyOvertimeKitDefaults(
|
||||
return data
|
||||
}
|
||||
|
||||
function resolveDurationField(kit: Record<string, unknown>): string | undefined {
|
||||
const binding = resolveBinding(kit)
|
||||
if (binding.durationField) return binding.durationField
|
||||
const props = (kit.props && typeof kit.props === 'object' ? kit.props : {}) as Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
const children = (
|
||||
Array.isArray(kit.children)
|
||||
? kit.children
|
||||
: Array.isArray(props.rule)
|
||||
? props.rule
|
||||
: []
|
||||
) as Record<string, any>[]
|
||||
for (const c of children) {
|
||||
if (!c?.field) continue
|
||||
const t = String(c.type || '')
|
||||
if ((t === 'inputNumber' || t === 'number') && String(c.title || '').includes('时长')) {
|
||||
return String(c.field)
|
||||
/** 未手改时写回时长;返回是否有变更 */
|
||||
export function applyOvertimeKitDurationsToFormData(
|
||||
schema: unknown,
|
||||
formData: Record<string, unknown>,
|
||||
isRestDay: RestDayResolver
|
||||
): { data: Record<string, unknown>; changed: boolean } {
|
||||
const data = { ...formData }
|
||||
let changed = false
|
||||
for (const kit of listOvertimeKitBindings(schema)) {
|
||||
const manualKey = OVERTIME_MANUAL_PREFIX + kit.durationField
|
||||
if (data[manualKey]) continue
|
||||
const hours = calcOvertimeHours(
|
||||
String(data[kit.startField] || ''),
|
||||
String(data[kit.endField] || ''),
|
||||
kit.windows,
|
||||
isRestDay
|
||||
)
|
||||
if (hours == null) continue
|
||||
if (data[kit.durationField] !== hours) {
|
||||
data[kit.durationField] = hours
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
return { data, changed }
|
||||
}
|
||||
|
||||
export function markOvertimeDurationManual(
|
||||
formData: Record<string, unknown>,
|
||||
durationField: string,
|
||||
manual = true
|
||||
) {
|
||||
const data = { ...formData }
|
||||
const key = OVERTIME_MANUAL_PREFIX + durationField
|
||||
if (manual) data[key] = true
|
||||
else delete data[key]
|
||||
return data
|
||||
}
|
||||
|
||||
export function isOvertimeDurationField(schema: unknown, field: string): boolean {
|
||||
return listOvertimeKitBindings(schema).some((k) => k.durationField === field)
|
||||
}
|
||||
|
||||
export function findOvertimeKitByStartOrEnd(
|
||||
schema: unknown,
|
||||
field: string
|
||||
): OvertimeKitBinding | null {
|
||||
return (
|
||||
listOvertimeKitBindings(schema).find(
|
||||
(k) => k.startField === field || k.endField === field
|
||||
) || null
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,14 +214,14 @@ export function ensureOvertimeKitRuleProps(rules: unknown): any[] {
|
||||
if (!raw || typeof raw !== 'object') return raw
|
||||
const rule: any = { ...(raw as object) }
|
||||
if (String(rule.type || '') === 'overtimeKit') {
|
||||
const durationField = resolveDurationField(rule)
|
||||
const binding = resolveBinding(rule)
|
||||
const patchChildren = (list: any[]): any[] =>
|
||||
list.map((c) => {
|
||||
if (!c || typeof c !== 'object') return c
|
||||
const child: any = { ...c }
|
||||
const t = String(child.type || '')
|
||||
const isDuration =
|
||||
(durationField && child.field === durationField) ||
|
||||
(binding && child.field === binding.durationField) ||
|
||||
((t === 'inputNumber' || t === 'number') &&
|
||||
String(child.title || '').includes('时长'))
|
||||
if (isDuration) {
|
||||
|
||||
Reference in new issue
Block a user