@tmagic/form 1.7.10 → 1.7.12

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 (38) hide show
  1. package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +5 -69
  2. package/dist/es/{table → containers/table}/ActionsColumn.js +1 -1
  3. package/dist/es/{table → containers/table}/ActionsColumn.vue_vue_type_script_setup_true_lang.js +1 -1
  4. package/dist/es/{table → containers/table}/SortColumn.js +1 -1
  5. package/dist/es/{table → containers/table}/SortColumn.vue_vue_type_script_setup_true_lang.js +1 -1
  6. package/dist/es/{table → containers/table}/Table.js +1 -1
  7. package/dist/es/{table → containers/table}/Table.vue_vue_type_script_setup_true_lang.js +13 -60
  8. package/dist/es/containers/table/useFullscreen.js +22 -0
  9. package/dist/es/{table → containers/table}/useImport.js +3 -5
  10. package/dist/es/{table → containers/table}/usePagination.js +2 -2
  11. package/dist/es/{table → containers/table}/useSelection.js +1 -1
  12. package/dist/es/{table → containers/table}/useSortable.js +2 -2
  13. package/dist/es/{table → containers/table}/useTableColumns.js +5 -5
  14. package/dist/es/containers/table-group-list/TableGroupList.js +5 -0
  15. package/dist/es/containers/table-group-list/TableGroupList.vue_vue_type_script_setup_true_lang.js +161 -0
  16. package/dist/es/{table → containers/table-group-list}/useAdd.js +6 -4
  17. package/dist/es/index.js +2 -3
  18. package/dist/es/plugin.js +3 -4
  19. package/dist/tmagic-form.umd.cjs +732 -677
  20. package/package.json +6 -6
  21. package/src/containers/GroupList.vue +5 -80
  22. package/src/{table → containers/table}/ActionsColumn.vue +1 -1
  23. package/src/{table → containers/table}/Table.vue +11 -56
  24. package/src/{table → containers/table}/type.ts +0 -1
  25. package/src/containers/table/useFullscreen.ts +31 -0
  26. package/src/{table → containers/table}/useImport.ts +2 -5
  27. package/src/{table → containers/table}/usePagination.ts +1 -1
  28. package/src/{table → containers/table}/useSortable.ts +1 -1
  29. package/src/{table → containers/table}/useTableColumns.ts +8 -5
  30. package/src/containers/table-group-list/TableGroupList.vue +173 -0
  31. package/src/{table → containers/table-group-list}/useAdd.ts +17 -7
  32. package/src/index.ts +3 -2
  33. package/src/plugin.ts +3 -4
  34. package/types/index.d.ts +245 -286
  35. package/dist/es/table/useFullscreen.js +0 -15
  36. package/src/table/useFullscreen.ts +0 -18
  37. /package/src/{table → containers/table}/SortColumn.vue +0 -0
  38. /package/src/{table → containers/table}/useSelection.ts +0 -0
@@ -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;
@@ -4688,235 +4689,487 @@
4688
4689
  }
4689
4690
  });
4690
4691
  //#endregion
4691
- //#region packages/form/src/table/useAdd.ts
4692
- var useAdd = (props, emit) => {
4693
- 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
- const newHandler = async (row) => {
4705
- const modelName = props.name || props.config.name || "";
4706
- if (props.config.max && props.model[modelName].length >= props.config.max) {
4707
- _tmagic_design.tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
4708
- return;
4709
- }
4710
- if (typeof props.config.beforeAddRow === "function") {
4711
- if (!props.config.beforeAddRow(mForm, {
4712
- model: props.model[modelName],
4713
- formValue: mForm?.values,
4714
- prop: props.prop
4715
- })) return;
4716
- }
4717
- const columns = props.config.items;
4718
- const enumValues = props.config.enum || [];
4719
- let enumV = [];
4720
- const { length } = props.model[modelName];
4721
- const key = props.config.key || "id";
4722
- let inputs = {};
4723
- if (enumValues.length) {
4724
- if (length >= enumValues.length) return;
4725
- enumV = enumValues.filter((item) => {
4726
- let i = 0;
4727
- for (; i < length; i++) if (item[key] === props.model[modelName][i][key]) break;
4728
- return i === length;
4729
- });
4730
- if (enumV.length > 0) inputs = enumV[0];
4731
- } else if (Array.isArray(row)) columns.forEach((column, index) => {
4732
- column.name && (inputs[column.name] = row[index]);
4733
- });
4734
- else {
4735
- if (typeof props.config.defaultAdd === "function") inputs = await props.config.defaultAdd(mForm, {
4736
- model: props.model[modelName],
4737
- prop: props.prop,
4738
- formValue: mForm?.values
4739
- });
4740
- else if (props.config.defaultAdd) inputs = props.config.defaultAdd;
4741
- inputs = await initValue(mForm, {
4742
- config: columns,
4743
- initValues: inputs
4744
- });
4745
- }
4746
- if (props.sortKey && length) inputs[props.sortKey] = props.model[modelName][length - 1][props.sortKey] - 1;
4747
- emit("change", [...props.model[modelName], inputs], { changeRecords: [{
4748
- propPath: `${props.prop}.${props.model[modelName].length}`,
4749
- value: inputs
4750
- }] });
4751
- };
4752
- return {
4753
- addable,
4754
- newHandler
4755
- };
4756
- };
4757
- //#endregion
4758
- //#region packages/form/src/table/useFullscreen.ts
4759
- var useFullscreen = () => {
4760
- const isFullscreen = (0, vue.ref)(false);
4761
- const toggleFullscreen = () => {
4762
- if (isFullscreen.value) isFullscreen.value = false;
4763
- else isFullscreen.value = true;
4764
- };
4765
- return {
4766
- isFullscreen,
4767
- toggleFullscreen
4768
- };
4769
- };
4770
- //#endregion
4771
- //#region packages/form/src/table/useImport.ts
4772
- var useImport = (props, emit, newHandler) => {
4773
- const mForm = (0, vue.inject)("mForm");
4774
- const modelName = (0, vue.computed)(() => props.name || props.config.name || "");
4775
- const importable = (0, vue.computed)(() => {
4776
- if (typeof props.config.importable === "function") return props.config.importable(mForm, {
4777
- formValue: mForm?.values,
4778
- model: props.model[modelName.value]
4779
- });
4780
- return typeof props.config.importable === "undefined" ? false : props.config.importable;
4781
- });
4782
- const excelBtn = (0, vue.useTemplateRef)("excelBtn");
4783
- const excelHandler = async (file) => {
4784
- if (!file?.raw) return false;
4785
- if (!globalThis.XLSX) await (0, _tmagic_utils.asyncLoadJs)("https://cdn.bootcdn.net/ajax/libs/xlsx/0.17.0/xlsx.full.min.js");
4786
- const reader = new FileReader();
4787
- reader.onload = () => {
4788
- const data = reader.result;
4789
- const pdata = globalThis.XLSX.read(data, { type: "array" });
4790
- pdata.SheetNames.forEach((sheetName) => {
4791
- const arr = globalThis.XLSX.utils.sheet_to_json(pdata.Sheets[sheetName], { header: 1 });
4792
- if (arr?.[0]) arr.forEach((row) => {
4793
- newHandler(row);
4794
- });
4795
- setTimeout(() => {
4796
- excelBtn.value?.clearFiles();
4797
- }, 300);
4798
- });
4799
- };
4800
- reader.readAsArrayBuffer(file.raw);
4801
- return false;
4802
- };
4803
- const clearHandler = () => {
4804
- emit("change", []);
4805
- mForm?.$emit("field-change", props.prop, props.model[modelName.value]);
4806
- };
4807
- return {
4808
- importable,
4809
- excelHandler,
4810
- clearHandler
4811
- };
4812
- };
4813
- //#endregion
4814
- //#region packages/form/src/table/usePagination.ts
4815
- var usePagination = (props, modelName) => {
4816
- const pageSize = (0, vue.ref)(10);
4817
- /**
4818
- * 当前页码
4819
- */
4820
- const currentPage = (0, vue.ref)(0);
4821
- const paginationData = (0, vue.computed)(() => getDataByPage(props.model[modelName.value], currentPage.value, pageSize.value));
4822
- const handleSizeChange = (val) => {
4823
- pageSize.value = val;
4824
- };
4825
- const handleCurrentChange = (val) => {
4826
- currentPage.value = val - 1;
4827
- };
4828
- return {
4829
- pageSize,
4830
- currentPage,
4831
- paginationData,
4832
- handleSizeChange,
4833
- handleCurrentChange
4834
- };
4835
- };
4836
- //#endregion
4837
- //#region packages/form/src/table/useSelection.ts
4838
- var useSelection = (props, emit, tMagicTableRef) => {
4839
- const mForm = (0, vue.inject)("mForm");
4840
- const selectHandle = (selection, row) => {
4841
- if (typeof props.config.selection === "string" && props.config.selection === "single") {
4842
- tMagicTableRef.value?.clearSelection();
4843
- tMagicTableRef.value?.toggleRowSelection(row, true);
4844
- }
4845
- emit("select", selection, row);
4846
- if (typeof props.config.onSelect === "function") props.config.onSelect(mForm, {
4847
- selection,
4848
- row,
4849
- config: props.config
4850
- });
4851
- };
4852
- const toggleRowSelection = (row, selected) => {
4853
- tMagicTableRef.value?.toggleRowSelection.call(tMagicTableRef.value?.getTableRef(), row, selected);
4854
- };
4855
- return {
4856
- selectHandle,
4857
- toggleRowSelection
4858
- };
4859
- };
4860
- //#endregion
4861
- //#region packages/form/src/table/useSortable.ts
4862
- var SortablePromise;
4863
- var loadSortable = () => SortablePromise ??= import("sortablejs").then((m) => m.default);
4864
- var useSortable = (props, emit, tMagicTableRef, modelName, updateKey) => {
4865
- const mForm = (0, vue.inject)("mForm");
4866
- let sortable;
4867
- const rowDrop = async () => {
4868
- sortable?.destroy();
4869
- const tableEl = tMagicTableRef.value?.getEl();
4870
- const tBodyEl = tableEl?.querySelector(".el-table__body > tbody") || tableEl?.querySelector(".t-table__body");
4871
- if (!tBodyEl) return;
4872
- sortable = (await loadSortable()).create(tBodyEl, {
4873
- draggable: ".tmagic-design-table-row",
4874
- filter: "input",
4875
- preventOnFilter: false,
4876
- direction: "vertical",
4877
- handle: props.config.dropSortHandle ? ".tmagic-form-table-drag-target" : void 0,
4878
- onEnd: ({ newIndex, oldIndex }) => {
4879
- if (typeof newIndex === "undefined") return;
4880
- if (typeof oldIndex === "undefined") return;
4881
- const newData = sortArray(props.model[modelName.value], newIndex, oldIndex, props.sortKey);
4882
- emit("change", newData);
4883
- mForm?.$emit("field-change", newData);
4884
- (0, vue.nextTick)(() => {
4885
- sortable?.destroy();
4886
- sortable = void 0;
4887
- updateKey.value += 1;
4888
- });
4889
- }
4890
- });
4891
- };
4892
- (0, vue.watchEffect)(() => {
4893
- if (props.config.dropSort) rowDrop();
4894
- });
4895
- };
4692
+ //#region packages/form/src/containers/GroupListItem.vue?vue&type=script&setup=true&lang.ts
4693
+ var _hoisted_1$9 = ["innerHTML"];
4694
+ var _hoisted_2$4 = { style: {
4695
+ "text-align": "right",
4696
+ "margin-top": "20px"
4697
+ } };
4698
+ var _hoisted_3$3 = ["innerHTML"];
4896
4699
  //#endregion
