@tmagic/form 1.7.10 → 1.7.11

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.
@@ -36,8 +36,8 @@
36
36
  enumerable: true
37
37
  }) : target, mod));
38
38
  //#endregion
39
- dayjs = __toESM(dayjs);
40
- dayjs_plugin_utc = __toESM(dayjs_plugin_utc);
39
+ dayjs = __toESM(dayjs, 1);
40
+ dayjs_plugin_utc = __toESM(dayjs_plugin_utc, 1);
41
41
  //#region node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
42
42
  /** Detect free variable `global` from Node.js. */
43
43
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
@@ -1497,7 +1497,8 @@
1497
1497
  * @param {Array} [entries] The key-value pairs to cache.
1498
1498
  */
1499
1499
  function Stack(entries) {
1500
- this.size = (this.__data__ = new ListCache(entries)).size;
1500
+ var data = this.__data__ = new ListCache(entries);
1501
+ this.size = data.size;
1501
1502
  }
1502
1503
  Stack.prototype.clear = stackClear;
1503
1504
  Stack.prototype["delete"] = stackDelete;
@@ -4691,16 +4692,6 @@
4691
4692
  //#region packages/form/src/table/useAdd.ts
4692
4693
  var useAdd = (props, emit) => {
4693
4694
  const mForm = (0, vue.inject)("mForm");
4694
- const addable = (0, vue.computed)(() => {
4695
- const modelName = props.name || props.config.name || "";
4696
- if (!props.model[modelName].length) return true;
4697
- if (typeof props.config.addable === "function") return props.config.addable(mForm, {
4698
- model: props.model[modelName],
4699
- formValue: mForm?.values,
4700
- prop: props.prop
4701
- });
4702
- return typeof props.config.addable === "undefined" ? true : props.config.addable;
4703
- });
4704
4695
  const newHandler = async (row) => {
4705
4696
  const modelName = props.name || props.config.name || "";
4706
4697
  if (props.config.max && props.model[modelName].length >= props.config.max) {
@@ -4708,7 +4699,7 @@
4708
4699
  return;
4709
4700
  }
4710
4701
  if (typeof props.config.beforeAddRow === "function") {
4711
- if (!props.config.beforeAddRow(mForm, {
4702
+ if (!await props.config.beforeAddRow(mForm, {
4712
4703
  model: props.model[modelName],
4713
4704
  formValue: mForm?.values,
4714
4705
  prop: props.prop
@@ -4749,10 +4740,7 @@
4749
4740
  value: inputs
4750
4741
  }] });
4751
4742
  };
4752
- return {
4753
- addable,
4754
- newHandler
4755
- };
4743
+ return { newHandler };
4756
4744
  };
4757
4745
  //#endregion
4758
4746
  //#region packages/form/src/table/useFullscreen.ts
@@ -5265,10 +5253,6 @@
5265
5253
  sortKey: { default: "" },
5266
5254
  text: {},
5267
5255
  size: {},
5268
- enableToggleMode: {
5269
- type: Boolean,
5270
- default: true
5271
- },
5272
5256
  showIndex: {
5273
5257
  type: Boolean,
5274
5258
  default: true
@@ -5287,34 +5271,17 @@
5287
5271
  const { pageSize, currentPage, paginationData, handleSizeChange, handleCurrentChange } = usePagination(props, modelName);
5288
5272
  const { nextZIndex } = (0, _tmagic_design.useZIndex)();
5289
5273
  const updateKey = (0, vue.ref)(1);
5290
- const { addable, newHandler } = useAdd(props, emit);
5274
+ const fullscreenZIndex = (0, vue.ref)(nextZIndex());
5275
+ const { newHandler } = useAdd(props, emit);
5291
5276
  const { columns } = useTableColumns(props, emit, currentPage, pageSize, modelName);
5292
5277
  useSortable(props, emit, tMagicTableRef, modelName, updateKey);
5293
5278
  const { isFullscreen, toggleFullscreen } = useFullscreen();
5279
+ (0, vue.watch)(isFullscreen, (value) => {
5280
+ if (value) fullscreenZIndex.value = nextZIndex();
5281
+ });
5294
5282
  const { importable, excelHandler, clearHandler } = useImport(props, emit, newHandler);
5295
5283
  const { selectHandle, toggleRowSelection } = useSelection(props, emit, tMagicTableRef);
5296
5284
  const data = (0, vue.computed)(() => props.config.pagination ? paginationData.value : props.model[modelName.value]);
5297
- const toggleMode = () => {
5298
- const calcLabelWidth = (label) => {
5299
- if (!label) return "0px";
5300
- const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
5301
- const chLength = label.length - zhLength;
5302
- return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
5303
- };
5304
- props.config.type = "groupList";
5305
- props.config.enableToggleMode = true;
5306
- props.config.tableItems = props.config.items;
5307
- props.config.items = props.config.groupItems || props.config.items.map((item) => {
5308
- const text = item.text || item.label;
5309
- const labelWidth = calcLabelWidth(text);
5310
- return {
5311
- ...item,
5312
- text,
5313
- labelWidth,
5314
- span: item.span || 12
5315
- };
5316
- });
5317
- };
5318
5285
  const sortChangeHandler = (sortOptions) => {
5319
5286
  const modelName = props.name || props.config.name || "";
5320
5287
  sortChange(props.model[modelName], sortOptions);
@@ -5326,7 +5293,7 @@
5326
5293
  disabled: !(0, vue.unref)(isFullscreen)
5327
5294
  }, [(0, vue.createElementVNode)("div", (0, vue.mergeProps)(_ctx.$attrs, {
5328
5295
  class: ["m-fields-table-wrap", { fixed: (0, vue.unref)(isFullscreen) }],
5329
- style: (0, vue.unref)(isFullscreen) ? `z-index: ${(0, vue.unref)(nextZIndex)()}` : ""
5296
+ style: (0, vue.unref)(isFullscreen) ? `z-index: ${fullscreenZIndex.value}` : ""
5330
5297
  }), [(0, vue.createElementVNode)("div", { class: (0, vue.normalizeClass)(["m-fields-table", { "m-fields-table-item-extra": __props.config.itemExtra }]) }, [
5331
5298
  __props.config.extra ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
5332
5299
  key: 0,
@@ -5363,15 +5330,7 @@
5363
5330
  }, 8, ["disabled"]),
5364
5331
  (0, vue.renderSlot)(_ctx.$slots, "default"),
5365
5332
  (0, vue.createElementVNode)("div", _hoisted_2$4, [(0, vue.createElementVNode)("div", _hoisted_3$3, [
5366
- __props.enableToggleMode && __props.config.enableToggleMode !== false && !(0, vue.unref)(isFullscreen) ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5367
- key: 0,
5368
- icon: (0, vue.unref)(_element_plus_icons_vue.Grid),
5369
- size: "small",
5370
- onClick: toggleMode
5371
- }, {
5372
- default: (0, vue.withCtx)(() => [..._cache[1] || (_cache[1] = [(0, vue.createTextVNode)("展开配置", -1)])]),
5373
- _: 1
5374
- }, 8, ["icon"])) : (0, vue.createCommentVNode)("v-if", true),
5333
+ !(0, vue.unref)(isFullscreen) ? (0, vue.renderSlot)(_ctx.$slots, "toggle-button", { key: 0 }) : (0, vue.createCommentVNode)("v-if", true),
5375
5334
  __props.config.enableFullscreen !== false ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5376
5335
  key: 1,
5377
5336
  icon: (0, vue.unref)(_element_plus_icons_vue.FullScreen),
@@ -5396,7 +5355,7 @@
5396
5355
  disabled: __props.disabled,
5397
5356
  plain: ""
5398
5357
  }, {
5399
- default: (0, vue.withCtx)(() => [..._cache[2] || (_cache[2] = [(0, vue.createTextVNode)("导入EXCEL", -1)])]),
5358
+ default: (0, vue.withCtx)(() => [..._cache[0] || (_cache[0] = [(0, vue.createTextVNode)("导入EXCEL", -1)])]),
5400
5359
  _: 1
5401
5360
  }, 8, ["disabled"])]),
5402
5361
  _: 1
@@ -5409,22 +5368,10 @@
5409
5368
  plain: "",
5410
5369
  onClick: (0, vue.unref)(clearHandler)
5411
5370
  }, {
5412
- default: (0, vue.withCtx)(() => [..._cache[3] || (_cache[3] = [(0, vue.createTextVNode)("清空", -1)])]),
5371
+ default: (0, vue.withCtx)(() => [..._cache[1] || (_cache[1] = [(0, vue.createTextVNode)("清空", -1)])]),
5413
5372
  _: 1
5414
5373
  }, 8, ["disabled", "onClick"])) : (0, vue.createCommentVNode)("v-if", true)
5415
- ]), (0, vue.unref)(addable) ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), (0, vue.mergeProps)({
5416
- key: 0,
5417
- class: "m-form-table-add-button",
5418
- size: "small",
5419
- plain: "",
5420
- icon: (0, vue.unref)(_element_plus_icons_vue.Plus)
5421
- }, __props.config.addButtonConfig?.props || { type: "primary" }, {
5422
- disabled: __props.disabled,
5423
- onClick: _cache[0] || (_cache[0] = ($event) => (0, vue.unref)(newHandler)())
5424
- }), {
5425
- default: (0, vue.withCtx)(() => [(0, vue.createTextVNode)((0, vue.toDisplayString)(__props.config.addButtonConfig?.text || "新增一行"), 1)]),
5426
- _: 1
5427
- }, 16, ["icon", "disabled"])) : (0, vue.createCommentVNode)("v-if", true)]),
5374
+ ]), (0, vue.renderSlot)(_ctx.$slots, "add-button", { trigger: (0, vue.unref)(newHandler) })]),
5428
5375
  __props.config.pagination ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_4$1, [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicPagination), {
5429
5376
  layout: "total, sizes, prev, pager, next, jumper",
5430
5377
  "hide-on-single-page": __props.model[modelName.value].length < (0, vue.unref)(pageSize),
@@ -5697,28 +5644,30 @@
5697
5644
  labelWidth: {},
5698
5645
  prop: {},
5699
5646
  size: {},
5700
- disabled: { type: Boolean }
5647
+ disabled: { type: Boolean },
5648
+ showIndex: { type: Boolean }
5701
5649
  },
