@tmagic/form 1.5.0-beta.14 → 1.5.0-beta.16

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");
@@ -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,9 +692,10 @@ 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) => {
@@ -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
1068
  type: "primary",
1028
- disabled: _ctx.disabled
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]) {
@@ -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, [
@@ -2824,7 +2892,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2824
2892
  preventSubmitDefault: { type: Boolean },
2825
2893
  extendState: {}
2826
2894
  },
2827
- emits: ["change", "error", "field-input", "field-change"],
2895
+ emits: ["change", "error", "field-input", "field-change", "update:stepActive"],
2828
2896
  setup(__props, { expose: __expose, emit: __emit }) {
2829
2897
  const props = __props;
2830
2898
  const emit = __emit;
@@ -2849,6 +2917,8 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2849
2917
  setField: (prop, field) => fields.set(prop, field),
2850
2918
  getField: (prop) => fields.get(prop),
2851
2919
  deleteField: (prop) => fields.delete(prop),
2920
+ $messageBox: tMagicMessageBox,
2921
+ $message: tMagicMessage,
2852
2922
  post: (options) => {
2853
2923
  if (requestFuc) {
2854
2924
  return requestFuc({
@@ -2874,9 +2944,11 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2874
2944
  }
2875
2945
  });
2876
2946
  provide("mForm", formState);
2947
+ const changeRecords = shallowRef([]);
2877
2948
  watch(
2878
2949
  [() => props.config, () => props.initValues],
2879
2950
  ([config], [preConfig]) => {
2951
+ changeRecords.value = [];
2880
2952
  if (!isEqual(toRaw(config), toRaw(preConfig))) {
2881
2953
  initialized.value = false;
2882
2954
  }
@@ -2899,8 +2971,11 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2899
2971
  },
2900
2972
  { immediate: true }
2901
2973
  );
2902
- const changeHandler = () => {
2903
- 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);
2904
2979
  };
2905
2980
  const submitHandler = (e) => {
2906
2981
  if (props.preventSubmitDefault) {
@@ -2912,8 +2987,12 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2912
2987
  lastValuesProcessed,
2913
2988
  formState,
2914
2989
  initialized,
2990
+ changeRecords,
2915
2991
  changeHandler,
2916
- resetForm: () => tMagicForm.value?.resetFields(),
2992
+ resetForm: () => {
2993
+ tMagicForm.value?.resetFields();
2994
+ changeRecords.value = [];
2995
+ },
2917
2996
  submitForm: async (native) => {
2918
2997
  try {
2919
2998
  await tMagicForm.value?.validate();
@@ -3022,7 +3101,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3022
3101
  const save = async () => {
3023
3102
  try {
3024
3103
  const values = await form.value?.submitForm();
3025
- emit("submit", values);
3104
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
3026
3105
  } catch (e) {
3027
3106
  emit("error", e);
3028
3107
  }
@@ -3033,8 +3112,8 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
3033
3112
  const nextStep = () => {
3034
3113
  stepActive.value += 1;
3035
3114
  };
3036
- const changeHandler = (value) => {
3037
- emit("change", value);
3115
+ const changeHandler = (value, eventData) => {
3116
+ emit("change", value, eventData);
3038
3117
  };
3039
3118
  const show = () => {
3040
3119
  dialogVisible.value = true;
@@ -3883,7 +3962,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
3883
3962
  }
3884
3963
  });
3885
3964
 
3886
- const _hoisted_1$1 = { class: "m-form-item__content" };
3965
+ const _hoisted_1$1 = { style: { "width": "100%" } };
3887
3966
  const _hoisted_2 = { style: { "display": "flex", "justify-content": "flex-end" } };
3888
3967
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3889
3968
  ...{
@@ -3928,11 +4007,11 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3928
4007
  emit("change", props.model[props.name].trim() || "");
3929
4008
  popoverVisible.value = false;
3930
4009
  };
3931
- const checkWhiteSpace = (value) => {
4010
+ const checkWhiteSpace = debounce((value) => {
3932
4011
  if (typeof value === "string" && !props.config.trim) {
3933
4012
  popoverVisible.value = value.trim() !== value;
3934
4013
  }
3935
- };
4014
+ }, 300);
3936
4015
  const changeHandler = (value) => {
3937
4016
  emit("change", value);
3938
4017
  };
@@ -3999,45 +4078,70 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3999
4078
  props.model[props.name] = `${num}${unit || ""}`;
4000
4079
  emit("change", props.model[props.name]);
4001
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
+ };
4002
4105
  return (_ctx, _cache) => {
4003
- return openBlock(), createBlock(unref(TMagicPopover), {
4004
- width: "220px",
4005
- visible: popoverVisible.value,
4006
- "destroy-on-close": true
4007
- }, {
4008
- reference: withCtx(() => [
4009
- createVNode(unref(TMagicInput), {
4010
- modelValue: _ctx.model[_ctx.name],
4011
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
4012
- clearable: "",
4013
- size: _ctx.size,
4014
- placeholder: _ctx.config.placeholder,
4015
- disabled: _ctx.disabled,
4016
- onChange: changeHandler,
4017
- onInput: inputHandler,
4018
- onKeyup: _cache[1] || (_cache[1] = ($event) => keyUpHandler($event))
4019
- }, createSlots({ _: 2 }, [
4020
- appendConfig.value ? {
4021
- name: "append",
4022
- fn: withCtx(() => [
4023
- appendConfig.value.type === "button" ? (openBlock(), createBlock(unref(TMagicButton), {
4024
- key: 0,
4025
- style: { "color": "#409eff" },
4026
- size: _ctx.size,
4027
- onClick: withModifiers(buttonClickHandler, ["prevent"])
4028
- }, {
4029
- default: withCtx(() => [
4030
- createTextVNode(toDisplayString(appendConfig.value.text), 1)
4031
- ]),
4032
- _: 1
4033
- }, 8, ["size"])) : createCommentVNode("", true)
4034
- ]),
4035
- key: "0"
4036
- } : void 0
4037
- ]), 1032, ["modelValue", "size", "placeholder", "disabled"])
4038
- ]),
4039
- default: withCtx(() => [
4040
- 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
+ }, [
4041
4145
  _cache[5] || (_cache[5] = createElementVNode("div", { class: "m-form-validate__warning" }, "输入内容前后有空格,是否移除空格?", -1)),
4042
4146
  createElementVNode("div", _hoisted_2, [
4043
4147
  createVNode(unref(TMagicButton), {
@@ -4060,11 +4164,14 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
4060
4164
  ])),
4061
4165
  _: 1
4062
4166
  })
4063
- ])
4064
- ])
4065
- ]),
4066
- _: 1
4067
- }, 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
+ ]);
4068
4175
  };