4897
- //#region packages/form/src/table/ActionsColumn.vue
4898
- var ActionsColumn_default = /* @__PURE__ */ (0, vue.defineComponent)({
4899
- __name: "ActionsColumn",
4700
+ //#region packages/form/src/containers/GroupListItem.vue
4701
+ var GroupListItem_default = /* @__PURE__ */ (0, vue.defineComponent)({
4702
+ name: "MFormGroupListItem",
4703
+ __name: "GroupListItem",
4900
4704
  props: {
4901
- config: {},
4902
4705
  model: {},
4903
- name: {},
4904
- disabled: { type: Boolean },
4905
- currentPage: {},
4906
- pageSize: {},
4907
- index: {},
4908
- row: {},
4706
+ lastValues: {},
4707
+ isCompare: { type: Boolean },
4708
+ groupModel: {},
4709
+ config: {},
4710
+ labelWidth: {},
4909
4711
  prop: {},
4910
- sortKey: {}
4712
+ size: {},
4713
+ index: {},
4714
+ disabled: { type: Boolean }
4911
4715
  },
4912
- emits: ["change"],
4716
+ emits: [
4717
+ "swap-item",
4718
+ "remove-item",
4719
+ "change",
4720
+ "addDiffCount",
4721
+ "copy-item"
4722
+ ],
4913
4723
  setup(__props, { emit: __emit }) {
4914
- const emit = __emit;
4915
4724
  const props = __props;
4725
+ const emit = __emit;
4916
4726
  const mForm = (0, vue.inject)("mForm");
4917
- const removeHandler = (index) => {
4918
- if (props.disabled) return;
4919
- emit("change", props.model[props.name].toSpliced(index, 1));
4727
+ const defaultExpandQuantity = props.config.defaultExpandQuantity ?? 7;
4728
+ const expand = (0, vue.ref)(props.config.expandAll || defaultExpandQuantity > props.index);
4729
+ const rowConfig = (0, vue.computed)(() => ({
4730
+ type: "row",
4731
+ span: props.config.span || 24,
4732
+ items: props.config.items,
4733
+ labelWidth: props.config.labelWidth,
4734
+ [mForm?.keyProp || "__key"]: `${props.config[mForm?.keyProp || "__key"]}${String(props.index)}`
4735
+ }));
4736
+ const title = (0, vue.computed)(() => {
4737
+ if (props.config.titleKey && props.model[props.config.titleKey]) return props.model[props.config.titleKey];
4738
+ if (props.config.title) return filterFunction(mForm, props.config.title, props);
4739
+ return `${props.config.titlePrefix || "组"} ${String(props.index + 1)}`;
4740
+ });
4741
+ const length = (0, vue.computed)(() => props.groupModel?.length || 0);
4742
+ const itemExtra = (0, vue.computed)(() => filterFunction(mForm, props.config.itemExtra, props));
4743
+ const removeHandler = () => emit("remove-item", props.index);
4744
+ const changeHandler = (v, eventData) => {
4745
+ emit("change", props.model, eventData);
4746
+ };
4747
+ const expandHandler = () => {
4748
+ expand.value = !expand.value;
4749
+ };
4750
+ const showDelete = (0, vue.computed)(() => {
4751
+ const deleteFunc = props.config.delete;
4752
+ if (deleteFunc && typeof deleteFunc === "function") return deleteFunc(props.model, props.index, mForm?.values);
4753
+ return true;
4754
+ });
4755
+ const changeOrder = (offset = 0) => emit("swap-item", props.index, props.index + offset);
4756
+ const movable = (0, vue.computed)(() => {
4757
+ const { movable } = props.config;
4758
+ if (movable === void 0) return true;
4759
+ if (typeof movable === "function") return movable(mForm, props.index || 0, props.model, props.groupModel);
4760
+ return movable;
4761
+ });
4762
+ const copyable = (0, vue.computed)(() => filterFunction(mForm, props.config.copyable, props));
4763
+ const onAddDiffCount = () => emit("addDiffCount");
4764
+ const copyHandler = () => {
4765
+ emit("copy-item", props.index);
4766
+ };
4767
+ const moveSpecifyLocationVisible = (0, vue.ref)(false);
4768
+ const moveSpecifyLocationIndex = (0, vue.ref)(1);
4769
+ const moveSpecifyLocationHandler = () => {
4770
+ moveSpecifyLocationVisible.value = false;
4771
+ emit("swap-item", props.index, moveSpecifyLocationIndex.value - 1);
4772
+ };
4773
+ return (_ctx, _cache) => {
4774
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicCard), {
4775
+ class: "m-fields-group-list-item",
4776
+ "body-style": { display: expand.value ? "block" : "none" }
4777
+ }, {
4778
+ header: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("div", null, [
4779
+ (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4780
+ link: "",
4781
+ disabled: __props.disabled,
4782
+ onClick: expandHandler
4783
+ }, {
4784
+ default: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicIcon), null, {
4785
+ default: (0, vue.withCtx)(() => [expand.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_element_plus_icons_vue.CaretBottom), { key: 0 })) : ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_element_plus_icons_vue.CaretRight), { key: 1 }))]),
4786
+ _: 1
4787
+ }), (0, vue.createElementVNode)("span", { innerHTML: title.value }, null, 8, _hoisted_1$9)]),
4788
+ _: 1
4789
+ }, 8, ["disabled"]),
4790
+ (0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4791
+ type: "danger",
4792
+ size: "small",
4793
+ link: "",
4794
+ icon: (0, vue.unref)(_element_plus_icons_vue.Delete),
4795
+ disabled: __props.disabled,
4796
+ onClick: removeHandler
4797
+ }, null, 8, ["icon", "disabled"]), [[vue.vShow, showDelete.value]]),
4798
+ copyable.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
4799
+ key: 0,
4800
+ link: "",
4801
+ size: "small",
4802
+ type: "primary",
4803
+ icon: (0, vue.unref)(_element_plus_icons_vue.DocumentCopy),
4804
+ disabled: __props.disabled,
4805
+ onClick: copyHandler
4806
+ }, {
4807
+ default: (0, vue.withCtx)(() => [..._cache[6] || (_cache[6] = [(0, vue.createTextVNode)("复制", -1)])]),
4808
+ _: 1
4809
+ }, 8, ["icon", "disabled"])) : (0, vue.createCommentVNode)("v-if", true),
4810
+ movable.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, { key: 1 }, [(0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4811
+ link: "",
4812
+ size: "small",
4813
+ disabled: __props.disabled,
4814
+ icon: (0, vue.unref)(_element_plus_icons_vue.CaretTop),
4815
+ onClick: _cache[0] || (_cache[0] = ($event) => changeOrder(-1))
4816
+ }, {
4817
+ default: (0, vue.withCtx)(() => [..._cache[7] || (_cache[7] = [(0, vue.createTextVNode)("上移", -1)])]),
4818
+ _: 1
4819
+ }, 8, ["disabled", "icon"]), [[vue.vShow, __props.index !== 0]]), (0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4820
+ link: "",
4821
+ size: "small",
4822
+ disabled: __props.disabled,
4823
+ icon: (0, vue.unref)(_element_plus_icons_vue.CaretBottom),
4824
+ onClick: _cache[1] || (_cache[1] = ($event) => changeOrder(1))
4825
+ }, {
4826
+ default: (0, vue.withCtx)(() => [..._cache[8] || (_cache[8] = [(0, vue.createTextVNode)("下移", -1)])]),
4827
+ _: 1
4828
+ }, 8, ["disabled", "icon"]), [[vue.vShow, __props.index !== length.value - 1]])], 64)) : (0, vue.createCommentVNode)("v-if", true),
4829
+ __props.config.moveSpecifyLocation ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicPopover), {
4830
+ key: 2,
4831
+ trigger: "click",
4832
+ placement: "top",
4833
+ width: "200",
4834
+ visible: moveSpecifyLocationVisible.value
4835
+ }, {
4836
+ reference: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4837
+ link: "",
4838
+ size: "small",
4839
+ type: "primary",
4840
+ icon: (0, vue.unref)(_element_plus_icons_vue.Position),
4841
+ disabled: __props.disabled,
4842
+ onClick: _cache[2] || (_cache[2] = ($event) => moveSpecifyLocationVisible.value = true)
4843
+ }, {
4844
+ default: (0, vue.withCtx)(() => [..._cache[9] || (_cache[9] = [(0, vue.createTextVNode)("移动至", -1)])]),
4845
+ _: 1
4846
+ }, 8, ["icon", "disabled"])]),
4847
+ default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("div", null, [(0, vue.createElementVNode)("div", null, [
4848
+ _cache[10] || (_cache[10] = (0, vue.createTextVNode)(" 第", -1)),
4849
+ (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicInputNumber), {
4850
+ style: { "margin": "0 5px" },
4851
+ modelValue: moveSpecifyLocationIndex.value,
4852
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => moveSpecifyLocationIndex.value = $event),
4853
+ size: "small",
4854
+ min: 1,
4855
+ disabled: __props.disabled
4856
+ }, null, 8, ["modelValue", "disabled"]),
4857
+ _cache[11] || (_cache[11] = (0, vue.createTextVNode)("行 ", -1))
4858
+ ]), (0, vue.createElementVNode)("div", _hoisted_2$4, [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4859
+ size: "small",
4860
+ text: "",
4861
+ onClick: _cache[4] || (_cache[4] = ($event) => moveSpecifyLocationVisible.value = false)
4862
+ }, {
4863
+ default: (0, vue.withCtx)(() => [..._cache[12] || (_cache[12] = [(0, vue.createTextVNode)("取消", -1)])]),
4864
+ _: 1
4865
+ }), (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
4866
+ size: "small",
4867
+ type: "primary",
4868
+ onClick: moveSpecifyLocationHandler
4869
+ }, {
4870
+ default: (0, vue.withCtx)(() => [..._cache[13] || (_cache[13] = [(0, vue.createTextVNode)("确认", -1)])]),
4871
+ _: 1
4872
+ })])])]),
4873
+ _: 1
4874
+ }, 8, ["visible"])) : (0, vue.createCommentVNode)("v-if", true),
4875
+ itemExtra.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
4876
+ key: 3,
4877
+ innerHTML: itemExtra.value,
4878
+ class: "m-form-tip"
4879
+ }, null, 8, _hoisted_3$3)) : (0, vue.createCommentVNode)("v-if", true)
4880
+ ])]),
4881
+ default: (0, vue.withCtx)(() => [expand.value ? ((0, vue.openBlock)(), (0, vue.createBlock)(Container_default, {
4882
+ key: 0,
4883
+ config: rowConfig.value,
4884
+ model: __props.model,
4885
+ lastValues: __props.lastValues,
4886
+ "is-compare": __props.isCompare,
4887
+ labelWidth: __props.labelWidth,
4888
+ prop: `${__props.prop}${__props.prop ? "." : ""}${String(__props.index)}`,
4889
+ size: __props.size,
4890
+ disabled: __props.disabled,
4891
+ onChange: changeHandler,
4892
+ onAddDiffCount: _cache[5] || (_cache[5] = ($event) => onAddDiffCount())
4893
+ }, null, 8, [
4894
+ "config",
4895
+ "model",
4896
+ "lastValues",
4897
+ "is-compare",
4898
+ "labelWidth",
4899
+ "prop",
4900
+ "size",
4901
+ "disabled"
4902
+ ])) : (0, vue.createCommentVNode)("v-if", true)]),
4903
+ _: 1
4904
+ }, 8, ["body-style"]);
4905
+ };
4906
+ }
4907
+ });
4908
+ //#endregion
4909
+ //#region packages/form/src/containers/GroupList.vue?vue&type=script&setup=true&lang.ts
4910
+ var _hoisted_1$8 = { class: "m-fields-group-list" };
4911
+ var _hoisted_2$3 = ["innerHTML"];
4912
+ var _hoisted_3$2 = {
4913
+ key: 1,
4914
+ class: "el-table__empty-block"
4915
+ };
4916
+ var _hoisted_4$1 = { class: "m-fields-group-list-footer" };
4917
+ var _hoisted_5 = { style: {
4918
+ "display": "flex",
4919
+ "justify-content": "flex-end",
4920
+ "flex": "1"
4921
+ } };
4922
+ //#endregion
4923
+ //#region packages/form/src/containers/GroupList.vue
4924
+ var GroupList_default = /* @__PURE__ */ (0, vue.defineComponent)({
4925
+ name: "MFormGroupList",
4926
+ __name: "GroupList",
4927
+ props: {
4928
+ model: {},
4929
+ lastValues: {},
4930
+ isCompare: { type: Boolean },
4931
+ config: {},
4932
+ name: {},
4933
+ labelWidth: {},
4934
+ prop: {},
4935
+ size: {},
4936
+ disabled: { type: Boolean },
4937
+ showIndex: { type: Boolean }
4938
+ },
4939
+ emits: ["change", "addDiffCount"],
4940
+ setup(__props, { emit: __emit }) {
4941
+ const props = __props;
4942
+ const emit = __emit;
4943
+ const changeHandler = (v, eventData) => {
4944
+ emit("change", props.model, eventData);
4945
+ };
4946
+ const removeHandler = (index) => {
4947
+ if (!props.name) return false;
4948
+ props.model[props.name].splice(index, 1);
4949
+ emit("change", props.model[props.name]);
4950
+ };
4951
+ const copyHandler = (index) => {
4952
+ props.model[props.name].push(cloneDeep(props.model[props.name][index]));
4953
+ };
4954
+ const swapHandler = (idx1, idx2) => {
4955
+ if (!props.name) return false;
4956
+ const { length } = props.model[props.name];
4957
+ const [currRow] = props.model[props.name].splice(idx1, 1);
4958
+ props.model[props.name].splice(Math.min(Math.max(idx2, 0), length - 1), 0, currRow);
4959
+ emit("change", props.model[props.name]);
4960
+ };
4961
+ const onAddDiffCount = () => emit("addDiffCount");
4962
+ const getLastValues = (item, index) => item?.[index] || {};
4963
+ return (_ctx, _cache) => {
4964
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1$8, [
4965
+ __props.config.extra ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
4966
+ key: 0,
4967
+ innerHTML: __props.config.extra,
4968
+ style: { "color": "rgba(0, 0, 0, 0.45)" }
4969
+ }, null, 8, _hoisted_2$3)) : (0, vue.createCommentVNode)("v-if", true),
4970
+ !__props.model[__props.name] || !__props.model[__props.name].length ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_3$2, [..._cache[1] || (_cache[1] = [(0, vue.createElementVNode)("span", { class: "el-table__empty-text t-table__empty" }, "暂无数据", -1)])])) : ((0, vue.openBlock)(true), (0, vue.createElementBlock)(vue.Fragment, { key: 2 }, (0, vue.renderList)(__props.model[__props.name], (item, index) => {
4971
+ return (0, vue.openBlock)(), (0, vue.createBlock)(GroupListItem_default, {
4972
+ key: index,
4973
+ model: item,
4974
+ lastValues: getLastValues(__props.lastValues?.[__props.name], Number(index)),
4975
+ "is-compare": __props.isCompare,
4976
+ config: __props.config,
4977
+ prop: __props.prop,
4978
+ index: Number(index),
4979
+ "label-width": __props.labelWidth,
4980
+ size: __props.size,
4981
+ disabled: __props.disabled,
4982
+ "group-model": __props.model[__props.name],
4983
+ onRemoveItem: removeHandler,
4984
+ onCopyItem: copyHandler,
4985
+ onSwapItem: swapHandler,
4986
+ onChange: changeHandler,
4987
+ onAddDiffCount: _cache[0] || (_cache[0] = ($event) => onAddDiffCount())
4988
+ }, null, 8, [
4989
+ "model",
4990
+ "lastValues",
4991
+ "is-compare",
4992
+ "config",
4993
+ "prop",
4994
+ "index",
4995
+ "label-width",
4996
+ "size",
4997
+ "disabled",
4998
+ "group-model"
4999
+ ]);
5000
+ }), 128)),
5001
+ (0, vue.createElementVNode)("div", _hoisted_4$1, [(0, vue.renderSlot)(_ctx.$slots, "toggle-button"), (0, vue.createElementVNode)("div", _hoisted_5, [(0, vue.renderSlot)(_ctx.$slots, "add-button")])])
5002
+ ]);
5003
+ };
5004
+ }
5005
+ });
5006
+ //#endregion
5007
+ //#region packages/form/src/containers/table/useFullscreen.ts
5008
+ var useFullscreen = () => {
5009
+ const { nextZIndex } = (0, _tmagic_design.useZIndex)();
5010
+ const fullscreenZIndex = (0, vue.ref)(nextZIndex());
5011
+ const isFullscreen = (0, vue.ref)(false);
5012
+ const toggleFullscreen = () => {
5013
+ if (isFullscreen.value) isFullscreen.value = false;
5014
+ else isFullscreen.value = true;
5015
+ };
5016
+ (0, vue.watch)(isFullscreen, (value) => {
5017
+ if (value) fullscreenZIndex.value = nextZIndex();
5018
+ });
5019
+ return {
5020
+ isFullscreen,
5021
+ fullscreenZIndex,
5022
+ toggleFullscreen
5023
+ };
5024
+ };
5025
+ //#endregion
5026
+ //#region packages/form/src/containers/table/useImport.ts
5027
+ var useImport = (props, emit) => {
5028
+ const mForm = (0, vue.inject)("mForm");
5029
+ const modelName = (0, vue.computed)(() => props.name || props.config.name || "");
5030
+ const importable = (0, vue.computed)(() => {
5031
+ if (typeof props.config.importable === "function") return props.config.importable(mForm, {
5032
+ formValue: mForm?.values,
5033
+ model: props.model[modelName.value]
5034
+ });
5035
+ return typeof props.config.importable === "undefined" ? false : props.config.importable;
5036
+ });
5037
+ const excelBtn = (0, vue.useTemplateRef)("excelBtn");
5038
+ const excelHandler = async (file) => {
5039
+ if (!file?.raw) return false;
5040
+ if (!globalThis.XLSX) await (0, _tmagic_utils.asyncLoadJs)("https://cdn.bootcdn.net/ajax/libs/xlsx/0.17.0/xlsx.full.min.js");
5041
+ const reader = new FileReader();
5042
+ reader.onload = () => {
5043
+ const data = reader.result;
5044
+ const pdata = globalThis.XLSX.read(data, { type: "array" });
5045
+ pdata.SheetNames.forEach((sheetName) => {
5046
+ const arr = globalThis.XLSX.utils.sheet_to_json(pdata.Sheets[sheetName], { header: 1 });
5047
+ if (arr?.[0]) emit("add", arr);
5048
+ setTimeout(() => {
5049
+ excelBtn.value?.clearFiles();
5050
+ }, 300);
5051
+ });
5052
+ };
5053
+ reader.readAsArrayBuffer(file.raw);
5054
+ return false;
5055
+ };
5056
+ const clearHandler = () => {
5057
+ emit("change", []);
5058
+ mForm?.$emit("field-change", props.prop, props.model[modelName.value]);
5059
+ };
5060
+ return {
5061
+ importable,
5062
+ excelHandler,
5063
+ clearHandler
5064
+ };
5065
+ };
5066
+ //#endregion
5067
+ //#region packages/form/src/containers/table/usePagination.ts
5068
+ var usePagination = (props, modelName) => {
5069
+ const pageSize = (0, vue.ref)(10);
5070
+ /**
5071
+ * 当前页码
5072
+ */
5073
+ const currentPage = (0, vue.ref)(0);
5074
+ const paginationData = (0, vue.computed)(() => getDataByPage(props.model[modelName.value], currentPage.value, pageSize.value));
5075
+ const handleSizeChange = (val) => {
5076
+ pageSize.value = val;
5077
+ };
5078
+ const handleCurrentChange = (val) => {
5079
+ currentPage.value = val - 1;
5080
+ };
5081
+ return {
5082
+ pageSize,
5083
+ currentPage,
5084
+ paginationData,
5085
+ handleSizeChange,
5086
+ handleCurrentChange
5087
+ };
5088
+ };
5089
+ //#endregion
5090
+ //#region packages/form/src/containers/table/useSelection.ts
5091
+ var useSelection = (props, emit, tMagicTableRef) => {
5092
+ const mForm = (0, vue.inject)("mForm");
5093
+ const selectHandle = (selection, row) => {
5094
+ if (typeof props.config.selection === "string" && props.config.selection === "single") {
5095
+ tMagicTableRef.value?.clearSelection();
5096
+ tMagicTableRef.value?.toggleRowSelection(row, true);
5097
+ }
5098
+ emit("select", selection, row);
5099
+ if (typeof props.config.onSelect === "function") props.config.onSelect(mForm, {
5100
+ selection,
5101
+ row,
5102
+ config: props.config
5103
+ });
5104
+ };
5105
+ const toggleRowSelection = (row, selected) => {
5106
+ tMagicTableRef.value?.toggleRowSelection.call(tMagicTableRef.value?.getTableRef(), row, selected);
5107
+ };
5108
+ return {
5109
+ selectHandle,
5110
+ toggleRowSelection
5111
+ };
5112
+ };
5113
+ //#endregion
5114
+ //#region packages/form/src/containers/table/useSortable.ts
5115
+ var SortablePromise;
5116
+ var loadSortable = () => SortablePromise ??= import("sortablejs").then((m) => m.default);
5117
+ var useSortable = (props, emit, tMagicTableRef, modelName, updateKey) => {
5118
+ const mForm = (0, vue.inject)("mForm");
5119
+ let sortable;
5120
+ const rowDrop = async () => {
5121
+ sortable?.destroy();
5122
+ const tableEl = tMagicTableRef.value?.getEl();
5123
+ const tBodyEl = tableEl?.querySelector(".el-table__body > tbody") || tableEl?.querySelector(".t-table__body");
5124
+ if (!tBodyEl) return;
5125
+ sortable = (await loadSortable()).create(tBodyEl, {
5126
+ draggable: ".tmagic-design-table-row",
5127
+ filter: "input",
5128
+ preventOnFilter: false,
5129
+ direction: "vertical",
5130
+ handle: props.config.dropSortHandle ? ".tmagic-form-table-drag-target" : void 0,
5131
+ onEnd: ({ newIndex, oldIndex }) => {
5132
+ if (typeof newIndex === "undefined") return;
5133
+ if (typeof oldIndex === "undefined") return;
5134
+ const newData = sortArray(props.model[modelName.value], newIndex, oldIndex, props.sortKey);
5135
+ emit("change", newData);
5136
+ mForm?.$emit("field-change", newData);
5137
+ (0, vue.nextTick)(() => {
5138
+ sortable?.destroy();
5139
+ sortable = void 0;
5140
+ updateKey.value += 1;
5141
+ });
5142
+ }
5143
+ });
5144
+ };
5145
+ (0, vue.watchEffect)(() => {
5146
+ if (props.config.dropSort) rowDrop();
5147
+ });
5148
+ };
5149
+ //#endregion
5150
+ //#region packages/form/src/containers/table/ActionsColumn.vue
5151
+ var ActionsColumn_default = /* @__PURE__ */ (0, vue.defineComponent)({
5152
+ __name: "ActionsColumn",
5153
+ props: {
5154
+ config: {},
5155
+ model: {},
5156
+ name: {},
5157
+ disabled: { type: Boolean },
5158
+ currentPage: {},
5159
+ pageSize: {},
5160
+ index: {},
5161
+ row: {},
5162
+ prop: {},
5163
+ sortKey: {}
5164
+ },
5165
+ emits: ["change"],
5166
+ setup(__props, { emit: __emit }) {
5167
+ const emit = __emit;
5168
+ const props = __props;
5169
+ const mForm = (0, vue.inject)("mForm");
5170
+ const removeHandler = (index) => {
5171
+ if (props.disabled) return;
5172
+ emit("change", props.model[props.name].toSpliced(index, 1));
4920
5173
  };
4921
5174
  const copyHandler = (index) => {
4922
5175
  let inputs = cloneDeep(props.model[props.name][index]);
@@ -4996,7 +5249,7 @@
4996
5249
  }
4997
5250
  });
4998
5251
  //#endregion
4999
- //#region packages/form/src/table/SortColumn.vue
5252
+ //#region packages/form/src/containers/table/SortColumn.vue
5000
5253
  var SortColumn_default = /* @__PURE__ */ (0, vue.defineComponent)({
5001
5254
  __name: "SortColumn",
5002
5255
  props: {
@@ -5080,7 +5333,7 @@
5080
5333
  }
5081
5334
  });
5082
5335
  //#endregion
5083
- //#region packages/form/src/table/useTableColumns.ts
5336
+ //#region packages/form/src/containers/table/useTableColumns.ts
5084
5337
  var useTableColumns = (props, emit, currentPage, pageSize, modelName) => {
5085
5338
  const mForm = (0, vue.inject)("mForm");
5086
5339
  const display$1 = (fuc) => display(mForm, fuc, props);
@@ -5197,7 +5450,7 @@
5197
5450
  columns.push({
5198
5451
  props: {
5199
5452
  prop: column.name,
5200
- label: column.label,
5453
+ label: column.label || column.text,
5201
5454
  width: column.width,
5202
5455
  sortable: column.sortable,
5203
5456
  sortOrders: ["ascending", "descending"],
@@ -5221,7 +5474,7 @@
5221
5474
  display: "inline-flex",
5222
5475
  alignItems: "center",
5223
5476
  gap: "5px"
5224
- } }, [(0, vue.h)("span", column.label), (0, vue.h)(_tmagic_design.TMagicIcon, {}, { default: () => (0, vue.h)(_element_plus_icons_vue.WarningFilled) })]),
5477
+ } }, [(0, vue.h)("span", column.label || column.text), (0, vue.h)(_tmagic_design.TMagicIcon, {}, { default: () => (0, vue.h)(_element_plus_icons_vue.WarningFilled) })]),
5225
5478
  content: () => (0, vue.h)("div", { innerHTML: titleTipValue })
