@tmagic/form 1.5.0-beta.9 → 1.5.0

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.
@@ -1,11 +1,12 @@
1
- import { toRaw, defineComponent, inject, ref, computed, watchEffect, watch, resolveComponent, openBlock, createElementBlock, normalizeStyle, normalizeClass, createBlock, resolveDynamicComponent, Fragment, createVNode, unref, withCtx, createElementVNode, createCommentVNode, renderList, createTextVNode, toDisplayString, withDirectives, vShow, renderSlot, onMounted, Teleport, toRefs, mergeProps, getCurrentInstance, reactive, onBeforeUnmount, vModelText, provide, onBeforeMount, nextTick, resolveDirective, createSlots, withModifiers } from 'vue';
1
+ import { toRaw, defineComponent, inject, ref, computed, watchEffect, watch, resolveComponent, openBlock, createElementBlock, normalizeStyle, normalizeClass, createBlock, resolveDynamicComponent, Fragment, createVNode, unref, withCtx, createElementVNode, createCommentVNode, renderList, createTextVNode, toDisplayString, withDirectives, vShow, renderSlot, onMounted, Teleport, toRefs, mergeProps, getCurrentInstance, reactive, onBeforeUnmount, vModelText, provide, shallowRef, onBeforeMount, nextTick, resolveDirective, createSlots, withModifiers } from 'vue';
2
2
  import { WarningFilled, CaretBottom, CaretRight, Delete, CaretTop, Grid, ArrowUp, ArrowDown, FullScreen } from '@element-plus/icons-vue';
3
- import { cloneDeep, isEqual, isEmpty } from 'lodash-es';
4
- import { TMagicFormItem, TMagicTooltip, TMagicIcon, TMagicButton, TMagicCheckbox, TMagicCard, TMagicCol, TMagicRow, TMagicSteps, TMagicStep, useZIndex, TMagicTable, TMagicTableColumn, TMagicUpload, TMagicPagination, tMagicMessage, getDesignConfig, TMagicBadge, TMagicCascader, TMagicCheckboxGroup, TMagicColorPicker, TMagicDatePicker, TMagicForm, TMagicInput, TMagicDialog, TMagicInputNumber, TMagicRadioGroup, TMagicRadio, TMagicSelect, TMagicSwitch, TMagicPopover, TMagicTimePicker, TMagicDrawer, TMagicScrollbar } from '@tmagic/design';
3
+ import { cloneDeep, isEqual, isEmpty, debounce } from 'lodash-es';
4
+ import { TMagicFormItem, TMagicTooltip, TMagicIcon, TMagicButton, TMagicCheckbox, TMagicCard, TMagicCol, TMagicRow, TMagicSteps, TMagicStep, useZIndex, TMagicTable, TMagicTableColumn, TMagicUpload, TMagicPagination, tMagicMessage, getDesignConfig, TMagicBadge, TMagicCascader, TMagicCheckboxGroup, TMagicColorPicker, TMagicDatePicker, TMagicForm, TMagicInput, tMagicMessageBox, TMagicDialog, TMagicInputNumber, TMagicRadioGroup, TMagicRadio, TMagicSelect, TMagicSwitch, TMagicTimePicker, TMagicDrawer, TMagicScrollbar } from '@tmagic/design';
5
5
  import dayjs from 'dayjs';
6
6
  import utc from 'dayjs/plugin/utc';
7
7
  import Sortable from 'sortablejs';
8
8
  import { sleep, asyncLoadJs, getValueByKeyPath, isNumber } from '@tmagic/utils';
9
+ import { createPopper } from '@popperjs/core';
9
10
 
10
11
  const isTableSelect = (type) => typeof type === "string" && ["table-select", "tableSelect"].includes(type);
11
12
  const asyncLoadConfig = (value, initValue2, { asyncLoad, name, type }) => {
@@ -243,7 +244,10 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
243
244
  } else {
244
245
  return props.prop;
245
246
  }
246
- return `${props.prop}${props.prop ? "." : ""}${n}`;
247
+ if (typeof props.prop !== "undefined" && props.prop !== "") {
248
+ return `${props.prop}.${n}`;
249
+ }
250
+ return `${n}`;
247
251
  });
248
252
  const tagName = computed(() => `m-${items.value ? "form" : "fields"}-${type.value}`);
249
253
  const disabled = computed(() => props.disabled || filterFunction(mForm, props.config.disabled, props));
@@ -299,40 +303,69 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
299
303
  }
300
304
  return value;
301
305
  };
302
- const changeHandler = (onChange, value) => {
303
- if (typeof onChange === "function") {
304
- return onChange(mForm, value, {
305
- model: props.model,
306
- values: mForm?.initValues,
307
- formValue: mForm?.values,
308
- prop: itemProp.value,
309
- config: props.config
310
- });
311
- }
312
- };
313
306
  const trimHandler = (trim, value) => {
314
307
  if (typeof value === "string" && trim) {
315
308
  return value.replace(/^\s*/, "").replace(/\s*$/, "");
316
309
  }
317
310
  };
318
311
  const onAddDiffCount = () => emit("addDiffCount");
