mirror of
https://github.com/1Panel-dev/CordysCRM.git
synced 2026-05-14 03:02:10 +08:00
feat: formula calc occupancy
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user