5702
5650
  emits: ["change", "addDiffCount"],
5703
5651
  setup(__props, { emit: __emit }) {
5704
5652
  const props = __props;
5705
5653
  const emit = __emit;
5706
5654
  const mForm = (0, vue.inject)("mForm");
5707
- const addable = (0, vue.computed)(() => {
5708
- if (!props.name) return false;
5709
- if (typeof props.config.addable === "function") return props.config.addable(mForm, {
5710
- model: props.model[props.name],
5711
- formValue: mForm?.values,
5712
- prop: props.prop,
5713
- config: props.config
5714
- });
5715
- return typeof props.config.addable === "undefined" ? true : props.config.addable;
5716
- });
5717
5655
  const changeHandler = (v, eventData) => {
5718
5656
  emit("change", props.model, eventData);
5719
5657
  };
5720
5658
  const addHandler = async () => {
5721
5659
  if (!props.name) return false;
5660
+ if (props.config.max && props.model[props.name].length >= props.config.max) {
5661
+ _tmagic_design.tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
5662
+ return;
5663
+ }
5664
+ if (typeof props.config.beforeAddRow === "function") {
5665
+ if (!await props.config.beforeAddRow(mForm, {
5666
+ model: props.model[props.name],
5667
+ formValue: mForm?.values,
5668
+ prop: props.prop
5669
+ })) return;
5670
+ }
5722
5671
  let initValues = {};
5723
5672
  if (typeof props.config.defaultAdd === "function") initValues = await props.config.defaultAdd(mForm, {
5724
5673
  model: props.model[props.name],
@@ -5752,15 +5701,6 @@
5752
5701
  props.model[props.name].splice(Math.min(Math.max(idx2, 0), length - 1), 0, currRow);
5753
5702
  emit("change", props.model[props.name]);
5754
5703
  };
5755
- const toggleMode = () => {
5756
- props.config.type = "table";
5757
- props.config.groupItems = props.config.items;
5758
- props.config.items = props.config.tableItems || props.config.items.map((item) => ({
5759
- ...item,
5760
- label: item.label || item.text,
5761
- text: null
5762
- }));
5763
- };
5764
5704
  const onAddDiffCount = () => emit("addDiffCount");
5765
5705
  const getLastValues = (item, index) => item?.[index] || {};
5766
5706
  return (_ctx, _cache) => {
@@ -5774,7 +5714,7 @@
5774
5714
  return (0, vue.openBlock)(), (0, vue.createBlock)(GroupListItem_default, {
5775
5715
  key: index,
5776
5716
  model: item,
5777
- lastValues: getLastValues(__props.lastValues[__props.name], Number(index)),
5717
+ lastValues: getLastValues(__props.lastValues?.[__props.name], Number(index)),
5778
5718
  "is-compare": __props.isCompare,
5779
5719
  config: __props.config,
5780
5720
  prop: __props.prop,
@@ -5801,29 +5741,163 @@
5801
5741
  "group-model"
5802
5742
  ]);
5803
5743
  }), 128)),
