feat: formula calc occupancy

This commit is contained in:
xinxin.wu
2026-03-26 19:02:51 +08:00
committed by zhao
parent 9ac2f85243
commit c340f9c2f0
3 changed files with 16 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import { FieldTypeEnum } from '@lib/shared/enums/formDesignEnum';
import { IRNodeType } from '@lib/shared/enums/formula';
import {
@@ -81,7 +82,16 @@ function parseDateWithPrecision(raw: string | number | Date): number {
export function resolveFieldValue(rawVal: any, node: IRNode, ctx?: EvaluateContext): any {
const meta = node.type === 'field' ? ctx?.getFieldMeta?.(node.fieldId) : undefined;
if (rawVal == null || rawVal === '') {
const isEmptyString = typeof rawVal === 'string' && rawVal.trim() === '';
const isEmptyValue = rawVal == null || rawVal === '' || isEmptyString;
if (isEmptyValue) {
// 只有流水号字段,在取不到值时保留占位符 ${name}
if (node.type === 'field' && meta?.fieldType === FieldTypeEnum.SERIAL_NUMBER) {
return `\${${ctx?.getFieldMeta?.(node.fieldId)?.name || node.fieldId}}`;
}
if (meta?.valueType === 'date' || meta?.valueType === 'number') {
return null;
}

View File

@@ -33,6 +33,8 @@ export function getValueType(field: FormCreateField): ValueType {
function buildFieldTypeInfo(field: FormCreateField): FieldMeta {
return {
valueType: getValueType(field),
fieldType: field.type,
name: field.name,
...(field.type === FieldTypeEnum.INPUT_NUMBER
? {
numberType: field.numberFormat === 'percent' ? 'percent' : 'number',

View File

@@ -1,3 +1,4 @@
import { FieldTypeEnum } from '@lib/shared/enums/formDesignEnum';
import { IRNodeType } from '@lib/shared/enums/formula';
import { FormCreateField } from '@/components/business/crm-form-create/types';
@@ -54,6 +55,8 @@ export type ValueType = 'number' | 'string' | 'boolean' | 'date' | 'unknown';
export interface FieldMeta {
valueType: ValueType;
name: string;
fieldType: FieldTypeEnum;
numberType?: 'number' | 'percent';
}