@tmagic/form 1.7.11 → 1.7.13-beta.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.
Files changed (40) hide show
  1. package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +1 -1
  2. package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +2 -36
  3. package/dist/es/{table → containers/table}/ActionsColumn.js +1 -1
  4. package/dist/es/{table → containers/table}/ActionsColumn.vue_vue_type_script_setup_true_lang.js +1 -1
  5. package/dist/es/{table → containers/table}/SortColumn.js +1 -1
  6. package/dist/es/{table → containers/table}/SortColumn.vue_vue_type_script_setup_true_lang.js +1 -1
  7. package/dist/es/{table → containers/table}/Table.js +1 -1
  8. package/dist/es/{table → containers/table}/Table.vue_vue_type_script_setup_true_lang.js +10 -16
  9. package/dist/es/containers/table/useFullscreen.js +22 -0
  10. package/dist/es/{table → containers/table}/useImport.js +3 -5
  11. package/dist/es/{table → containers/table}/usePagination.js +2 -2
  12. package/dist/es/{table → containers/table}/useSelection.js +1 -1
  13. package/dist/es/{table → containers/table}/useSortable.js +2 -2
  14. package/dist/es/{table → containers/table}/useTableColumns.js +5 -5
  15. package/dist/es/containers/{TableGroupList.js → table-group-list/TableGroupList.js} +1 -1
  16. package/dist/es/containers/{TableGroupList.vue_vue_type_script_setup_true_lang.js → table-group-list/TableGroupList.vue_vue_type_script_setup_true_lang.js} +25 -26
  17. package/dist/es/{table → containers/table-group-list}/useAdd.js +19 -4
  18. package/dist/es/index.js +1 -1
  19. package/dist/es/plugin.js +1 -1
  20. package/dist/tmagic-form.umd.cjs +645 -665
  21. package/package.json +4 -4
  22. package/src/FormDialog.vue +1 -1
  23. package/src/containers/GroupList.vue +2 -55
  24. package/src/{table → containers/table}/ActionsColumn.vue +1 -1
  25. package/src/{table → containers/table}/Table.vue +8 -18
  26. package/src/containers/table/useFullscreen.ts +31 -0
  27. package/src/{table → containers/table}/useImport.ts +2 -5
  28. package/src/{table → containers/table}/usePagination.ts +1 -1
  29. package/src/{table → containers/table}/useSortable.ts +1 -1
  30. package/src/{table → containers/table}/useTableColumns.ts +8 -5
  31. package/src/containers/{TableGroupList.vue → table-group-list/TableGroupList.vue} +21 -29
  32. package/src/{table → containers/table-group-list}/useAdd.ts +33 -7
  33. package/src/index.ts +3 -3
  34. package/src/plugin.ts +1 -1
  35. package/types/index.d.ts +4 -2
  36. package/dist/es/table/useFullscreen.js +0 -15
  37. package/src/table/useFullscreen.ts +0 -18
  38. /package/src/{table → containers/table}/SortColumn.vue +0 -0
  39. /package/src/{table → containers/table}/type.ts +0 -0
  40. /package/src/{table → containers/table}/useSelection.ts +0 -0
@@ -72,7 +72,7 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
72
72
  };
73
73
  const save = async () => {
74
74
  try {
75
- const changeRecords = form.value?.changeRecords;
75
+ const changeRecords = [...form.value?.changeRecords || []];
76
76
  emit("submit", await form.value?.submitForm(), { changeRecords });
77
77
  } catch (e) {
78
78
  emit("error", e);
@@ -1,8 +1,6 @@
1
- import { initValue } from "../utils/form.js";
2
1
  import GroupListItem_default from "./GroupListItem.js";
3
- import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, inject, openBlock, renderList, renderSlot } from "vue";
2
+ import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, openBlock, renderList, renderSlot } from "vue";
4
3
  import { cloneDeep } from "lodash-es";
5
- import { tMagicMessage } from "@tmagic/design";
6
4
  //#region packages/form/src/containers/GroupList.vue?vue&type=script&setup=true&lang.ts
7
5
  var _hoisted_1 = { class: "m-fields-group-list" };
