@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,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@element-plus/icons-vue'), require('lodash-es'), require('@tmagic/design'), require('dayjs'), require('dayjs/plugin/utc'), require('sortablejs'), require('@tmagic/utils')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', '@element-plus/icons-vue', 'lodash-es', '@tmagic/design', 'dayjs', 'dayjs/plugin/utc', 'sortablejs', '@tmagic/utils'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicForm = {}, global.Vue, global.iconsVue, global.lodashEs, global.design, global.dayjs, global.utc, global.Sortable, global.utils));
5
- })(this, (function (exports, vue, iconsVue, lodashEs, design, dayjs, utc, Sortable, utils) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@element-plus/icons-vue'), require('lodash-es'), require('@tmagic/design'), require('dayjs'), require('dayjs/plugin/utc'), require('sortablejs'), require('@tmagic/utils'), require('@popperjs/core')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', '@element-plus/icons-vue', 'lodash-es', '@tmagic/design', 'dayjs', 'dayjs/plugin/utc', 'sortablejs', '@tmagic/utils', '@popperjs/core'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicForm = {}, global.Vue, global.iconsVue, global.lodashEs, global.design, global.dayjs, global.utc, global.Sortable, global.utils, global.core));
5
+ })(this, (function (exports, vue, iconsVue, lodashEs, design, dayjs, utc, Sortable, utils, core) { 'use strict';
6
6
 
7
7
  const isTableSelect = (type) => typeof type === "string" && ["table-select", "tableSelect"].includes(type);
8
8
  const asyncLoadConfig = (value, initValue2, { asyncLoad, name, type }) => {
@@ -240,7 +240,10 @@
240
240
  } else {
241
241
  return props.prop;
242
242
  }
243
- return `${props.prop}${props.prop ? "." : ""}${n}`;
243
+ if (typeof props.prop !== "undefined" && props.prop !== "") {
244
+ return `${props.prop}.${n}`;
245
+ }
246
+ return `${n}`;
244
247
  });
245
248
  const tagName = vue.computed(() => `m-${items.value ? "form" : "fields"}-${type.value}`);
246
249
  const disabled = vue.computed(() => props.disabled || filterFunction(mForm, props.config.disabled, props));
@@ -296,40 +299,69 @@
296
299
  }
297
300
  return value;
298
301
  };
299
- const changeHandler = (onChange, value) => {
300
- if (typeof onChange === "function") {
301
- return onChange(mForm, value, {
302
- model: props.model,
303
- values: mForm?.initValues,
304
- formValue: mForm?.values,
305
- prop: itemProp.value,
306
- config: props.config
307
- });
308
- }
309
- };
310
302
  const trimHandler = (trim, value) => {
311
303
  if (typeof value === "string" && trim) {
312
304
  return value.replace(/^\s*/, "").replace(/\s*$/, "");
313
305
  }
314
306
  };
315
307
  const onAddDiffCount = () => emit("addDiffCount");