5226
5479
  }) : void 0
5227
5480
  });
@@ -5231,21 +5484,21 @@
5231
5484
  }) };
5232
5485
  };
5233
5486
  //#endregion
5234
- //#region packages/form/src/table/Table.vue?vue&type=script&setup=true&lang.ts
5235
- var _hoisted_1$9 = ["innerHTML"];
5236
- var _hoisted_2$4 = { style: {
5487
+ //#region packages/form/src/containers/table/Table.vue?vue&type=script&setup=true&lang.ts
5488
+ var _hoisted_1$7 = ["innerHTML"];
5489
+ var _hoisted_2$2 = { style: {
5237
5490
  "display": "flex",
5238
5491
  "justify-content": "space-between",
5239
5492
  "margin": "10px 0"
5240
5493
  } };
5241
- var _hoisted_3$3 = { style: { "display": "flex" } };
5242
- var _hoisted_4$1 = {
5494
+ var _hoisted_3$1 = { style: { "display": "flex" } };
5495
+ var _hoisted_4 = {
5243
5496
  key: 1,
5244
5497
  class: "bottom",
5245
5498
  style: { "text-align": "right" }
5246
5499
  };
5247
5500
  //#endregion
5248
- //#region packages/form/src/table/Table.vue
5501
+ //#region packages/form/src/containers/table/Table.vue
5249
5502
  var Table_default = /* @__PURE__ */ (0, vue.defineComponent)({
5250
5503
  name: "MFormTable",
5251
5504
  __name: "Table",
@@ -5265,10 +5518,6 @@
5265
5518
  sortKey: { default: "" },
5266
5519
  text: {},
5267
5520
  size: {},
5268
- enableToggleMode: {
5269
- type: Boolean,
5270
- default: true
5271
- },
5272
5521
  showIndex: {
5273
5522
  type: Boolean,
5274
5523
  default: true
@@ -5277,7 +5526,8 @@
5277
5526
  emits: [
5278
5527
  "change",
5279
5528
  "select",
5280
- "addDiffCount"
5529
+ "addDiffCount",
5530
+ "add"
5281
5531
  ],
5282
5532
  setup(__props, { expose: __expose, emit: __emit }) {
5283
5533
  const props = __props;
@@ -5285,36 +5535,13 @@
5285
5535
  const modelName = (0, vue.computed)(() => props.name || props.config.name || "");
5286
5536
  const tMagicTableRef = (0, vue.useTemplateRef)("tMagicTable");
5287
5537
  const { pageSize, currentPage, paginationData, handleSizeChange, handleCurrentChange } = usePagination(props, modelName);
5288
- const { nextZIndex } = (0, _tmagic_design.useZIndex)();
5289
5538
  const updateKey = (0, vue.ref)(1);
5290
- const { addable, newHandler } = useAdd(props, emit);
5291
5539
  const { columns } = useTableColumns(props, emit, currentPage, pageSize, modelName);
5292
5540
  useSortable(props, emit, tMagicTableRef, modelName, updateKey);
5293
- const { isFullscreen, toggleFullscreen } = useFullscreen();
5294
- const { importable, excelHandler, clearHandler } = useImport(props, emit, newHandler);
5541
+ const { isFullscreen, fullscreenZIndex, toggleFullscreen } = useFullscreen();
5542
+ const { importable, excelHandler, clearHandler } = useImport(props, emit);
5295
5543
  const { selectHandle, toggleRowSelection } = useSelection(props, emit, tMagicTableRef);
5296
5544
  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
5545
  const sortChangeHandler = (sortOptions) => {
5319
5546
  const modelName = props.name || props.config.name || "";
5320
5547
  sortChange(props.model[modelName], sortOptions);
@@ -5326,13 +5553,13 @@
5326
5553
  disabled: !(0, vue.unref)(isFullscreen)
5327
5554
  }, [(0, vue.createElementVNode)("div", (0, vue.mergeProps)(_ctx.$attrs, {
5328
5555
  class: ["m-fields-table-wrap", { fixed: (0, vue.unref)(isFullscreen) }],
5329
- style: (0, vue.unref)(isFullscreen) ? `z-index: ${(0, vue.unref)(nextZIndex)()}` : ""
5556
+ style: (0, vue.unref)(isFullscreen) ? `z-index: ${(0, vue.unref)(fullscreenZIndex)}` : ""
5330
5557
  }), [(0, vue.createElementVNode)("div", { class: (0, vue.normalizeClass)(["m-fields-table", { "m-fields-table-item-extra": __props.config.itemExtra }]) }, [
5331
5558
  __props.config.extra ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
5332
5559
  key: 0,
5333
5560
  style: { "color": "rgba(0, 0, 0, 0.45)" },
5334
5561
  innerHTML: __props.config.extra
5335
- }, null, 8, _hoisted_1$9)) : (0, vue.createCommentVNode)("v-if", true),
5562
+ }, null, 8, _hoisted_1$7)) : (0, vue.createCommentVNode)("v-if", true),
5336
5563
  (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicTooltip), {
5337
5564
  content: "拖拽可排序",
5338
5565
  placement: "left-start",
@@ -5362,16 +5589,8 @@
5362
5589
  _: 1
5363
5590
  }, 8, ["disabled"]),
5364
5591
  (0, vue.renderSlot)(_ctx.$slots, "default"),
5365
- (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),
5592
+ (0, vue.createElementVNode)("div", _hoisted_2$2, [(0, vue.createElementVNode)("div", _hoisted_3$1, [
5593
+ !(0, vue.unref)(isFullscreen) ? (0, vue.renderSlot)(_ctx.$slots, "toggle-button", { key: 0 }) : (0, vue.createCommentVNode)("v-if", true),
5375
5594
  __props.config.enableFullscreen !== false ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5376
5595
  key: 1,
5377
5596
  icon: (0, vue.unref)(_element_plus_icons_vue.FullScreen),
@@ -5390,440 +5609,275 @@
5390
5609
  "on-change": (0, vue.unref)(excelHandler),
5391
5610
  "auto-upload": false
5392
5611
  }, {
5393
- default: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5394
- size: "small",
5395
- type: "success",
5396
- disabled: __props.disabled,
5397
- plain: ""
5398
- }, {
5399
- default: (0, vue.withCtx)(() => [..._cache[2] || (_cache[2] = [(0, vue.createTextVNode)("导入EXCEL", -1)])]),
5400
- _: 1
5401
- }, 8, ["disabled"])]),
5402
- _: 1
5403
- }, 8, ["disabled", "on-change"])) : (0, vue.createCommentVNode)("v-if", true),
5404
- (0, vue.unref)(importable) ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5405
- key: 3,
5406
- size: "small",
5407
- type: "warning",
5408
- disabled: __props.disabled,
5409
- plain: "",
5410
- onClick: (0, vue.unref)(clearHandler)
5411
- }, {
5412
- default: (0, vue.withCtx)(() => [..._cache[3] || (_cache[3] = [(0, vue.createTextVNode)("清空", -1)])]),
5413
- _: 1
5414
- }, 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)]),
5428
- __props.config.pagination ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_4$1, [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicPagination), {
5429
- layout: "total, sizes, prev, pager, next, jumper",
5430
- "hide-on-single-page": __props.model[modelName.value].length < (0, vue.unref)(pageSize),
5431
- "current-page": (0, vue.unref)(currentPage) + 1,
5432
- "page-sizes": [
5433
- (0, vue.unref)(pageSize),
5434
- 60,
5435
- 120,
5436
- 300
5437
- ],
5438
- "page-size": (0, vue.unref)(pageSize),
5439
- total: __props.model[modelName.value].length,
5440
- onSizeChange: (0, vue.unref)(handleSizeChange),
5441
- onCurrentChange: (0, vue.unref)(handleCurrentChange)
5442
- }, null, 8, [
5443
- "hide-on-single-page",
5444
- "current-page",
5445
- "page-sizes",
5446
- "page-size",
5447
- "total",
5448
- "onSizeChange",
5449
- "onCurrentChange"
5450
- ])])) : (0, vue.createCommentVNode)("v-if", true)
5451
- ], 2)], 16)], 8, ["disabled"]);
5452
- };
5453
- }
5454
- });
5455
- //#endregion
5456
- //#region packages/form/src/containers/GroupListItem.vue?vue&type=script&setup=true&lang.ts
5457
- var _hoisted_1$8 = ["innerHTML"];
5458
- var _hoisted_2$3 = { style: {
5459
- "text-align": "right",
5460
- "margin-top": "20px"
5461
- } };
5462
- var _hoisted_3$2 = ["innerHTML"];
5463
- //#endregion
5464
- //#region packages/form/src/containers/GroupListItem.vue
5465
- var GroupListItem_default = /* @__PURE__ */ (0, vue.defineComponent)({
5466
- name: "MFormGroupListItem",
5467
- __name: "GroupListItem",
5468
- props: {
5469
- model: {},
5470
- lastValues: {},
5471
- isCompare: { type: Boolean },
5472
- groupModel: {},
5473
- config: {},
5474
- labelWidth: {},
5475
- prop: {},
5476
- size: {},
5477
- index: {},
5478
- disabled: { type: Boolean }
5479
- },
5480
- emits: [
5481
- "swap-item",
5482
- "remove-item",
5483
- "change",
5484
- "addDiffCount",
5485
- "copy-item"
5486
- ],
5487
- setup(__props, { emit: __emit }) {
5488
- const props = __props;
5489
- const emit = __emit;
5490
- const mForm = (0, vue.inject)("mForm");
5491
- const defaultExpandQuantity = props.config.defaultExpandQuantity ?? 7;
5492
- const expand = (0, vue.ref)(props.config.expandAll || defaultExpandQuantity > props.index);
5493
- const rowConfig = (0, vue.computed)(() => ({
5494
- type: "row",
5495
- span: props.config.span || 24,
5496
- items: props.config.items,
5497
- labelWidth: props.config.labelWidth,
5498
- [mForm?.keyProp || "__key"]: `${props.config[mForm?.keyProp || "__key"]}${String(props.index)}`
5499
- }));
5500
- const title = (0, vue.computed)(() => {
5501
- if (props.config.titleKey && props.model[props.config.titleKey]) return props.model[props.config.titleKey];
5502
- if (props.config.title) return filterFunction(mForm, props.config.title, props);
5503
- return `${props.config.titlePrefix || "组"} ${String(props.index + 1)}`;
5504
- });
5505
- const length = (0, vue.computed)(() => props.groupModel?.length || 0);
5506
- const itemExtra = (0, vue.computed)(() => filterFunction(mForm, props.config.itemExtra, props));
5507
- const removeHandler = () => emit("remove-item", props.index);
5508
- const changeHandler = (v, eventData) => {
5509
- emit("change", props.model, eventData);
5510
- };
5511
- const expandHandler = () => {
5512
- expand.value = !expand.value;
5513
- };
5514
- const showDelete = (0, vue.computed)(() => {
5515
- const deleteFunc = props.config.delete;
5516
- if (deleteFunc && typeof deleteFunc === "function") return deleteFunc(props.model, props.index, mForm?.values);
5517
- return true;
5518
- });
5519
- const changeOrder = (offset = 0) => emit("swap-item", props.index, props.index + offset);
5520
- const movable = (0, vue.computed)(() => {
5521
- const { movable } = props.config;
5522
- if (movable === void 0) return true;
5523
- if (typeof movable === "function") return movable(mForm, props.index || 0, props.model, props.groupModel);
5524
- return movable;
5525
- });
5526
- const copyable = (0, vue.computed)(() => filterFunction(mForm, props.config.copyable, props));
5527
- const onAddDiffCount = () => emit("addDiffCount");
5528
- const copyHandler = () => {
5529
- emit("copy-item", props.index);
5530
- };
5531
- const moveSpecifyLocationVisible = (0, vue.ref)(false);
5532
- const moveSpecifyLocationIndex = (0, vue.ref)(1);
5533
- const moveSpecifyLocationHandler = () => {
5534
- moveSpecifyLocationVisible.value = false;
5535
- emit("swap-item", props.index, moveSpecifyLocationIndex.value - 1);
5536
- };
5537
- return (_ctx, _cache) => {
5538
- return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicCard), {
5539
- class: "m-fields-group-list-item",
5540
- "body-style": { display: expand.value ? "block" : "none" }
5541
- }, {
5542
- header: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("div", null, [
5543
- (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5544
- link: "",
5545
- disabled: __props.disabled,
5546
- onClick: expandHandler
5547
- }, {
5548
- default: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicIcon), null, {
5549
- default: (0, vue.withCtx)(() => [expand.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_element_plus_icons_vue.CaretBottom), { key: 0 })) : ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_element_plus_icons_vue.CaretRight), { key: 1 }))]),
5550
- _: 1
5551
- }), (0, vue.createElementVNode)("span", { innerHTML: title.value }, null, 8, _hoisted_1$8)]),
5552
- _: 1
5553
- }, 8, ["disabled"]),
5554
- (0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5555
- type: "danger",
5556
- size: "small",
5557
- link: "",
5558
- icon: (0, vue.unref)(_element_plus_icons_vue.Delete),
5559
- disabled: __props.disabled,
5560
- onClick: removeHandler
5561
- }, null, 8, ["icon", "disabled"]), [[vue.vShow, showDelete.value]]),
5562
- copyable.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5563
- key: 0,
5564
- link: "",
5565
- size: "small",
5566
- type: "primary",
5567
- icon: (0, vue.unref)(_element_plus_icons_vue.DocumentCopy),
5568
- disabled: __props.disabled,
5569
- onClick: copyHandler
5570
- }, {
5571
- default: (0, vue.withCtx)(() => [..._cache[6] || (_cache[6] = [(0, vue.createTextVNode)("复制", -1)])]),
5572
- _: 1
5573
- }, 8, ["icon", "disabled"])) : (0, vue.createCommentVNode)("v-if", true),
5574
- movable.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, { key: 1 }, [(0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5575
- link: "",
5576
- size: "small",
5577
- disabled: __props.disabled,
5578
- icon: (0, vue.unref)(_element_plus_icons_vue.CaretTop),
5579
- onClick: _cache[0] || (_cache[0] = ($event) => changeOrder(-1))
5580
- }, {
5581
- default: (0, vue.withCtx)(() => [..._cache[7] || (_cache[7] = [(0, vue.createTextVNode)("上移", -1)])]),
5582
- _: 1
5583
- }, 8, ["disabled", "icon"]), [[vue.vShow, __props.index !== 0]]), (0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5584
- link: "",
5585
- size: "small",
5586
- disabled: __props.disabled,
5587
- icon: (0, vue.unref)(_element_plus_icons_vue.CaretBottom),
5588
- onClick: _cache[1] || (_cache[1] = ($event) => changeOrder(1))
5589
- }, {
5590
- default: (0, vue.withCtx)(() => [..._cache[8] || (_cache[8] = [(0, vue.createTextVNode)("下移", -1)])]),
5591
- _: 1
5592
- }, 8, ["disabled", "icon"]), [[vue.vShow, __props.index !== length.value - 1]])], 64)) : (0, vue.createCommentVNode)("v-if", true),
5593
- __props.config.moveSpecifyLocation ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicPopover), {
5594
- key: 2,
5595
- trigger: "click",
5596
- placement: "top",
5597
- width: "200",
5598
- visible: moveSpecifyLocationVisible.value
5599
- }, {
5600
- reference: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5601
- link: "",
5602
- size: "small",
5603
- type: "primary",
5604
- icon: (0, vue.unref)(_element_plus_icons_vue.Position),
5605
- disabled: __props.disabled,
5606
- onClick: _cache[2] || (_cache[2] = ($event) => moveSpecifyLocationVisible.value = true)
5607
- }, {
5608
- default: (0, vue.withCtx)(() => [..._cache[9] || (_cache[9] = [(0, vue.createTextVNode)("移动至", -1)])]),
5609
- _: 1
5610
- }, 8, ["icon", "disabled"])]),
5611
- default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("div", null, [(0, vue.createElementVNode)("div", null, [
5612
- _cache[10] || (_cache[10] = (0, vue.createTextVNode)(" 第", -1)),
5613
- (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicInputNumber), {
5614
- style: { "margin": "0 5px" },
5615
- modelValue: moveSpecifyLocationIndex.value,
5616
- "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => moveSpecifyLocationIndex.value = $event),
5617
- size: "small",
5618
- min: 1,
5619
- disabled: __props.disabled
5620
- }, null, 8, ["modelValue", "disabled"]),
5621
- _cache[11] || (_cache[11] = (0, vue.createTextVNode)("行 ", -1))
5622
- ]), (0, vue.createElementVNode)("div", _hoisted_2$3, [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5623
- size: "small",
5624
- text: "",
5625
- onClick: _cache[4] || (_cache[4] = ($event) => moveSpecifyLocationVisible.value = false)
5626
- }, {
5627
- default: (0, vue.withCtx)(() => [..._cache[12] || (_cache[12] = [(0, vue.createTextVNode)("取消", -1)])]),
5628
- _: 1
5629
- }), (0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5612
+ default: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
5630
5613
  size: "small",
5631
- type: "primary",
5632
- onClick: moveSpecifyLocationHandler
5614
+ type: "success",
5615
+ disabled: __props.disabled,
5616
+ plain: ""
5633
5617
  }, {
5634
- default: (0, vue.withCtx)(() => [..._cache[13] || (_cache[13] = [(0, vue.createTextVNode)("确认", -1)])]),
5618
+ default: (0, vue.withCtx)(() => [..._cache[0] || (_cache[0] = [(0, vue.createTextVNode)("导入EXCEL", -1)])]),
5635
5619
  _: 1
5636
- })])])]),
5620
+ }, 8, ["disabled"])]),
5637
5621
  _: 1
