Skip to content

Commit 0ab6a28

Browse files
committed
fix: formula field changed tooltip
1 parent ef4152c commit 0ab6a28

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

frontend/packages/web/src/components/business/crm-form-create/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@
311311
});
312312
}
313313
314+
provide('formFieldsProvider', readonly(fieldList));
315+
314316
function handleFieldChange(
315317
value: any,
316318
source: Record<string, any>[],

frontend/packages/web/src/components/business/crm-formula/index.vue

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,59 @@
5050
default: 0,
5151
});
5252
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+
});
56106
57107
function getScalarFieldValue(
58108
fieldId: string,

0 commit comments

Comments
 (0)