316
- const onChangeHandler = async function(v, key2) {
317
- const { filter, onChange, trim, name: name2, dynamicKey } = props.config;
318
- let value = v;
308
+ const hasModifyKey = (eventDataItem) => typeof eventDataItem?.modifyKey !== "undefined" && eventDataItem.modifyKey !== "";
309
+ const isValidName = () => {
310
+ const valueType = typeof name.value;
311
+ if (valueType !== "string" && valueType !== "symbol" && valueType !== "number") {
312
+ return false;
313
+ }
314
+ if (name.value === "") {
315
+ return false;
316
+ }
317
+ if (typeof name.value === "number") {
318
+ return name.value >= 0;
319
+ }
320
+ return true;
321
+ };
322
+ const onChangeHandler = async function(v, eventData = {}) {
323
+ const { filter, onChange, trim, dynamicKey } = props.config;
324
+ let value = vue.toRaw(v);
325
+ const changeRecords = eventData.changeRecords || [];
326
+ const newChangeRecords = [...changeRecords];
319
327
  try {
320
328
  value = filterHandler(filter, v);
321
- value = await changeHandler(onChange, value) ?? value;
329
+ if (typeof onChange === "function") {
330
+ value = await onChange(mForm, value, {
331
+ model: props.model,
332
+ values: mForm?.initValues,
333
+ formValue: mForm?.values,
334
+ prop: itemProp.value,
335
+ config: props.config,
336
+ changeRecords: newChangeRecords
337
+ }) ?? value;
338
+ }
322
339
  value = trimHandler(trim, value) ?? value;
323
340
  } catch (e) {
324
341
  console.error(e);
325
342
  }
326
- if ((name2 || name2 === 0) && props.model !== value && (v !== value || props.model[name2] !== value)) {
327
- props.model[name2] = value;
343
+ let valueProp = itemProp.value;
344
+ if (hasModifyKey(eventData)) {
345
+ if (dynamicKey) {
346
+ props.model[eventData.modifyKey] = value;
347
+ } else if (isValidName()) {
348
+ props.model[name.value][eventData.modifyKey] = value;
349
+ }
350
+ valueProp = valueProp ? `${valueProp}.${eventData.modifyKey}` : eventData.modifyKey;
351
+ delete eventData.modifyKey;
352
+ } else if (isValidName() && props.model !== value && (v !== value || props.model[name.value] !== value)) {
353
+ props.model[name.value] = value;
328
354
  }
329
- if (key2 !== void 0 && dynamicKey) {
330
- props.model[key2] = value;
355
+ if (changeRecords.length === 0) {
356
+ newChangeRecords.push({
357
+ propPath: valueProp,
358
+ value
359
+ });
331
360
  }
332
- emit("change", props.model);
361
+ emit("change", props.model, {
362
+ ...eventData,
363
+ changeRecords: newChangeRecords
364
+ });
333
365
  };
334
366
  return (_ctx, _cache) => {
335
367
  const _component_m_fields_hidden = vue.resolveComponent("m-fields-hidden");
@@ -574,11 +606,11 @@
574
606
  _: 1
575
607
  })) : vue.createCommentVNode("", true)
576
608
  ], 64)) : items.value && display$1.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 4 }, [
577
- (name.value || name.value === 0 ? _ctx.model[name.value] : _ctx.model) ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 0 }, vue.renderList(items.value, (item) => {
609
+ (isValidName() ? _ctx.model[name.value] : _ctx.model) ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 0 }, vue.renderList(items.value, (item) => {
578
610
  return vue.openBlock(), vue.createBlock(_component_Container, {
579
611
  key: key(item),
580
- model: name.value || name.value === 0 ? _ctx.model[name.value] : _ctx.model,
581
- "last-values": name.value || name.value === 0 ? _ctx.lastValues[name.value] || {} : _ctx.lastValues,
612
+ model: isValidName() ? _ctx.model[name.value] : _ctx.model,
613
+ "last-values": isValidName() ? _ctx.lastValues[name.value] || {} : _ctx.lastValues,
582
614
  "is-compare": _ctx.isCompare,
583
615
  config: item,
584
616
  size: _ctx.size,
@@ -656,9 +688,10 @@
656
688
  }
657
689
  return props.config.labelWidth || props.labelWidth || (props.config.text ? void 0 : "0");
658
690
  });
659
- const change = () => {
660
- emit("change", props.model);
691
+ const valueChangeHandler = (value) => {
692
+ emit("change", value, { modifyKey: "value" });
661
693
  };
694
+ const changeHandler = (v, eventData) => emit("change", v, eventData);
662
695
  const key = (item, index) => item[mForm?.keyProp || "__key"] ?? index;
663
696
  const onAddDiffCount = () => emit("addDiffCount");
664
697
  return (_ctx, _cache) => {
@@ -673,7 +706,7 @@
673
706
  modelValue: _ctx.model[name.value].value,
674
707
  "onUpdate:modelValue": [
675
708
  _cache[0] || (_cache[0] = ($event) => _ctx.model[name.value].value = $event),
676
- change
709
+ valueChangeHandler
677
710
  ],
678
711
  prop: `${_ctx.prop}${_ctx.prop ? "." : ""}${_ctx.config.name}.value`,
679
712
  "true-value": 1,
@@ -717,7 +750,7 @@
717
750
  disabled: _ctx.disabled,
718
751
  labelWidth: lWidth.value,
719
752
  size: _ctx.size,
720
- onChange: change,
753
+ onChange: changeHandler,
721
754
  onAddDiffCount: _cache[1] || (_cache[1] = ($event) => onAddDiffCount())
722
755
  }, null, 8, ["model", "lastValues", "is-compare", "rules", "config", "prop", "disabled", "labelWidth", "size"]);
723
756
  }), 128))
@@ -738,7 +771,7 @@
738
771
  labelWidth: lWidth.value,
739
772
  size: _ctx.size,
740
773
  disabled: _ctx.disabled,
