@tmagic/form 1.5.20 → 1.5.21

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.
@@ -4018,7 +4018,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4018
4018
  lastValues: {}
4019
4019
  },
4020
4020
  emits: ["change"],
4021
- setup(__props, { emit: __emit }) {
4021
+ setup(__props, { expose: __expose, emit: __emit }) {
4022
4022
  const props = __props;
4023
4023
  const emit = __emit;
4024
4024
  const optionComponent = getDesignConfig("components")?.option;
@@ -4094,7 +4094,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4094
4094
  postOptions.data = body;
4095
4095
  const requestFuc = getConfig("request");
4096
4096
  if (typeof option.beforeRequest === "function") {
4097
- postOptions = option.beforeRequest(mForm, postOptions, {
4097
+ postOptions = await option.beforeRequest(mForm, postOptions, {
4098
4098
  model: props.model,
4099
4099
  formValue: mForm?.values,
4100
4100
  formValues: mForm?.values,
@@ -4107,7 +4107,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4107
4107
  }
4108
4108
  let res = await requestFuc(postOptions);
4109
4109
  if (typeof option.afterRequest === "function") {
4110
- res = option.afterRequest(mForm, res, {
4110
+ res = await option.afterRequest(mForm, res, {
4111
4111
  model: props.model,
4112
4112
  formValue: mForm?.values,
4113
4113
  formValues: mForm?.values,
@@ -4196,7 +4196,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4196
4196
  json: option.json || false
4197
4197
  };
4198
4198
  if (typeof option.beforeInitRequest === "function") {
4199
- postOptions = option.beforeInitRequest(mForm, postOptions, {
4199
+ postOptions = await option.beforeInitRequest(mForm, postOptions, {
4200
4200
  model: props.model,
4201
4201
  formValue: mForm?.values,
4202
4202
  formValues: mForm?.values,
@@ -4210,7 +4210,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4210
4210
  const requestFuc = getConfig("request");
4211
4211
  let res = await requestFuc(postOptions);
4212
4212
  if (typeof option.afterRequest === "function") {
4213
- res = option.afterRequest(mForm, res, {
4213
+ res = await option.afterRequest(mForm, res, {
4214
4214
  model: props.model,
4215
4215
  formValue: mForm?.values,
4216
4216
  formValues: mForm?.values,
@@ -4232,6 +4232,9 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4232
4232
  }
4233
4233
  return options2;
4234
4234
  };
4235
+ const setOptions = (data) => {
4236
+ options.value = data;
4237
+ };
4235
4238
  if (typeof props.config.options === "function") {
4236
4239
  watchEffect(() => {
4237
4240
  typeof props.config.options === "function" && Promise.resolve(
@@ -4243,12 +4246,12 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4243
4246
  config: props.config
4244
4247
  })
4245
4248
  ).then((data) => {
4246
- options.value = data;
4249
+ setOptions(data);
4247
4250
  });
4248
4251
  });
4249
4252
  } else if (Array.isArray(props.config.options)) {
4250
4253
  watchEffect(() => {
4251
- options.value = props.config.options;
4254
+ setOptions(props.config.options);
4252
4255
  });
4253
4256
  } else if (props.config.option) {
4254
4257
  onBeforeMount(() => {
@@ -4256,7 +4259,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4256
4259
  const v = props.model[props.name];
4257
4260
  if (Array.isArray(v) ? v.length : typeof v !== "undefined") {
4258
4261
  getInitOption().then((data) => {
4259
- options.value = data;
4262
+ setOptions(data);
4260
4263
  });
4261
4264
  }
4262
4265
  });
@@ -4282,7 +4285,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4282
4285
  }
4283
4286
  moreLoadingVisible.value = true;
4284
4287
  pgIndex.value += 1;
4285
- options.value = await getOptions();
4288
+ setOptions(await getOptions());
4286
4289
  moreLoadingVisible.value = false;
4287
4290
  });
4288
4291
  },
@@ -4303,20 +4306,24 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4303
4306
  tMagicSelect.value.setPreviousQuery(query.value);
4304
4307
  tMagicSelect.value.setSelectedLabel(query.value);
4305
4308
  } else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
4306
- options.value = await getOptions();
4309
+ setOptions(await getOptions());
4307
4310
  }
4308
4311
  };
4309
4312
  const remoteMethod = async (q) => {
4310
4313
  if (!localOptions.value.length) {
4311
4314
  query.value = q;
4312
4315
  pgIndex.value = 0;
4313
- options.value = await getOptions();
4316
+ setOptions(await getOptions());
4314
4317
  if (props.config.multiple)
4315
4318
  setTimeout(() => {
4316
4319
  tMagicSelect.value?.setSelected();
4317
4320
  }, 0);
4318
4321
  }
4319
4322
  };
4323
+ __expose({
4324
+ options,
4325
+ setOptions
4326
+ });
4320
4327
  return (_ctx, _cache) => {
4321
4328
  const _directive_loading = resolveDirective("loading");
4322
4329
  return _ctx.model ? withDirectives((openBlock(), createBlock(unref(TMagicSelect), {
@@ -6948,7 +6948,7 @@
6948
6948
  lastValues: {}
6949
6949
  },
6950
6950
  emits: ["change"],
6951
- setup(__props, { emit: __emit }) {
6951
+ setup(__props, { expose: __expose, emit: __emit }) {
6952
6952
  const props = __props;
6953
6953
  const emit = __emit;
6954
6954
  const optionComponent = design.getDesignConfig("components")?.option;
@@ -7024,7 +7024,7 @@
7024
7024
  postOptions.data = body;
7025
7025
  const requestFuc = getConfig("request");
7026
7026
  if (typeof option.beforeRequest === "function") {
7027
- postOptions = option.beforeRequest(mForm, postOptions, {
7027
+ postOptions = await option.beforeRequest(mForm, postOptions, {
7028
7028
  model: props.model,
7029
7029
  formValue: mForm?.values,
7030
7030
  formValues: mForm?.values,
@@ -7037,7 +7037,7 @@
7037
7037
  }
7038
7038
  let res = await requestFuc(postOptions);
7039
7039
  if (typeof option.afterRequest === "function") {
7040
- res = option.afterRequest(mForm, res, {
7040
+ res = await option.afterRequest(mForm, res, {
7041
7041
  model: props.model,
7042
7042
  formValue: mForm?.values,
7043
7043
  formValues: mForm?.values,
@@ -7126,7 +7126,7 @@
7126
7126
  json: option.json || false
7127
7127
  };
7128
7128
  if (typeof option.beforeInitRequest === "function") {
7129
- postOptions = option.beforeInitRequest(mForm, postOptions, {
7129
+ postOptions = await option.beforeInitRequest(mForm, postOptions, {
7130
7130
  model: props.model,
7131
7131
  formValue: mForm?.values,
7132
7132
  formValues: mForm?.values,
@@ -7140,7 +7140,7 @@
7140
7140
  const requestFuc = getConfig("request");
7141
7141
  let res = await requestFuc(postOptions);
7142
7142
  if (typeof option.afterRequest === "function") {
7143
- res = option.afterRequest(mForm, res, {
7143
+ res = await option.afterRequest(mForm, res, {
7144
7144
  model: props.model,
7145
7145
  formValue: mForm?.values,
7146
7146
  formValues: mForm?.values,
@@ -7162,6 +7162,9 @@
7162
7162
  }
7163
7163
  return options2;
7164
7164
  };
7165
+ const setOptions = (data) => {
7166
+ options.value = data;
7167
+ };
7165
7168
  if (typeof props.config.options === "function") {
7166
7169
  vue.watchEffect(() => {
7167
7170
  typeof props.config.options === "function" && Promise.resolve(
@@ -7173,12 +7176,12 @@
7173
7176
  config: props.config
7174
7177
  })
7175
7178
  ).then((data) => {
7176
- options.value = data;
7179
+ setOptions(data);
7177
7180
  });
7178
7181
  });
7179
7182
  } else if (Array.isArray(props.config.options)) {
7180
7183
  vue.watchEffect(() => {
7181
- options.value = props.config.options;
7184
+ setOptions(props.config.options);
7182
7185
  });
7183
7186
  } else if (props.config.option) {
7184
7187
  vue.onBeforeMount(() => {
@@ -7186,7 +7189,7 @@
7186
7189
  const v = props.model[props.name];
7187
7190
  if (Array.isArray(v) ? v.length : typeof v !== "undefined") {
7188
7191
  getInitOption().then((data) => {
7189
- options.value = data;
7192
+ setOptions(data);
7190
7193
  });
7191
7194
  }
7192
7195
  });
@@ -7212,7 +7215,7 @@
7212
7215
  }
7213
7216
  moreLoadingVisible.value = true;
7214
7217
  pgIndex.value += 1;
7215
- options.value = await getOptions();
7218
+ setOptions(await getOptions());
7216
7219
  moreLoadingVisible.value = false;
7217
7220
  });
7218
7221
  },
@@ -7233,20 +7236,24 @@
7233
7236
  tMagicSelect.value.setPreviousQuery(query.value);
7234
7237
  tMagicSelect.value.setSelectedLabel(query.value);
7235
7238
  } else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
7236
- options.value = await getOptions();
7239
+ setOptions(await getOptions());
7237
7240
  }
7238
7241
  };
7239
7242
  const remoteMethod = async (q) => {
7240
7243
  if (!localOptions.value.length) {
7241
7244
  query.value = q;
7242
7245
  pgIndex.value = 0;
7243
- options.value = await getOptions();
7246
+ setOptions(await getOptions());
7244
7247
  if (props.config.multiple)
7245
7248
  setTimeout(() => {
7246
7249
  tMagicSelect.value?.setSelected();
7247
7250
  }, 0);
7248
7251
  }
7249
7252
  };
7253
+ __expose({
7254
+ options,
7255
+ setOptions
7256
+ });
7250
7257
  return (_ctx, _cache) => {
7251
7258
  const _directive_loading = vue.resolveDirective("loading");
7252
7259
  return _ctx.model ? vue.withDirectives((vue.openBlock(), vue.createBlock(vue.unref(design.TMagicSelect), {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.20",
2
+ "version": "1.5.21",
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/design": "1.5.21",
55
+ "@tmagic/form-schema": "1.5.21",
56
+ "@tmagic/utils": "1.5.21"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "typescript": {
@@ -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>
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as vue from 'vue';
2
2
  import { App } from 'vue';
3
3
  import * as _tmagic_form_schema from '@tmagic/form-schema';
4
- import { FormState, FormConfig, TabPaneConfig, FormValue, FilterFunction, Rule, ChildConfig, FieldsetConfig, PanelConfig, RowConfig, TabConfig, TableConfig, SortProp, TableColumnConfig, GroupListConfig, FieldProps, TextConfig, NumberConfig, NumberRangeConfig, TextareaConfig, HiddenConfig, DateConfig, DateTimeConfig, TimeConfig, CheckboxConfig, SwitchConfig, DaterangeConfig, ColorPickConfig, CheckboxGroupConfig, RadioGroupConfig, DisplayConfig, LinkConfig, SelectConfig, CascaderConfig, DynamicFieldConfig } from '@tmagic/form-schema';
4
+ import { FormState, FormConfig, TabPaneConfig, FormValue, FilterFunction, Rule, ChildConfig, FieldsetConfig, PanelConfig, RowConfig, TabConfig, TableConfig, SortProp, TableColumnConfig, GroupListConfig, FieldProps, TextConfig, NumberConfig, NumberRangeConfig, TextareaConfig, HiddenConfig, DateConfig, DateTimeConfig, TimeConfig, CheckboxConfig, SwitchConfig, DaterangeConfig, ColorPickConfig, CheckboxGroupConfig, RadioGroupConfig, DisplayConfig, LinkConfig, SelectConfig, SelectOption, SelectGroupOption, CascaderConfig, DynamicFieldConfig } from '@tmagic/form-schema';
5
5
  export * from '@tmagic/form-schema';
6
6
  import * as _tmagic_editor from '@tmagic/editor';
7
7
  import * as _tmagic_design from '@tmagic/design';
@@ -2448,7 +2448,36 @@ declare const _default$4: vue.DefineComponent<__VLS_Props$3, {}, {}, {}, {}, vue
2448
2448
  }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, false, {}, any>;
2449
2449
 
2450
2450
  type __VLS_Props$2 = FieldProps<SelectConfig>;
2451
- declare const _default$3: vue.DefineComponent<__VLS_Props$2, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
2451
+ declare const _default$3: vue.DefineComponent<__VLS_Props$2, {
2452
+ options: vue.Ref<{
2453
+ text: string;
2454
+ value: any;
2455
+ disabled?: boolean | undefined;
2456
+ }[] | {
2457
+ label: string;
2458
+ disabled: boolean;
2459
+ options: {
2460
+ label?: string | undefined;
2461
+ text?: string | undefined;
2462
+ value: any;
2463
+ disabled?: boolean | undefined;
2464
+ }[];
2465
+ }[], SelectOption[] | SelectGroupOption[] | {
2466
+ text: string;
2467
+ value: any;
2468
+ disabled?: boolean | undefined;
2469
+ }[] | {
2470
+ label: string;
2471
+ disabled: boolean;
2472
+ options: {
2473
+ label?: string | undefined;
2474
+ text?: string | undefined;
2475
+ value: any;
2476
+ disabled?: boolean | undefined;
2477
+ }[];
2478
+ }[]>;
2479
+ setOptions: (data: SelectOption[] | SelectGroupOption[]) => void;
2480
+ }, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
2452
2481
  change: (...args: any[]) => void;
2453
2482
  }, string, vue.PublicProps, Readonly<__VLS_Props$2> & Readonly<{
2454
2483
  onChange?: ((...args: any[]) => any) | undefined;