5638
- }, 8, ["visible"])) : (0, vue.createCommentVNode)("v-if", true),
5639
- itemExtra.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
5622
+ }, 8, ["disabled", "on-change"])) : (0, vue.createCommentVNode)("v-if", true),
5623
+ (0, vue.unref)(importable) ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5640
5624
  key: 3,
5641
- innerHTML: itemExtra.value,
5642
- class: "m-form-tip"
5643
- }, null, 8, _hoisted_3$2)) : (0, vue.createCommentVNode)("v-if", true)
5644
- ])]),
5645
- default: (0, vue.withCtx)(() => [expand.value ? ((0, vue.openBlock)(), (0, vue.createBlock)(Container_default, {
5646
- key: 0,
5647
- config: rowConfig.value,
5648
- model: __props.model,
5649
- lastValues: __props.lastValues,
5650
- "is-compare": __props.isCompare,
5651
- labelWidth: __props.labelWidth,
5652
- prop: `${__props.prop}${__props.prop ? "." : ""}${String(__props.index)}`,
5653
- size: __props.size,
5654
- disabled: __props.disabled,
5655
- onChange: changeHandler,
5656
- onAddDiffCount: _cache[5] || (_cache[5] = ($event) => onAddDiffCount())
5625
+ size: "small",
5626
+ type: "warning",
5627
+ disabled: __props.disabled,
5628
+ plain: "",
5629
+ onClick: (0, vue.unref)(clearHandler)
5630
+ }, {
5631
+ default: (0, vue.withCtx)(() => [..._cache[1] || (_cache[1] = [(0, vue.createTextVNode)("清空", -1)])]),
5632
+ _: 1
5633
+ }, 8, ["disabled", "onClick"])) : (0, vue.createCommentVNode)("v-if", true)
5634
+ ]), (0, vue.renderSlot)(_ctx.$slots, "add-button")]),
5635
+ __props.config.pagination ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_4, [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicPagination), {
5636
+ layout: "total, sizes, prev, pager, next, jumper",
5637
+ "hide-on-single-page": __props.model[modelName.value].length < (0, vue.unref)(pageSize),
5638
+ "current-page": (0, vue.unref)(currentPage) + 1,
5639
+ "page-sizes": [
5640
+ (0, vue.unref)(pageSize),
5641
+ 60,
5642
+ 120,
5643
+ 300
5644
+ ],
5645
+ "page-size": (0, vue.unref)(pageSize),
5646
+ total: __props.model[modelName.value].length,
5647
+ onSizeChange: (0, vue.unref)(handleSizeChange),
5648
+ onCurrentChange: (0, vue.unref)(handleCurrentChange)
5657
5649
  }, null, 8, [
5658
- "config",
5659
- "model",
5660
- "lastValues",
5661
- "is-compare",
5662
- "labelWidth",
5663
- "prop",
5664
- "size",
5665
- "disabled"
5666
- ])) : (0, vue.createCommentVNode)("v-if", true)]),
5667
- _: 1
5668
- }, 8, ["body-style"]);
5650
+ "hide-on-single-page",
5651
+ "current-page",
5652
+ "page-sizes",
5653
+ "page-size",
5654
+ "total",
5655
+ "onSizeChange",
5656
+ "onCurrentChange"
5657
+ ])])) : (0, vue.createCommentVNode)("v-if", true)
5658
+ ], 2)], 16)], 8, ["disabled"]);
5669
5659
  };