741
- onChange: change,
774
+ onChange: changeHandler,
742
775
  onAddDiffCount: _cache[2] || (_cache[2] = ($event) => onAddDiffCount())
743
776
  }, null, 8, ["model", "lastValues", "is-compare", "rules", "config", "prop", "labelWidth", "size", "disabled"]);
744
777
  }), 128)) : vue.createCommentVNode("", true)
@@ -792,7 +825,9 @@
792
825
  const length = vue.computed(() => props.groupModel?.length || 0);
793
826
  const itemExtra = vue.computed(() => filterFunction(mForm, props.config.itemExtra, props));
794
827
  const removeHandler = () => emit("remove-item", props.index);
795
- const changeHandler = () => emit("change");
828
+ const changeHandler = (v, eventData) => {
829
+ emit("change", props.model, eventData);
830
+ };
796
831
  const expandHandler = () => {
797
832
  expand.value = !expand.value;
798
833
  };
@@ -944,9 +979,8 @@
944
979
  }
945
980
  return typeof props.config.addable === "undefined" ? true : props.config.addable;
946
981
  });
947
- const changeHandler = () => {
948
- if (!props.name) return false;
949
- emit("change", props.model[props.name]);
982
+ const changeHandler = (v, eventData) => {
983
+ emit("change", props.model, eventData);
950
984
  };
951
985
  const addHandler = async () => {
952
986
  if (!props.name) return false;
@@ -966,18 +1000,25 @@
966
1000
  initValues
967
1001
  });
968
1002
  props.model[props.name].push(groupValue);
969
- changeHandler();
1003
+ emit("change", props.model[props.name], {
1004
+ changeRecords: [
1005
+ {
1006
+ propPath: `${props.prop}.${props.model[props.name].length - 1}`,
1007
+ value: groupValue
1008
+ }
1009
+ ]
1010
+ });
970
1011
  };
971
1012
  const removeHandler = (index) => {
972
1013
  if (!props.name) return false;
973
1014
  props.model[props.name].splice(index, 1);
974
- changeHandler();
1015
+ emit("change", props.model[props.name]);
975
1016
  };
976
1017
  const swapHandler = (idx1, idx2) => {
977
1018
  if (!props.name) return false;
978
1019
  const [currRow] = props.model[props.name].splice(idx1, 1);
979
1020
  props.model[props.name].splice(idx2, 0, currRow);
980
- changeHandler();
1021
+ emit("change", props.model[props.name]);
981
1022
  };
982
1023
  const toggleMode = () => {
983
1024
  props.config.type = "table";
@@ -1020,15 +1061,16 @@
1020
1061
  }), 128)),
1021
1062
  addable.value ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
1022
1063
  key: 3,
1023
- onClick: addHandler,
1024
1064
  type: "primary",
1025
- disabled: _ctx.disabled
1065
+ size: _ctx.config.enableToggleMode ? "small" : "default",
1066
+ disabled: _ctx.disabled,
1067
+ onClick: addHandler
1026
1068
  }, {
1027
1069
  default: vue.withCtx(() => _cache[2] || (_cache[2] = [
1028
1070
  vue.createTextVNode("新增")
1029
1071
  ])),
1030
1072
  _: 1
1031
- }, 8, ["disabled"])) : vue.createCommentVNode("", true),
1073
+ }, 8, ["size", "disabled"])) : vue.createCommentVNode("", true),
1032
1074
  _ctx.config.enableToggleMode ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
1033
1075
  key: 4,
1034
1076
  icon: vue.unref(iconsVue.Grid),
@@ -1077,7 +1119,9 @@
1077
1119
  const expand = vue.ref(props.config.expand !== false);
1078
1120
  const items = vue.computed(() => props.config.items);
1079
1121
  const filter = (config) => filterFunction(mForm, config, props);
1080
- const changeHandler = () => emit("change", props.model);
1122
+ const changeHandler = (v, eventData) => {
1123
+ emit("change", props.model, eventData);
1124
+ };
1081
1125
  const onAddDiffCount = () => emit("addDiffCount");