5804
- (0, vue.createElementVNode)("div", _hoisted_4, [__props.config.enableToggleMode ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5744
+ (0, vue.createElementVNode)("div", _hoisted_4, [(0, vue.renderSlot)(_ctx.$slots, "toggle-button"), (0, vue.createElementVNode)("div", _hoisted_5, [(0, vue.renderSlot)(_ctx.$slots, "add-button", { trigger: addHandler })])])
5745
+ ]);
5746
+ };
5747
+ }
5748
+ });
5749
+ //#endregion
5750
+ //#region packages/form/src/containers/TableGroupList.vue
5751
+ var TableGroupList_default = /* @__PURE__ */ (0, vue.defineComponent)({
5752
+ name: "MFormTableGroupList",
5753
+ inheritAttrs: false,
5754
+ __name: "TableGroupList",
5755
+ props: {
5756
+ model: {},
5757
+ lastValues: {},
5758
+ isCompare: { type: Boolean },
5759
+ config: {},
5760
+ name: {},
5761
+ prop: {},
5762
+ labelWidth: {},
5763
+ disabled: { type: Boolean },
5764
+ size: {},
5765
+ enableToggleMode: { type: Boolean },
5766
+ showIndex: { type: Boolean },
5767
+ sortKey: {},
5768
+ sort: { type: Boolean }
5769
+ },
5770
+ emits: [
5771
+ "change",
5772
+ "select",
5773
+ "addDiffCount"
5774
+ ],
5775
+ setup(__props, { emit: __emit }) {
5776
+ const props = __props;
5777
+ const emit = __emit;
5778
+ const mForm = (0, vue.inject)("mForm");
5779
+ const addable = (0, vue.computed)(() => {
5780
+ const modelName = props.name || props.config.name || "";
5781
+ if (!modelName) return false;
5782
+ if (!props.model[modelName].length) return true;
5783
+ if (typeof props.config.addable === "function") return props.config.addable(mForm, {
5784
+ model: props.model[modelName],
5785
+ formValue: mForm?.values,
5786
+ prop: props.prop,
5787
+ config: props.config
5788
+ });
5789
+ return typeof props.config.addable === "undefined" ? true : props.config.addable;
5790
+ });
5791
+ const isGroupListType = (type) => type === "groupList" || type === "group-list";
5792
+ const displayMode = (0, vue.ref)(isGroupListType(props.config.type) ? "groupList" : "table");
5793
+ const calcLabelWidth = (label) => {
5794
+ if (!label) return "0px";
5795
+ const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
5796
+ const chLength = label.length - zhLength;
5797
+ return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
5798
+ };
5799
+ const tableConfig = (0, vue.computed)(() => {
5800
+ if (!isGroupListType(props.config.type)) return props.config;
5801
+ const source = props.config;
5802
+ return {
5803
+ ...props.config,
5804
+ type: "table",
5805
+ groupItems: source.items,
5806
+ items: source.tableItems || source.items.map((item) => ({
5807
+ ...item,
5808
+ label: item.label || item.text,
5809
+ text: null
5810
+ }))
5811
+ };
5812
+ });
5813
+ const groupListConfig = (0, vue.computed)(() => {
5814
+ if (isGroupListType(props.config.type)) return props.config;
5815
+ const source = props.config;
5816
+ return {
5817
+ ...props.config,
5818
+ type: "groupList",
5819
+ tableItems: source.items,
5820
+ items: source.groupItems || source.items.map((item) => {
5821
+ const text = item.text || item.label;
5822
+ return {
5823
+ ...item,
5824
+ text,
5825
+ labelWidth: calcLabelWidth(text),
5826
+ span: item.span || 12
5827
+ };
5828
+ })
5829
+ };
5830
+ });
5831
+ const currentConfig = (0, vue.computed)(() => displayMode.value === "table" ? tableConfig.value : groupListConfig.value);
5832
+ const addButtonSize = (0, vue.computed)(() => {
5833
+ if (displayMode.value === "table") return "small";
5834
+ return props.config.enableToggleMode !== false ? "small" : "default";
5835
+ });
5836
+ const toggleDisplayMode = () => {
5837
+ displayMode.value = displayMode.value === "table" ? "groupList" : "table";
5838
+ };
5839
+ const onChange = (v, eventData) => emit("change", v, eventData);
5840
+ const onSelect = (...args) => emit("select", ...args);
5841
+ const onAddDiffCount = () => emit("addDiffCount");
5842
+ return (_ctx, _cache) => {
5843
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(displayMode.value === "table" ? Table_default : GroupList_default), (0, vue.mergeProps)(_ctx.$attrs, {
5844
+ model: __props.model,
5845
+ name: `${__props.name}`,
5846
+ config: currentConfig.value,
5847
+ disabled: __props.disabled,
5848
+ size: __props.size,
5849
+ "is-compare": __props.isCompare,
5850
+ "last-values": __props.lastValues,
5851
+ prop: __props.prop,
5852
+ "label-width": __props.labelWidth,
5853
+ "show-index": __props.showIndex,
5854
+ "sort-key": __props.sortKey,
5855
+ sort: __props.sort,
5856
+ onChange,
5857
+ onSelect,
5858
+ onAddDiffCount
5859
+ }), {
5860
+ "toggle-button": (0, vue.withCtx)(() => [__props.config.enableToggleMode || __props.enableToggleMode ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5805
5861
  key: 0,
5806
5862
  icon: (0, vue.unref)(_element_plus_icons_vue.Grid),
5807
5863
  size: "small",
5808
- onClick: toggleMode
5864
+ onClick: toggleDisplayMode
5809
5865
  }, {
5810
- default: (0, vue.withCtx)(() => [..._cache[2] || (_cache[2] = [(0, vue.createTextVNode)("切换为表格", -1)])]),
5866
+ default: (0, vue.withCtx)(() => [(0, vue.createTextVNode)((0, vue.toDisplayString)(displayMode.value === "table" ? "展开配置" : "切换为表格"), 1)]),
5811
5867
  _: 1
5812
- }, 8, ["icon"])) : (0, vue.createCommentVNode)("v-if", true), (0, vue.createElementVNode)("div", _hoisted_5, [addable.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), (0, vue.mergeProps)({
5868
+ }, 8, ["icon"])) : (0, vue.createCommentVNode)("v-if", true)]),
5869
+ "add-button": (0, vue.withCtx)(({ trigger }) => [addable.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), (0, vue.mergeProps)({
5813
5870
  key: 0,
5814
- size: __props.config.enableToggleMode ? "small" : "default",
5815
- icon: (0, vue.unref)(_element_plus_icons_vue.Plus)
5816
- }, __props.config.addButtonConfig?.props || { type: "primary" }, {
5817
- disabled: __props.disabled,
5818
- onClick: addHandler
5819
- }), {
5820
- default: (0, vue.withCtx)(() => [(0, vue.createTextVNode)((0, vue.toDisplayString)(__props.config.addButtonConfig?.text || "新增"), 1)]),
5871
+ class: displayMode.value === "table" ? "m-form-table-add-button" : "",
5872
+ size: addButtonSize.value,
5873
+ plain: displayMode.value === "table",
5874
+ icon: (0, vue.unref)(_element_plus_icons_vue.Plus),
5875
+ disabled: __props.disabled
5876
+ }, currentConfig.value.addButtonConfig?.props || { type: "primary" }, { onClick: trigger }), {
5877
+ default: (0, vue.withCtx)(() => [(0, vue.createTextVNode)((0, vue.toDisplayString)(currentConfig.value.addButtonConfig?.text || (displayMode.value === "table" ? "新增一行" : "新增")), 1)]),
5821
5878
  _: 1
5822
5879
  }, 16, [
5880
+ "class",
5823
5881
  "size",
5882
+ "plain",
5824
5883
  "icon",
5825
- "disabled"
5826
- ])) : (0, vue.createCommentVNode)("v-if", true)])])
5884
+ "disabled",
5885
+ "onClick"
5886
+ ])) : (0, vue.createCommentVNode)("v-if", true)]),
5887
+ _: 1
5888
+ }, 16, [
5889
+ "model",
5890
+ "name",
5891
+ "config",
5892
+ "disabled",
5893
+ "size",
5894
+ "is-compare",
5895
+ "last-values",
5896
+ "prop",
5897
+ "label-width",
5898
+ "show-index",
5899
+ "sort-key",
5900
+ "sort"
5827
5901
  ]);
