Skip to content

Commit 33aab37

Browse files
ba1q1fit2-zhao
authored andcommitted
fix: form create
1 parent 5778e90 commit 33aab37

5 files changed

Lines changed: 37 additions & 12 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<n-form-item
3+
ref="crmFormItemRef"
34
:label="props.fieldConfig.name"
45
:path="props.path"
56
:rule="props.fieldConfig.rules"
@@ -52,6 +53,7 @@
5253

5354
<script setup lang="ts">
5455
import {
56+
type FormItemInst,
5557
NFormItem,
5658
NUpload,
5759
NUploadDragger,
@@ -85,6 +87,7 @@
8587
});
8688
const fileList = ref<UploadFileInfo[]>([]);
8789
const fileKeysMap = ref<Record<string, string>>({});
90+
const crmFormItemRef = ref<FormItemInst>();
8891
8992
async function beforeUpload({
9093
file,
@@ -151,6 +154,7 @@
151154
onFinish();
152155
fileKeys.value.push(...res.data);
153156
[fileKeysMap.value[file.id]] = res.data;
157+
crmFormItemRef.value?.validate();
154158
emit('change', fileKeys.value, fileList.value);
155159
} catch (error) {
156160
// eslint-disable-next-line no-console
@@ -164,6 +168,7 @@
164168
function handleFileListChange(files: UploadFileInfo[]) {
165169
if (fileKeys.value.length > files.length) {
166170
fileKeys.value = fileKeys.value.filter((key) => files.some((file) => file.id === key));
171+
crmFormItemRef.value?.validate();
167172
emit('change', fileKeys.value, fileList.value);
168173
}
169174
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<n-form-item
3+
ref="crmFormItemRef"
34
:label="props.fieldConfig.name"
45
:path="props.path"
56
:rule="props.fieldConfig.rules"
@@ -33,13 +34,7 @@
3334
multiple
3435
directory-dnd
3536
@before-upload="beforeUpload"
36-
@update-file-list="
37-
() => {
38-
if (fileKeys.length !== 0 || fileKeys.length === fileList.length) {
39-
emit('change', fileKeys, fileList);
40-
}
41-
}
42-
"
37+
@update-file-list="handleUploadFileListChange"
4338
@remove="handleFileRemove"
4439
>
4540
<n-upload-dragger>
@@ -56,6 +51,7 @@
5651

5752
<script setup lang="ts">
5853
import {
54+
type FormItemInst,
5955
NDivider,
6056
NFormItem,
6157
NUpload,
@@ -96,6 +92,7 @@
9692
});
9793
const fileList = ref<UploadFileInfo[]>([]);
9894
const fileKeysMap = ref<Record<string, string>>({});
95+
const crmFormItemRef = ref<FormItemInst>();
9996
10097
const getTriggerStyle = computed(() => {
10198
if (props.isSubTableField || props.isSubTableRender) {
@@ -163,6 +160,7 @@
163160
onFinish();
164161
fileKeys.value.push(...res.data);
165162
[fileKeysMap.value[file.id]] = res.data;
163+
crmFormItemRef.value?.validate();
166164
emit('change', fileKeys.value, fileList.value);
167165
} catch (error) {
168166
// eslint-disable-next-line no-console
@@ -186,6 +184,13 @@
186184
}
187185
}
188186
187+
function handleUploadFileListChange() {
188+
if (fileKeys.value.length !== 0 || fileKeys.value.length === fileList.value.length) {
189+
crmFormItemRef.value?.validate();
190+
emit('change', fileKeys.value, fileList.value);
191+
}
192+
}
193+
189194
watch(
190195
() => fileKeys.value,
191196
(keys: string[]) => {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,6 @@
344344
dataSourceFormFields
345345
);
346346
}
347-
if (item.type === FieldTypeEnum.ATTACHMENT) {
348-
formRef.value?.validate();
349-
}
350347
if (item.type === FieldTypeEnum.DATA_SOURCE && item.showFields?.length) {
351348
// 数据源显示字段联动
352349
const showFields = fieldList.value.filter((f) => f.resourceFieldId === item.id);

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<n-data-table
33
:columns="realColumns"
4-
:data="data"
4+
:data="data || []"
55
:paging="false"
66
:pagination="false"
77
:scroll-x="scrollXWidth"
@@ -58,6 +58,7 @@
5858
5959
const data = defineModel<Record<string, any>[]>('value', {
6060
required: true,
61+
default: () => [],
6162
});
6263
6364
function makeTitle(field: FormCreateField) {
@@ -685,6 +686,18 @@
685686
});
686687
return summaryRes;
687688
};
689+
690+
watch(
691+
() => data.value,
692+
(val) => {
693+
if (val === null || val === undefined) {
694+
data.value = [];
695+
}
696+
},
697+
{
698+
immediate: true,
699+
}
700+
);
688701
</script>
689702

690703
<style lang="less">

frontend/packages/web/src/hooks/useFormCreateApi.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,12 @@ export default function useFormCreateApi(props: FormCreateApiProps) {
11521152
staticRule.message = t(staticRule.message as string, { value: t(item.name) });
11531153
staticRule.type = getRuleType(item);
11541154
if (
1155-
[FieldTypeEnum.DATA_SOURCE, FieldTypeEnum.DATA_SOURCE_MULTIPLE, FieldTypeEnum.PICTURE].includes(item.type)
1155+
[
1156+
FieldTypeEnum.DATA_SOURCE,
1157+
FieldTypeEnum.DATA_SOURCE_MULTIPLE,
1158+
FieldTypeEnum.PICTURE,
1159+
FieldTypeEnum.ATTACHMENT,
1160+
].includes(item.type)
11561161
) {
11571162
staticRule.trigger = 'none';
11581163
}

0 commit comments

Comments
 (0)