5670
5660
  }
5671
5661
  });
5672
5662
  //#endregion
5673
- //#region packages/form/src/containers/GroupList.vue?vue&type=script&setup=true&lang.ts
5674
- var _hoisted_1$7 = { class: "m-fields-group-list" };
5675
- var _hoisted_2$2 = ["innerHTML"];
5676
- var _hoisted_3$1 = {
5677
- key: 1,
5678
- class: "el-table__empty-block"
5663
+ //#region packages/form/src/containers/table-group-list/useAdd.ts
5664
+ var useAdd = (props, emit) => {
5665
+ const mForm = (0, vue.inject)("mForm");
5666
+ const addable = (0, vue.computed)(() => {
5667
+ const modelName = props.name || props.config.name || "";
5668
+ if (!modelName) return false;
5669
+ if (!props.model[modelName].length) return true;
5670
+ if (typeof props.config.addable === "function") return props.config.addable(mForm, {
5671
+ model: props.model[modelName],
5672
+ formValue: mForm?.values,
5673
+ prop: props.prop,
5674
+ config: props.config
5675
+ });
5676
+ return typeof props.config.addable === "undefined" ? true : props.config.addable;
5677
+ });
5678
+ const newHandler = async (row) => {
5679
+ const modelName = props.name || props.config.name || "";
5680
+ if (props.config.max && props.model[modelName].length >= props.config.max) {
5681
+ _tmagic_design.tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
5682
+ return;
5683
+ }
5684
+ if (typeof props.config.beforeAddRow === "function") {
5685
+ if (!await props.config.beforeAddRow(mForm, {
5686
+ model: props.model[modelName],
5687
+ formValue: mForm?.values,
5688
+ prop: props.prop
5689
+ })) return;
5690
+ }
5691
+ const columns = props.config.items;
5692
+ const enumValues = props.config.enum || [];
5693
+ let enumV = [];
5694
+ const { length } = props.model[modelName];
5695
+ const key = props.config.key || "id";
5696
+ let inputs = {};
5697
+ if (enumValues.length) {
5698
+ if (length >= enumValues.length) return;
5699
+ enumV = enumValues.filter((item) => {
5700
+ let i = 0;
5701
+ for (; i < length; i++) if (item[key] === props.model[modelName][i][key]) break;
5702
+ return i === length;
5703
+ });
5704
+ if (enumV.length > 0) inputs = enumV[0];
5705
+ } else if (Array.isArray(row)) columns.forEach((column, index) => {
5706
+ column.name && (inputs[column.name] = row[index]);
5707
+ });
5708
+ else {
5709
+ if (typeof props.config.defaultAdd === "function") inputs = await props.config.defaultAdd(mForm, {
5710
+ model: props.model[modelName],
5711
+ prop: props.prop,
5712
+ formValue: mForm?.values
5713
+ });
5714
+ else if (props.config.defaultAdd) inputs = props.config.defaultAdd;
5715
+ inputs = await initValue(mForm, {
5716
+ config: columns,
5717
+ initValues: inputs
5718
+ });
5719
+ }
5720
+ if (props.sortKey && length) inputs[props.sortKey] = props.model[modelName][length - 1][props.sortKey] - 1;
5721
+ emit("change", [...props.model[modelName], inputs], { changeRecords: [{
5722
+ propPath: `${props.prop}.${props.model[modelName].length}`,
5723
+ value: inputs
5724
+ }] });
5725
+ };
5726
+ return {
5727
+ addable,
5728
+ newHandler
5729
+ };
5679
5730
  };
5680
- var _hoisted_4 = { class: "m-fields-group-list-footer" };
5681
- var _hoisted_5 = { style: {
5682
- "display": "flex",
5683
- "justify-content": "flex-end",
5684
- "flex": "1"
5685
- } };
5686
5731
  //#endregion
5687
- //#region packages/form/src/containers/GroupList.vue
5688
- var GroupList_default = /* @__PURE__ */ (0, vue.defineComponent)({
5689
- name: "MFormGroupList",
5690
- __name: "GroupList",
5732
+ //#region packages/form/src/containers/table-group-list/TableGroupList.vue
5733
+ var TableGroupList_default = /* @__PURE__ */ (0, vue.defineComponent)({
5734
+ name: "MFormTableGroupList",
5735
+ inheritAttrs: false,
5736
+ __name: "TableGroupList",
5691
5737
  props: {
5692
5738
  model: {},
5693
5739
  lastValues: {},
5694
5740
  isCompare: { type: Boolean },
5695
5741
  config: {},
5696
5742
  name: {},
5697
- labelWidth: {},
5698
5743
  prop: {},
5744
+ labelWidth: {},
5745
+ disabled: { type: Boolean },
5699
5746
  size: {},
5700
- disabled: { type: Boolean }
5747
+ enableToggleMode: { type: Boolean },
5748
+ showIndex: { type: Boolean },
5749
+ sortKey: {},
5750
+ sort: { type: Boolean }
5701
5751
  },
5702
- emits: ["change", "addDiffCount"],
5703
- setup(__props, { emit: __emit }) {
5752
+ emits: [
5753
+ "change",
5754
+ "select",
5755
+ "addDiffCount"
5756
+ ],
5757
+ setup(__props, { expose: __expose, emit: __emit }) {
5704
5758
  const props = __props;
5705
5759
  const emit = __emit;
5706
- 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;
5760
+ const { addable, newHandler } = useAdd(props, emit);
5761
+ const isGroupListType = (type) => type === "groupList" || type === "group-list";
5762
+ const displayMode = (0, vue.ref)(isGroupListType(props.config.type) ? "groupList" : "table");
5763
+ const calcLabelWidth = (label) => {
5764
+ if (!label) return "0px";
5765
+ const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
5766
+ const chLength = label.length - zhLength;
5767
+ return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
5768
+ };
5769
+ const tableConfig = (0, vue.computed)(() => {
5770
+ if (!isGroupListType(props.config.type)) return props.config;
5771
+ const source = props.config;
5772
+ return {
5773
+ ...props.config,
5774
+ type: "table",
5775
+ groupItems: source.items,
5776
+ items: source.tableItems || source.items.map((item) => ({
5777
+ ...item,
5778
+ label: item.label || item.text,
5779
+ text: null
5780
+ }))
5781
+ };
5716
5782
  });
5717
- const changeHandler = (v, eventData) => {
5718
- emit("change", props.model, eventData);
5783
+ const groupListConfig = (0, vue.computed)(() => {
5784
+ if (isGroupListType(props.config.type)) return props.config;
5785
+ const source = props.config;
5786
+ return {
5787
+ ...props.config,
5788
+ type: "groupList",
5789
+ tableItems: source.items,
5790
+ items: source.groupItems || source.items.map((item) => {
5791
+ const text = item.text || item.label;
5792
+ return {
5793
+ ...item,
5794
+ text,
5795
+ labelWidth: calcLabelWidth(text),
5796
+ span: item.span || 12
5797
+ };
5798
+ })
5799
+ };
5800
+ });
5801
+ const currentConfig = (0, vue.computed)(() => displayMode.value === "table" ? tableConfig.value : groupListConfig.value);
5802
+ const addButtonSize = (0, vue.computed)(() => {
5803
+ if (displayMode.value === "table") return "small";
5804
+ return props.config.enableToggleMode !== false ? "small" : "default";
5805
+ });
5806
+ const toggleDisplayMode = () => {
5807
+ displayMode.value = displayMode.value === "table" ? "groupList" : "table";
5719
5808
  };
5720
- const addHandler = async () => {
5721
- if (!props.name) return false;
5722
- let initValues = {};
5723
- if (typeof props.config.defaultAdd === "function") initValues = await props.config.defaultAdd(mForm, {
5724
- model: props.model[props.name],
5725
- formValue: mForm?.values,
5726
- prop: props.prop,
5727
- config: props.config
5728
- });
5729
- else if (props.config.defaultAdd) initValues = props.config.defaultAdd;
5730
- const groupValue = await initValue(mForm, {
5731
- config: props.config.items,
5732
- initValues
5809
+ const onChange = (v, eventData) => emit("change", v, eventData);
5810
+ const onSelect = (...args) => emit("select", ...args);
5811
+ const onAddDiffCount = () => emit("addDiffCount");
5812
+ const onAdd = (rows) => {
5813
+ rows.forEach((row) => {
5814
+ newHandler(row);
5733
5815
  });
5734
- props.model[props.name].push(groupValue);
5735
- emit("change", props.model[props.name], { changeRecords: [{
5736
- propPath: `${props.prop}.${props.model[props.name].length - 1}`,
5737
- value: groupValue
5738
- }] });
5739
- };
5740
- const removeHandler = (index) => {
5741
- if (!props.name) return false;
5742
- props.model[props.name].splice(index, 1);
5743
- emit("change", props.model[props.name]);
5744
- };
5745
- const copyHandler = (index) => {
5746
- props.model[props.name].push(cloneDeep(props.model[props.name][index]));
5747
- };
5748
- const swapHandler = (idx1, idx2) => {
5749
- if (!props.name) return false;
5750
- const { length } = props.model[props.name];
5751
- const [currRow] = props.model[props.name].splice(idx1, 1);
5752
- props.model[props.name].splice(Math.min(Math.max(idx2, 0), length - 1), 0, currRow);
5753
- emit("change", props.model[props.name]);
5754
- };
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
5816
  };
5764
- const onAddDiffCount = () => emit("addDiffCount");
5765
- const getLastValues = (item, index) => item?.[index] || {};
5817
+ const tableGroupListRef = (0, vue.useTemplateRef)("tableGroupList");
5818
+ __expose({ toggleRowSelection: (row, selected) => tableGroupListRef.value?.toggleRowSelection?.(row, selected) });
5766
5819
  return (_ctx, _cache) => {
5767
- return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1$7, [
5768
- __props.config.extra ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
5769
- key: 0,
5770
- innerHTML: __props.config.extra,
5771
- style: { "color": "rgba(0, 0, 0, 0.45)" }
5772
- }, null, 8, _hoisted_2$2)) : (0, vue.createCommentVNode)("v-if", true),
5773
- !__props.model[__props.name] || !__props.model[__props.name].length ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_3$1, [..._cache[1] || (_cache[1] = [(0, vue.createElementVNode)("span", { class: "el-table__empty-text t-table__empty" }, "暂无数据", -1)])])) : ((0, vue.openBlock)(true), (0, vue.createElementBlock)(vue.Fragment, { key: 2 }, (0, vue.renderList)(__props.model[__props.name], (item, index) => {
5774
- return (0, vue.openBlock)(), (0, vue.createBlock)(GroupListItem_default, {
5775
- key: index,
5776
- model: item,
5777
- lastValues: getLastValues(__props.lastValues[__props.name], Number(index)),
5778
- "is-compare": __props.isCompare,
5779
- config: __props.config,
5780
- prop: __props.prop,
5781
- index: Number(index),
5782
- "label-width": __props.labelWidth,
5783
- size: __props.size,
5784
- disabled: __props.disabled,
5785
- "group-model": __props.model[__props.name],
5786
- onRemoveItem: removeHandler,
5787
- onCopyItem: copyHandler,
5788
- onSwapItem: swapHandler,
5789
- onChange: changeHandler,
5790
- onAddDiffCount: _cache[0] || (_cache[0] = ($event) => onAddDiffCount())
5791
- }, null, 8, [
5792
- "model",
5793
- "lastValues",
5794
- "is-compare",
5795
- "config",
5796
- "prop",
5797
- "index",
5798
- "label-width",
5799
- "size",
5800
- "disabled",
5801
- "group-model"
5802
- ]);
5803
- }), 128)),
5804
- (0, vue.createElementVNode)("div", _hoisted_4, [__props.config.enableToggleMode ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5820
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(displayMode.value === "table" ? Table_default : GroupList_default), (0, vue.mergeProps)({ ref: "tableGroupList" }, _ctx.$attrs, {
5821
+ model: __props.model,
5822
+ name: `${__props.name}`,
5823
+ config: currentConfig.value,
5824
+ disabled: __props.disabled,
5825
+ size: __props.size,
5826
+ "is-compare": __props.isCompare,
5827
+ "last-values": __props.lastValues,
5828
+ prop: __props.prop,
5829
+ "label-width": __props.labelWidth,
5830
+ "show-index": __props.showIndex,
5831
+ "sort-key": __props.sortKey,
5832
+ sort: __props.sort,
5833
+ onChange,
5834
+ onSelect,
5835
+ onAddDiffCount,
5836
+ onAdd
5837
+ }), (0, vue.createSlots)({
5838
+ "toggle-button": (0, vue.withCtx)(() => [__props.config.enableToggleMode || __props.enableToggleMode ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicButton), {
5805
5839
  key: 0,
5806
5840
  icon: (0, vue.unref)(_element_plus_icons_vue.Grid),
5807
5841
  size: "small",
5808
- onClick: toggleMode
5842
+ onClick: toggleDisplayMode
5809
5843
  }, {
5810
- default: (0, vue.withCtx)(() => [..._cache[2] || (_cache[2] = [(0, vue.createTextVNode)("切换为表格", -1)])]),
5844
+ default: (0, vue.withCtx)(() => [(0, vue.createTextVNode)((0, vue.toDisplayString)(displayMode.value === "table" ? "展开配置" : "切换为表格"), 1)]),
5811
5845
  _: 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)({
5813
- 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)]),
5846
+ }, 8, ["icon"])) : (0, vue.createCommentVNode)("v-if", true)]),
5847
+ _: 2
5848
+ }, [(0, vue.unref)(addable) ? {
5849
+ name: "add-button",
5850
+ fn: (0, vue.withCtx)(() => [(0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), (0, vue.mergeProps)({
5851
+ class: displayMode.value === "table" ? "m-form-table-add-button" : "",
5852
+ size: addButtonSize.value,
5853
+ plain: displayMode.value === "table",
5854
+ icon: (0, vue.unref)(_element_plus_icons_vue.Plus),
5855
+ disabled: __props.disabled
5856
+ }, currentConfig.value.addButtonConfig?.props || { type: "primary" }, { onClick: (0, vue.unref)(newHandler) }), {
5857
+ default: (0, vue.withCtx)(() => [(0, vue.createTextVNode)((0, vue.toDisplayString)(currentConfig.value.addButtonConfig?.text || (displayMode.value === "table" ? "新增一行" : "新增")), 1)]),
5821
5858
  _: 1
5822
5859
  }, 16, [
5860
+ "class",
5823
5861
  "size",
5862
+ "plain",
5824
5863
  "icon",
5825
- "disabled"
5826
- ])) : (0, vue.createCommentVNode)("v-if", true)])])
5864
+ "disabled",
5865
+ "onClick"
5866
+ ])]),
5867
+ key: "0"
5868
+ } : void 0]), 1040, [
5869
+ "model",
5870
+ "name",
5871
+ "config",
5872
+ "disabled",
5873
+ "size",
5874
+ "is-compare",
5875
+ "last-values",
5876
+ "prop",
5877
+ "label-width",
5878
+ "show-index",
5879
+ "sort-key",
5880
+ "sort"
5827
5881
  ]);