4069
4176
  }
4070
4177
  });
@@ -4269,13 +4376,13 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
4269
4376
  const submitHandler = async () => {
4270
4377
  try {
4271
4378
  const values = await form.value?.submitForm();
4272
- emit("submit", values);
4379
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4273
4380
  } catch (e) {
4274
4381
  emit("error", e);
4275
4382
  }
4276
4383
  };
4277
- const changeHandler = (value) => {
4278
- emit("change", value);
4384
+ const changeHandler = (value, eventData) => {
4385
+ emit("change", value, eventData);
4279
4386
  };
4280
4387
  const openHandler = () => {
4281
4388
  emit("open");
@@ -4418,7 +4525,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4418
4525
  labelPosition: {},
4419
4526
  preventSubmitDefault: { type: Boolean }
4420
4527
  },
4421
- emits: ["submit", "change", "error"],
4528
+ emits: ["change", "submit", "error"],
4422
4529
  setup(__props, { expose: __expose, emit: __emit }) {
4423
4530
  const props = __props;
4424
4531
  const emit = __emit;
@@ -4444,13 +4551,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4444
4551
  const submitHandler = async () => {
4445
4552
  try {
4446
4553
  const values = await form.value?.submitForm();
4447
- emit("submit", values);
4554
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4448
4555
  } catch (e) {
4449
4556
  emit("error", e);
4450
4557
  }
4451
4558
  };
4452
- const changeHandler = (value) => {
4453
- emit("change", value);
4559
+ const changeHandler = (value, eventData) => {
4560
+ emit("change", value, eventData);
4454
4561
  };
4455
4562
  const show = () => {
4456
4563
  };
@@ -4524,8 +4631,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4524
4631
  const createForm = (config) => config;
4525
4632
  const defaultInstallOpt = {};
4526
4633
  const index = {
4527
- install(app, opt) {
4528
- const option = Object.assign(defaultInstallOpt, opt || {});
4634
+ install(app, opt = {}) {
4635
+ const option = Object.assign(defaultInstallOpt, opt);
4529
4636
  app.config.globalProperties.$MAGIC_FORM = option;
4530
4637
  setConfig(option);
4531
4638
  app.component("m-form", _sfc_main$d);