1082
1126
  return (_ctx, _cache) => {
1083
1127
  return items.value && items.value.length ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicCard), {
@@ -1174,7 +1218,7 @@
1174
1218
  const emit = __emit;
1175
1219
  const mForm = vue.inject("mForm");
1176
1220
  const display$1 = vue.computed(() => display(mForm, props.config.display, props));
1177
- const changeHandler = () => emit("change", props.model);
1221
+ const changeHandler = (v, eventData) => emit("change", v, eventData);
1178
1222
  const onAddDiffCount = () => emit("addDiffCount");
1179
1223
  return (_ctx, _cache) => {
1180
1224
  return vue.withDirectives((vue.openBlock(), vue.createBlock(vue.unref(design.TMagicCol), { span: _ctx.span }, {
@@ -1223,7 +1267,9 @@
1223
1267
  const props = __props;
1224
1268
  const emit = __emit;
1225
1269
  const mForm = vue.inject("mForm");
1226
- const changeHandler = () => emit("change", props.name ? props.model[props.name] : props.model);
1270
+ const changeHandler = (v, eventData) => {
1271
+ emit("change", props.name ? props.model[props.name] : props.model, eventData);
1272
+ };
1227
1273
  const onAddDiffCount = () => emit("addDiffCount");
1228
1274
  return (_ctx, _cache) => {
1229
1275
  return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicRow), { gutter: 10 }, {
@@ -1259,6 +1305,7 @@
1259
1305
  __name: "Step",
1260
1306
  props: {
1261
1307
  model: {},
1308
+ name: {},
1262
1309
  lastValues: {},
1263
1310
  isCompare: { type: Boolean },
1264
1311
  config: {},
@@ -1280,8 +1327,8 @@
1280
1327
  active.value = index + 1;
1281
1328
  mForm?.$emit("update:stepActive", active.value);
1282
1329
  };
1283
- const changeHandler = () => {
1284
- emit("change", props.model);
1330
+ const changeHandler = (v, eventData) => {
1331
+ emit("change", props.model, eventData);
1285
1332
  };
1286
1333
  const onAddDiffCount = () => emit("addDiffCount");
1287
1334
  return (_ctx, _cache) => {
@@ -1490,7 +1537,14 @@
1490
1537
  inputs[props.sortKey] = props.model[modelName.value][length - 1][props.sortKey] - 1;
1491
1538
  }
1492
1539
  props.model[modelName.value].push(inputs);
1493
- emit("change", props.model[modelName.value]);
1540
+ emit("change", props.model[modelName.value], {
1541
+ changeRecords: [
1542
+ {
1543
+ propPath: `${props.prop}.${props.model[modelName.value].length - 1}`,
1544
+ value: inputs
1545
+ }
1546
+ ]
1547
+ });
1494
1548
  };
1495
1549
  vue.onMounted(() => {
1496
1550
  if (props.config.defautSort) {
@@ -1693,6 +1747,9 @@
1693
1747
  return `${prop.value}${prop.value ? "." : ""}${index + 1 + pagecontext.value * pagesize.value - 1}`;
1694
1748
  };
1695
1749
  const onAddDiffCount = () => emit("addDiffCount");
1750
+ const changeHandler = (v, eventData) => {
1751
+ emit("change", props.model, eventData);
1752
+ };
1696
1753
  __expose({
1697
1754
  toggleRowSelection
1698
1755
  });
@@ -1856,8 +1913,8 @@
1856
1913
  lastValues: lastData.value[scope.$index],
1857
1914
  "is-compare": _ctx.isCompare,
1858
1915
  size: _ctx.size,
1859
- onChange: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("change", _ctx.model[modelName.value])),
1860
- onAddDiffCount: _cache[1] || (_cache[1] = ($event) => onAddDiffCount())
1916
+ onChange: changeHandler,
1917
+ onAddDiffCount: _cache[0] || (_cache[0] = ($event) => onAddDiffCount())
1861
1918
  }, null, 8, ["disabled", "prop", "rules", "config", "model", "lastValues", "is-compare", "size"])) : vue.createCommentVNode("", true)
1862
1919
  ]),
1863
1920
  _: 2
@@ -1878,9 +1935,9 @@
1878
1935
  type: "primary",
1879
1936
  disabled: _ctx.disabled,
1880
1937
  plain: "",
1881
- onClick: _cache[2] || (_cache[2] = ($event) => newHandler())
1938
+ onClick: _cache[1] || (_cache[1] = ($event) => newHandler())
1882
1939
  }, {
1883
- default: vue.withCtx(() => _cache[4] || (_cache[4] = [
1940
+ default: vue.withCtx(() => _cache[3] || (_cache[3] = [
1884
1941
  vue.createTextVNode("新增一行")
1885
1942
  ])),
1886
1943
  _: 1
@@ -1893,7 +1950,7 @@
1893
1950
  type: "primary",
1894
1951
  onClick: toggleMode
1895
1952
  }, {
1896
- default: vue.withCtx(() => _cache[5] || (_cache[5] = [
1953
+ default: vue.withCtx(() => _cache[4] || (_cache[4] = [
1897
1954
  vue.createTextVNode("展开配置")
1898
1955
  ])),
1899
1956
  _: 1
@@ -1927,7 +1984,7 @@
1927
1984
  disabled: _ctx.disabled,
1928
1985
  plain: ""
1929
1986
  }, {
1930
- default: vue.withCtx(() => _cache[6] || (_cache[6] = [
1987
+ default: vue.withCtx(() => _cache[5] || (_cache[5] = [
1931
1988
  vue.createTextVNode("导入EXCEL")
1932
1989
  ])),
1933
1990
  _: 1
@@ -1941,9 +1998,9 @@
1941
1998
  type: "warning",
1942
1999
  disabled: _ctx.disabled,
1943
2000
  plain: "",
1944
- onClick: _cache[3] || (_cache[3] = ($event) => clearHandler())
2001
+ onClick: _cache[2] || (_cache[2] = ($event) => clearHandler())
1945
2002
  }, {
1946
- default: vue.withCtx(() => _cache[7] || (_cache[7] = [
2003
+ default: vue.withCtx(() => _cache[6] || (_cache[6] = [
1947
2004
  vue.createTextVNode("清空")
1948
2005
  ])),
1949
2006
  _: 1
@@ -2032,24 +2089,35 @@
2032
2089
  });
2033
2090
  const tabItems = (tab) => props.config.dynamic ? props.config.items : tab.items;
2034
2091
  const tabClickHandler = (tab) => tabClick(mForm, tab, props);
2035
- const onTabAdd = () => {
2036
- if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2092
+ const onTabAdd = async () => {
2093
+ if (!props.name) throw new Error("dynamic tab 必须配置name");
2037
2094
  if (typeof props.config.onTabAdd === "function") {
2038
2095
  props.config.onTabAdd(mForm, {
2039
2096
  model: props.model,
2040
2097
  prop: props.prop,
2041
2098
  config: props.config
2042
2099
  });
2043
- } else if (tabs.value.length > 0) {
2044
- const newObj = lodashEs.cloneDeep(tabs.value[0]);
2100
+ emit("change", props.model);
2101
+ } else {
2102
+ const newObj = await initValue(mForm, {
2103
+ config: props.config.items,
2104
+ initValues: {}
2105
+ });
2045
2106
  newObj.title = `标签${tabs.value.length + 1}`;
2046
- props.model[props.config.name].push(newObj);
2107
+ props.model[props.name].push(newObj);
2108
+ emit("change", props.model[props.name], {
2109
+ changeRecords: [
2110
+ {
2111
+ propPath: `${props.prop}.${props.model[props.name].length - 1}`,
2112
+ value: newObj
2113
+ }
2114
+ ]
2115
+ });
2047
2116
  }
2048
- emit("change", props.model);
2049
- mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2117
+ mForm?.$emit("field-change", props.prop, props.model[props.name]);
2050
2118
  };
2051
2119
  const onTabRemove = (tabName) => {
2052
- if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2120
+ if (!props.name) throw new Error("dynamic tab 必须配置name");
2053
2121
  if (typeof props.config.onTabRemove === "function") {
2054
2122
  props.config.onTabRemove(mForm, tabName, {
2055
2123
  model: props.model,
@@ -2057,20 +2125,17 @@
2057
2125
  config: props.config
2058
2126
  });
2059
2127
  } else {
2060
- props.model[props.config.name].splice(+tabName, 1);
2061
- if (tabName < activeTabName.value || activeTabName.value >= props.model[props.config.name].length) {
2128
+ props.model[props.name].splice(+tabName, 1);
2129
+ if (tabName < activeTabName.value || activeTabName.value >= props.model[props.name].length) {
2062
2130
  activeTabName.value = (+activeTabName.value - 1).toString();
2063
2131
  tabClick(mForm, { name: activeTabName.value }, props);
2064
2132
  }
2065
2133
  }
2066
2134
  emit("change", props.model);
2067
- mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2135
+ mForm?.$emit("field-change", props.prop, props.model[props.name]);
2068
2136
  };
2069
- const changeHandler = () => {
2070
- emit("change", props.model);
2071
- if (typeof props.config.onChange === "function") {
2072
- props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
2073
- }
2137
+ const changeHandler = (v, eventData) => {
2138
+ emit("change", props.model, eventData);
2074
2139
  };
2075
2140
  const onAddDiffCount = (tabIndex) => {
2076
2141
  if (!diffCount.value[tabIndex]) {
@@ -2714,7 +2779,7 @@
2714
2779
  let oldVal = props.model?.[v.name] || "";
2715
2780
  if (!oldVal && v.defaultValue !== void 0) {
2716
2781
  oldVal = v.defaultValue;
2717
- emit("change", oldVal, v.name);
2782
+ emit("change", oldVal, { modifyKey: v.name });
2718
2783
  }
2719
2784
  fieldMap.value[v.name] = oldVal;
2720
2785
  fieldLabelMap.value[v.name] = v.label || "";
@@ -2737,7 +2802,9 @@
2737
2802
  }
2738
2803
  });
2739
2804
  const inputChangeHandler = (key) => {
2740
- emit("change", fieldMap.value[key], key);
2805
+ emit("change", fieldMap.value[key], {
2806
+ modifyKey: key
2807
+ });
2741
2808
  };
2742
2809
  return (_ctx, _cache) => {
2743
2810
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$6, [
@@ -2821,7 +2888,7 @@
2821
2888
  preventSubmitDefault: { type: Boolean },
2822
2889
  extendState: {}
2823
2890
  },
2824
- emits: ["change", "error", "field-input", "field-change"],
2891
+ emits: ["change", "error", "field-input", "field-change", "update:stepActive"],
2825
2892
  setup(__props, { expose: __expose, emit: __emit }) {
2826
2893
  const props = __props;
2827
2894
  const emit = __emit;
@@ -2846,6 +2913,8 @@
2846
2913
  setField: (prop, field) => fields.set(prop, field),
2847
2914
  getField: (prop) => fields.get(prop),
2848
2915
  deleteField: (prop) => fields.delete(prop),
2916
+ $messageBox: design.tMagicMessageBox,
2917
+ $message: design.tMagicMessage,
2849
2918
  post: (options) => {
2850
2919
  if (requestFuc) {
2851
2920
  return requestFuc({
@@ -2871,9 +2940,11 @@
2871
2940
  }
2872
2941
  });
2873
2942
  vue.provide("mForm", formState);
2943
+ const changeRecords = vue.shallowRef([]);
2874
2944
  vue.watch(
2875
2945
  [() => props.config, () => props.initValues],
2876
2946
  ([config], [preConfig]) => {
2947
+ changeRecords.value = [];
2877
2948
  if (!lodashEs.isEqual(vue.toRaw(config), vue.toRaw(preConfig))) {
2878
2949
  initialized.value = false;
2879
2950
  }
@@ -2896,8 +2967,11 @@
2896
2967
  },
2897
2968
  { immediate: true }
2898
2969
  );
2899
- const changeHandler = () => {
2900
- emit("change", values.value);
2970
+ const changeHandler = (v, eventData) => {
2971
+ if (eventData.changeRecords?.length) {
2972
+ changeRecords.value.push(...eventData.changeRecords);
2973
+ }
2974
+ emit("change", values.value, eventData);
2901
2975
  };
2902
2976
  const submitHandler = (e) => {
2903
2977
  if (props.preventSubmitDefault) {
@@ -2909,8 +2983,12 @@
2909
2983
  lastValuesProcessed,
2910
2984
  formState,
2911
2985
  initialized,
2986
+ changeRecords,
2912
2987
  changeHandler,
2913
- resetForm: () => tMagicForm.value?.resetFields(),
2988
+ resetForm: () => {
2989
+ tMagicForm.value?.resetFields();
2990
+ changeRecords.value = [];
2991
+ },
2914
2992
  submitForm: async (native) => {
2915
2993
  try {
2916
2994
  await tMagicForm.value?.validate();
@@ -3019,7 +3097,7 @@
3019
3097
  const save = async () => {
3020
3098
  try {
3021
3099
  const values = await form.value?.submitForm();
3022
- emit("submit", values);
3100
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
3023
3101
  } catch (e) {
3024
3102
  emit("error", e);
3025
3103
  }
@@ -3030,8 +3108,8 @@
3030
3108
  const nextStep = () => {
3031
3109
  stepActive.value += 1;
3032
3110
  };
3033
- const changeHandler = (value) => {
3034
- emit("change", value);
3111
+ const changeHandler = (value, eventData) => {
3112
+ emit("change", value, eventData);
3035
3113
  };
3036
3114
  const show = () => {
3037
3115
  dialogVisible.value = true;
@@ -3880,7 +3958,7 @@
3880
3958
  }
3881
3959
  });
3882
3960
 
3883
- const _hoisted_1$1 = { class: "m-form-item__content" };
3961
+ const _hoisted_1$1 = { style: { "width": "100%" } };
3884
3962
  const _hoisted_2 = { style: { "display": "flex", "justify-content": "flex-end" } };
3885
3963
  const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
3886
3964
  ...{
@@ -3925,11 +4003,11 @@
3925
4003
  emit("change", props.model[props.name].trim() || "");
3926
4004
  popoverVisible.value = false;
3927
4005
  };
3928
- const checkWhiteSpace = (value) => {
4006
+ const checkWhiteSpace = lodashEs.debounce((value) => {
3929
4007
  if (typeof value === "string" && !props.config.trim) {
3930
4008
  popoverVisible.value = value.trim() !== value;
3931
4009
  }
3932
- };
4010
+ }, 300);
3933
4011
  const changeHandler = (value) => {
3934
4012
  emit("change", value);
3935
4013
  };
@@ -3996,45 +4074,70 @@
3996
4074
  props.model[props.name] = `${num}${unit || ""}`;
3997
4075
  emit("change", props.model[props.name]);
3998
4076
  };
4077
+ const popoverEl = vue.ref();
4078
+ const input = vue.ref();
4079
+ const instanceRef = vue.shallowRef();
4080
+ vue.watch(popoverEl, (el) => {
4081
+ destroyPopover();
4082
+ if (!input.value?.$el || !el) return;
4083
+ instanceRef.value = core.createPopper(input.value.$el, el, {
4084
+ placement: props.config.tooltip ? "top" : "bottom",
4085
+ strategy: "absolute",
4086
+ modifiers: [
4087
+ {
4088
+ name: "offset",
4089
+ options: {
4090
+ offset: [0, 10]
4091
+ }
4092
+ }
4093
+ ]
4094
+ });
4095
+ });
4096
+ const destroyPopover = () => {
4097
+ if (!instanceRef.value) return;
4098
+ instanceRef.value.destroy();
4099
+ instanceRef.value = void 0;
4100
+ };
3999
4101
  return (_ctx, _cache) => {
4000
- return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicPopover), {
4001
- width: "220px",
4002
- visible: popoverVisible.value,
4003
- "destroy-on-close": true
4004
- }, {
4005
- reference: vue.withCtx(() => [
4006
- vue.createVNode(vue.unref(design.TMagicInput), {
4007
- modelValue: _ctx.model[_ctx.name],
4008
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
4009
- clearable: "",
4010
- size: _ctx.size,
4011
- placeholder: _ctx.config.placeholder,
4012
- disabled: _ctx.disabled,
4013
- onChange: changeHandler,
4014
- onInput: inputHandler,
4015
- onKeyup: _cache[1] || (_cache[1] = ($event) => keyUpHandler($event))
4016
- }, vue.createSlots({ _: 2 }, [
4017
- appendConfig.value ? {
4018
- name: "append",
4019
- fn: vue.withCtx(() => [
4020
- appendConfig.value.type === "button" ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
4021
- key: 0,
4022
- style: { "color": "#409eff" },
4023
- size: _ctx.size,
4024
- onClick: vue.withModifiers(buttonClickHandler, ["prevent"])
4025
- }, {
4026
- default: vue.withCtx(() => [
4027
- vue.createTextVNode(vue.toDisplayString(appendConfig.value.text), 1)
4028
- ]),
4029
- _: 1
4030
- }, 8, ["size"])) : vue.createCommentVNode("", true)
4031
- ]),
4032
- key: "0"
4033
- } : void 0
4034
- ]), 1032, ["modelValue", "size", "placeholder", "disabled"])
4035
- ]),
4036
- default: vue.withCtx(() => [
4037
- vue.createElementVNode("div", _hoisted_1$1, [
4102
+ return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
4103
+ vue.createVNode(vue.unref(design.TMagicInput), {
4104
+ modelValue: _ctx.model[_ctx.name],
4105
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
4106
+ ref_key: "input",
4107
+ ref: input,
4108
+ clearable: "",
4109
+ size: _ctx.size,
4110
+ placeholder: _ctx.config.placeholder,
4111
+ disabled: _ctx.disabled,
4112
+ onChange: changeHandler,
4113
+ onInput: inputHandler,
4114
+ onKeyup: _cache[1] || (_cache[1] = ($event) => keyUpHandler($event))
4115
+ }, vue.createSlots({ _: 2 }, [
4116
+ appendConfig.value ? {
4117
+ name: "append",
4118
+ fn: vue.withCtx(() => [
4119
+ appendConfig.value.type === "button" ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
4120
+ key: 0,
4121
+ style: { "color": "#409eff" },
4122
+ size: _ctx.size,
4123
+ onClick: vue.withModifiers(buttonClickHandler, ["prevent"])
4124
+ }, {
4125
+ default: vue.withCtx(() => [
4126
+ vue.createTextVNode(vue.toDisplayString(appendConfig.value.text), 1)
4127
+ ]),
4128
+ _: 1
4129
+ }, 8, ["size"])) : vue.createCommentVNode("", true)
4130
+ ]),
4131
+ key: "0"
4132
+ } : void 0
4133
+ ]), 1032, ["modelValue", "size", "placeholder", "disabled"]),
4134
+ (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
4135
+ popoverVisible.value ? (vue.openBlock(), vue.createElementBlock("div", {
4136
+ key: 0,
4137
+ class: "tmagic-form-text-popper m-form-item__content",
4138
+ ref_key: "popoverEl",
4139
+ ref: popoverEl
4140
+ }, [
4038
4141
  _cache[5] || (_cache[5] = vue.createElementVNode("div", { class: "m-form-validate__warning" }, "输入内容前后有空格,是否移除空格?", -1)),
4039
4142
  vue.createElementVNode("div", _hoisted_2, [
4040
4143
  vue.createVNode(vue.unref(design.TMagicButton), {
@@ -4057,11 +4160,14 @@
4057
4160
  ])),
4058
4161
  _: 1
4059
4162
  })
4060
- ])
4061
- ])
4062
- ]),
4063
- _: 1
4064
- }, 8, ["visible"]);
4163
+ ]),
4164
+ _cache[6] || (_cache[6] = vue.createElementVNode("span", {
4165
+ class: "tmagic-form-text-popper-arrow",
4166
+ "data-popper-arrow": ""
4167
+ }, null, -1))
4168
+ ], 512)) : vue.createCommentVNode("", true)
4169
+ ]))
4170
+ ]);
4065
4171
  };
4066
4172
  }
4067
4173
  });
@@ -4266,13 +4372,13 @@
4266
4372
  const submitHandler = async () => {
4267
4373
  try {
4268
4374
  const values = await form.value?.submitForm();
4269
- emit("submit", values);
4375
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4270
4376
  } catch (e) {
4271
4377
  emit("error", e);
4272
4378
  }
4273
4379
  };
4274
- const changeHandler = (value) => {
4275
- emit("change", value);
4380
+ const changeHandler = (value, eventData) => {
4381
+ emit("change", value, eventData);
4276
4382
  };
4277
4383
  const openHandler = () => {
4278
4384
  emit("open");
@@ -4415,7 +4521,7 @@
4415
4521
  labelPosition: {},
4416
4522
  preventSubmitDefault: { type: Boolean }
4417
4523
  },
4418
- emits: ["submit", "change", "error"],
4524
+ emits: ["change", "submit", "error"],
4419
4525
  setup(__props, { expose: __expose, emit: __emit }) {
4420
4526
  const props = __props;
4421
4527
  const emit = __emit;
@@ -4441,13 +4547,13 @@
4441
4547
  const submitHandler = async () => {
4442
4548
  try {
4443
4549
  const values = await form.value?.submitForm();
4444
- emit("submit", values);
4550
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4445
4551
  } catch (e) {
4446
4552
  emit("error", e);
4447
4553
  }
4448
4554
  };
4449
- const changeHandler = (value) => {
4450
- emit("change", value);
4555
+ const changeHandler = (value, eventData) => {
4556
+ emit("change", value, eventData);
4451
4557
  };
4452
4558
  const show = () => {
4453
4559
  };
@@ -4521,8 +4627,8 @@
4521
4627
  const createForm = (config) => config;
4522
4628
  const defaultInstallOpt = {};
4523
4629
  const index = {
4524
- install(app, opt) {
4525
- const option = Object.assign(defaultInstallOpt, opt || {});
4630
+ install(app, opt = {}) {
4631
+ const option = Object.assign(defaultInstallOpt, opt);
4526
4632
  app.config.globalProperties.$MAGIC_FORM = option;
4527
4633
  setConfig(option);
4528
4634
  app.component("m-form", _sfc_main$d);