@tmagic/form 1.5.0-beta.8 → 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,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");
@@ -366,7 +398,7 @@
366
398
  }, 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 ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 2 }, [
367
399
  vue.createVNode(vue.unref(design.TMagicFormItem), {
368
400
  style: vue.normalizeStyle(_ctx.config.tip ? "flex: 1" : ""),
369
- class: vue.normalizeClass({ hidden: `${itemLabelWidth.value}` === "0" || !text.value }),
401
+ class: vue.normalizeClass({ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value }),
370
402
  prop: itemProp.value,
371
403
  "label-width": itemLabelWidth.value,
372
404
  rules: rule.value
@@ -439,7 +471,7 @@
439
471
  ], 64)) : type.value && display$1.value && showDiff.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 3 }, [
440
472
  vue.createVNode(vue.unref(design.TMagicFormItem), {
441
473
  style: vue.normalizeStyle([_ctx.config.tip ? "flex: 1" : "", { "background": "#f7dadd" }]),
442
- class: vue.normalizeClass({ hidden: `${itemLabelWidth.value}` === "0" || !text.value }),
474
+ class: vue.normalizeClass({ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value }),
443
475
  prop: itemProp.value,
444
476
  "label-width": itemLabelWidth.value,
445
477
  rules: rule.value
@@ -507,7 +539,7 @@
507
539
  })) : vue.createCommentVNode("", true),
