|
|
@@ -0,0 +1,105 @@
|
|
|
+/** 加班套件运行时:时长仅手动填写,补齐数字框左对齐 */
|
|
|
+
|
|
|
+function asRules(schema: unknown): Record<string, unknown>[] {
|
|
|
+ if (Array.isArray(schema)) return schema.filter((r) => r && typeof r === 'object') as any
|
|
|
+ if (schema && typeof schema === 'object') {
|
|
|
+ const s = schema as any
|
|
|
+ const rules = s.rule || s.rules || s.fields
|
|
|
+ if (Array.isArray(rules)) return rules.filter((r: any) => r && typeof r === 'object')
|
|
|
+ if (s.type || s.field) return [s]
|
|
|
+ }
|
|
|
+ return []
|
|
|
+}
|
|
|
+
|
|
|
+function resolveDurationField(kit: Record<string, unknown>): string | undefined {
|
|
|
+ const props = (kit.props && typeof kit.props === 'object' ? kit.props : {}) as Record<
|
|
|
+ string,
|
|
|
+ any
|
|
|
+ >
|
|
|
+ if (props.durationField) return String(props.durationField)
|
|
|
+ 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
|
|
|
+ if (String(c.props?._fc_kit_field || '') === 'overtimeDuration') return String(c.field)
|
|
|
+ const t = String(c.type || '')
|
|
|
+ if ((t === 'inputNumber' || t === 'number') && String(c.title || '').includes('时长')) {
|
|
|
+ return String(c.field)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return undefined
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 运行时补齐加班套件子规则:时长数字框默认左对齐。
|
|
|
+ */
|
|
|
+export function ensureOvertimeKitRuleProps(rules: unknown): any[] {
|
|
|
+ if (!Array.isArray(rules)) return []
|
|
|
+ return rules.map((raw) => {
|
|
|
+ if (!raw || typeof raw !== 'object') return raw
|
|
|
+ const rule: any = { ...(raw as object) }
|
|
|
+ if (String(rule.type || '') === 'overtimeKit') {
|
|
|
+ const durationField = resolveDurationField(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) ||
|
|
|
+ ((t === 'inputNumber' || t === 'number') &&
|
|
|
+ String(child.title || '').includes('时长'))
|
|
|
+ if (isDuration) {
|
|
|
+ child.props = { ...(child.props || {}), align: 'left' }
|
|
|
+ const cls = String(child.class || child.className || '')
|
|
|
+ if (!cls.includes('oa-overtime-duration')) {
|
|
|
+ child.class = (cls ? cls + ' ' : '') + 'oa-overtime-duration'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Array.isArray(child.children)) {
|
|
|
+ child.children = patchChildren(child.children)
|
|
|
+ }
|
|
|
+ return child
|
|
|
+ })
|
|
|
+ if (Array.isArray(rule.children)) {
|
|
|
+ rule.children = patchChildren(rule.children)
|
|
|
+ }
|
|
|
+ if (Array.isArray(rule.props?.rule)) {
|
|
|
+ rule.props = {
|
|
|
+ ...rule.props,
|
|
|
+ rule: patchChildren(rule.props.rule)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Array.isArray(rule.children)) {
|
|
|
+ rule.children = ensureOvertimeKitRuleProps(rule.children)
|
|
|
+ }
|
|
|
+ if (Array.isArray(rule.props?.rule)) {
|
|
|
+ rule.props = {
|
|
|
+ ...rule.props,
|
|
|
+ rule: ensureOvertimeKitRuleProps(rule.props.rule)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rule
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/** 供类型检查 / 后续扩展:当前 schema 是否含加班套件 */
|
|
|
+export function hasOvertimeKit(schema: unknown): boolean {
|
|
|
+ const flat: Record<string, unknown>[] = []
|
|
|
+ const walk = (rules: Record<string, unknown>[]) => {
|
|
|
+ for (const r of rules) {
|
|
|
+ flat.push(r)
|
|
|
+ if (Array.isArray(r.children)) walk(r.children as any)
|
|
|
+ const props = r.props as any
|
|
|
+ if (props && Array.isArray(props.rule)) walk(props.rule)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ walk(asRules(schema))
|
|
|
+ return flat.some((r) => String(r.type || '') === 'overtimeKit')
|
|
|
+}
|