@tmagic/form 1.4.7 → 1.4.9

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.
@@ -153,8 +153,7 @@ const getRules = function(mForm, rules = [], props) {
153
153
  });
154
154
  };
155
155
  const initValue = async (mForm, { initValues, config }) => {
156
- if (!Array.isArray(config))
157
- throw new Error("config应该为数组");
156
+ if (!Array.isArray(config)) throw new Error("config应该为数组");
158
157
  let valuesTmp = createValues(mForm, config, toRaw(initValues), {});
159
158
  const [firstForm] = config;
160
159
  if (firstForm && typeof firstForm.onInitValue === "function") {
@@ -208,8 +207,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
208
207
  const expand = ref(false);
209
208
  const name = computed(() => props.config.name || "");
210
209
  const showDiff = computed(() => {
211
- if (!props.isCompare)
212
- return false;
210
+ if (!props.isCompare) return false;
213
211
  const curValue = name.value ? props.model[name.value] : props.model;
214
212
  const lastValue = name.value ? props.lastValues[name.value] : props.lastValues;
215
213
  return !isEqual(curValue, lastValue);
@@ -236,10 +234,8 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
236
234
  const type = computed(() => {
237
235
  let { type: type2 } = props.config;
238
236
  type2 = type2 && filterFunction(mForm, type2, props);
239
- if (type2 === "form")
240
- return "";
241
- if (type2 === "container")
242
- return "";
237
+ if (type2 === "form") return "";
238
+ if (type2 === "container") return "";
243
239
  return type2?.replace(/([A-Z])/g, "-$1").toLowerCase() || (items.value ? "" : "text");
244
240
  });
245
241
  const display$1 = computed(() => {
@@ -256,10 +252,8 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
256
252
  watch(
257
253
  showDiff,
258
254
  (showDiff2) => {
259
- if (type.value === "hidden")
260
- return;
261
- if (items.value && !text.value && type.value && display$1.value)
262
- return;
255
+ if (type.value === "hidden") return;
256
+ if (items.value && !text.value && type.value && display$1.value) return;
263
257
  if (display$1.value && showDiff2 && type.value) {
264
258
  emit("addDiffCount");
265
259
  }
@@ -795,8 +789,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
795
789
  const changeOrder = (offset = 0) => emit("swap-item", props.index, props.index + offset);
796
790
  const movable = () => {
797
791
  const { movable: movable2 } = props.config;
798
- if (movable2 === void 0)
799
- return true;
792
+ if (movable2 === void 0) return true;
800
793
  if (typeof movable2 === "function") {
801
794
  return movable2(mForm, props.index || 0, props.model, props.groupModel);
802
795
  }
@@ -927,8 +920,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
927
920
  const emit = __emit;
928
921
  const mForm = inject("mForm");
929
922
  const addable = computed(() => {
930
- if (!props.name)
931
- return false;
923
+ if (!props.name) return false;
932
924
  if (typeof props.config.addable === "function") {
933
925
  return props.config.addable(mForm, {
934
926
  model: props.model[props.name],
@@ -940,13 +932,11 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
940
932
  return typeof props.config.addable === "undefined" ? true : props.config.addable;
941
933
  });
942
934
  const changeHandler = () => {
943
- if (!props.name)
944
- return false;
935
+ if (!props.name) return false;
945
936
  emit("change", props.model[props.name]);
946
937
  };
947
938
  const addHandler = async () => {
948
- if (!props.name)
949
- return false;
939
+ if (!props.name) return false;
950
940
  let initValues = {};
951
941
  if (typeof props.config.defaultAdd === "function") {
952
942
  initValues = await props.config.defaultAdd(mForm, {
@@ -965,14 +955,12 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
965
955
  props.model[props.name].push(groupValue);
966
956
  };
967
957
  const removeHandler = (index) => {
968
- if (!props.name)
969
- return false;
958
+ if (!props.name) return false;
970
959
  props.model[props.name].splice(index, 1);
971
960
  changeHandler();
972
961
  };
973
962
  const swapHandler = (idx1, idx2) => {
974
- if (!props.name)
975
- return false;
963
+ if (!props.name) return false;
976
964
  const [currRow] = props.model[props.name].splice(idx1, 1);
977
965
  props.model[props.name].splice(idx2, 0, currRow);
978
966
  changeHandler();
@@ -1409,10 +1397,8 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1409
1397
  if (tBodyEl) {
1410
1398
  const sortable = Sortable.create(tBodyEl, {
1411
1399
  onEnd: ({ newIndex, oldIndex }) => {
1412
- if (typeof newIndex === "undefined")
1413
- return;
1414
- if (typeof oldIndex === "undefined")
1415
- return;
1400
+ if (typeof newIndex === "undefined") return;
1401
+ if (typeof oldIndex === "undefined") return;
1416
1402
  swapArray(newIndex, oldIndex);
1417
1403
  emit("change", props.model[modelName.value]);
1418
1404
  foreUpdate();
@@ -1442,8 +1428,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1442
1428
  formValue: mForm?.values,
1443
1429
  prop: props.prop
1444
1430
  });
1445
- if (!beforeCheckRes)
1446
- return;
1431
+ if (!beforeCheckRes) return;
1447
1432
  }
1448
1433
  const columns = props.config.items;
1449
1434
  const enumValues = props.config.enum || [];
@@ -1548,8 +1533,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1548
1533
  return fuc;
1549
1534
  };
1550
1535
  const removeHandler = (index) => {
1551
- if (props.disabled)
1552
- return;
1536
+ if (props.disabled) return;
1553
1537
  props.model[modelName.value].splice(index, 1);
1554
1538
  emit("change", props.model[modelName.value]);
1555
1539
  };
@@ -1656,8 +1640,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1656
1640
  };
1657
1641
  const toggleMode = () => {
1658
1642
  const calcLabelWidth = (label) => {
1659
- if (!label)
1660
- return "0px";
1643
+ if (!label) return "0px";
1661
1644
  const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
1662
1645
  const chLength = label.length - zhLength;
1663
1646
  return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
@@ -1677,8 +1660,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1677
1660
  });
1678
1661
  };
1679
1662
  const toggleFullscreen = () => {
1680
- if (!mTable.value)
1681
- return;
1663
+ if (!mTable.value) return;
1682
1664
  if (isFullscreen.value) {
1683
1665
  mTable.value.classList.remove("fixed");
1684
1666
  isFullscreen.value = false;
@@ -1993,12 +1975,9 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
1993
1975
  const getActive = (mForm2, props2, activeTabName2) => {
1994
1976
  const { config, model, prop } = props2;
1995
1977
  const { active } = config;
1996
- if (typeof active === "function")
1997
- return active(mForm2, { model, formValue: mForm2?.values, prop });
1998
- if (+activeTabName2 >= props2.config.items.length)
1999
- return "0";
2000
- if (typeof active !== "undefined")
2001
- return active;
1978
+ if (typeof active === "function") return active(mForm2, { model, formValue: mForm2?.values, prop });
1979
+ if (+activeTabName2 >= props2.config.items.length) return "0";
1980
+ if (typeof active !== "undefined") return active;
2002
1981
  return "0";
2003
1982
  };
2004
1983
  const tabClick = (mForm2, tab, props2) => {
@@ -2019,8 +1998,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2019
1998
  const diffCount = ref({});
2020
1999
  const tabs = computed(() => {
2021
2000
  if (props.config.dynamic) {
2022
- if (!props.config.name)
2023
- throw new Error("dynamic tab 必须配置name");
2001
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2024
2002
  return props.model[props.config.name] || [];
2025
2003
  }
2026
2004
  return props.config.items.filter((item) => display(mForm, item.display, props));
@@ -2037,8 +2015,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2037
2015
  const tabItems = (tab) => props.config.dynamic ? props.config.items : tab.items;
2038
2016
  const tabClickHandler = (tab) => tabClick(mForm, tab, props);
2039
2017
  const onTabAdd = () => {
2040
- if (!props.config.name)
2041
- throw new Error("dynamic tab 必须配置name");
2018
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2042
2019
  if (typeof props.config.onTabAdd === "function") {
2043
2020
  props.config.onTabAdd(mForm, {
2044
2021
  model: props.model,
@@ -2054,8 +2031,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2054
2031
  mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2055
2032
  };
2056
2033
  const onTabRemove = (tabName) => {
2057
- if (!props.config.name)
2058
- throw new Error("dynamic tab 必须配置name");
2034
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2059
2035
  if (typeof props.config.onTabRemove === "function") {
2060
2036
  props.config.onTabRemove(mForm, tabName, {
2061
2037
  model: props.model,
@@ -2158,8 +2134,7 @@ const setConfig = (option) => {
2158
2134
  const getConfig = (key) => $MAGIC_FORM[key];
2159
2135
 
2160
2136
  const useAddField = (prop) => {
2161
- if (!prop)
2162
- return;
2137
+ if (!prop) return;
2163
2138
  const mForm = inject("mForm");
2164
2139
  const instance = getCurrentInstance();
2165
2140
  watch(
@@ -2223,8 +2198,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2223
2198
  const setRemoteOptions = async function() {
2224
2199
  const { config } = props;
2225
2200
  const { option } = config;
2226
- if (!option)
2227
- return;
2201
+ if (!option) return;
2228
2202
  let { body } = option;
2229
2203
  const postOptions = {
2230
2204
  url: option.url,
@@ -2269,8 +2243,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2269
2243
  });
2270
2244
  }
2271
2245
  const changeHandler = () => {
2272
- if (!tMagicCascader.value)
2273
- return;
2246
+ if (!tMagicCascader.value) return;
2274
2247
  tMagicCascader.value.setQuery("");
2275
2248
  tMagicCascader.value.setPreviousQuery(null);
2276
2249
  emit("change", props.model[props.name]);
@@ -2392,10 +2365,8 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
2392
2365
  };
2393
2366
  const mForm = inject("mForm");
2394
2367
  const options = computed(() => {
2395
- if (Array.isArray(props.config.options))
2396
- return props.config.options;
2397
- if (typeof props.config.options === "function")
2398
- return filterFunction(mForm, props.config.options, props);
2368
+ if (Array.isArray(props.config.options)) return props.config.options;
2369
+ if (typeof props.config.options === "function") return filterFunction(mForm, props.config.options, props);
2399
2370
  return [];
2400
2371
  });
2401
2372
  return (_ctx, _cache) => {
@@ -2533,12 +2504,9 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2533
2504
  if (!value.value) {
2534
2505
  value.value = [];
2535
2506
  }
2536
- if (!start || !end)
2537
- value.value = [];
2538
- if (start !== preStart)
2539
- value.value[0] = new Date(start);
2540
- if (end !== preEnd)
2541
- value.value[1] = new Date(end);
2507
+ if (!start || !end) value.value = [];
2508
+ if (start !== preStart) value.value[0] = new Date(start);
2509
+ if (end !== preEnd) value.value[1] = new Date(end);
2542
2510
  },
2543
2511
  {
2544
2512
  immediate: true
@@ -2548,8 +2516,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2548
2516
  watch(
2549
2517
  () => props.model[props.name],
2550
2518
  (start, preStart) => {
2551
- if (start !== preStart)
2552
- value.value = start.map((item) => item ? new Date(item) : void 0);
2519
+ if (start !== preStart) value.value = start.map((item) => item ? new Date(item) : void 0);
2553
2520
  },
2554
2521
  {
2555
2522
  immediate: true
@@ -2575,8 +2542,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2575
2542
  emit(
2576
2543
  "change",
2577
2544
  value2.map((item) => {
2578
- if (item)
2579
- return datetimeFormatter(item, "");
2545
+ if (item) return datetimeFormatter(item, "");
2580
2546
  return void 0;
2581
2547
  })
2582
2548
  );
@@ -2714,14 +2680,12 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2714
2680
  value: {}
2715
2681
  });
2716
2682
  const changeFieldMap = async () => {
2717
- if (typeof props.config.returnFields !== "function" || !props.model)
2718
- return;
2683
+ if (typeof props.config.returnFields !== "function" || !props.model) return;
2719
2684
  const fields = await props.config.returnFields(props.config, props.model, request);
2720
2685
  fieldMap.value = {};
2721
2686
  fieldLabelMap.value = {};
2722
2687
  fields.forEach((v) => {
2723
- if (typeof v !== "object" || v.name === void 0)
2724
- return;
2688
+ if (typeof v !== "object" || v.name === void 0) return;
2725
2689
  let oldVal = props.model?.[v.name] || "";
2726
2690
  if (!oldVal && v.defaultValue !== void 0) {
2727
2691
  oldVal = v.defaultValue;
@@ -2925,12 +2889,9 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2925
2889
  const error = [];
2926
2890
  Object.entries(invalidFields).forEach(([, ValidateError]) => {
2927
2891
  ValidateError.forEach(({ field, message }) => {
2928
- if (field && message)
2929
- error.push(`${field} -> ${message}`);
2930
- if (field && !message)
2931
- error.push(`${field} -> 出现错误`);
2932
- if (!field && message)
2933
- error.push(`${message}`);
2892
+ if (field && message) error.push(`${field} -> ${message}`);
2893
+ if (field && !message) error.push(`${field} -> 出现错误`);
2894
+ if (!field && message) error.push(`${message}`);
2934
2895
  });
2935
2896
  });
2936
2897
  throw new Error(error.join("<br>"));
@@ -3453,8 +3414,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3453
3414
  const emit = __emit;
3454
3415
  const optionComponent = getConfig$1("components")?.option;
3455
3416
  const optionGroupComponent = getConfig$1("components")?.optionGroup;
3456
- if (!props.model)
3457
- throw new Error("不能没有model");
3417
+ if (!props.model) throw new Error("不能没有model");
3458
3418
  useAddField(props.prop);
3459
3419
  const tMagicSelect = ref();
3460
3420
  const mForm = inject("mForm");
@@ -3489,16 +3449,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3489
3449
  }));
3490
3450
  };
3491
3451
  const getOptions = async () => {
3492
- if (!props.model)
3493
- return [];
3452
+ if (!props.model) return [];
3494
3453
  if (localOptions.value.length) {
3495
3454
  return localOptions.value;
3496
3455
  }
3497
3456
  loading.value = true;
3498
3457
  let items = [];
3499
3458
  const { option } = props.config;
3500
- if (!option)
3501
- return [];
3459
+ if (!option) return [];
3502
3460
  const { root = "", totalKey = "total" } = option;
3503
3461
  let { body = {}, url } = option;
3504
3462
  if (typeof url === "function") {
@@ -3571,8 +3529,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3571
3529
  return pgIndex.value === 0 ? selectedOptions.concat(items) : options.value.concat(items);
3572
3530
  };
3573
3531
  const getInitLocalOption = async () => {
3574
- if (!props.model)
3575
- return [];
3532
+ if (!props.model) return [];
3576
3533
  const value = props.model[props.name];
3577
3534
  const { config } = props;
3578
3535
  localOptions.value = await getOptions();
@@ -3593,11 +3550,9 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3593
3550
  return localOptions.value.filter((item) => equalValue(item.value, value));
3594
3551
  };
3595
3552
  const getInitOption = async () => {
3596
- if (!props.model)
3597
- return [];
3553
+ if (!props.model) return [];
3598
3554
  const { option } = props.config;
3599
- if (!option)
3600
- return [];
3555
+ if (!option) return [];
3601
3556
  const { root = "", initRoot = "" } = option;
3602
3557
  let { initBody = {} } = option;
3603
3558
  let options2 = [];
@@ -3680,8 +3635,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3680
3635
  });
3681
3636
  } else if (props.config.option) {
3682
3637
  onBeforeMount(() => {
3683
- if (!props.model)
3684
- return;
3638
+ if (!props.model) return;
3685
3639
  const v = props.model[props.name];
3686
3640
  if (Array.isArray(v) ? v.length : typeof v !== "undefined") {
3687
3641
  getInitOption().then((data) => {
@@ -3725,10 +3679,8 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3725
3679
  emit("change", value);
3726
3680
  };
3727
3681
  const visibleHandler = async (visible) => {
3728
- if (!visible)
3729
- return;
3730
- if (!props.config.remote)
3731
- return;
3682
+ if (!visible) return;
3683
+ if (!props.config.remote) return;
3732
3684
  if (query.value && tMagicSelect.value) {
3733
3685
  tMagicSelect.value.setQuery(query.value);
3734
3686
  tMagicSelect.value.setPreviousQuery(query.value);
@@ -3955,8 +3907,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3955
3907
  mForm?.$emit("field-input", props.prop, v);
3956
3908
  };
3957
3909
  const buttonClickHandler = () => {
3958
- if (!appendConfig.value)
3959
- return;
3910
+ if (!appendConfig.value) return;
3960
3911
  if (typeof appendConfig.value.handler === "function") {
3961
3912
  appendConfig.value.handler(mForm, {
3962
3913
  model: props.model,
@@ -3965,10 +3916,8 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3965
3916
  }
3966
3917
  };
3967
3918
  const keyUpHandler = ($event) => {
3968
- if (!props.model)
3969
- return;
3970
- if (!props.name)
3971
- return;
3919
+ if (!props.model) return;
3920
+ if (!props.name) return;
3972
3921
  const arrowUp = $event.key === "ArrowUp";
3973
3922
  const arrowDown = $event.key === "ArrowDown";
3974
3923
  if (!arrowUp && !arrowDown) {
@@ -4198,12 +4147,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
4198
4147
  if (!value.value) {
4199
4148
  value.value = [];
4200
4149
  }
4201
- if (!start || !end)
4202
- value.value = [];
4203
- if (start !== preStart)
4204
- value.value[0] = start;
4205
- if (end !== preEnd)
4206
- value.value[1] = end;
4150
+ if (!start || !end) value.value = [];
4151
+ if (start !== preStart) value.value[0] = start;
4152
+ if (end !== preEnd) value.value[1] = end;
4207
4153
  },
4208
4154
  {
4209
4155
  immediate: true
@@ -152,8 +152,7 @@
152
152
  });
153
153
  };
154
154
  const initValue = async (mForm, { initValues, config }) => {
155
- if (!Array.isArray(config))
156
- throw new Error("config应该为数组");
155
+ if (!Array.isArray(config)) throw new Error("config应该为数组");
157
156
  let valuesTmp = createValues(mForm, config, vue.toRaw(initValues), {});
158
157
  const [firstForm] = config;
159
158
  if (firstForm && typeof firstForm.onInitValue === "function") {
@@ -207,8 +206,7 @@
207
206
  const expand = vue.ref(false);
208
207
  const name = vue.computed(() => props.config.name || "");
209
208
  const showDiff = vue.computed(() => {
210
- if (!props.isCompare)
211
- return false;
209
+ if (!props.isCompare) return false;
212
210
  const curValue = name.value ? props.model[name.value] : props.model;
213
211
  const lastValue = name.value ? props.lastValues[name.value] : props.lastValues;
214
212
  return !lodashEs.isEqual(curValue, lastValue);
@@ -235,10 +233,8 @@
235
233
  const type = vue.computed(() => {
236
234
  let { type: type2 } = props.config;
237
235
  type2 = type2 && filterFunction(mForm, type2, props);
238
- if (type2 === "form")
239
- return "";
240
- if (type2 === "container")
241
- return "";
236
+ if (type2 === "form") return "";
237
+ if (type2 === "container") return "";
242
238
  return type2?.replace(/([A-Z])/g, "-$1").toLowerCase() || (items.value ? "" : "text");
243
239
  });
244
240
  const display$1 = vue.computed(() => {
@@ -255,10 +251,8 @@
255
251
  vue.watch(
256
252
  showDiff,
257
253
  (showDiff2) => {
258
- if (type.value === "hidden")
259
- return;
260
- if (items.value && !text.value && type.value && display$1.value)
261
- return;
254
+ if (type.value === "hidden") return;
255
+ if (items.value && !text.value && type.value && display$1.value) return;
262
256
  if (display$1.value && showDiff2 && type.value) {
263
257
  emit("addDiffCount");
264
258
  }
@@ -794,8 +788,7 @@
794
788
  const changeOrder = (offset = 0) => emit("swap-item", props.index, props.index + offset);
795
789
  const movable = () => {
796
790
  const { movable: movable2 } = props.config;
797
- if (movable2 === void 0)
798
- return true;
791
+ if (movable2 === void 0) return true;
799
792
  if (typeof movable2 === "function") {
800
793
  return movable2(mForm, props.index || 0, props.model, props.groupModel);
801
794
  }
@@ -926,8 +919,7 @@
926
919
  const emit = __emit;
927
920
  const mForm = vue.inject("mForm");
928
921
  const addable = vue.computed(() => {
929
- if (!props.name)
930
- return false;
922
+ if (!props.name) return false;
931
923
  if (typeof props.config.addable === "function") {
932
924
  return props.config.addable(mForm, {
933
925
  model: props.model[props.name],
@@ -939,13 +931,11 @@
939
931
  return typeof props.config.addable === "undefined" ? true : props.config.addable;
940
932
  });
941
933
  const changeHandler = () => {
942
- if (!props.name)
943
- return false;
934
+ if (!props.name) return false;
944
935
  emit("change", props.model[props.name]);
945
936
  };
946
937
  const addHandler = async () => {
947
- if (!props.name)
948
- return false;
938
+ if (!props.name) return false;
949
939
  let initValues = {};
950
940
  if (typeof props.config.defaultAdd === "function") {
951
941
  initValues = await props.config.defaultAdd(mForm, {
@@ -964,14 +954,12 @@
964
954
  props.model[props.name].push(groupValue);
965
955
  };
966
956
  const removeHandler = (index) => {
967
- if (!props.name)
968
- return false;
957
+ if (!props.name) return false;
969
958
  props.model[props.name].splice(index, 1);
970
959
  changeHandler();
971
960
  };
972
961
  const swapHandler = (idx1, idx2) => {
973
- if (!props.name)
974
- return false;
962
+ if (!props.name) return false;
975
963
  const [currRow] = props.model[props.name].splice(idx1, 1);
976
964
  props.model[props.name].splice(idx2, 0, currRow);
977
965
  changeHandler();
@@ -1408,10 +1396,8 @@
1408
1396
  if (tBodyEl) {
1409
1397
  const sortable = Sortable.create(tBodyEl, {
1410
1398
  onEnd: ({ newIndex, oldIndex }) => {
1411
- if (typeof newIndex === "undefined")
1412
- return;
1413
- if (typeof oldIndex === "undefined")
1414
- return;
1399
+ if (typeof newIndex === "undefined") return;
1400
+ if (typeof oldIndex === "undefined") return;
1415
1401
  swapArray(newIndex, oldIndex);
1416
1402
  emit("change", props.model[modelName.value]);
1417
1403
  foreUpdate();
@@ -1441,8 +1427,7 @@
1441
1427
  formValue: mForm?.values,
1442
1428
  prop: props.prop
1443
1429
  });
1444
- if (!beforeCheckRes)
1445
- return;
1430
+ if (!beforeCheckRes) return;
1446
1431
  }
1447
1432
  const columns = props.config.items;
1448
1433
  const enumValues = props.config.enum || [];
@@ -1547,8 +1532,7 @@
1547
1532
  return fuc;
1548
1533
  };
1549
1534
  const removeHandler = (index) => {
1550
- if (props.disabled)
1551
- return;
1535
+ if (props.disabled) return;
1552
1536
  props.model[modelName.value].splice(index, 1);
1553
1537
  emit("change", props.model[modelName.value]);
1554
1538
  };
@@ -1655,8 +1639,7 @@
1655
1639
  };
1656
1640
  const toggleMode = () => {
1657
1641
  const calcLabelWidth = (label) => {
1658
- if (!label)
1659
- return "0px";
1642
+ if (!label) return "0px";
1660
1643
  const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
1661
1644
  const chLength = label.length - zhLength;
1662
1645
  return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
@@ -1676,8 +1659,7 @@
1676
1659
  });
1677
1660
  };
1678
1661
  const toggleFullscreen = () => {
1679
- if (!mTable.value)
1680
- return;
1662
+ if (!mTable.value) return;
1681
1663
  if (isFullscreen.value) {
1682
1664
  mTable.value.classList.remove("fixed");
1683
1665
  isFullscreen.value = false;
@@ -1992,12 +1974,9 @@
1992
1974
  const getActive = (mForm2, props2, activeTabName2) => {
1993
1975
  const { config, model, prop } = props2;
1994
1976
  const { active } = config;
1995
- if (typeof active === "function")
1996
- return active(mForm2, { model, formValue: mForm2?.values, prop });
1997
- if (+activeTabName2 >= props2.config.items.length)
1998
- return "0";
1999
- if (typeof active !== "undefined")
2000
- return active;
1977
+ if (typeof active === "function") return active(mForm2, { model, formValue: mForm2?.values, prop });
1978
+ if (+activeTabName2 >= props2.config.items.length) return "0";
1979
+ if (typeof active !== "undefined") return active;
2001
1980
  return "0";
2002
1981
  };
2003
1982
  const tabClick = (mForm2, tab, props2) => {
@@ -2018,8 +1997,7 @@
2018
1997
  const diffCount = vue.ref({});
2019
1998
  const tabs = vue.computed(() => {
2020
1999
  if (props.config.dynamic) {
2021
- if (!props.config.name)
2022
- throw new Error("dynamic tab 必须配置name");
2000
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2023
2001
  return props.model[props.config.name] || [];
2024
2002
  }
2025
2003
  return props.config.items.filter((item) => display(mForm, item.display, props));
@@ -2036,8 +2014,7 @@
2036
2014
  const tabItems = (tab) => props.config.dynamic ? props.config.items : tab.items;
2037
2015
  const tabClickHandler = (tab) => tabClick(mForm, tab, props);
2038
2016
  const onTabAdd = () => {
2039
- if (!props.config.name)
2040
- throw new Error("dynamic tab 必须配置name");
2017
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2041
2018
  if (typeof props.config.onTabAdd === "function") {
2042
2019
  props.config.onTabAdd(mForm, {
2043
2020
  model: props.model,
@@ -2053,8 +2030,7 @@
2053
2030
  mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2054
2031
  };
2055
2032
  const onTabRemove = (tabName) => {
2056
- if (!props.config.name)
2057
- throw new Error("dynamic tab 必须配置name");
2033
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2058
2034
  if (typeof props.config.onTabRemove === "function") {
2059
2035
  props.config.onTabRemove(mForm, tabName, {
2060
2036
  model: props.model,
@@ -2157,8 +2133,7 @@
2157
2133
  const getConfig = (key) => $MAGIC_FORM[key];
2158
2134
 
2159
2135
  const useAddField = (prop) => {
2160
- if (!prop)
2161
- return;
2136
+ if (!prop) return;
2162
2137
  const mForm = vue.inject("mForm");
2163
2138
  const instance = vue.getCurrentInstance();
2164
2139
  vue.watch(
@@ -2222,8 +2197,7 @@
2222
2197
  const setRemoteOptions = async function() {
2223
2198
  const { config } = props;
2224
2199
  const { option } = config;
2225
- if (!option)
2226
- return;
2200
+ if (!option) return;
2227
2201
  let { body } = option;
2228
2202
  const postOptions = {
2229
2203
  url: option.url,
@@ -2268,8 +2242,7 @@
2268
2242
  });
2269
2243
  }
2270
2244
  const changeHandler = () => {
2271
- if (!tMagicCascader.value)
2272
- return;
2245
+ if (!tMagicCascader.value) return;
2273
2246
  tMagicCascader.value.setQuery("");
2274
2247
  tMagicCascader.value.setPreviousQuery(null);
2275
2248
  emit("change", props.model[props.name]);
@@ -2391,10 +2364,8 @@
2391
2364
  };
2392
2365
  const mForm = vue.inject("mForm");
2393
2366
  const options = vue.computed(() => {
2394
- if (Array.isArray(props.config.options))
2395
- return props.config.options;
2396
- if (typeof props.config.options === "function")
2397
- return filterFunction(mForm, props.config.options, props);
2367
+ if (Array.isArray(props.config.options)) return props.config.options;
2368
+ if (typeof props.config.options === "function") return filterFunction(mForm, props.config.options, props);
2398
2369
  return [];
2399
2370
  });
2400
2371
  return (_ctx, _cache) => {
@@ -2532,12 +2503,9 @@
2532
2503
  if (!value.value) {
2533
2504
  value.value = [];
2534
2505
  }
2535
- if (!start || !end)
2536
- value.value = [];
2537
- if (start !== preStart)
2538
- value.value[0] = new Date(start);
2539
- if (end !== preEnd)
2540
- value.value[1] = new Date(end);
2506
+ if (!start || !end) value.value = [];
2507
+ if (start !== preStart) value.value[0] = new Date(start);
2508
+ if (end !== preEnd) value.value[1] = new Date(end);
2541
2509
  },
2542
2510
  {
2543
2511
  immediate: true
@@ -2547,8 +2515,7 @@
2547
2515
  vue.watch(
2548
2516
  () => props.model[props.name],
2549
2517
  (start, preStart) => {
2550
- if (start !== preStart)
2551
- value.value = start.map((item) => item ? new Date(item) : void 0);
2518
+ if (start !== preStart) value.value = start.map((item) => item ? new Date(item) : void 0);
2552
2519
  },
2553
2520
  {
2554
2521
  immediate: true
@@ -2574,8 +2541,7 @@
2574
2541
  emit(
2575
2542
  "change",
2576
2543
  value2.map((item) => {
2577
- if (item)
2578
- return utils.datetimeFormatter(item, "");
2544
+ if (item) return utils.datetimeFormatter(item, "");
2579
2545
  return void 0;
2580
2546
  })
2581
2547
  );
@@ -2713,14 +2679,12 @@
2713
2679
  value: {}
2714
2680
  });
2715
2681
  const changeFieldMap = async () => {
2716
- if (typeof props.config.returnFields !== "function" || !props.model)
2717
- return;
2682
+ if (typeof props.config.returnFields !== "function" || !props.model) return;
2718
2683
  const fields = await props.config.returnFields(props.config, props.model, request);
2719
2684
  fieldMap.value = {};
2720
2685
  fieldLabelMap.value = {};
2721
2686
  fields.forEach((v) => {
2722
- if (typeof v !== "object" || v.name === void 0)
2723
- return;
2687
+ if (typeof v !== "object" || v.name === void 0) return;
2724
2688
  let oldVal = props.model?.[v.name] || "";
2725
2689
  if (!oldVal && v.defaultValue !== void 0) {
2726
2690
  oldVal = v.defaultValue;
@@ -2924,12 +2888,9 @@
2924
2888
  const error = [];
2925
2889
  Object.entries(invalidFields).forEach(([, ValidateError]) => {
2926
2890
  ValidateError.forEach(({ field, message }) => {
2927
- if (field && message)
2928
- error.push(`${field} -> ${message}`);
2929
- if (field && !message)
2930
- error.push(`${field} -> 出现错误`);
2931
- if (!field && message)
2932
- error.push(`${message}`);
2891
+ if (field && message) error.push(`${field} -> ${message}`);
2892
+ if (field && !message) error.push(`${field} -> 出现错误`);
2893
+ if (!field && message) error.push(`${message}`);
2933
2894
  });
2934
2895
  });
2935
2896
  throw new Error(error.join("<br>"));
@@ -3452,8 +3413,7 @@
3452
3413
  const emit = __emit;
3453
3414
  const optionComponent = design.getConfig("components")?.option;
3454
3415
  const optionGroupComponent = design.getConfig("components")?.optionGroup;
3455
- if (!props.model)
3456
- throw new Error("不能没有model");
3416
+ if (!props.model) throw new Error("不能没有model");
3457
3417
  useAddField(props.prop);
3458
3418
  const tMagicSelect = vue.ref();
3459
3419
  const mForm = vue.inject("mForm");
@@ -3488,16 +3448,14 @@
3488
3448
  }));
3489
3449
  };
3490
3450
  const getOptions = async () => {
3491
- if (!props.model)
3492
- return [];
3451
+ if (!props.model) return [];
3493
3452
  if (localOptions.value.length) {
3494
3453
  return localOptions.value;
3495
3454
  }
3496
3455
  loading.value = true;
3497
3456
  let items = [];
3498
3457
  const { option } = props.config;
3499
- if (!option)
3500
- return [];
3458
+ if (!option) return [];
3501
3459
  const { root = "", totalKey = "total" } = option;
3502
3460
  let { body = {}, url } = option;
3503
3461
  if (typeof url === "function") {
@@ -3570,8 +3528,7 @@
3570
3528
  return pgIndex.value === 0 ? selectedOptions.concat(items) : options.value.concat(items);
3571
3529
  };
3572
3530
  const getInitLocalOption = async () => {
3573
- if (!props.model)
3574
- return [];
3531
+ if (!props.model) return [];
3575
3532
  const value = props.model[props.name];
3576
3533
  const { config } = props;
3577
3534
  localOptions.value = await getOptions();
@@ -3592,11 +3549,9 @@
3592
3549
  return localOptions.value.filter((item) => equalValue(item.value, value));
3593
3550
  };
3594
3551
  const getInitOption = async () => {
3595
- if (!props.model)
3596
- return [];
3552
+ if (!props.model) return [];
3597
3553
  const { option } = props.config;
3598
- if (!option)
3599
- return [];
3554
+ if (!option) return [];
3600
3555
  const { root = "", initRoot = "" } = option;
3601
3556
  let { initBody = {} } = option;
3602
3557
  let options2 = [];
@@ -3679,8 +3634,7 @@
3679
3634
  });
3680
3635
  } else if (props.config.option) {
3681
3636
  vue.onBeforeMount(() => {
3682
- if (!props.model)
3683
- return;
3637
+ if (!props.model) return;
3684
3638
  const v = props.model[props.name];
3685
3639
  if (Array.isArray(v) ? v.length : typeof v !== "undefined") {
3686
3640
  getInitOption().then((data) => {
@@ -3724,10 +3678,8 @@
3724
3678
  emit("change", value);
3725
3679
  };
3726
3680
  const visibleHandler = async (visible) => {
3727
- if (!visible)
3728
- return;
3729
- if (!props.config.remote)
3730
- return;
3681
+ if (!visible) return;
3682
+ if (!props.config.remote) return;
3731
3683
  if (query.value && tMagicSelect.value) {
3732
3684
  tMagicSelect.value.setQuery(query.value);
3733
3685
  tMagicSelect.value.setPreviousQuery(query.value);
@@ -3954,8 +3906,7 @@
3954
3906
  mForm?.$emit("field-input", props.prop, v);
3955
3907
  };
3956
3908
  const buttonClickHandler = () => {
3957
- if (!appendConfig.value)
3958
- return;
3909
+ if (!appendConfig.value) return;
3959
3910
  if (typeof appendConfig.value.handler === "function") {
3960
3911
  appendConfig.value.handler(mForm, {
3961
3912
  model: props.model,
@@ -3964,10 +3915,8 @@
3964
3915
  }
3965
3916
  };
3966
3917
  const keyUpHandler = ($event) => {
3967
- if (!props.model)
3968
- return;
3969
- if (!props.name)
3970
- return;
3918
+ if (!props.model) return;
3919
+ if (!props.name) return;
3971
3920
  const arrowUp = $event.key === "ArrowUp";
3972
3921
  const arrowDown = $event.key === "ArrowDown";
3973
3922
  if (!arrowUp && !arrowDown) {
@@ -4197,12 +4146,9 @@
4197
4146
  if (!value.value) {
4198
4147
  value.value = [];
4199
4148
  }
4200
- if (!start || !end)
4201
- value.value = [];
4202
- if (start !== preStart)
4203
- value.value[0] = start;
4204
- if (end !== preEnd)
4205
- value.value[1] = end;
4149
+ if (!start || !end) value.value = [];
4150
+ if (start !== preStart) value.value[0] = start;
4151
+ if (end !== preEnd) value.value[1] = end;
4206
4152
  },
4207
4153
  {
4208
4154
  immediate: true
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
- "version": "1.4.7",
2
+ "version": "1.4.9",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
- "dist/*",
7
6
  "src/theme/*"
8
7
  ],
9
8
  "main": "dist/tmagic-form.umd.cjs",
@@ -22,6 +21,11 @@
22
21
  },
23
22
  "./*": "./*"
24
23
  },
24
+ "files": [
25
+ "dist",
26
+ "types",
27
+ "src"
28
+ ],
25
29
  "license": "Apache-2.0",
26
30
  "engines": {
27
31
  "node": ">=18"
@@ -44,14 +48,14 @@
44
48
  "@vue/test-utils": "^2.4.6",
45
49
  "rimraf": "^3.0.2",
46
50
  "sass": "^1.77.0",
47
- "vite": "^5.2.11",
48
- "vue-tsc": "^2.0.16"
51
+ "vite": "^5.3.1",
52
+ "vue-tsc": "^2.0.19"
49
53
  },
50
54
  "peerDependencies": {
51
55
  "vue": "^3.4.27",
52
56
  "typescript": "*",
53
- "@tmagic/design": "1.4.7",
54
- "@tmagic/utils": "1.4.7"
57
+ "@tmagic/design": "1.4.9",
58
+ "@tmagic/utils": "1.4.9"
55
59
  },
56
60
  "peerDependenciesMeta": {
57
61
  "typescript": {
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "declaration": true,
6
- "declarationDir": "types",
7
- "forceConsistentCasingInFileNames": true,
8
- "paths": {},
9
- },
10
- "include": [
11
- "src"
12
- ],
13
- }