5828
5882
  };
5829
5883
  }
@@ -7607,11 +7661,11 @@
7607
7661
  app.component("m-form-dialog", FormDialog_default);
7608
7662
  app.component("m-form-container", Container_default);
7609
7663
  app.component("m-form-fieldset", Fieldset_default);
7610
- app.component("m-form-group-list", GroupList_default);
7664
+ app.component("m-form-group-list", TableGroupList_default);
7611
7665
  app.component("m-form-panel", Panel_default);
7612
7666
  app.component("m-form-row", Row_default);
7613
7667
  app.component("m-form-step", Step_default);
7614
- app.component("m-form-table", Table_default);
7668
+ app.component("m-form-table", TableGroupList_default);
7615
7669
  app.component("m-form-tab", Tabs_default);
7616
7670
  app.component("m-form-flex-layout", FlexLayout_default);
7617
7671
  app.component("m-fields-text", Text_default);
@@ -7654,7 +7708,7 @@
7654
7708
  exports.MFormBox = FormBox_default;
7655
7709
  exports.MFormDialog = FormDialog_default;
7656
7710
  exports.MFormDrawer = FormDrawer_default;
7657
- exports.MGroupList = GroupList_default;
7711
+ exports.MGroupList = TableGroupList_default;
7658
7712
  exports.MHidden = Hidden_default;
7659
7713
  exports.MLink = Link_default;
7660
7714
  exports.MNumber = Number_default;
@@ -7664,7 +7718,8 @@
7664
7718
  exports.MRow = Row_default;
7665
7719
  exports.MSelect = Select_default;
7666
7720
  exports.MSwitch = Switch_default;
7667
- exports.MTable = Table_default;
7721
+ exports.MTable = TableGroupList_default;
7722
+ exports.MTableGroupList = TableGroupList_default;
7668
7723
  exports.MTabs = Tabs_default;
7669
7724
  exports.MText = Text_default;
7670
7725
  exports.MTextarea = Textarea_default;