8
6
  var _hoisted_2 = ["innerHTML"];
@@ -35,41 +33,9 @@ var GroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
35
33
  setup(__props, { emit: __emit }) {
36
34
  const props = __props;
37
35
  const emit = __emit;
38
- const mForm = inject("mForm");
39
36
  const changeHandler = (v, eventData) => {
40
37
  emit("change", props.model, eventData);
41
38
  };
42
- const addHandler = async () => {
43
- if (!props.name) return false;
44
- if (props.config.max && props.model[props.name].length >= props.config.max) {
45
- tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
46
- return;
47
- }
48
- if (typeof props.config.beforeAddRow === "function") {
49
- if (!await props.config.beforeAddRow(mForm, {
50
- model: props.model[props.name],
51
- formValue: mForm?.values,
52
- prop: props.prop
53
- })) return;
54
- }
55
- let initValues = {};
56
- if (typeof props.config.defaultAdd === "function") initValues = await props.config.defaultAdd(mForm, {
57
- model: props.model[props.name],
58
- formValue: mForm?.values,
59
- prop: props.prop,
60
- config: props.config
61
- });
62
- else if (props.config.defaultAdd) initValues = props.config.defaultAdd;
63
- const groupValue = await initValue(mForm, {
64
- config: props.config.items,
65
- initValues
66
- });
67
- props.model[props.name].push(groupValue);
68
- emit("change", props.model[props.name], { changeRecords: [{
69
- propPath: `${props.prop}.${props.model[props.name].length - 1}`,
70
- value: groupValue
71
- }] });
72
- };
73
39
  const removeHandler = (index) => {
74
40
  if (!props.name) return false;
75
41
  props.model[props.name].splice(index, 1);
@@ -125,7 +91,7 @@ var GroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
125
91
  "group-model"
126
92
  ]);
127
93
  }), 128)),
128
- createElementVNode("div", _hoisted_4, [renderSlot(_ctx.$slots, "toggle-button"), createElementVNode("div", _hoisted_5, [renderSlot(_ctx.$slots, "add-button", { trigger: addHandler })])])
94
+ createElementVNode("div", _hoisted_4, [renderSlot(_ctx.$slots, "toggle-button"), createElementVNode("div", _hoisted_5, [renderSlot(_ctx.$slots, "add-button")])])
129
95
  ]);
130
96
  };
131
97
  }
@@ -1,5 +1,5 @@
1
1
  import ActionsColumn_vue_vue_type_script_setup_true_lang_default from "./ActionsColumn.vue_vue_type_script_setup_true_lang.js";
2
- //#region packages/form/src/table/ActionsColumn.vue
2
+ //#region packages/form/src/containers/table/ActionsColumn.vue
3
3
  var ActionsColumn_default = ActionsColumn_vue_vue_type_script_setup_true_lang_default;
4
4
  //#endregion
5
5
  export { ActionsColumn_default as default };