319
- const onChangeHandler = async function(v, key2) {
320
- const { filter, onChange, trim, name: name2, dynamicKey } = props.config;
321
- let value = v;
312
+ const hasModifyKey = (eventDataItem) => typeof eventDataItem?.modifyKey !== "undefined" && eventDataItem.modifyKey !== "";
313
+ const isValidName = () => {
314
+ const valueType = typeof name.value;
315
+ if (valueType !== "string" && valueType !== "symbol" && valueType !== "number") {
316
+ return false;
317
+ }
318
+ if (name.value === "") {
319
+ return false;
320
+ }
321
+ if (typeof name.value === "number") {
322
+ return name.value >= 0;
323
+ }
324
+ return true;
325
+ };
326
+ const onChangeHandler = async function(v, eventData = {}) {
327
+ const { filter, onChange, trim, dynamicKey } = props.config;
328
+ let value = toRaw(v);
329
+ const changeRecords = eventData.changeRecords || [];
330
+ const newChangeRecords = [...changeRecords];
322
331
  try {
323
332
  value = filterHandler(filter, v);
324
- value = await changeHandler(onChange, value) ?? value;
333
+ if (typeof onChange === "function") {
334
+ value = await onChange(mForm, value, {
335
+ model: props.model,
336
+ values: mForm?.initValues,
337
+ formValue: mForm?.values,
338
+ prop: itemProp.value,
339
+ config: props.config,
340
+ changeRecords: newChangeRecords
341
+ }) ?? value;
342
+ }
325
343
  value = trimHandler(trim, value) ?? value;
326
344
  } catch (e) {
327
345
  console.error(e);
328
346
  }
329
- if ((name2 || name2 === 0) && props.model !== value && (v !== value || props.model[name2] !== value)) {
330
- props.model[name2] = value;
347
+ let valueProp = itemProp.value;
348
+ if (hasModifyKey(eventData)) {
349
+ if (dynamicKey) {
350
+ props.model[eventData.modifyKey] = value;
351
+ } else if (isValidName()) {
352
+ props.model[name.value][eventData.modifyKey] = value;
353
+ }
354
+ valueProp = valueProp ? `${valueProp}.${eventData.modifyKey}` : eventData.modifyKey;
355
+ delete eventData.modifyKey;
356
+ } else if (isValidName() && props.model !== value && (v !== value || props.model[name.value] !== value)) {
357
+ props.model[name.value] = value;
331
358
  }
332
- if (key2 !== void 0 && dynamicKey) {
333
- props.model[key2] = value;
359
+ if (changeRecords.length === 0) {
360
+ newChangeRecords.push({
361
+ propPath: valueProp,
362
+ value
363
+ });
334
364
  }
335
- emit("change", props.model);
365
+ emit("change", props.model, {
366
+ ...eventData,
367
+ changeRecords: newChangeRecords
368
+ });
336
369
  };
337
370
  return (_ctx, _cache) => {
338
371
  const _component_m_fields_hidden = resolveComponent("m-fields-hidden");
@@ -369,7 +402,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
369
402
  }, null, 40, ["size", "model", "last-values", "is-compare", "config", "disabled", "name", "prop", "step-active", "expand-more", "label-width"])) : type.value && display$1.value && !showDiff.value ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
370
403
  createVNode(unref(TMagicFormItem), {
371
404
  style: normalizeStyle(_ctx.config.tip ? "flex: 1" : ""),
372
- class: normalizeClass({ hidden: `${itemLabelWidth.value}` === "0" || !text.value }),
405
+ class: normalizeClass({ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value }),
373
406
  prop: itemProp.value,
374
407
  "label-width": itemLabelWidth.value,
375
408
  rules: rule.value
@@ -442,7 +475,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
442
475
  ], 64)) : type.value && display$1.value && showDiff.value ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
443
476
  createVNode(unref(TMagicFormItem), {
444
477
  style: normalizeStyle([_ctx.config.tip ? "flex: 1" : "", { "background": "#f7dadd" }]),
445
- class: normalizeClass({ hidden: `${itemLabelWidth.value}` === "0" || !text.value }),
478
+ class: normalizeClass({ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value }),
446
479
  prop: itemProp.value,
447
480
  "label-width": itemLabelWidth.value,
448
481
  rules: rule.value
@@ -510,7 +543,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
510
543
  })) : createCommentVNode("", true),
511
544
  createVNode(unref(TMagicFormItem), {
512
545
  style: normalizeStyle([_ctx.config.tip ? "flex: 1" : "", { "background": "#def7da" }]),
513
- class: normalizeClass({ hidden: `${itemLabelWidth.value}` === "0" || !text.value }),
546
+ class: normalizeClass({ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value }),
514
547
  prop: itemProp.value,
515
548
  "label-width": itemLabelWidth.value,
516
549
  rules: rule.value
@@ -577,11 +610,11 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
577
610
  _: 1
578
611
  })) : createCommentVNode("", true)
