File tree Expand file tree Collapse file tree
frontend/packages/web/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<template >
22 <n-form-item
3+ ref =" crmFormItemRef"
34 :label =" props.fieldConfig.name"
45 :path =" props.path"
56 :rule =" props.fieldConfig.rules"
5253
5354<script setup lang="ts">
5455 import {
56+ type FormItemInst ,
5557 NFormItem ,
5658 NUpload ,
5759 NUploadDragger ,
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 ,
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
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 }
Original file line number Diff line number Diff line change 11<template >
22 <n-form-item
3+ ref =" crmFormItemRef"
34 :label =" props.fieldConfig.name"
45 :path =" props.path"
56 :rule =" props.fieldConfig.rules"
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 >
5651
5752<script setup lang="ts">
5853 import {
54+ type FormItemInst ,
5955 NDivider ,
6056 NFormItem ,
6157 NUpload ,
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 ) {
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
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 []) => {
Original file line number Diff line number Diff line change 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 );
Original file line number Diff line number Diff line change 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"
5858
5959 const data = defineModel <Record <string , any >[]>(' value' , {
6060 required: true ,
61+ default : () => [],
6162 });
6263
6364 function makeTitle(field : FormCreateField ) {
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">
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments