@tmagic/form 1.5.20 → 1.5.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.20",
2
+ "version": "1.5.22",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -51,9 +51,9 @@
51
51
  "peerDependencies": {
52
52
  "vue": ">=3.5.0",
53
53
  "typescript": "*",
54
- "@tmagic/utils": "1.5.20",
55
- "@tmagic/form-schema": "1.5.20",
56
- "@tmagic/design": "1.5.20"
54
+ "@tmagic/utils": "1.5.22",
55
+ "@tmagic/form-schema": "1.5.22",
56
+ "@tmagic/design": "1.5.22"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "typescript": {
@@ -133,7 +133,9 @@ const props = defineProps<{
133
133
  const emit = defineEmits(['swap-item', 'remove-item', 'change', 'addDiffCount', 'copy-item']);
134
134
 
135
135
  const mForm = inject<FormState | undefined>('mForm');
136
- const expand = ref(props.config.expandAll || !props.index);
136
+
137
+ const defaultExpandQuantity = props.config.defaultExpandQuantity ?? 7;
138
+ const expand = ref(props.config.expandAll || defaultExpandQuantity > props.index);
137
139
 
138
140
  const rowConfig = computed(() => ({
139
141
  type: 'row',
@@ -188,7 +188,7 @@ const getOptions = async () => {
188
188
  const requestFuc = getConfig('request') as Function;
189
189
 
190
190
  if (typeof option.beforeRequest === 'function') {
191
- postOptions = option.beforeRequest(mForm, postOptions, {
191
+ postOptions = await option.beforeRequest(mForm, postOptions, {
192
192
  model: props.model,
193
193
  formValue: mForm?.values,
194
194
  formValues: mForm?.values,
@@ -204,7 +204,7 @@ const getOptions = async () => {
204
204
  let res = await requestFuc(postOptions);
205
205
 
206
206
  if (typeof option.afterRequest === 'function') {
207
- res = option.afterRequest(mForm, res, {
207
+ res = await option.afterRequest(mForm, res, {
208
208
  model: props.model,
209
209
  formValue: mForm?.values,
210
210
  formValues: mForm?.values,
@@ -270,6 +270,7 @@ const getInitLocalOption = async () => {
270
270
  if (config.multiple && value.findIndex) {
271
271
  return (localOptions.value as any[]).filter((item) => value.findIndex((v: any) => equalValue(item.value, v)) > -1);
272
272
  }
273
+
273
274
  return (localOptions.value as any[]).filter((item) => equalValue(item.value, value));
274
275
  };
275
276
 
@@ -316,7 +317,7 @@ const getInitOption = async () => {
316
317
  };
317
318
 
318
319
  if (typeof option.beforeInitRequest === 'function') {
319
- postOptions = option.beforeInitRequest(mForm, postOptions, {
320
+ postOptions = await option.beforeInitRequest(mForm, postOptions, {
320
321
  model: props.model,
321
322
  formValue: mForm?.values,
322
323
  formValues: mForm?.values,
@@ -333,7 +334,7 @@ const getInitOption = async () => {
333
334
  let res = await requestFuc(postOptions);
334
335
 
335
336
  if (typeof option.afterRequest === 'function') {
336
- res = option.afterRequest(mForm, res, {
337
+ res = await option.afterRequest(mForm, res, {
337
338
  model: props.model,
338
339
  formValue: mForm?.values,
339
340
  formValues: mForm?.values,
@@ -359,6 +360,10 @@ const getInitOption = async () => {
359
360
  return options;
360
361
  };
361
362
 
363
+ const setOptions = (data: SelectOption[] | SelectGroupOption[]) => {
364
+ options.value = data;
365
+ };
366
+
362
367
  if (typeof props.config.options === 'function') {
363
368
  watchEffect(() => {
364
369
  typeof props.config.options === 'function' &&
@@ -371,12 +376,12 @@ if (typeof props.config.options === 'function') {
371
376
  config: props.config,
372
377
  }),
373
378
  ).then((data) => {
374
- options.value = data;
379
+ setOptions(data);
375
380
  });
376
381
  });
377
382
  } else if (Array.isArray(props.config.options)) {
378
383
  watchEffect(() => {
379
- options.value = props.config.options as SelectOption[] | SelectGroupOption[];
384
+ setOptions(props.config.options as SelectOption[] | SelectGroupOption[]);
380
385
  });
381
386
  } else if (props.config.option) {
382
387
  onBeforeMount(() => {
@@ -384,7 +389,7 @@ if (typeof props.config.options === 'function') {
384
389
  const v = props.model[props.name];
385
390
  if (Array.isArray(v) ? v.length : typeof v !== 'undefined') {
386
391
  getInitOption().then((data) => {
387
- options.value = data;
392
+ setOptions(data);
388
393
  });
389
394
  }
390
395
  });
@@ -413,7 +418,7 @@ if (props.config.remote) {
413
418
  }
414
419
  moreLoadingVisible.value = true;
415
420
  pgIndex.value += 1;
416
- options.value = await getOptions();
421
+ setOptions(await getOptions());
417
422
  moreLoadingVisible.value = false;
418
423
  });
419
424
  },
@@ -438,7 +443,7 @@ const visibleHandler = async (visible: boolean) => {
438
443
  tMagicSelect.value.setPreviousQuery(query.value);
439
444
  tMagicSelect.value.setSelectedLabel(query.value);
440
445
  } else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
441
- options.value = await getOptions();
446
+ setOptions(await getOptions());
442
447
  }
443
448
  };
444
449
 
@@ -446,7 +451,7 @@ const remoteMethod = async (q: string) => {
446
451
  if (!localOptions.value.length) {
447
452
  query.value = q;
448
453
  pgIndex.value = 0;
449
- options.value = await getOptions();
454
+ setOptions(await getOptions());
450
455
  // 多选时如果过滤选项会导致已选好的标签异常,需要重新刷新一下el-select的状态
451
456
  if (props.config.multiple)
452
457
  setTimeout(() => {
@@ -454,4 +459,9 @@ const remoteMethod = async (q: string) => {
454
459
  }, 0);
455
460
  }
456
461
  };
462
+
463
+ defineExpose({
464
+ options,
465
+ setOptions,
466
+ });
457
467
  </script>