579
612
  ], 64)) : items.value && display$1.value ? (openBlock(), createElementBlock(Fragment, { key: 4 }, [
580
- (name.value || name.value === 0 ? _ctx.model[name.value] : _ctx.model) ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(items.value, (item) => {
613
+ (isValidName() ? _ctx.model[name.value] : _ctx.model) ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(items.value, (item) => {
581
614
  return openBlock(), createBlock(_component_Container, {
582
615
  key: key(item),
583
- model: name.value || name.value === 0 ? _ctx.model[name.value] : _ctx.model,
584
- "last-values": name.value || name.value === 0 ? _ctx.lastValues[name.value] || {} : _ctx.lastValues,
616
+ model: isValidName() ? _ctx.model[name.value] : _ctx.model,
617
+ "last-values": isValidName() ? _ctx.lastValues[name.value] || {} : _ctx.lastValues,
585
618
  "is-compare": _ctx.isCompare,
586
619
  config: item,
587
620
  size: _ctx.size,
@@ -659,16 +692,17 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
659
692
  }
660
693
  return props.config.labelWidth || props.labelWidth || (props.config.text ? void 0 : "0");
661
694
  });
662
- const change = () => {
663
- emit("change", props.model);
695
+ const valueChangeHandler = (value) => {
696
+ emit("change", value, { modifyKey: "value" });
664
697
  };
698
+ const changeHandler = (v, eventData) => emit("change", v, eventData);
665
699
  const key = (item, index) => item[mForm?.keyProp || "__key"] ?? index;
666
700
  const onAddDiffCount = () => emit("addDiffCount");
667
701
  return (_ctx, _cache) => {
668
702
  return (name.value ? _ctx.model[name.value] : _ctx.model) ? (openBlock(), createElementBlock("fieldset", {
669
703
  key: 0,
670
704
  class: "m-fieldset",
671
- style: normalizeStyle(show.value ? "padding: 15px 15px 0 5px;" : "border: 0")
705
+ style: normalizeStyle(show.value ? "padding: 15px" : "border: 0")
672
706
  }, [
673
707
  name.value && _ctx.config.checkbox ? (openBlock(), createBlock(resolveDynamicComponent(!show.value ? "div" : "legend"), { key: 0 }, {
674
708
  default: withCtx(() => [
@@ -676,7 +710,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
676
710
  modelValue: _ctx.model[name.value].value,
677
711
  "onUpdate:modelValue": [
678
712
  _cache[0] || (_cache[0] = ($event) => _ctx.model[name.value].value = $event),
679
- change
713
+ valueChangeHandler
680
714
  ],
681
715
  prop: `${_ctx.prop}${_ctx.prop ? "." : ""}${_ctx.config.name}.value`,
682
716
  "true-value": 1,
@@ -720,7 +754,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
720
754
  disabled: _ctx.disabled,
721
755
  labelWidth: lWidth.value,
722
756
  size: _ctx.size,
723
- onChange: change,
757
+ onChange: changeHandler,
724
758
  onAddDiffCount: _cache[1] || (_cache[1] = ($event) => onAddDiffCount())
725
759
  }, null, 8, ["model", "lastValues", "is-compare", "rules", "config", "prop", "disabled", "labelWidth", "size"]);
726
760
  }), 128))
@@ -741,7 +775,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
741
775
  labelWidth: lWidth.value,
742
776
  size: _ctx.size,
743
777
  disabled: _ctx.disabled,
744
- onChange: change,
778
+ onChange: changeHandler,
745
779
  onAddDiffCount: _cache[2] || (_cache[2] = ($event) => onAddDiffCount())
746
780
  }, null, 8, ["model", "lastValues", "is-compare", "rules", "config", "prop", "labelWidth", "size", "disabled"]);
747
781
  }), 128)) : createCommentVNode("", true)
@@ -795,7 +829,9 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
795
829
  const length = computed(() => props.groupModel?.length || 0);
796
830
  const itemExtra = computed(() => filterFunction(mForm, props.config.itemExtra, props));
797
831
  const removeHandler = () => emit("remove-item", props.index);
798
- const changeHandler = () => emit("change");
832
+ const changeHandler = (v, eventData) => {
833
+ emit("change", props.model, eventData);
834
+ };
799
835
  const expandHandler = () => {
800
836
  expand.value = !expand.value;
801
837
  };
@@ -947,9 +983,8 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
947
983
  }
948
984
  return typeof props.config.addable === "undefined" ? true : props.config.addable;
949
985
  });
950
- const changeHandler = () => {
951
- if (!props.name) return false;
952
- emit("change", props.model[props.name]);
986
+ const changeHandler = (v, eventData) => {
987
+ emit("change", props.model, eventData);
953
988
  };
954
989
  const addHandler = async () => {
955
990
  if (!props.name) return false;
@@ -969,18 +1004,25 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
969
1004
  initValues
970
1005
  });
971
1006
  props.model[props.name].push(groupValue);
972
- changeHandler();
1007
+ emit("change", props.model[props.name], {
1008
+ changeRecords: [
1009
+ {
1010
+ propPath: `${props.prop}.${props.model[props.name].length - 1}`,
1011
+ value: groupValue
1012
+ }
1013
+ ]
1014
+ });
973
1015
  };
974
1016
  const removeHandler = (index) => {
975
1017
  if (!props.name) return false;
976
1018
  props.model[props.name].splice(index, 1);
977
- changeHandler();
1019
+ emit("change", props.model[props.name]);
978
1020
  };
979
1021
  const swapHandler = (idx1, idx2) => {
980
1022
  if (!props.name) return false;
981
1023
  const [currRow] = props.model[props.name].splice(idx1, 1);
982
1024
  props.model[props.name].splice(idx2, 0, currRow);
983
- changeHandler();
1025
+ emit("change", props.model[props.name]);
984
1026
  };
985
1027
  const toggleMode = () => {
986
1028
  props.config.type = "table";
@@ -1023,15 +1065,16 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
1023
1065
  }), 128)),
1024
1066
  addable.value ? (openBlock(), createBlock(unref(TMagicButton), {
1025
1067
  key: 3,
1026
- onClick: addHandler,
1027
- size: "small",
1028
- disabled: _ctx.disabled
1068
+ type: "primary",
1069
+ size: _ctx.config.enableToggleMode ? "small" : "default",
1070
+ disabled: _ctx.disabled,
1071
+ onClick: addHandler
1029
1072
  }, {
1030
1073
  default: withCtx(() => _cache[2] || (_cache[2] = [
1031
1074
  createTextVNode("新增")
1032
1075
  ])),
1033
1076
  _: 1
1034
- }, 8, ["disabled"])) : createCommentVNode("", true),
1077
+ }, 8, ["size", "disabled"])) : createCommentVNode("", true),
1035
1078
  _ctx.config.enableToggleMode ? (openBlock(), createBlock(unref(TMagicButton), {
1036
1079
  key: 4,
1037
1080
  icon: unref(Grid),
@@ -1080,7 +1123,9 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
1080
1123
  const expand = ref(props.config.expand !== false);
1081
1124
  const items = computed(() => props.config.items);
1082
1125
  const filter = (config) => filterFunction(mForm, config, props);
1083
- const changeHandler = () => emit("change", props.model);
1126
+ const changeHandler = (v, eventData) => {
1127
+ emit("change", props.model, eventData);
1128
+ };
1084
1129
  const onAddDiffCount = () => emit("addDiffCount");
1085
1130
  return (_ctx, _cache) => {
1086
1131
  return items.value && items.value.length ? (openBlock(), createBlock(unref(TMagicCard), {
@@ -1177,7 +1222,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
1177
1222
  const emit = __emit;
1178
1223
  const mForm = inject("mForm");
1179
1224
  const display$1 = computed(() => display(mForm, props.config.display, props));
1180
- const changeHandler = () => emit("change", props.model);
1225
+ const changeHandler = (v, eventData) => emit("change", v, eventData);
1181
1226
  const onAddDiffCount = () => emit("addDiffCount");
1182
1227
  return (_ctx, _cache) => {
1183
1228
  return withDirectives((openBlock(), createBlock(unref(TMagicCol), { span: _ctx.span }, {
@@ -1226,7 +1271,9 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
1226
1271
  const props = __props;
1227
1272
  const emit = __emit;
1228
1273
  const mForm = inject("mForm");
1229
- const changeHandler = () => emit("change", props.name ? props.model[props.name] : props.model);
1274
+ const changeHandler = (v, eventData) => {
1275
+ emit("change", props.name ? props.model[props.name] : props.model, eventData);
1276
+ };
1230
1277
  const onAddDiffCount = () => emit("addDiffCount");
1231
1278
  return (_ctx, _cache) => {
1232
1279
  return openBlock(), createBlock(unref(TMagicRow), { gutter: 10 }, {
@@ -1262,6 +1309,7 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
1262
1309
  __name: "Step",
1263
1310
  props: {
1264
1311
  model: {},
1312
+ name: {},
1265
1313
  lastValues: {},
1266
1314
  isCompare: { type: Boolean },
1267
1315
  config: {},
@@ -1283,8 +1331,8 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
1283
1331
  active.value = index + 1;
1284
1332
  mForm?.$emit("update:stepActive", active.value);
1285
1333
  };
1286
- const changeHandler = () => {
1287
- emit("change", props.model);
1334
+ const changeHandler = (v, eventData) => {
1335
+ emit("change", props.model, eventData);
1288
1336
  };
1289
1337
  const onAddDiffCount = () => emit("addDiffCount");
1290
1338
  return (_ctx, _cache) => {
@@ -1493,7 +1541,14 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1493
1541
  inputs[props.sortKey] = props.model[modelName.value][length - 1][props.sortKey] - 1;
1494
1542
  }
1495
1543
  props.model[modelName.value].push(inputs);
1496
- emit("change", props.model[modelName.value]);
1544
+ emit("change", props.model[modelName.value], {
1545
+ changeRecords: [
1546
+ {
1547
+ propPath: `${props.prop}.${props.model[modelName.value].length - 1}`,
1548
+ value: inputs
1549
+ }
1550
+ ]
1551
+ });
1497
1552
  };
1498
1553
  onMounted(() => {
1499
1554
  if (props.config.defautSort) {
@@ -1696,6 +1751,9 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1696
1751
  return `${prop.value}${prop.value ? "." : ""}${index + 1 + pagecontext.value * pagesize.value - 1}`;
1697
1752
  };
1698
1753
  const onAddDiffCount = () => emit("addDiffCount");
1754
+ const changeHandler = (v, eventData) => {
1755
+ emit("change", props.model, eventData);
1756
+ };
1699
1757
  __expose({
1700
1758
  toggleRowSelection
1701
1759
  });
@@ -1859,8 +1917,8 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1859
1917
  lastValues: lastData.value[scope.$index],
1860
1918
  "is-compare": _ctx.isCompare,
1861
1919
  size: _ctx.size,
1862
- onChange: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("change", _ctx.model[modelName.value])),
1863
- onAddDiffCount: _cache[1] || (_cache[1] = ($event) => onAddDiffCount())
1920
+ onChange: changeHandler,
1921
+ onAddDiffCount: _cache[0] || (_cache[0] = ($event) => onAddDiffCount())
1864
1922
  }, null, 8, ["disabled", "prop", "rules", "config", "model", "lastValues", "is-compare", "size"])) : createCommentVNode("", true)
1865
1923
  ]),
1866
1924
  _: 2
@@ -1881,9 +1939,9 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1881
1939
  type: "primary",
1882
1940
  disabled: _ctx.disabled,
1883
1941
  plain: "",
1884
- onClick: _cache[2] || (_cache[2] = ($event) => newHandler())
1942
+ onClick: _cache[1] || (_cache[1] = ($event) => newHandler())
1885
1943
  }, {
1886
- default: withCtx(() => _cache[4] || (_cache[4] = [
1944
+ default: withCtx(() => _cache[3] || (_cache[3] = [
1887
1945
  createTextVNode("新增一行")
1888
1946
  ])),
1889
1947
  _: 1
@@ -1896,7 +1954,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1896
1954
  type: "primary",
1897
1955
  onClick: toggleMode
1898
1956
  }, {
1899
- default: withCtx(() => _cache[5] || (_cache[5] = [
1957
+ default: withCtx(() => _cache[4] || (_cache[4] = [
1900
1958
  createTextVNode("展开配置")
1901
1959
  ])),
1902
1960
  _: 1
@@ -1930,7 +1988,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1930
1988
  disabled: _ctx.disabled,
1931
1989
  plain: ""
1932
1990
  }, {
1933
- default: withCtx(() => _cache[6] || (_cache[6] = [
1991
+ default: withCtx(() => _cache[5] || (_cache[5] = [
1934
1992
  createTextVNode("导入EXCEL")
1935
1993
  ])),
1936
1994
  _: 1
@@ -1944,9 +2002,9 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1944
2002
  type: "warning",
1945
2003
  disabled: _ctx.disabled,
1946
2004
  plain: "",
1947
- onClick: _cache[3] || (_cache[3] = ($event) => clearHandler())
2005
+ onClick: _cache[2] || (_cache[2] = ($event) => clearHandler())
1948
2006
  }, {
1949
- default: withCtx(() => _cache[7] || (_cache[7] = [
2007
+ default: withCtx(() => _cache[6] || (_cache[6] = [
1950
2008
  createTextVNode("清空")
1951
2009
  ])),
1952
2010
  _: 1
@@ -2035,24 +2093,35 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2035
2093
  });
2036
2094
  const tabItems = (tab) => props.config.dynamic ? props.config.items : tab.items;
2037
2095
  const tabClickHandler = (tab) => tabClick(mForm, tab, props);
2038
- const onTabAdd = () => {
2039
- if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2096
+ const onTabAdd = async () => {
2097
+ if (!props.name) throw new Error("dynamic tab 必须配置name");
2040
2098
  if (typeof props.config.onTabAdd === "function") {
2041
2099
  props.config.onTabAdd(mForm, {
2042
2100
  model: props.model,
2043
2101
  prop: props.prop,
2044
2102
  config: props.config
2045
2103
  });
2046
- } else if (tabs.value.length > 0) {
2047
- const newObj = cloneDeep(tabs.value[0]);
2104
+ emit("change", props.model);
2105
+ } else {
2106
+ const newObj = await initValue(mForm, {
2107
+ config: props.config.items,
2108
+ initValues: {}
2109
+ });
2048
2110
  newObj.title = `标签${tabs.value.length + 1}`;
2049
- props.model[props.config.name].push(newObj);
2111
+ props.model[props.name].push(newObj);
2112
+ emit("change", props.model[props.name], {
2113
+ changeRecords: [
2114
+ {
2115
+ propPath: `${props.prop}.${props.model[props.name].length - 1}`,
2116
+ value: newObj
2117
+ }
2118
+ ]
2119
+ });
2050
2120
  }
2051
- emit("change", props.model);
2052
- mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2121
+ mForm?.$emit("field-change", props.prop, props.model[props.name]);
2053
2122
  };
2054
2123
  const onTabRemove = (tabName) => {
2055
- if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2124
+ if (!props.name) throw new Error("dynamic tab 必须配置name");
2056
2125
  if (typeof props.config.onTabRemove === "function") {
2057
2126
  props.config.onTabRemove(mForm, tabName, {
2058
2127
  model: props.model,
@@ -2060,20 +2129,17 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2060
2129
  config: props.config
2061
2130
  });
2062
2131
  } else {
2063
- props.model[props.config.name].splice(+tabName, 1);
2064
- if (tabName < activeTabName.value || activeTabName.value >= props.model[props.config.name].length) {
2132
+ props.model[props.name].splice(+tabName, 1);
2133
+ if (tabName < activeTabName.value || activeTabName.value >= props.model[props.name].length) {
2065
2134
  activeTabName.value = (+activeTabName.value - 1).toString();
2066
2135
  tabClick(mForm, { name: activeTabName.value }, props);
2067
2136
  }
2068
2137
  }
2069
2138
  emit("change", props.model);
2070
- mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2139
+ mForm?.$emit("field-change", props.prop, props.model[props.name]);
2071
2140
  };
2072
- const changeHandler = () => {
2073
- emit("change", props.model);
2074
- if (typeof props.config.onChange === "function") {
2075
- props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
2076
- }
2141
+ const changeHandler = (v, eventData) => {
2142
+ emit("change", props.model, eventData);
2077
2143
  };
2078
2144
  const onAddDiffCount = (tabIndex) => {
2079
2145
  if (!diffCount.value[tabIndex]) {
@@ -2616,9 +2682,9 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2616
2682
  const props = __props;
2617
2683
  const emit = __emit;
2618
2684
  useAddField(props.prop);
2619
- const value = props.model?.[props.name].toString();
2685
+ const value = props.model?.[props.name]?.toString();
2620
2686
  if (props.model) {
2621
- if (value === "Invalid Date") {
2687
+ if (!value || value === "Invalid Date") {
2622
2688
  props.model[props.name] = "";
2623
2689
  } else {
2624
2690
  props.model[props.name] = datetimeFormatter(
@@ -2717,7 +2783,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2717
2783
  let oldVal = props.model?.[v.name] || "";
2718
2784
  if (!oldVal && v.defaultValue !== void 0) {
2719
2785
  oldVal = v.defaultValue;
2720
- emit("change", oldVal, v.name);
2786
+ emit("change", oldVal, { modifyKey: v.name });
2721
2787
  }
2722
2788
  fieldMap.value[v.name] = oldVal;
2723
2789
  fieldLabelMap.value[v.name] = v.label || "";
@@ -2740,7 +2806,9 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2740
2806
  }
2741
2807
  });
2742
2808
  const inputChangeHandler = (key) => {
2743
- emit("change", fieldMap.value[key], key);
2809
+ emit("change", fieldMap.value[key], {
2810
+ modifyKey: key
2811
+ });
2744
2812
  };
2745
2813
  return (_ctx, _cache) => {
2746
2814
  return openBlock(), createElementBlock("div", _hoisted_1$6, [
@@ -2821,9 +2889,10 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2821
2889
  labelPosition: { default: "right" },
2822
2890
  keyProp: { default: "__key" },
2823
2891
  popperClass: {},
2892
+ preventSubmitDefault: { type: Boolean },
2824
2893
  extendState: {}
2825
2894
  },
2826
- emits: ["change", "error", "field-input", "field-change"],
2895
+ emits: ["change", "error", "field-input", "field-change", "update:stepActive"],
2827
2896
  setup(__props, { expose: __expose, emit: __emit }) {
2828
2897
  const props = __props;
2829
2898
  const emit = __emit;
@@ -2848,11 +2917,13 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2848
2917
  setField: (prop, field) => fields.set(prop, field),
2849
2918
  getField: (prop) => fields.get(prop),
2850
2919
  deleteField: (prop) => fields.delete(prop),
2920
+ $messageBox: tMagicMessageBox,
2921
+ $message: tMagicMessage,
2851
2922
  post: (options) => {
2852
2923
  if (requestFuc) {
2853
2924
  return requestFuc({
2854
- ...options,
2855
- method: "POST"
2925
+ method: "POST",
2926
+ ...options
2856
2927
  });
2857
2928
  }
2858
2929
  }
@@ -2873,9 +2944,11 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2873
2944
  }
2874
2945
  });
2875
2946
  provide("mForm", formState);
2947
+ const changeRecords = shallowRef([]);
2876
2948
  watch(
2877
2949
  [() => props.config, () => props.initValues],
2878
2950
  ([config], [preConfig]) => {
2951
+ changeRecords.value = [];
2879
2952
  if (!isEqual(toRaw(config), toRaw(preConfig))) {
2880
2953
  initialized.value = false;
2881
2954
  }
@@ -2898,16 +2971,28 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2898
2971
  },
2899
2972
  { immediate: true }
2900
2973
  );
2901
- const changeHandler = () => {
2902
- emit("change", values.value);
2974
+ const changeHandler = (v, eventData) => {
2975
+ if (eventData.changeRecords?.length) {
2976
+ changeRecords.value.push(...eventData.changeRecords);
2977
+ }
2978
+ emit("change", values.value, eventData);
2979
+ };
2980
+ const submitHandler = (e) => {
2981
+ if (props.preventSubmitDefault) {
2982
+ e.preventDefault();
2983
+ }
2903
2984
  };
2904
2985
  __expose({
2905
2986
  values,
2906
2987
  lastValuesProcessed,
2907
2988
  formState,
2908
2989
  initialized,
2990
+ changeRecords,
2909
2991
  changeHandler,
2910
- resetForm: () => tMagicForm.value?.resetFields(),
2992
+ resetForm: () => {
2993
+ tMagicForm.value?.resetFields();
2994
+ changeRecords.value = [];
2995
+ },
2911
2996
  submitForm: async (native) => {
2912
2997
  try {
2913
2998
  await tMagicForm.value?.validate();
@@ -2935,7 +3020,8 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2935
3020
  "label-width": _ctx.labelWidth,
2936
3021
  style: normalizeStyle(`height: ${_ctx.height}`),
2937
3022
  inline: _ctx.inline,
2938
- "label-position": _ctx.labelPosition
3023
+ "label-position": _ctx.labelPosition,
3024
+ onSubmit: submitHandler
2939
3025
  }, {
2940
3026
  default: withCtx(() => [
2941
3027
  initialized.value && Array.isArray(_ctx.config) ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.config, (item, index) => {
@@ -2978,7 +3064,8 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
2978
3064
  labelPosition: {},
2979
3065
  zIndex: {},
2980
3066
  size: {},
2981
- confirmText: { default: "确定" }
3067
+ confirmText: { default: "确定" },
3068
+ preventSubmitDefault: { type: Boolean }
2982
3069
  },
2983
3070
  emits: ["close", "submit", "error", "change"],
2984
3071
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -3014,7 +3101,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3014
3101
  const save = async () => {
3015
3102
  try {
3016
3103
  const values = await form.value?.submitForm();
3017
- emit("submit", values);
3104
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
3018
3105
  } catch (e) {
3019
3106
  emit("error", e);
3020
3107
  }
@@ -3025,8 +3112,8 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3025
3112
  const nextStep = () => {
3026
3113
  stepActive.value += 1;
3027
3114
  };
3028
- const changeHandler = (value) => {
3029
- emit("change", value);
3115
+ const changeHandler = (value, eventData) => {
3116
+ emit("change", value, eventData);
3030
3117
  };
3031
3118
  const show = () => {
3032
3119
  dialogVisible.value = true;
@@ -3147,8 +3234,9 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3147
3234
  "label-width": _ctx.labelWidth,
3148
3235
  "label-position": _ctx.labelPosition,
3149
3236
  inline: _ctx.inline,
3237
+ "prevent-submit-default": _ctx.preventSubmitDefault,
3150
3238
  onChange: changeHandler
3151
- }, null, 8, ["modelValue", "size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline"]),
3239
+ }, null, 8, ["modelValue", "size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline", "prevent-submit-default"]),
3152
3240
  renderSlot(_ctx.$slots, "default")
3153
3241
  ], 4)) : createCommentVNode("", true)
3154
3242
  ]),
@@ -3874,7 +3962,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3874
3962
  }
3875
3963
  });
3876
3964
 
3877
- const _hoisted_1$1 = { class: "m-form-item__content" };
3965
+ const _hoisted_1$1 = { style: { "width": "100%" } };
3878
3966
  const _hoisted_2 = { style: { "display": "flex", "justify-content": "flex-end" } };
3879
3967
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3880
3968
  ...{
@@ -3919,11 +4007,11 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3919
4007
  emit("change", props.model[props.name].trim() || "");
3920
4008
  popoverVisible.value = false;
3921
4009
  };
3922
- const checkWhiteSpace = (value) => {
4010
+ const checkWhiteSpace = debounce((value) => {
3923
4011
  if (typeof value === "string" && !props.config.trim) {
3924
4012
  popoverVisible.value = value.trim() !== value;
3925
4013
  }
3926
- };
4014
+ }, 300);
3927
4015
  const changeHandler = (value) => {
3928
4016
  emit("change", value);
3929
4017
  };
@@ -3990,45 +4078,70 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3990
4078
  props.model[props.name] = `${num}${unit || ""}`;
3991
4079
  emit("change", props.model[props.name]);
3992
4080
  };
4081
+ const popoverEl = ref();
4082
+ const input = ref();
4083
+ const instanceRef = shallowRef();
4084
+ watch(popoverEl, (el) => {
4085
+ destroyPopover();
4086
+ if (!input.value?.$el || !el) return;
4087
+ instanceRef.value = createPopper(input.value.$el, el, {
4088
+ placement: props.config.tooltip ? "top" : "bottom",
4089
+ strategy: "absolute",
4090
+ modifiers: [
4091
+ {
4092
+ name: "offset",
4093
+ options: {
4094
+ offset: [0, 10]
4095
+ }
4096
+ }
4097
+ ]
4098
+ });
4099
+ });
4100
+ const destroyPopover = () => {
4101
+ if (!instanceRef.value) return;
4102
+ instanceRef.value.destroy();
4103
+ instanceRef.value = void 0;
4104
+ };
3993
4105
  return (_ctx, _cache) => {
3994
- return openBlock(), createBlock(unref(TMagicPopover), {
3995
- width: "220px",
3996
- visible: popoverVisible.value,
3997
- "destroy-on-close": true
3998
- }, {
3999
- reference: withCtx(() => [
4000
- createVNode(unref(TMagicInput), {
4001
- modelValue: _ctx.model[_ctx.name],
4002
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
4003
- clearable: "",
4004
- size: _ctx.size,
4005
- placeholder: _ctx.config.placeholder,
4006
- disabled: _ctx.disabled,
4007
- onChange: changeHandler,
4008
- onInput: inputHandler,
4009
- onKeyup: _cache[1] || (_cache[1] = ($event) => keyUpHandler($event))
4010
- }, createSlots({ _: 2 }, [
4011
- appendConfig.value ? {
4012
- name: "append",
4013
- fn: withCtx(() => [
4014
- appendConfig.value.type === "button" ? (openBlock(), createBlock(unref(TMagicButton), {
4015
- key: 0,
4016
- style: { "color": "#409eff" },
4017
- size: _ctx.size,
4018
- onClick: withModifiers(buttonClickHandler, ["prevent"])
4019
- }, {
4020
- default: withCtx(() => [
4021
- createTextVNode(toDisplayString(appendConfig.value.text), 1)
4022
- ]),
4023
- _: 1
4024
- }, 8, ["size"])) : createCommentVNode("", true)
4025
- ]),
4026
- key: "0"
4027
- } : void 0
4028
- ]), 1032, ["modelValue", "size", "placeholder", "disabled"])
4029
- ]),
4030
- default: withCtx(() => [
4031
- createElementVNode("div", _hoisted_1$1, [
4106
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
4107
+ createVNode(unref(TMagicInput), {
4108
+ modelValue: _ctx.model[_ctx.name],
4109
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
4110
+ ref_key: "input",
4111
+ ref: input,
4112
+ clearable: "",
4113
+ size: _ctx.size,
4114
+ placeholder: _ctx.config.placeholder,
4115
+ disabled: _ctx.disabled,
4116
+ onChange: changeHandler,
4117
+ onInput: inputHandler,
4118
+ onKeyup: _cache[1] || (_cache[1] = ($event) => keyUpHandler($event))
4119
+ }, createSlots({ _: 2 }, [
4120
+ appendConfig.value ? {
4121
+ name: "append",
4122
+ fn: withCtx(() => [
4123
+ appendConfig.value.type === "button" ? (openBlock(), createBlock(unref(TMagicButton), {
4124
+ key: 0,
4125
+ style: { "color": "#409eff" },
4126
+ size: _ctx.size,
4127
+ onClick: withModifiers(buttonClickHandler, ["prevent"])
4128
+ }, {
4129
+ default: withCtx(() => [
4130
+ createTextVNode(toDisplayString(appendConfig.value.text), 1)
4131
+ ]),
4132
+ _: 1
4133
+ }, 8, ["size"])) : createCommentVNode("", true)
4134
+ ]),
4135
+ key: "0"
4136
+ } : void 0
4137
+ ]), 1032, ["modelValue", "size", "placeholder", "disabled"]),
4138
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
4139
+ popoverVisible.value ? (openBlock(), createElementBlock("div", {
4140
+ key: 0,
4141
+ class: "tmagic-form-text-popper m-form-item__content",
4142
+ ref_key: "popoverEl",
4143
+ ref: popoverEl
4144
+ }, [
4032
4145
  _cache[5] || (_cache[5] = createElementVNode("div", { class: "m-form-validate__warning" }, "输入内容前后有空格,是否移除空格?", -1)),
4033
4146
  createElementVNode("div", _hoisted_2, [
4034
4147
  createVNode(unref(TMagicButton), {
@@ -4051,11 +4164,14 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4051
4164
  ])),
4052
4165
  _: 1
4053
4166
  })
4054
- ])
4055
- ])
4056
- ]),
4057
- _: 1
4058
- }, 8, ["visible"]);
4167
+ ]),
4168
+ _cache[6] || (_cache[6] = createElementVNode("span", {
4169
+ class: "tmagic-form-text-popper-arrow",
4170
+ "data-popper-arrow": ""
4171
+ }, null, -1))
4172
+ ], 512)) : createCommentVNode("", true)
4173
+ ]))
4174
+ ]);
4059
4175
  };
4060
4176
  }
4061
4177
  });
@@ -4240,6 +4356,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4240
4356
  confirmText: { default: "确定" },
4241
4357
  inline: { type: Boolean },
4242
4358
  labelPosition: {},
4359
+ preventSubmitDefault: { type: Boolean },
4243
4360
  beforeClose: {}
4244
4361
  },
4245
4362
  emits: ["close", "closed", "submit", "error", "change", "open", "opened"],
@@ -4259,13 +4376,13 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4259
4376
  const submitHandler = async () => {
4260
4377
  try {
4261
4378
  const values = await form.value?.submitForm();
4262
- emit("submit", values);
4379
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4263
4380
  } catch (e) {
4264
4381
  emit("error", e);
4265
4382
  }
4266
4383
  };
4267
- const changeHandler = (value) => {
4268
- emit("change", value);
4384
+ const changeHandler = (value, eventData) => {
4385
+ emit("change", value, eventData);
4269
4386
  };
4270
4387
  const openHandler = () => {
4271
4388
  emit("open");
@@ -4376,8 +4493,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4376
4493
  "label-width": _ctx.labelWidth,
4377
4494
  "label-position": _ctx.labelPosition,
4378
4495
  inline: _ctx.inline,
4496
+ "prevent-submit-default": _ctx.preventSubmitDefault,
4379
4497
  onChange: changeHandler
4380
- }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline"]),
4498
+ }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline", "prevent-submit-default"]),
4381
4499
  renderSlot(_ctx.$slots, "default")
4382
4500
  ], 512)) : createCommentVNode("", true)
4383
4501
  ]),
@@ -4404,9 +4522,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4404
4522
  size: {},
4405
4523
  confirmText: { default: "确定" },
4406
4524
  inline: { type: Boolean },
4407
- labelPosition: {}
4525
+ labelPosition: {},
4526
+ preventSubmitDefault: { type: Boolean }
4408
4527
  },
4409
- emits: ["submit", "change", "error"],
4528
+ emits: ["change", "submit", "error"],
4410
4529
  setup(__props, { expose: __expose, emit: __emit }) {
4411
4530
  const props = __props;
4412
4531
  const emit = __emit;
@@ -4432,13 +4551,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4432
4551
  const submitHandler = async () => {
4433
4552
  try {
4434
4553
  const values = await form.value?.submitForm();
4435
- emit("submit", values);
4554
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4436
4555
  } catch (e) {
4437
4556
  emit("error", e);
4438
4557
  }
4439
4558
  };
4440
- const changeHandler = (value) => {
4441
- emit("change", value);
4559
+ const changeHandler = (value, eventData) => {
4560
+ emit("change", value, eventData);
4442
4561
  };
4443
4562
  const show = () => {
4444
4563
  };
@@ -4472,8 +4591,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4472
4591
  "label-width": _ctx.labelWidth,
4473
4592
  "label-position": _ctx.labelPosition,
4474
4593
  inline: _ctx.inline,
4594
+ "prevent-submit-default": _ctx.preventSubmitDefault,
4475
4595
  onChange: changeHandler
4476
- }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline"]),
4596
+ }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline", "prevent-submit-default"]),
4477
4597
  renderSlot(_ctx.$slots, "default")
4478
4598
  ]),
4479
4599
  _: 3
@@ -4511,8 +4631,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4511
4631
  const createForm = (config) => config;
4512
4632
  const defaultInstallOpt = {};
4513
4633
  const index = {
4514
- install(app, opt) {
4515
- const option = Object.assign(defaultInstallOpt, opt || {});
4634
+ install(app, opt = {}) {
4635
+ const option = Object.assign(defaultInstallOpt, opt);
4516
4636
  app.config.globalProperties.$MAGIC_FORM = option;
4517
4637
  setConfig(option);
4518
4638
  app.component("m-form", _sfc_main$d);