5828
5902
  };
5829
5903
  }
@@ -7607,11 +7681,11 @@
7607
7681
  app.component("m-form-dialog", FormDialog_default);
7608
7682
  app.component("m-form-container", Container_default);
7609
7683
  app.component("m-form-fieldset", Fieldset_default);
7610
- app.component("m-form-group-list", GroupList_default);
7684
+ app.component("m-form-group-list", TableGroupList_default);
7611
7685
  app.component("m-form-panel", Panel_default);
7612
7686
  app.component("m-form-row", Row_default);
7613
7687
  app.component("m-form-step", Step_default);
7614
- app.component("m-form-table", Table_default);
7688
+ app.component("m-form-table", TableGroupList_default);
7615
7689
  app.component("m-form-tab", Tabs_default);
7616
7690
  app.component("m-form-flex-layout", FlexLayout_default);
7617
7691
  app.component("m-fields-text", Text_default);
@@ -7654,7 +7728,7 @@
7654
7728
  exports.MFormBox = FormBox_default;
7655
7729
  exports.MFormDialog = FormDialog_default;
7656
7730
  exports.MFormDrawer = FormDrawer_default;
7657
- exports.MGroupList = GroupList_default;
7731
+ exports.MGroupList = TableGroupList_default;
7658
7732
  exports.MHidden = Hidden_default;
