|
50 | 50 | default: 0, |
51 | 51 | }); |
52 | 52 |
|
53 | | - const formulaTooltip = computed( |
54 | | - () => safeParseFormula(props.fieldConfig.formula ?? '').display || t('crmFormDesign.formulaTooltip') |
55 | | - ); |
| 53 | + const fieldList = inject('formFieldsProvider', ref([])); |
| 54 | +
|
| 55 | + function resolveFieldId(e: FormCreateField, inSubTable?: boolean) { |
| 56 | + if (e.resourceFieldId) { |
| 57 | + return e.id; |
| 58 | + } |
| 59 | +
|
| 60 | + return inSubTable ? e.businessKey || e.id : e.id; |
| 61 | + } |
| 62 | +
|
| 63 | + function flatAllFields(fields: FormCreateField[]) { |
| 64 | + const result: (FormCreateField & { parentId?: string; parentName?: string; inSubTable?: boolean })[] = []; |
| 65 | + fields?.forEach((field) => { |
| 66 | + if (field.subFields) { |
| 67 | + field.subFields.forEach((sub) => { |
| 68 | + result.push({ |
| 69 | + ...sub, |
| 70 | + name: `${field.name}.${sub.name}`, |
| 71 | + parentId: field.id, |
| 72 | + id: props.isSubTableRender ? sub.id : `${field.id}.${resolveFieldId(sub, true)}`, |
| 73 | + parentName: field.name, |
| 74 | + inSubTable: true, |
| 75 | + }); |
| 76 | + }); |
| 77 | + } else { |
| 78 | + result.push({ |
| 79 | + ...field, |
| 80 | + inSubTable: false, |
| 81 | + }); |
| 82 | + } |
| 83 | + }); |
| 84 | +
|
| 85 | + return result; |
| 86 | + } |
| 87 | +
|
| 88 | + const allFieldIds = computed(() => { |
| 89 | + const fields = fieldList.value ?? []; |
| 90 | + return flatAllFields(fields).map((e) => e.id); |
| 91 | + }); |
| 92 | + const isFormulaInvalid = computed(() => { |
| 93 | + const { fields } = safeParseFormula(props.fieldConfig.formula ?? ''); |
| 94 | + const savedFields = fields?.map((e: any) => e.fieldId); |
| 95 | +
|
| 96 | + return savedFields.some((fieldId: string) => !allFieldIds.value.includes(fieldId)); |
| 97 | + }); |
| 98 | +
|
| 99 | + const formulaTooltip = computed(() => { |
| 100 | + const { display } = safeParseFormula(props.fieldConfig.formula ?? ''); |
| 101 | + if (display) { |
| 102 | + return isFormulaInvalid.value ? t('crmFormDesign.formulaFieldChanged') : display; |
| 103 | + } |
| 104 | + return t('crmFormDesign.formulaTooltip'); |
| 105 | + }); |
56 | 106 |
|
57 | 107 | function getScalarFieldValue( |
58 | 108 | fieldId: string, |
|
0 commit comments