508
540
  vue.createVNode(vue.unref(design.TMagicFormItem), {
509
541
  style: vue.normalizeStyle([_ctx.config.tip ? "flex: 1" : "", { "background": "#def7da" }]),
510
- class: vue.normalizeClass({ hidden: `${itemLabelWidth.value}` === "0" || !text.value }),
542
+ class: vue.normalizeClass({ "tmagic-form-hidden": `${itemLabelWidth.value}` === "0" || !text.value }),
511
543
  prop: itemProp.value,
512
544
  "label-width": itemLabelWidth.value,
513
545
  rules: rule.value
@@ -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,16 +688,17 @@
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) => {
665
698
  return (name.value ? _ctx.model[name.value] : _ctx.model) ? (vue.openBlock(), vue.createElementBlock("fieldset", {
666
699
  key: 0,
667
700
  class: "m-fieldset",
668
- style: vue.normalizeStyle(show.value ? "padding: 15px 15px 0 5px;" : "border: 0")
701
+ style: vue.normalizeStyle(show.value ? "padding: 15px" : "border: 0")
669
702
  }, [
670
703
  name.value && _ctx.config.checkbox ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(!show.value ? "div" : "legend"), { key: 0 }, {
671
704
  default: vue.withCtx(() => [
@@ -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
- size: "small",
1025
- disabled: _ctx.disabled
1064
+ type: "primary",
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]) {
@@ -2613,9 +2678,9 @@
2613
2678
  const props = __props;
2614
2679
  const emit = __emit;
2615
2680
  useAddField(props.prop);
2616
- const value = props.model?.[props.name].toString();
2681
+ const value = props.model?.[props.name]?.toString();
2617
2682
  if (props.model) {
2618
- if (value === "Invalid Date") {
2683
+ if (!value || value === "Invalid Date") {
2619
2684
  props.model[props.name] = "";
2620
2685
  } else {
2621
2686
  props.model[props.name] = datetimeFormatter(
@@ -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, [
@@ -2818,9 +2885,10 @@
2818
2885
  labelPosition: { default: "right" },
2819
2886
  keyProp: { default: "__key" },
2820
2887
  popperClass: {},
2888
+ preventSubmitDefault: { type: Boolean },
2821
2889
  extendState: {}
2822
2890
  },
2823
- emits: ["change", "error", "field-input", "field-change"],
2891
+ emits: ["change", "error", "field-input", "field-change", "update:stepActive"],
2824
2892
  setup(__props, { expose: __expose, emit: __emit }) {
2825
2893
  const props = __props;
2826
2894
  const emit = __emit;
@@ -2845,11 +2913,13 @@
2845
2913
  setField: (prop, field) => fields.set(prop, field),
2846
2914
  getField: (prop) => fields.get(prop),
2847
2915
  deleteField: (prop) => fields.delete(prop),
2916
+ $messageBox: design.tMagicMessageBox,
2917
+ $message: design.tMagicMessage,
2848
2918
  post: (options) => {
2849
2919
  if (requestFuc) {
2850
2920
  return requestFuc({
2851
- ...options,
2852
- method: "POST"
2921
+ method: "POST",
2922
+ ...options
2853
2923
  });
2854
2924
  }
2855
2925
  }
@@ -2870,9 +2940,11 @@
2870
2940
  }
2871
2941
  });
2872
2942
  vue.provide("mForm", formState);
2943
+ const changeRecords = vue.shallowRef([]);
2873
2944
  vue.watch(
2874
2945
  [() => props.config, () => props.initValues],
2875
2946
  ([config], [preConfig]) => {
2947
+ changeRecords.value = [];
2876
2948
  if (!lodashEs.isEqual(vue.toRaw(config), vue.toRaw(preConfig))) {
2877
2949
  initialized.value = false;
2878
2950
  }
@@ -2895,16 +2967,28 @@
2895
2967
  },
2896
2968
  { immediate: true }
2897
2969
  );
2898
- const changeHandler = () => {
2899
- 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);
2975
+ };
2976
+ const submitHandler = (e) => {
2977
+ if (props.preventSubmitDefault) {
2978
+ e.preventDefault();
2979
+ }
2900
2980
  };
2901
2981
  __expose({
2902
2982
  values,
2903
2983
  lastValuesProcessed,
2904
2984
  formState,
2905
2985
  initialized,
2986
+ changeRecords,
2906
2987
  changeHandler,
2907
- resetForm: () => tMagicForm.value?.resetFields(),
2988
+ resetForm: () => {
2989
+ tMagicForm.value?.resetFields();
2990
+ changeRecords.value = [];
2991
+ },
2908
2992
  submitForm: async (native) => {
2909
2993
  try {
2910
2994
  await tMagicForm.value?.validate();
@@ -2932,7 +3016,8 @@
2932
3016
  "label-width": _ctx.labelWidth,
2933
3017
  style: vue.normalizeStyle(`height: ${_ctx.height}`),
2934
3018
  inline: _ctx.inline,
2935
- "label-position": _ctx.labelPosition
3019
+ "label-position": _ctx.labelPosition,
3020
+ onSubmit: submitHandler
2936
3021
  }, {
2937
3022
  default: vue.withCtx(() => [
2938
3023
  initialized.value && Array.isArray(_ctx.config) ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 0 }, vue.renderList(_ctx.config, (item, index) => {
@@ -2975,7 +3060,8 @@
2975
3060
  labelPosition: {},
2976
3061
  zIndex: {},
2977
3062
  size: {},
2978
- confirmText: { default: "确定" }
3063
+ confirmText: { default: "确定" },
3064
+ preventSubmitDefault: { type: Boolean }
2979
3065
  },
2980
3066
  emits: ["close", "submit", "error", "change"],
2981
3067
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -3011,7 +3097,7 @@
3011
3097
  const save = async () => {
3012
3098
  try {
3013
3099
  const values = await form.value?.submitForm();
3014
- emit("submit", values);
3100
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
3015
3101
  } catch (e) {
3016
3102
  emit("error", e);
3017
3103
  }
@@ -3022,8 +3108,8 @@
3022
3108
  const nextStep = () => {
3023
3109
  stepActive.value += 1;
3024
3110
  };
3025
- const changeHandler = (value) => {
3026
- emit("change", value);
3111
+ const changeHandler = (value, eventData) => {
3112
+ emit("change", value, eventData);
3027
3113
  };
3028
3114
  const show = () => {
3029
3115
  dialogVisible.value = true;
@@ -3144,8 +3230,9 @@
3144
3230
  "label-width": _ctx.labelWidth,
3145
3231
  "label-position": _ctx.labelPosition,
3146
3232
  inline: _ctx.inline,
3233
+ "prevent-submit-default": _ctx.preventSubmitDefault,
3147
3234
  onChange: changeHandler
3148
- }, null, 8, ["modelValue", "size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline"]),
3235
+ }, null, 8, ["modelValue", "size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline", "prevent-submit-default"]),
3149
3236
  vue.renderSlot(_ctx.$slots, "default")
3150
3237
  ], 4)) : vue.createCommentVNode("", true)
3151
3238
  ]),
@@ -3871,7 +3958,7 @@
3871
3958
  }
3872
3959
  });
3873
3960
 
3874
- const _hoisted_1$1 = { class: "m-form-item__content" };
3961
+ const _hoisted_1$1 = { style: { "width": "100%" } };
3875
3962
  const _hoisted_2 = { style: { "display": "flex", "justify-content": "flex-end" } };
3876
3963
  const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
3877
3964
  ...{
@@ -3916,11 +4003,11 @@
3916
4003
  emit("change", props.model[props.name].trim() || "");
3917
4004
  popoverVisible.value = false;
3918
4005
  };
3919
- const checkWhiteSpace = (value) => {
4006
+ const checkWhiteSpace = lodashEs.debounce((value) => {
3920
4007
  if (typeof value === "string" && !props.config.trim) {
3921
4008
  popoverVisible.value = value.trim() !== value;
3922
4009
  }
3923
- };
4010
+ }, 300);
3924
4011
  const changeHandler = (value) => {
3925
4012
  emit("change", value);
3926
4013
  };
@@ -3987,45 +4074,70 @@
3987
4074
  props.model[props.name] = `${num}${unit || ""}`;
3988
4075
  emit("change", props.model[props.name]);
3989
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
+ };
3990
4101
  return (_ctx, _cache) => {
3991
- return vue.openBlock(), vue.createBlock(vue.unref(design.TMagicPopover), {
3992
- width: "220px",
3993
- visible: popoverVisible.value,
3994
- "destroy-on-close": true
3995
- }, {
3996
- reference: vue.withCtx(() => [
3997
- vue.createVNode(vue.unref(design.TMagicInput), {
3998
- modelValue: _ctx.model[_ctx.name],
3999
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
4000
- clearable: "",
4001
- size: _ctx.size,
4002
- placeholder: _ctx.config.placeholder,
4003
- disabled: _ctx.disabled,
4004
- onChange: changeHandler,
4005
- onInput: inputHandler,
4006
- onKeyup: _cache[1] || (_cache[1] = ($event) => keyUpHandler($event))
4007
- }, vue.createSlots({ _: 2 }, [
4008
- appendConfig.value ? {
4009
- name: "append",
4010
- fn: vue.withCtx(() => [
4011
- appendConfig.value.type === "button" ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
4012
- key: 0,
4013
- style: { "color": "#409eff" },
4014
- size: _ctx.size,
4015
- onClick: vue.withModifiers(buttonClickHandler, ["prevent"])
4016
- }, {
4017
- default: vue.withCtx(() => [
4018
- vue.createTextVNode(vue.toDisplayString(appendConfig.value.text), 1)
4019
- ]),
4020
- _: 1
4021
- }, 8, ["size"])) : vue.createCommentVNode("", true)
4022
- ]),
4023
- key: "0"
4024
- } : void 0
4025
- ]), 1032, ["modelValue", "size", "placeholder", "disabled"])
4026
- ]),
4027
- default: vue.withCtx(() => [
4028
- 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
+ }, [
4029
4141
  _cache[5] || (_cache[5] = vue.createElementVNode("div", { class: "m-form-validate__warning" }, "输入内容前后有空格,是否移除空格?", -1)),
4030
4142
  vue.createElementVNode("div", _hoisted_2, [
4031
4143
  vue.createVNode(vue.unref(design.TMagicButton), {
@@ -4048,11 +4160,14 @@
4048
4160
  ])),
4049
4161
  _: 1
4050
4162
  })
4051
- ])
4052
- ])
4053
- ]),
4054
- _: 1
4055
- }, 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
+ ]);
4056
4171
  };