7659
7733
  exports.MLink = Link_default;
7660
7734
  exports.MNumber = Number_default;
@@ -7664,7 +7738,8 @@
7664
7738
  exports.MRow = Row_default;
7665
7739
  exports.MSelect = Select_default;
7666
7740
  exports.MSwitch = Switch_default;
7667
- exports.MTable = Table_default;
7741
+ exports.MTable = TableGroupList_default;
7742
+ exports.MTableGroupList = TableGroupList_default;
7668
7743
  exports.MTabs = Tabs_default;
7669
7744
  exports.MText = Text_default;
7670
7745
  exports.MTextarea = Textarea_default;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.10",
2
+ "version": "1.7.11",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -50,11 +50,11 @@
50
50
  "@vue/test-utils": "^2.4.6"
51
51
  },
52
52
  "peerDependencies": {
53
- "vue": "^3.5.24",
54
- "typescript": "^6.0.2",
55
- "@tmagic/design": "1.7.10",
56
- "@tmagic/form-schema": "1.7.10",
57
- "@tmagic/utils": "1.7.10"
53
+ "vue": "^3.5.33",
54
+ "typescript": "^6.0.3",
55
+ "@tmagic/form-schema": "1.7.11",
56
+ "@tmagic/design": "1.7.11",
57
+ "@tmagic/utils": "1.7.11"
58
58
  },