@@ -2,7 +2,7 @@ import { Fragment, createBlock, createCommentVNode, createElementBlock, createVN
2
2
  import { cloneDeep } from "lodash-es";
3
3
  import { TMagicButton, TMagicTooltip } from "@tmagic/design";
4
4
  import { Delete, DocumentCopy, Sort } from "@element-plus/icons-vue";
5
- //#region packages/form/src/table/ActionsColumn.vue?vue&type=script&setup=true&lang.ts
5
+ //#region packages/form/src/containers/table/ActionsColumn.vue?vue&type=script&setup=true&lang.ts
6
6
  var ActionsColumn_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
7
7
  __name: "ActionsColumn",
8
8
  props: {
@@ -1,5 +1,5 @@
1
1
  import SortColumn_vue_vue_type_script_setup_true_lang_default from "./SortColumn.vue_vue_type_script_setup_true_lang.js";
2
- //#region packages/form/src/table/SortColumn.vue
2
+ //#region packages/form/src/containers/table/SortColumn.vue
3
3
  var SortColumn_default = SortColumn_vue_vue_type_script_setup_true_lang_default;
4
4
  //#endregion
5
5
  export { SortColumn_default as default };
@@ -1,7 +1,7 @@
1
1
  import { Fragment, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, openBlock, unref, withCtx } from "vue";
2
2
  import { TMagicButton, TMagicTooltip } from "@tmagic/design";
3
3
  import { ArrowDown, ArrowUp } from "@element-plus/icons-vue";
4
- //#region packages/form/src/table/SortColumn.vue?vue&type=script&setup=true&lang.ts
4
+ //#region packages/form/src/containers/table/SortColumn.vue?vue&type=script&setup=true&lang.ts
5
5
  var SortColumn_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
6
6
  __name: "SortColumn",
7
7
  props: {
@@ -1,5 +1,5 @@
1
1
  import Table_vue_vue_type_script_setup_true_lang_default from "./Table.vue_vue_type_script_setup_true_lang.js";
2
- //#region packages/form/src/table/Table.vue
2
+ //#region packages/form/src/containers/table/Table.vue
3
3
  var Table_default = Table_vue_vue_type_script_setup_true_lang_default;
4
4
  //#endregion
5
5
  export { Table_default as default };
@@ -1,15 +1,14 @@
1
- import { sortChange } from "../utils/form.js";
2
- import { useAdd } from "./useAdd.js";
1
+ import { sortChange } from "../../utils/form.js";
3
2
  import { useFullscreen } from "./useFullscreen.js";
4
3
  import { useImport } from "./useImport.js";
5
4
  import { usePagination } from "./usePagination.js";
6
5
  import { useSelection } from "./useSelection.js";
7
6
  import { useSortable } from "./useSortable.js";
8
7
  import { useTableColumns } from "./useTableColumns.js";
9
- import { Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeProps, normalizeClass, openBlock, ref, renderSlot, toDisplayString, unref, useTemplateRef, watch, withCtx } from "vue";
10
- import { TMagicButton, TMagicPagination, TMagicTable, TMagicTooltip, TMagicUpload, useZIndex } from "@tmagic/design";
8
+ import { Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeProps, normalizeClass, openBlock, ref, renderSlot, toDisplayString, unref, useTemplateRef, withCtx } from "vue";
9
+ import { TMagicButton, TMagicPagination, TMagicTable, TMagicTooltip, TMagicUpload } from "@tmagic/design";
11
10
  import { FullScreen } from "@element-plus/icons-vue";
12
- //#region packages/form/src/table/Table.vue?vue&type=script&setup=true&lang.ts
11
+ //#region packages/form/src/containers/table/Table.vue?vue&type=script&setup=true&lang.ts
13
12
  var _hoisted_1 = ["innerHTML"];
14
13
  var _hoisted_2 = { style: {
15
14
  "display": "flex",
@@ -49,7 +48,8 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
49
48
  emits: [
50
49
  "change",
51
50
  "select",
52
- "addDiffCount"
51
+ "addDiffCount",
52
+ "add"
53
53
  ],
54
54
  setup(__props, { expose: __expose, emit: __emit }) {
55
55
  const props = __props;
@@ -57,17 +57,11 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
57
57
  const modelName = computed(() => props.name || props.config.name || "");
58
58
  const tMagicTableRef = useTemplateRef("tMagicTable");
59
59
  const { pageSize, currentPage, paginationData, handleSizeChange, handleCurrentChange } = usePagination(props, modelName);
60
- const { nextZIndex } = useZIndex();
61
60
  const updateKey = ref(1);
62
- const fullscreenZIndex = ref(nextZIndex());
63
- const { newHandler } = useAdd(props, emit);
64
61
  const { columns } = useTableColumns(props, emit, currentPage, pageSize, modelName);
65
62
  useSortable(props, emit, tMagicTableRef, modelName, updateKey);
66
- const { isFullscreen, toggleFullscreen } = useFullscreen();
67
- watch(isFullscreen, (value) => {
68
- if (value) fullscreenZIndex.value = nextZIndex();
69
- });
70
- const { importable, excelHandler, clearHandler } = useImport(props, emit, newHandler);
63
+ const { isFullscreen, fullscreenZIndex, toggleFullscreen } = useFullscreen();
64
+ const { importable, excelHandler, clearHandler } = useImport(props, emit);
71
65
  const { selectHandle, toggleRowSelection } = useSelection(props, emit, tMagicTableRef);
72
66
  const data = computed(() => props.config.pagination ? paginationData.value : props.model[modelName.value]);
73
67
  const sortChangeHandler = (sortOptions) => {
@@ -81,7 +75,7 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
81
75
  disabled: !unref(isFullscreen)
82
76
  }, [createElementVNode("div", mergeProps(_ctx.$attrs, {
83
77
  class: ["m-fields-table-wrap", { fixed: unref(isFullscreen) }],
84
- style: unref(isFullscreen) ? `z-index: ${fullscreenZIndex.value}` : ""
78
+ style: unref(isFullscreen) ? `z-index: ${unref(fullscreenZIndex)}` : ""
85
79
  }), [createElementVNode("div", { class: normalizeClass(["m-fields-table", { "m-fields-table-item-extra": __props.config.itemExtra }]) }, [
86
80
  __props.config.extra ? (openBlock(), createElementBlock("span", {
87
81
  key: 0,
@@ -159,7 +153,7 @@ var Table_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
159
153
  default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("清空", -1)])]),
160
154
  _: 1
161
155
  }, 8, ["disabled", "onClick"])) : createCommentVNode("v-if", true)
162
- ]), renderSlot(_ctx.$slots, "add-button", { trigger: unref(newHandler) })]),
156
+ ]), renderSlot(_ctx.$slots, "add-button")]),
163
157
  __props.config.pagination ? (openBlock(), createElementBlock("div", _hoisted_4, [createVNode(unref(TMagicPagination), {
164
158
  layout: "total, sizes, prev, pager, next, jumper",
165
159
  "hide-on-single-page": __props.model[modelName.value].length < unref(pageSize),
@@ -0,0 +1,22 @@
1
+ import { ref, watch } from "vue";
2
+ import { useZIndex } from "@tmagic/design";
3
+ //#region packages/form/src/containers/table/useFullscreen.ts
4
+ var useFullscreen = () => {
5
+ const { nextZIndex } = useZIndex();
6
+ const fullscreenZIndex = ref(nextZIndex());
7
+ const isFullscreen = ref(false);
8
+ const toggleFullscreen = () => {
9
+ if (isFullscreen.value) isFullscreen.value = false;
10
+ else isFullscreen.value = true;
11
+ };
12
+ watch(isFullscreen, (value) => {
13
+ if (value) fullscreenZIndex.value = nextZIndex();
14
+ });
15
+ return {
16
+ isFullscreen,
17
+ fullscreenZIndex,
18
+ toggleFullscreen
19
+ };
20
+ };
21
+ //#endregion
22
+ export { useFullscreen };
@@ -1,7 +1,7 @@
1
1
  import { computed, inject, useTemplateRef } from "vue";
2
2
  import { asyncLoadJs } from "@tmagic/utils";
3
- //#region packages/form/src/table/useImport.ts
4
- var useImport = (props, emit, newHandler) => {
3
+ //#region packages/form/src/containers/table/useImport.ts
4
+ var useImport = (props, emit) => {
5
5
  const mForm = inject("mForm");
6
6
  const modelName = computed(() => props.name || props.config.name || "");
7
7
  const importable = computed(() => {
@@ -21,9 +21,7 @@ var useImport = (props, emit, newHandler) => {
21
21
  const pdata = globalThis.XLSX.read(data, { type: "array" });
22
22
  pdata.SheetNames.forEach((sheetName) => {
23
23
  const arr = globalThis.XLSX.utils.sheet_to_json(pdata.Sheets[sheetName], { header: 1 });
24
- if (arr?.[0]) arr.forEach((row) => {
25
- newHandler(row);
26
- });
24
+ if (arr?.[0]) emit("add", arr);
27
25
  setTimeout(() => {
28
26
  excelBtn.value?.clearFiles();
29
27
  }, 300);
@@ -1,6 +1,6 @@
1
- import { getDataByPage } from "../utils/form.js";
1
+ import { getDataByPage } from "../../utils/form.js";
2
2
  import { computed, ref } from "vue";
3
- //#region packages/form/src/table/usePagination.ts
3
+ //#region packages/form/src/containers/table/usePagination.ts
4
4
  var usePagination = (props, modelName) => {
5
5
  const pageSize = ref(10);
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { inject } from "vue";
2
- //#region packages/form/src/table/useSelection.ts
2
+ //#region packages/form/src/containers/table/useSelection.ts
3
3
  var useSelection = (props, emit, tMagicTableRef) => {
4
4
  const mForm = inject("mForm");
5
5
  const selectHandle = (selection, row) => {
@@ -1,6 +1,6 @@
1
- import { sortArray } from "../utils/form.js";
1
+ import { sortArray } from "../../utils/form.js";
2
2
  import { inject, nextTick, watchEffect } from "vue";
3
- //#region packages/form/src/table/useSortable.ts
3
+ //#region packages/form/src/containers/table/useSortable.ts
4
4
  var SortablePromise;
5
5
  var loadSortable = () => SortablePromise ??= import("sortablejs").then((m) => m.default);
6
6
  var useSortable = (props, emit, tMagicTableRef, modelName, updateKey) => {
@@ -1,12 +1,12 @@
1
- import { display, getDataByPage, sortArray } from "../utils/form.js";
2
- import Container_default from "../containers/Container.js";
1
+ import { display, getDataByPage, sortArray } from "../../utils/form.js";
2
+ import Container_default from "../Container.js";
3
3
  import ActionsColumn_default from "./ActionsColumn.js";
4
4
  import SortColumn_default from "./SortColumn.js";
5
5
  import { computed, h, inject } from "vue";
6
6
  import { cloneDeep } from "lodash-es";
7
7
  import { TMagicIcon, TMagicTooltip } from "@tmagic/design";
8
8
  import { WarningFilled } from "@element-plus/icons-vue";
9
- //#region packages/form/src/table/useTableColumns.ts
9
+ //#region packages/form/src/containers/table/useTableColumns.ts
10
10
  var useTableColumns = (props, emit, currentPage, pageSize, modelName) => {
11
11
  const mForm = inject("mForm");
12
12
  const display$1 = (fuc) => display(mForm, fuc, props);
@@ -123,7 +123,7 @@ var useTableColumns = (props, emit, currentPage, pageSize, modelName) => {
123
123
  columns.push({
124
124
  props: {
125
125
  prop: column.name,
126
- label: column.label,
126
+ label: column.label || column.text,
127
127
  width: column.width,
128
128
  sortable: column.sortable,
129
129
  sortOrders: ["ascending", "descending"],
@@ -147,7 +147,7 @@ var useTableColumns = (props, emit, currentPage, pageSize, modelName) => {
147
147
  display: "inline-flex",
148
148
  alignItems: "center",
149
149
  gap: "5px"
150
- } }, [h("span", column.label), h(TMagicIcon, {}, { default: () => h(WarningFilled) })]),
150
+ } }, [h("span", column.label || column.text), h(TMagicIcon, {}, { default: () => h(WarningFilled) })]),
151
151
  content: () => h("div", { innerHTML: titleTipValue })
152
152
  }) : void 0
153
153
  });
@@ -1,5 +1,5 @@
1
1
  import TableGroupList_vue_vue_type_script_setup_true_lang_default from "./TableGroupList.vue_vue_type_script_setup_true_lang.js";
2
- //#region packages/form/src/containers/TableGroupList.vue
2
+ //#region packages/form/src/containers/table-group-list/TableGroupList.vue
3
3
  var TableGroupList_default = TableGroupList_vue_vue_type_script_setup_true_lang_default;
4
4
  //#endregion
5
5
  export { TableGroupList_default as default };
@@ -1,9 +1,10 @@
1
+ import GroupList_default from "../GroupList.js";
1
2
  import Table_default from "../table/Table.js";
2
- import GroupList_default from "./GroupList.js";
3
- import { computed, createBlock, createCommentVNode, createTextVNode, defineComponent, inject, mergeProps, openBlock, ref, resolveDynamicComponent, toDisplayString, unref, withCtx } from "vue";
3
+ import { useAdd } from "./useAdd.js";
4
+ import { computed, createBlock, createCommentVNode, createSlots, createTextVNode, createVNode, defineComponent, mergeProps, openBlock, ref, resolveDynamicComponent, toDisplayString, unref, useTemplateRef, withCtx } from "vue";
4
5
  import { TMagicButton } from "@tmagic/design";
5
6
  import { Grid, Plus } from "@element-plus/icons-vue";
6
- //#region packages/form/src/containers/TableGroupList.vue?vue&type=script&setup=true&lang.ts
7
+ //#region packages/form/src/containers/table-group-list/TableGroupList.vue?vue&type=script&setup=true&lang.ts
7
8
  var TableGroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
8
9
  name: "MFormTableGroupList",
9
10
  inheritAttrs: false,
@@ -28,22 +29,10 @@ var TableGroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
28
29
  "select",
29
30
  "addDiffCount"
30
31
  ],
31
- setup(__props, { emit: __emit }) {
32
+ setup(__props, { expose: __expose, emit: __emit }) {
32
33
  const props = __props;
33
34
  const emit = __emit;
34
- const mForm = inject("mForm");
35
- const addable = computed(() => {
36
- const modelName = props.name || props.config.name || "";
37
- if (!modelName) return false;
38
- if (!props.model[modelName].length) return true;
39
- if (typeof props.config.addable === "function") return props.config.addable(mForm, {
40
- model: props.model[modelName],
41
- formValue: mForm?.values,
42
- prop: props.prop,
43
- config: props.config
44
- });
45
- return typeof props.config.addable === "undefined" ? true : props.config.addable;
46
- });
35
+ const { addable, newHandler } = useAdd(props, emit);
47
36
  const isGroupListType = (type) => type === "groupList" || type === "group-list";
48
37
  const displayMode = ref(isGroupListType(props.config.type) ? "groupList" : "table");
49
38
  const calcLabelWidth = (label) => {
@@ -95,8 +84,15 @@ var TableGroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
95
84
  const onChange = (v, eventData) => emit("change", v, eventData);
96
85
  const onSelect = (...args) => emit("select", ...args);
97
86
  const onAddDiffCount = () => emit("addDiffCount");
87
+ const onAdd = (rows) => {
88
+ rows.forEach((row) => {
89
+ newHandler(row);
90
+ });
91
+ };
92
+ const tableGroupListRef = useTemplateRef("tableGroupList");
93
+ __expose({ toggleRowSelection: (row, selected) => tableGroupListRef.value?.toggleRowSelection?.(row, selected) });
98
94
  return (_ctx, _cache) => {
99
- return openBlock(), createBlock(resolveDynamicComponent(displayMode.value === "table" ? Table_default : GroupList_default), mergeProps(_ctx.$attrs, {
95
+ return openBlock(), createBlock(resolveDynamicComponent(displayMode.value === "table" ? Table_default : GroupList_default), mergeProps({ ref: "tableGroupList" }, _ctx.$attrs, {
100
96
  model: __props.model,
101
97
  name: `${__props.name}`,
102
98
  config: currentConfig.value,
@@ -111,8 +107,9 @@ var TableGroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
111
107
  sort: __props.sort,
112
108
  onChange,
113
109
  onSelect,
114
- onAddDiffCount
115
- }), {
110
+ onAddDiffCount,
111
+ onAdd
112
+ }), createSlots({
116
113
  "toggle-button": withCtx(() => [__props.config.enableToggleMode || __props.enableToggleMode ? (openBlock(), createBlock(unref(TMagicButton), {
117
114
  key: 0,
118
115
  icon: unref(Grid),
@@ -122,14 +119,16 @@ var TableGroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
122
119
  default: withCtx(() => [createTextVNode(toDisplayString(displayMode.value === "table" ? "展开配置" : "切换为表格"), 1)]),
123
120
  _: 1
124
121
  }, 8, ["icon"])) : createCommentVNode("v-if", true)]),
125
- "add-button": withCtx(({ trigger }) => [addable.value ? (openBlock(), createBlock(unref(TMagicButton), mergeProps({
126
- key: 0,
122
+ _: 2
123
+ }, [unref(addable) ? {
124
+ name: "add-button",
125
+ fn: withCtx(() => [createVNode(unref(TMagicButton), mergeProps({
127
126
  class: displayMode.value === "table" ? "m-form-table-add-button" : "",
128
127
  size: addButtonSize.value,
129
128
  plain: displayMode.value === "table",
130
129
  icon: unref(Plus),
131
130
  disabled: __props.disabled
132
- }, currentConfig.value.addButtonConfig?.props || { type: "primary" }, { onClick: trigger }), {
131
+ }, currentConfig.value.addButtonConfig?.props || { type: "primary" }, { onClick: unref(newHandler) }), {
133
132
  default: withCtx(() => [createTextVNode(toDisplayString(currentConfig.value.addButtonConfig?.text || (displayMode.value === "table" ? "新增一行" : "新增")), 1)]),
134
133
  _: 1
135
134
  }, 16, [
@@ -139,9 +138,9 @@ var TableGroupList_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */
139
138
  "icon",
140
139
  "disabled",
141
140
  "onClick"
142
- ])) : createCommentVNode("v-if", true)]),
143
- _: 1
144
- }, 16, [
141
+ ])]),
142
+ key: "0"
143
+ } : void 0]), 1040, [
145
144
  "model",
146
145
  "name",
147
146
  "config",
@@ -1,9 +1,21 @@
1
- import { initValue } from "../utils/form.js";
2
- import { inject } from "vue";
1
+ import { initValue } from "../../utils/form.js";
2
+ import { computed, inject } from "vue";
3
3
  import { tMagicMessage } from "@tmagic/design";
4
- //#region packages/form/src/table/useAdd.ts
4
+ //#region packages/form/src/containers/table-group-list/useAdd.ts
5
5
  var useAdd = (props, emit) => {
6
6
  const mForm = inject("mForm");
7
+ const addable = computed(() => {
8
+ const modelName = props.name || props.config.name || "";
9
+ if (!modelName) return false;
10
+ if (!props.model[modelName].length) return true;
11
+ if (typeof props.config.addable === "function") return props.config.addable(mForm, {
12
+ model: props.model[modelName],
13
+ formValue: mForm?.values,
14
+ prop: props.prop,
15
+ config: props.config
16
+ });
17
+ return typeof props.config.addable === "undefined" ? true : props.config.addable;
18
+ });
7
19
  const newHandler = async (row) => {
8
20
  const modelName = props.name || props.config.name || "";
9
21
  if (props.config.max && props.model[modelName].length >= props.config.max) {
@@ -52,7 +64,10 @@ var useAdd = (props, emit) => {
52
64
  value: inputs
53
65
  }] });
54
66
  };
55
- return { newHandler };
67
+ return {
68
+ addable,
69
+ newHandler
70
+ };
56
71
  };
57
72
  //#endregion
58
73
  export { useAdd };
package/dist/es/index.js CHANGED
@@ -13,7 +13,7 @@ import FlexLayout_default from "./containers/FlexLayout.js";
13
13
  import Panel_default from "./containers/Panel.js";
14
14
  import Row_default from "./containers/Row.js";
15
15
  import Tabs_default from "./containers/Tabs.js";
16
- import TableGroupList_default from "./containers/TableGroupList.js";
16
+ import TableGroupList_default from "./containers/table-group-list/TableGroupList.js";
17
17
  import Text_default from "./fields/Text.js";
18
18
  import Number_default from "./fields/Number.js";
19
19
  import NumberRange_default from "./fields/NumberRange.js";
package/dist/es/plugin.js CHANGED
@@ -8,7 +8,7 @@ import FlexLayout_default from "./containers/FlexLayout.js";
8
8
  import Panel_default from "./containers/Panel.js";
9
9
  import Row_default from "./containers/Row.js";
10
10
  import Tabs_default from "./containers/Tabs.js";
11
- import TableGroupList_default from "./containers/TableGroupList.js";
11
+ import TableGroupList_default from "./containers/table-group-list/TableGroupList.js";
12
12
  import Text_default from "./fields/Text.js";
13
13
  import Number_default from "./fields/Number.js";
14
14
  import NumberRange_default from "./fields/NumberRange.js";