4057
4172
  }
4058
4173
  });
@@ -4237,6 +4352,7 @@
4237
4352
  confirmText: { default: "确定" },
4238
4353
  inline: { type: Boolean },
4239
4354
  labelPosition: {},
4355
+ preventSubmitDefault: { type: Boolean },
4240
4356
  beforeClose: {}
4241
4357
  },
4242
4358
  emits: ["close", "closed", "submit", "error", "change", "open", "opened"],
@@ -4256,13 +4372,13 @@
4256
4372
  const submitHandler = async () => {
4257
4373
  try {
4258
4374
  const values = await form.value?.submitForm();
4259
- emit("submit", values);
4375
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4260
4376
  } catch (e) {
4261
4377
  emit("error", e);
4262
4378
  }
4263
4379
  };
4264
- const changeHandler = (value) => {
4265
- emit("change", value);
4380
+ const changeHandler = (value, eventData) => {
4381
+ emit("change", value, eventData);
4266
4382
  };
4267
4383
  const openHandler = () => {
4268
4384
  emit("open");
@@ -4373,8 +4489,9 @@
4373
4489
  "label-width": _ctx.labelWidth,
4374
4490
  "label-position": _ctx.labelPosition,
4375
4491
  inline: _ctx.inline,
4492
+ "prevent-submit-default": _ctx.preventSubmitDefault,
4376
4493
  onChange: changeHandler
4377
- }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline"]),
4494
+ }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline", "prevent-submit-default"]),
4378
4495
  vue.renderSlot(_ctx.$slots, "default")