59
59
  "peerDependenciesMeta": {
60
60
  "typescript": {
@@ -10,7 +10,7 @@
10
10
  v-for="(item, index) in model[name]"
11
11
  :key="index"
12
12
  :model="item"
13
- :lastValues="getLastValues(lastValues[name], Number(index))"
13
+ :lastValues="getLastValues(lastValues?.[name], Number(index))"
14
14
  :is-compare="isCompare"
15
15
  :config="config"
16
16
  :prop="prop"
@@ -27,30 +27,19 @@
27
27
  ></MFieldsGroupListItem>
28
28
 
29
29
  <div class="m-fields-group-list-footer">
30
- <TMagicButton v-if="config.enableToggleMode" :icon="Grid" size="small" @click="toggleMode"
31
- >切换为表格</TMagicButton
32
- >
30
+ <slot name="toggle-button"></slot>
33
31
  <div style="display: flex; justify-content: flex-end; flex: 1">
34
- <TMagicButton
35
- v-if="addable"
36
- :size="config.enableToggleMode ? 'small' : 'default'"
37
- :icon="Plus"
38
- v-bind="config.addButtonConfig?.props || { type: 'primary' }"
39
- :disabled="disabled"
40
- @click="addHandler"
41
- >{{ config.addButtonConfig?.text || '新增' }}</TMagicButton
42
- >
32
+ <slot name="add-button" :trigger="addHandler"></slot>
43
33
  </div>
44
34
  </div>
45
35
  </div>
46
36
  </template>
47
37
 
48
38
  <script setup lang="ts">
49
- import { computed, inject } from 'vue';
50
- import { Grid, Plus } from '@element-plus/icons-vue';
39
+ import { inject } from 'vue';
51
40
  import { cloneDeep } from 'lodash-es';
52
41
 
53
- import { TMagicButton } from '@tmagic/design';
42
+ import { tMagicMessage } from '@tmagic/design';
54
43
 
55
44
  import type { ContainerChangeEventData, FormState, GroupListConfig } from '../schema';
56
45
  import { initValue } from '../utils/form';
@@ -71,6 +60,7 @@ const props = defineProps<{
71
60
  prop?: string;
72
61
  size?: string;
73
62
  disabled?: boolean;
63
+ showIndex?: boolean;
74
64
  }>();
75
65
 
76
66
  const emit = defineEmits<{
@@ -80,28 +70,27 @@ const emit = defineEmits<{
80
70
 
81
71
  const mForm = inject<FormState | undefined>('mForm');
82
72
 
83
- const addable = computed(() => {
73
+ const changeHandler = (v: any, eventData: ContainerChangeEventData) => {
74
+ emit('change', props.model, eventData);
75
+ };
76
+
77
+ const addHandler = async () => {
84
78
  if (!props.name) return false;
85
79
 
86
- if (typeof props.config.addable === 'function') {
87
- return props.config.addable(mForm, {
80
+ if (props.config.max && props.model[props.name].length >= props.config.max) {
81
+ tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
82
+ return;
83
+ }
84
+
85
+ if (typeof props.config.beforeAddRow === 'function') {
86
+ const beforeCheckRes = await props.config.beforeAddRow(mForm, {
88
87
  model: props.model[props.name],
89
88
  formValue: mForm?.values,
90
89
  prop: props.prop,
91
- config: props.config,
92
90
  });
91
+ if (!beforeCheckRes) return;
93
92
  }
94
93
 
95
- return typeof props.config.addable === 'undefined' ? true : props.config.addable;
96
- });
97
-
98
- const changeHandler = (v: any, eventData: ContainerChangeEventData) => {
99
- emit('change', props.model, eventData);
100
- };
101
-
102
- const addHandler = async () => {
103
- if (!props.name) return false;
104
-
105
94
  let initValues = {};
106
95
 
107
96
  if (typeof props.config.defaultAdd === 'function') {
@@ -153,17 +142,6 @@ const swapHandler = (idx1: number, idx2: number) => {
153
142
  emit('change', props.model[props.name]);
154
143
  };
155
144
 
156
- const toggleMode = () => {
157
- props.config.type = 'table';
158
- props.config.groupItems = props.config.items;
159
- props.config.items = (props.config.tableItems ||
160
- props.config.items.map((item: any) => ({
161
- ...item,
162
- label: item.label || item.text,
163
- text: null,
164
- }))) as any;
165
- };
166
-
167
145
  const onAddDiffCount = () => emit('addDiffCount');
168
146
 
169
147
  const getLastValues = (item: any, index: number) => item?.[index] || {};