4379
4496
  ], 512)) : vue.createCommentVNode("", true)
4380
4497
  ]),
@@ -4401,9 +4518,10 @@
4401
4518
  size: {},
4402
4519
  confirmText: { default: "确定" },
4403
4520
  inline: { type: Boolean },
4404
- labelPosition: {}
4521
+ labelPosition: {},
4522
+ preventSubmitDefault: { type: Boolean }
4405
4523
  },
4406
- emits: ["submit", "change", "error"],
4524
+ emits: ["change", "submit", "error"],
4407
4525
  setup(__props, { expose: __expose, emit: __emit }) {
4408
4526
  const props = __props;
4409
4527
  const emit = __emit;
@@ -4429,13 +4547,13 @@
4429
4547
  const submitHandler = async () => {
4430
4548
  try {
4431
4549
  const values = await form.value?.submitForm();
4432
- emit("submit", values);
4550
+ emit("submit", values, { changeRecords: form.value?.changeRecords });
4433
4551
  } catch (e) {
4434
4552
  emit("error", e);
4435
4553
  }
4436
4554
  };
4437
- const changeHandler = (value) => {
4438
- emit("change", value);
4555
+ const changeHandler = (value, eventData) => {
4556
+ emit("change", value, eventData);
4439
4557
  };
4440
4558
  const show = () => {
4441
4559
  };
@@ -4469,8 +4587,9 @@
4469
4587
  "label-width": _ctx.labelWidth,
4470
4588
  "label-position": _ctx.labelPosition,
4471
4589
  inline: _ctx.inline,
4590
+ "prevent-submit-default": _ctx.preventSubmitDefault,
4472
4591
  onChange: changeHandler
4473
- }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline"]),
4592
+ }, null, 8, ["size", "disabled", "config", "init-values", "parent-values", "label-width", "label-position", "inline", "prevent-submit-default"]),
4474
4593
  vue.renderSlot(_ctx.$slots, "default")
4475
4594
  ]),
4476
4595
  _: 3
@@ -4508,8 +4627,8 @@
4508
4627
  const createForm = (config) => config;
4509
4628
  const defaultInstallOpt = {};
4510
4629
  const index = {
4511
- install(app, opt) {
4512
- const option = Object.assign(defaultInstallOpt, opt || {});
4630
+ install(app, opt = {}) {
4631
+ const option = Object.assign(defaultInstallOpt, opt);
4513
4632
  app.config.globalProperties.$MAGIC_FORM = option;
4514
4633
  setConfig(option);
4515
4634
  app.component("m-form", _sfc_main$d);