@qin-ui/antd-vue-pro 1.1.25 → 2.0.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.
package/es/table/index.js CHANGED
@@ -1,149 +1,79 @@
1
- import { createVNode, defineComponent, ref, onMounted, computed, openBlock, createBlock, unref, mergeProps, withCtx, createTextVNode, toDisplayString, normalizeStyle, createCommentVNode, mergeModels, useModel, watch, createElementVNode, createElementBlock, Fragment, renderList, withModifiers, renderSlot, useAttrs, useSlots, toValue, createSlots, normalizeProps, guardReactiveProps, nextTick } from "vue";
1
+ import { createElementBlock, openBlock, createElementVNode, defineComponent, ref, computed, watch, watchEffect, createBlock, unref, mergeProps, withCtx, createVNode, createCommentVNode, createTextVNode, toDisplayString, normalizeStyle, toValue, renderSlot, useAttrs, Fragment, renderList, withModifiers, inject, useSlots, onMounted, normalizeClass, isRef, createSlots, normalizeProps, guardReactiveProps, nextTick, reactive } from "vue";
2
+ import { I as INJECT_CONFIG, g as getObject } from "../component-provider/index-DtsWFG3s.js";
3
+ import _sfc_main$9, { ContainerFragment as _sfc_main$a, useForm } from "../form/index.js";
2
4
  import { Space, Button, Dropdown, Menu, MenuItem, Checkbox, MenuDivider, Table } from "ant-design-vue";
3
- import { useInjectProps, INJECT_KEYS } from "../component-provider/index.js";
4
- import { A as AntdIcon, _ as _sfc_main$6, g as get, a as _export_sfc, o as omit, b as _sfc_main$7, c as cloneDeep, u as useForm } from "../form/index-1cdda7ac.js";
5
- var ColumnHeightOutlined$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M840 836H184c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h656c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm0-724H184c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h656c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zM610.8 378c6 0 9.4-7 5.7-11.7L515.7 238.7a7.14 7.14 0 00-11.3 0L403.6 366.3a7.23 7.23 0 005.7 11.7H476v268h-62.8c-6 0-9.4 7-5.7 11.7l100.8 127.5c2.9 3.7 8.5 3.7 11.3 0l100.8-127.5c3.7-4.7.4-11.7-5.7-11.7H548V378h62.8z" } }] }, "name": "column-height", "theme": "outlined" };
6
- const ColumnHeightOutlinedSvg = ColumnHeightOutlined$2;
7
- function _objectSpread$2(target) {
8
- for (var i = 1; i < arguments.length; i++) {
9
- var source = arguments[i] != null ? Object(arguments[i]) : {};
10
- var ownKeys = Object.keys(source);
11
- if (typeof Object.getOwnPropertySymbols === "function") {
12
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
13
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
14
- }));
15
- }
16
- ownKeys.forEach(function(key) {
17
- _defineProperty$2(target, key, source[key]);
18
- });
5
+ import { p as pick, c as cloneDeep } from "../vendor/utils/lodash-es-Bu1KKNMo.js";
6
+ import { tableProps } from "ant-design-vue/es/table";
7
+ const _export_sfc = (sfc, props) => {
8
+ const target = sfc.__vccOpts || sfc;
9
+ for (const [key, val] of props) {
10
+ target[key] = val;
19
11
  }
20
12
  return target;
21
- }
22
- function _defineProperty$2(obj, key, value) {
23
- if (key in obj) {
24
- Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
25
- } else {
26
- obj[key] = value;
27
- }
28
- return obj;
29
- }
30
- var ColumnHeightOutlined = function ColumnHeightOutlined2(props, context) {
31
- var p = _objectSpread$2({}, props, context.attrs);
32
- return createVNode(AntdIcon, _objectSpread$2({}, p, {
33
- "icon": ColumnHeightOutlinedSvg
34
- }), null);
35
13
  };
36
- ColumnHeightOutlined.displayName = "ColumnHeightOutlined";
37
- ColumnHeightOutlined.inheritAttrs = false;
38
- const ColumnHeightOutlined$1 = ColumnHeightOutlined;
39
- var DownOutlined$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z" } }] }, "name": "down", "theme": "outlined" };
40
- const DownOutlinedSvg = DownOutlined$2;
41
- function _objectSpread$1(target) {
42
- for (var i = 1; i < arguments.length; i++) {
43
- var source = arguments[i] != null ? Object(arguments[i]) : {};
44
- var ownKeys = Object.keys(source);
45
- if (typeof Object.getOwnPropertySymbols === "function") {
46
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
47
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
48
- }));
49
- }
50
- ownKeys.forEach(function(key) {
51
- _defineProperty$1(target, key, source[key]);
52
- });
53
- }
54
- return target;
55
- }
56
- function _defineProperty$1(obj, key, value) {
57
- if (key in obj) {
58
- Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
59
- } else {
60
- obj[key] = value;
61
- }
62
- return obj;
63
- }
64
- var DownOutlined = function DownOutlined2(props, context) {
65
- var p = _objectSpread$1({}, props, context.attrs);
66
- return createVNode(AntdIcon, _objectSpread$1({}, p, {
67
- "icon": DownOutlinedSvg
68
- }), null);
14
+ const _sfc_main$8 = {};
15
+ const _hoisted_1$7 = {
16
+ focusable: "false",
17
+ "data-icon": "down",
18
+ width: "1em",
19
+ height: "1em",
20
+ fill: "currentColor",
21
+ "aria-hidden": "true",
22
+ viewBox: "64 64 896 896"
69
23
  };
70
- DownOutlined.displayName = "DownOutlined";
71
- DownOutlined.inheritAttrs = false;
72
- const DownOutlined$1 = DownOutlined;
73
- var FilterOutlined$2 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M880.1 154H143.9c-24.5 0-39.8 26.7-27.5 48L349 597.4V838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3 31.8-32V597.4L907.7 202c12.2-21.3-3.1-48-27.6-48zM603.4 798H420.6V642h182.9v156zm9.6-236.6l-9.5 16.6h-183l-9.5-16.6L212.7 226h598.6L613 561.4z" } }] }, "name": "filter", "theme": "outlined" };
74
- const FilterOutlinedSvg = FilterOutlined$2;
75
- function _objectSpread(target) {
76
- for (var i = 1; i < arguments.length; i++) {
77
- var source = arguments[i] != null ? Object(arguments[i]) : {};
78
- var ownKeys = Object.keys(source);
79
- if (typeof Object.getOwnPropertySymbols === "function") {
80
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
81
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
82
- }));
83
- }
84
- ownKeys.forEach(function(key) {
85
- _defineProperty(target, key, source[key]);
86
- });
87
- }
88
- return target;
89
- }
90
- function _defineProperty(obj, key, value) {
91
- if (key in obj) {
92
- Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
93
- } else {
94
- obj[key] = value;
95
- }
96
- return obj;
24
+ function _sfc_render$4(_ctx, _cache) {
25
+ return openBlock(), createElementBlock("svg", _hoisted_1$7, _cache[0] || (_cache[0] = [
26
+ createElementVNode("path", { d: "M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z" }, null, -1)
27
+ ]));
97
28
  }
98
- var FilterOutlined = function FilterOutlined2(props, context) {
99
- var p = _objectSpread({}, props, context.attrs);
100
- return createVNode(AntdIcon, _objectSpread({}, p, {
101
- "icon": FilterOutlinedSvg
102
- }), null);
103
- };
104
- FilterOutlined.displayName = "FilterOutlined";
105
- FilterOutlined.inheritAttrs = false;
106
- const FilterOutlined$1 = FilterOutlined;
107
- const rowGap = 16;
108
- const columnGap = 24;
109
- const _sfc_main$5 = /* @__PURE__ */ defineComponent({
110
- ...{
111
- name: "SearchForm",
112
- inheritAttrs: false
113
- },
29
+ const DownOutlined = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$4]]);
30
+ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
31
+ ...{ name: "SearchForm" },
114
32
  __name: "SearchForm",
115
33
  props: {
116
34
  form: {},
117
35
  layout: { default: "grid" },
118
- minExpandRows: { default: 1 },
119
- defaultExpandStatus: { type: Boolean, default: false }
36
+ expand: { type: [Boolean, Object], default: true },
37
+ class: {},
38
+ style: {}
120
39
  },
121
40
  emits: ["search", "reset"],
122
41
  setup(__props, { emit: __emit }) {
123
42
  const props = __props;
124
43
  const emit = __emit;
125
- let proFormHeight = "unset";
126
- let collapseHeight = 0;
44
+ const proFormHeight = ref("unset");
45
+ const collapseHeight = ref(0);
46
+ let rowHeight = 32;
47
+ const rowGap = 16;
48
+ const columnGap = 24;
49
+ const computedExpand = computed(() => {
50
+ if (!props.expand) return false;
51
+ if (props.expand === true) return { minExpandRows: 2, expandStatus: false };
52
+ return {
53
+ minExpandRows: Math.max(Math.floor(props.expand.minExpandRows ?? 2), 1),
54
+ expandStatus: props.expand.expandStatus ?? false
55
+ };
56
+ });
127
57
  const showExpandToggle = ref(false);
128
- const proFormRef = ref();
129
58
  const expandStatus = ref(true);
130
- const expand = () => {
59
+ const changeExpandStatus = () => {
131
60
  expandStatus.value = !expandStatus.value;
132
61
  };
62
+ const { formRef, getFormData } = props.form;
133
63
  const setInitExpandStatus = () => {
134
64
  expandStatus.value = false;
135
- if (proFormRef.value) {
136
- const formEl = proFormRef.value.$el;
65
+ if (formRef.value && props.expand) {
66
+ const formEl = formRef.value.$el;
137
67
  const formItemsEl = formEl.querySelectorAll(".ant-form-item>[path]");
138
68
  const observer = new IntersectionObserver(
139
69
  (entries) => {
140
70
  expandStatus.value = entries.some((e) => {
141
71
  if (e.intersectionRatio === 0) {
142
72
  const path = e.target.getAttribute("path");
143
- const searchFieldValue = path ? get(props.form.formData.value, path) : void 0;
73
+ const searchFieldValue = path ? getFormData == null ? void 0 : getFormData(path) : void 0;
144
74
  return ![null, void 0].includes(searchFieldValue);
145
75
  }
146
- return props.defaultExpandStatus;
76
+ return props.expand.expandStatus;
147
77
  });
148
78
  observer.disconnect();
149
79
  },
@@ -154,20 +84,43 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
154
84
  });
155
85
  }
156
86
  };
157
- onMounted(() => {
158
- var _a, _b, _c, _d, _e;
159
- if (props.layout === "grid") {
160
- const proFormEl = (_a = proFormRef.value) == null ? void 0 : _a.$el;
87
+ watch(
88
+ [
89
+ () => {
90
+ var _a, _b, _c;
91
+ return (_c = (_b = (_a = props.form) == null ? void 0 : _a.fields.value) == null ? void 0 : _b.filter((f) => !f.hidden)) == null ? void 0 : _c.length;
92
+ },
93
+ () => formRef.value
94
+ ],
95
+ () => {
96
+ var _a, _b, _c, _d, _e;
97
+ if (!expandStatus.value || !formRef.value) return;
98
+ const proFormEl = (_a = formRef.value) == null ? void 0 : _a.$el;
161
99
  const { height = 0 } = ((_b = proFormEl == null ? void 0 : proFormEl.getBoundingClientRect) == null ? void 0 : _b.call(proFormEl)) || {};
162
- proFormHeight = height;
163
- const rowHeight = (_e = (_d = (_c = proFormEl.querySelector(".ant-form-item")) == null ? void 0 : _c.getBoundingClientRect) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.height;
164
- collapseHeight = props.minExpandRows * rowHeight + (props.minExpandRows - 1) * rowGap;
165
- showExpandToggle.value = height > collapseHeight;
166
- if (showExpandToggle.value) {
167
- setInitExpandStatus();
100
+ proFormHeight.value = height;
101
+ rowHeight = (_e = (_d = (_c = proFormEl == null ? void 0 : proFormEl.querySelector(".ant-form-item")) == null ? void 0 : _c.getBoundingClientRect) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.height;
102
+ },
103
+ { flush: "post", immediate: true }
104
+ );
105
+ watchEffect(
106
+ () => {
107
+ if (typeof proFormHeight.value !== "number") return;
108
+ if (props.layout === "grid" && computedExpand.value) {
109
+ const { minExpandRows } = computedExpand.value;
110
+ collapseHeight.value = Math.min(
111
+ minExpandRows * rowHeight + (minExpandRows - 1) * rowGap,
112
+ +proFormHeight.value
113
+ );
114
+ showExpandToggle.value = +proFormHeight.value > collapseHeight.value;
115
+ if (showExpandToggle.value) {
116
+ setInitExpandStatus();
117
+ }
118
+ } else {
119
+ showExpandToggle.value = false;
168
120
  }
169
- }
170
- });
121
+ },
122
+ { flush: "post" }
123
+ );
171
124
  const layoutProps = computed(
172
125
  () => props.layout === "grid" ? {
173
126
  grid: {
@@ -177,19 +130,19 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
177
130
  style: {
178
131
  display: "flex",
179
132
  overflow: "hidden",
180
- height: `${expandStatus.value ? proFormHeight : collapseHeight}px`
133
+ height: `${expandStatus.value ? proFormHeight.value : collapseHeight.value}px`
181
134
  }
182
135
  } : {
183
136
  layout: "inline",
184
- style: { gap: `${rowGap}px ${columnGap}px` }
137
+ style: { gap: `${rowGap}px ${columnGap}px` },
138
+ grid: false
185
139
  }
186
140
  );
187
141
  return (_ctx, _cache) => {
188
- return openBlock(), createBlock(unref(_sfc_main$6), mergeProps({
189
- ref_key: "proFormRef",
190
- ref: proFormRef,
191
- form: _ctx.form
192
- }, layoutProps.value, { class: "pro-form expand-transition" }), {
142
+ return openBlock(), createBlock(unref(_sfc_main$9), mergeProps(layoutProps.value, {
143
+ form: _ctx.form,
144
+ class: "search-form transition"
145
+ }), {
193
146
  default: withCtx(() => [
194
147
  createVNode(unref(Space), { align: "start" }, {
195
148
  default: withCtx(() => [
@@ -197,9 +150,10 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
197
150
  onClick: _cache[0] || (_cache[0] = ($event) => emit("reset"))
198
151
  }, {
199
152
  default: withCtx(() => _cache[2] || (_cache[2] = [
200
- createTextVNode("重置")
153
+ createTextVNode("重置", -1)
201
154
  ])),
202
- _: 1
155
+ _: 1,
156
+ __: [2]
203
157
  }),
204
158
  createVNode(unref(Button), {
205
159
  type: "primary",
@@ -207,20 +161,22 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
207
161
  onClick: _cache[1] || (_cache[1] = ($event) => emit("search"))
208
162
  }, {
209
163
  default: withCtx(() => _cache[3] || (_cache[3] = [
210
- createTextVNode(" 查询 ")
164
+ createTextVNode(" 查询 ", -1)
211
165
  ])),
212
- _: 1
166
+ _: 1,
167
+ __: [3]
213
168
  }),
214
169
  showExpandToggle.value ? (openBlock(), createBlock(unref(Button), {
215
170
  key: 0,
216
171
  type: "link",
217
- onClick: expand
172
+ class: "expand-toggle-button",
173
+ onClick: changeExpandStatus
218
174
  }, {
219
175
  default: withCtx(() => [
220
176
  createTextVNode(toDisplayString(expandStatus.value ? "收起" : "展开") + " ", 1),
221
- createVNode(unref(DownOutlined$1), {
222
- class: "expand-transition",
223
- style: normalizeStyle({ transform: `rotate(${expandStatus.value ? -180 : 0}deg)` })
177
+ createVNode(DownOutlined, {
178
+ class: "transition",
179
+ style: normalizeStyle([{ "margin-left": "4px" }, { transform: `rotate(${expandStatus.value ? -180 : 0}deg)` }])
224
180
  }, null, 8, ["style"])
225
181
  ]),
226
182
  _: 1
@@ -234,64 +190,157 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
234
190
  };
235
191
  }
236
192
  });
237
- const SearchForm_vue_vue_type_style_index_0_scoped_0ed9c0b6_lang = "";
238
- const SearchForm = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-0ed9c0b6"]]);
239
- const _sfc_main$4 = /* @__PURE__ */ defineComponent({
240
- __name: "Control",
241
- props: /* @__PURE__ */ mergeModels({
242
- columns: {},
243
- table: { default: void 0 }
244
- }, {
245
- "size": { default: "large" },
246
- "sizeModifiers": {}
247
- }),
248
- emits: ["update:size"],
193
+ const SearchForm = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-107a0198"]]);
194
+ function useModel(props, name, options) {
195
+ const eventName = `onUpdate:${name}`;
196
+ const emitUpdate = props[eventName];
197
+ const _modelValue = ref(toValue(options == null ? void 0 : options.default));
198
+ const modelValue = computed({
199
+ get: () => props[name] === void 0 ? _modelValue.value : props[name],
200
+ set: (val) => {
201
+ _modelValue.value = val;
202
+ emitUpdate == null ? void 0 : emitUpdate(val);
203
+ }
204
+ });
205
+ return modelValue;
206
+ }
207
+ const _sfc_main$6 = {};
208
+ const _hoisted_1$6 = { class: "search-form-container" };
209
+ function _sfc_render$3(_ctx, _cache) {
210
+ return openBlock(), createElementBlock("div", _hoisted_1$6, [
211
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
212
+ ]);
213
+ }
214
+ const DefaultSearchFormContainer = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$3], ["__scopeId", "data-v-5904d9f4"]]);
215
+ const _sfc_main$5 = {};
216
+ const _hoisted_1$5 = { class: "table-container" };
217
+ function _sfc_render$2(_ctx, _cache) {
218
+ return openBlock(), createElementBlock("div", _hoisted_1$5, [
219
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
220
+ ]);
221
+ }
222
+ const DefaultTableContainer = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$2], ["__scopeId", "data-v-f089d734"]]);
223
+ const _sfc_main$4 = {};
224
+ const _hoisted_1$4 = {
225
+ focusable: "false",
226
+ "data-icon": "column-height",
227
+ width: "1em",
228
+ height: "1em",
229
+ fill: "currentColor",
230
+ "aria-hidden": "true",
231
+ viewBox: "64 64 896 896"
232
+ };
233
+ function _sfc_render$1(_ctx, _cache) {
234
+ return openBlock(), createElementBlock("svg", _hoisted_1$4, _cache[0] || (_cache[0] = [
235
+ createElementVNode("path", { d: "M840 836H184c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h656c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zm0-724H184c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h656c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8zM610.8 378c6 0 9.4-7 5.7-11.7L515.7 238.7a7.14 7.14 0 00-11.3 0L403.6 366.3a7.23 7.23 0 005.7 11.7H476v268h-62.8c-6 0-9.4 7-5.7 11.7l100.8 127.5c2.9 3.7 8.5 3.7 11.3 0l100.8-127.5c3.7-4.7.4-11.7-5.7-11.7H548V378h62.8z" }, null, -1)
236
+ ]));
237
+ }
238
+ const ColumnHeightOutlined = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$1]]);
239
+ const _hoisted_1$3 = { class: "control-icon" };
240
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
241
+ __name: "SizeControl",
249
242
  setup(__props) {
250
- const props = __props;
251
- const size = useModel(__props, "size");
243
+ const attrs = useAttrs();
244
+ const size = useModel(attrs, "size", { default: "large" });
252
245
  const onSizeChange = (val) => {
253
246
  size.value = val.key;
254
247
  };
255
- const checkAll = ref(false);
256
- const indeterminate = ref(false);
257
248
  const sizeOptions = [
258
249
  { label: "默认", key: "large" },
259
250
  { label: "中等", key: "middle" },
260
251
  { label: "紧凑", key: "small" }
261
252
  ];
253
+ return (_ctx, _cache) => {
254
+ return openBlock(), createBlock(unref(Dropdown), {
255
+ arrow: "",
256
+ placement: "bottomRight"
257
+ }, {
258
+ overlay: withCtx(() => [
259
+ createVNode(unref(Menu), {
260
+ style: { "width": "100px", "text-align": "center" },
261
+ "selected-keys": unref(size) ? [unref(size)] : [],
262
+ items: sizeOptions,
263
+ onClick: onSizeChange
264
+ }, null, 8, ["selected-keys", "items"])
265
+ ]),
266
+ default: withCtx(() => [
267
+ createElementVNode("div", _hoisted_1$3, [
268
+ createVNode(ColumnHeightOutlined, { style: { "font-size": "16px" } })
269
+ ])
270
+ ]),
271
+ _: 1
272
+ });
273
+ };
274
+ }
275
+ });
276
+ const SizeControl = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-d8e78b5b"]]);
277
+ const _sfc_main$2 = {};
278
+ const _hoisted_1$2 = {
279
+ focusable: "false",
280
+ "data-icon": "filter",
281
+ width: "1em",
282
+ height: "1em",
283
+ fill: "currentColor",
284
+ "aria-hidden": "true",
285
+ viewBox: "64 64 896 896"
286
+ };
287
+ function _sfc_render(_ctx, _cache) {
288
+ return openBlock(), createElementBlock("svg", _hoisted_1$2, _cache[0] || (_cache[0] = [
289
+ createElementVNode("path", { d: "M880.1 154H143.9c-24.5 0-39.8 26.7-27.5 48L349 597.4V838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3 31.8-32V597.4L907.7 202c12.2-21.3-3.1-48-27.6-48zM603.4 798H420.6V642h182.9v156zm9.6-236.6l-9.5 16.6h-183l-9.5-16.6L212.7 226h598.6L613 561.4z" }, null, -1)
290
+ ]));
291
+ }
292
+ const FilterOutlined = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render]]);
293
+ const _hoisted_1$1 = { class: "control-icon" };
294
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
295
+ __name: "ColumnControl",
296
+ props: {
297
+ columns: {},
298
+ table: { default: void 0 }
299
+ },
300
+ setup(__props) {
301
+ const props = __props;
302
+ const checkAll = ref(false);
303
+ const indeterminate = ref(false);
262
304
  const checkedColumnsOptions = computed(
263
- () => {
264
- var _a;
265
- return (_a = props.columns) == null ? void 0 : _a.filter((item) => item.key && item.title).map((item) => ({
305
+ () => props.columns.flatMap(
306
+ (item) => item.key && item.title ? {
266
307
  label: item.title,
267
- value: item.key
268
- }));
269
- }
308
+ value: item.key,
309
+ checked: !item.hidden
310
+ } : []
311
+ )
270
312
  );
271
- const checkColumnsVisible = ref(false);
272
- const checkedColumns = computed({
313
+ const checkedColumnKeys = computed({
273
314
  get() {
274
- var _a, _b;
275
- return ((_b = (_a = props.table) == null ? void 0 : _a.showColumnKeys) == null ? void 0 : _b.value) || [];
315
+ return checkedColumnsOptions.value.flatMap(
316
+ (item) => item.checked ? item.value : []
317
+ ) || [];
276
318
  },
277
319
  set(val) {
278
320
  var _a;
279
- (_a = props.table) == null ? void 0 : _a.setShowColumnKeys(val || []);
321
+ (_a = checkedColumnsOptions.value) == null ? void 0 : _a.forEach((item) => {
322
+ var _a2, _b;
323
+ (_b = (_a2 = props.table) == null ? void 0 : _a2.setColumn) == null ? void 0 : _b.call(_a2, item.value, {
324
+ hidden: !val.includes(item.value)
325
+ });
326
+ });
280
327
  }
281
328
  });
282
329
  const onCheckAllChange = (e) => {
283
- checkedColumns.value = e.target.checked ? checkedColumnsOptions.value.map((item) => item.value) : [];
330
+ checkedColumnKeys.value = e.target.checked ? checkedColumnsOptions.value.map((item) => item.value) : [];
284
331
  indeterminate.value = false;
285
332
  };
286
333
  const checkColumnsMenuItemClick = (val) => {
287
- if (checkedColumns.value.includes(val)) {
288
- checkedColumns.value = checkedColumns.value.filter((item) => item !== val);
334
+ if (checkedColumnKeys.value.includes(val)) {
335
+ checkedColumnKeys.value = checkedColumnKeys.value.filter(
336
+ (item) => item !== val
337
+ );
289
338
  } else {
290
- checkedColumns.value = [...checkedColumns.value, val];
339
+ checkedColumnKeys.value = [...checkedColumnKeys.value, val];
291
340
  }
292
341
  };
293
342
  watch(
294
- checkedColumns,
343
+ checkedColumnKeys,
295
344
  (val) => {
296
345
  indeterminate.value = !!val.length && val.length < checkedColumnsOptions.value.length;
297
346
  checkAll.value = val.length === checkedColumnsOptions.value.length;
@@ -299,324 +348,259 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
299
348
  { immediate: true }
300
349
  );
301
350
  return (_ctx, _cache) => {
302
- return openBlock(), createBlock(unref(Space), { size: "middle" }, {
303
- default: withCtx(() => [
304
- createVNode(unref(Dropdown), {
305
- arrow: "",
306
- placement: "bottomRight"
307
- }, {
308
- overlay: withCtx(() => [
309
- createVNode(unref(Menu), {
310
- style: { "width": "100px", "text-align": "center" },
311
- "selected-keys": [size.value],
312
- items: sizeOptions,
313
- onClick: onSizeChange
314
- }, null, 8, ["selected-keys", "items"])
315
- ]),
316
- default: withCtx(() => [
317
- createVNode(unref(ColumnHeightOutlined$1), {
318
- style: { fontSize: "16px" },
319
- class: "control-icon"
320
- })
321
- ]),
322
- _: 1
323
- }),
324
- createVNode(unref(Dropdown), {
325
- open: checkColumnsVisible.value,
326
- "onUpdate:open": _cache[1] || (_cache[1] = ($event) => checkColumnsVisible.value = $event),
327
- arrow: "",
328
- placement: "bottomRight"
329
- }, {
330
- overlay: withCtx(() => [
331
- createElementVNode("div", null, [
332
- createVNode(unref(Menu), {
333
- style: { "min-width": "100px", "max-height": "500px", "overflow-y": "scroll" },
334
- selectable: false
335
- }, {
351
+ return openBlock(), createBlock(unref(Dropdown), {
352
+ arrow: "",
353
+ placement: "bottomRight"
354
+ }, {
355
+ overlay: withCtx(() => [
356
+ createElementVNode("div", null, [
357
+ createVNode(unref(Menu), {
358
+ style: { "min-width": "100px", "max-height": "500px", "overflow-y": "scroll" },
359
+ selectable: false
360
+ }, {
361
+ default: withCtx(() => [
362
+ (openBlock(), createBlock(unref(MenuItem), { key: 0 }, {
336
363
  default: withCtx(() => [
337
- (openBlock(), createBlock(unref(MenuItem), { key: 0 }, {
338
- default: withCtx(() => [
339
- createElementVNode("div", null, [
340
- createVNode(unref(Checkbox), {
341
- checked: checkAll.value,
342
- indeterminate: indeterminate.value,
343
- onChange: onCheckAllChange
344
- }, {
345
- default: withCtx(() => _cache[2] || (_cache[2] = [
346
- createTextVNode(" 全选 ")
347
- ])),
348
- _: 1
349
- }, 8, ["checked", "indeterminate"])
350
- ])
351
- ]),
352
- _: 1
353
- })),
354
- createVNode(unref(MenuDivider)),
355
- (openBlock(true), createElementBlock(Fragment, null, renderList(checkedColumnsOptions.value, (item) => {
356
- return openBlock(), createBlock(unref(MenuItem), {
357
- key: item.value,
358
- onClick: ($event) => checkColumnsMenuItemClick(item.value)
364
+ createElementVNode("div", null, [
365
+ createVNode(unref(Checkbox), {
366
+ checked: checkAll.value,
367
+ indeterminate: indeterminate.value,
368
+ onChange: onCheckAllChange
369
+ }, {
370
+ default: withCtx(() => _cache[1] || (_cache[1] = [
371
+ createTextVNode(" 全选 ", -1)
372
+ ])),
373
+ _: 1,
374
+ __: [1]
375
+ }, 8, ["checked", "indeterminate"])
376
+ ])
377
+ ]),
378
+ _: 1
379
+ })),
380
+ createVNode(unref(MenuDivider)),
381
+ (openBlock(true), createElementBlock(Fragment, null, renderList(checkedColumnsOptions.value, (item) => {
382
+ return openBlock(), createBlock(unref(MenuItem), {
383
+ key: item.value,
384
+ onClick: ($event) => checkColumnsMenuItemClick(item.value)
385
+ }, {
386
+ default: withCtx(() => [
387
+ createVNode(unref(Checkbox), {
388
+ checked: checkedColumnKeys.value.includes(item.value)
359
389
  }, {
360
390
  default: withCtx(() => [
361
- createVNode(unref(Checkbox), {
362
- checked: checkedColumns.value.includes(item.value)
363
- }, {
364
- default: withCtx(() => [
365
- createElementVNode("div", {
366
- onClick: _cache[0] || (_cache[0] = withModifiers(() => {
367
- }, ["stop"]))
368
- }, toDisplayString(item.label), 1)
369
- ]),
370
- _: 2
371
- }, 1032, ["checked"])
391
+ createElementVNode("div", {
392
+ onClick: _cache[0] || (_cache[0] = withModifiers(() => {
393
+ }, ["stop"]))
394
+ }, toDisplayString(item.label), 1)
372
395
  ]),
373
396
  _: 2
374
- }, 1032, ["onClick"]);
375
- }), 128))
376
- ]),
377
- _: 1
378
- })
379
- ])
380
- ]),
381
- default: withCtx(() => [
382
- createVNode(unref(FilterOutlined$1), {
383
- style: { fontSize: "16px" },
384
- class: "control-icon"
385
- })
386
- ]),
387
- _: 1
388
- }, 8, ["open"])
397
+ }, 1032, ["checked"])
398
+ ]),
399
+ _: 2
400
+ }, 1032, ["onClick"]);
401
+ }), 128))
402
+ ]),
403
+ _: 1
404
+ })
405
+ ])
406
+ ]),
407
+ default: withCtx(() => [
408
+ createElementVNode("div", _hoisted_1$1, [
409
+ createVNode(FilterOutlined, { style: { "font-size": "17px" } })
410
+ ])
389
411
  ]),
390
412
  _: 1
391
413
  });
392
414
  };
393
415
  }
394
416
  });
395
- const Control_vue_vue_type_style_index_0_scoped_4f46d39e_lang = "";
396
- const Control = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-4f46d39e"]]);
397
- const DefaultSearchContainer_vue_vue_type_style_index_0_scoped_c00ace37_lang = "";
398
- const _sfc_main$3 = {};
399
- const _hoisted_1$3 = { class: "search-container" };
400
- function _sfc_render$2(_ctx, _cache) {
401
- return openBlock(), createElementBlock("div", _hoisted_1$3, [
402
- renderSlot(_ctx.$slots, "default", {}, void 0, true)
403
- ]);
404
- }
405
- const DefaultSearchContainer = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$2], ["__scopeId", "data-v-c00ace37"]]);
406
- const DefaultTableContainer_vue_vue_type_style_index_0_scoped_db2f53ee_lang = "";
407
- const _sfc_main$2 = {};
408
- const _hoisted_1$2 = { class: "table-container" };
409
- function _sfc_render$1(_ctx, _cache) {
410
- return openBlock(), createElementBlock("div", _hoisted_1$2, [
411
- renderSlot(_ctx.$slots, "default", {}, void 0, true)
412
- ]);
413
- }
414
- const DefaultTableContainer = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$1], ["__scopeId", "data-v-db2f53ee"]]);
415
- const DefaultControlContainer_vue_vue_type_style_index_0_scoped_1d26ef2f_lang = "";
416
- const _sfc_main$1 = {};
417
- const _hoisted_1$1 = { class: "control-container" };
418
- function _sfc_render(_ctx, _cache) {
419
- return openBlock(), createElementBlock("div", _hoisted_1$1, [
420
- renderSlot(_ctx.$slots, "default", {}, void 0, true)
421
- ]);
422
- }
423
- const DefaultControlContainer = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render], ["__scopeId", "data-v-1d26ef2f"]]);
424
- const _hoisted_1 = {
417
+ const ColumnControl = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-88c80679"]]);
418
+ const _hoisted_1 = { class: "pro-table-header" };
419
+ const _hoisted_2 = {
425
420
  key: 0,
426
421
  style: { "flex": "1" }
427
422
  };
423
+ const _hoisted_3 = {
424
+ key: 1,
425
+ style: { "margin-left": "12px" }
426
+ };
427
+ const _hoisted_4 = {
428
+ key: 2,
429
+ style: { "margin-left": "12px" }
430
+ };
431
+ const _hoisted_5 = {
432
+ key: 3,
433
+ style: { "margin-left": "12px" }
434
+ };
428
435
  const _sfc_main = /* @__PURE__ */ defineComponent({
429
- ...{
430
- name: "ProTable",
431
- inheritAttrs: false
432
- },
433
- __name: "Table",
436
+ ...{ name: "ProTable", inheritAttrs: false },
437
+ __name: "BaseTable",
434
438
  props: {
435
439
  table: { default: void 0 },
436
- addIndexColumn: { type: Boolean, default: true },
437
- showControl: { type: Boolean, default: true },
438
- searchContainer: { default: DefaultSearchContainer },
439
- controlContainer: { default: DefaultControlContainer },
440
- tableContainer: { default: DefaultTableContainer },
441
- paramCache: { default: void 0 },
442
- immediateSearch: { type: Boolean, default: false },
443
- searchFormConfig: { default: void 0 }
440
+ search: { type: Function, default: void 0 },
441
+ addIndexColumn: { type: Boolean, default: void 0 },
442
+ immediateSearch: { type: Boolean, default: void 0 },
443
+ control: { type: [Boolean, Object], default: void 0 },
444
+ searchFormConfig: { default: void 0 },
445
+ tableContainer: { default: DefaultTableContainer }
444
446
  },
445
- emits: ["search"],
446
- setup(__props, { emit: __emit }) {
447
- var _a, _b, _c, _d, _e, _f;
447
+ setup(__props) {
448
448
  const props = __props;
449
- const injectProps = useInjectProps(INJECT_KEYS["pro-table"]);
450
- const injectAttrs = omit(injectProps, Object.keys(props));
451
- const cache = props.paramCache === null ? null : props.paramCache ?? (injectProps == null ? void 0 : injectProps.paramCache);
452
- const size = ref(unref(props.size ?? injectProps.size));
453
- const showControl = props.showControl ?? injectProps.showControl;
454
- const searchFormConfig = {
455
- ...injectProps.searchFormConfig,
456
- ...props.searchFormConfig
457
- };
458
- const attrs = useAttrs();
459
- const { table = {} } = props;
460
- const {
461
- columns,
462
- dataSource,
463
- pagination,
464
- setPagination,
465
- showColumnKeys,
466
- searchParam,
467
- setSearchParam
468
- } = table;
469
- const emit = __emit;
470
- const search = () => {
471
- var _a2, _b2;
472
- const { current, pageSize } = ((_a2 = props.table) == null ? void 0 : _a2.pagination.value) || {};
473
- emit("search", {
474
- ...(_b2 = props.table) == null ? void 0 : _b2.searchParam.value,
475
- current,
476
- pageSize
477
- });
478
- cache == null ? void 0 : cache.set(
479
- (pre = {}) => cloneDeep({
480
- ...pre,
481
- pagination: unref(pagination),
482
- searchParam: unref(searchParam)
483
- })
484
- );
449
+ const config = INJECT_CONFIG["pro-table"];
450
+ const injectProps = inject(config.injectionKey, config.default);
451
+ const injectAttrs = pick(
452
+ injectProps,
453
+ Object.keys(tableProps())
454
+ );
455
+ const computedSearchFormConfig = computed(() => {
456
+ return {
457
+ container: DefaultSearchFormContainer,
458
+ ...injectProps.searchFormConfig,
459
+ ...getObject(props.searchFormConfig)
460
+ };
461
+ });
462
+ const attrs = pick(useAttrs(), Object.keys(tableProps()));
463
+ const { columns, dataSource, searchForm, pageParam, setPageParam } = props.table || {};
464
+ const size = useModel(attrs, "size");
465
+ const loading = useModel(attrs, "loading");
466
+ const _search = async () => {
467
+ var _a;
468
+ const { current = 0, pageSize = 0 } = pageParam || {};
469
+ const param = { ...searchForm == null ? void 0 : searchForm.formData, current, pageSize };
470
+ try {
471
+ loading.value = true;
472
+ await ((_a = props.search) == null ? void 0 : _a.call(props, param));
473
+ } finally {
474
+ loading.value = false;
475
+ }
485
476
  };
486
477
  const reset = () => {
487
- var _a2;
488
- (_a2 = props.table) == null ? void 0 : _a2.resetQueryParams();
478
+ var _a;
479
+ (_a = props.table) == null ? void 0 : _a.resetQueryParams();
489
480
  nextTick(() => {
490
- search();
481
+ _search();
491
482
  });
492
483
  };
493
484
  const slots = useSlots();
494
- const tableSlots = omit(slots, ["search", "buttons", "table"]);
495
- const form = {
496
- formData: ((_a = props.table) == null ? void 0 : _a.searchParam) || {},
497
- fields: ((_b = props.table) == null ? void 0 : _b.searchFields) || [],
498
- setFormData: (_c = props.table) == null ? void 0 : _c.setSearchParam,
499
- setField: (_d = props.table) == null ? void 0 : _d.setSearchField
500
- };
501
- if (cache) {
502
- setPagination({
503
- ...unref(pagination),
504
- ...unref(((_e = cache.get()) == null ? void 0 : _e.pagination) ?? {})
505
- });
506
- setSearchParam({
507
- ...unref(searchParam),
508
- ...unref(((_f = cache.get()) == null ? void 0 : _f.searchParam) ?? {})
509
- });
510
- }
485
+ const {
486
+ "search-form": searchFormSlot,
487
+ "button-bar": buttonBarSlot,
488
+ toolbar: toolbarSlot,
489
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
490
+ table: tableSlot,
491
+ ...tableSlots
492
+ } = slots;
511
493
  const searchPage1st = () => {
512
- var _a2;
513
- if (props.table) {
514
- (_a2 = props.table) == null ? void 0 : _a2.setPagination({ ...props.table.pagination.value, current: 1 });
515
- search();
516
- }
494
+ setPageParam == null ? void 0 : setPageParam({ current: 1 });
495
+ _search();
517
496
  };
518
- const mergeTableProps = computed(() => {
519
- return {
520
- ...injectAttrs,
521
- ...attrs,
522
- columns: (attrs.columns ?? (columns == null ? void 0 : columns.value) ?? []).map(
523
- (item, index) => ({
524
- ...item,
525
- key: item.key ?? item.dataIndex.toString() ?? index
526
- })
527
- ),
528
- dataSource: attrs.dataSource ?? (dataSource == null ? void 0 : dataSource.value),
529
- pagination: attrs.pagination ?? {
530
- showTotal: (total) => `共 ${total} 条`,
531
- showSizeChanger: true,
532
- pageSizeOptions: ["10", "20", "30", "40", "50", "100"],
533
- showQuickJumper: true,
534
- ...pagination == null ? void 0 : pagination.value
535
- },
536
- onChange: table ? (...args) => {
537
- var _a2;
538
- setPagination(args[0]);
539
- (_a2 = attrs.onChange) == null ? void 0 : _a2.call(attrs, ...args);
540
- search();
541
- } : attrs.onChange
542
- };
497
+ const computedTableProps = computed(() => {
498
+ return { ...injectAttrs, ...attrs, onChange: void 0 };
543
499
  });
544
500
  const indexColumn = {
545
501
  title: "序号",
546
- dataIndex: "index",
502
+ dataIndex: "_index",
547
503
  width: 80,
548
504
  customRender: ({ index }) => index + 1
549
505
  };
550
- const visibleColumns = computed(() => {
551
- var _a2;
552
- let list = [];
553
- if (!props.table) {
554
- list = (mergeTableProps == null ? void 0 : mergeTableProps.value.columns) || [];
555
- } else {
556
- list = ((_a2 = mergeTableProps.value.columns) == null ? void 0 : _a2.filter(
557
- (item) => item.key && showColumnKeys.value.includes(item.key)
558
- )) || [];
559
- }
560
- if (props.addIndexColumn ?? injectProps.addIndexColumn) {
561
- list = [indexColumn, ...list];
562
- }
563
- return list;
506
+ const computedColumns = computed(() => [
507
+ ...props.addIndexColumn ?? injectProps.addIndexColumn ? [indexColumn] : [],
508
+ ...(attrs.columns ?? (columns == null ? void 0 : columns.value) ?? []).flatMap(
509
+ (item, index) => {
510
+ if (item.key) return [{ ...item, key: item.key }];
511
+ if (item.dataIndex) {
512
+ const dataIndexKey = Array.isArray(item.dataIndex) ? item.dataIndex.join(".") : item.dataIndex;
513
+ return [{ ...item, key: dataIndexKey }];
514
+ }
515
+ return [{ ...item, key: index }];
516
+ }
517
+ )
518
+ ]);
519
+ const visibleComputedColumns = computed(() => {
520
+ return computedColumns.value.filter((item) => !item.hidden);
521
+ });
522
+ const computedDataSource = computed(() => {
523
+ return attrs.dataSource ?? (dataSource == null ? void 0 : dataSource.value);
524
+ });
525
+ const computedPagination = computed(() => {
526
+ if (attrs.pagination === false) return false;
527
+ return { ...injectAttrs.pagination, ...pageParam, ...attrs.pagination };
528
+ });
529
+ const onTableChange = (...args) => {
530
+ var _a;
531
+ setPageParam == null ? void 0 : setPageParam(args[0]);
532
+ (_a = attrs.onChange) == null ? void 0 : _a.call(attrs, ...args);
533
+ _search();
534
+ };
535
+ const showSearch = computed(() => {
536
+ var _a, _b;
537
+ return !!(searchFormSlot || ((_a = computedSearchFormConfig.value) == null ? void 0 : _a.hidden) !== true && searchForm && ((_b = searchForm.fields.value.filter((item) => !item.hidden)) == null ? void 0 : _b.length) > 0);
538
+ });
539
+ const computedControl = computed(() => {
540
+ const control = props.control ?? injectProps.control;
541
+ const sizeControl = (control == null ? void 0 : control.sizeControl) ?? control;
542
+ const columnControl = (control == null ? void 0 : control.columnControl) ?? control;
543
+ return { sizeControl, columnControl };
564
544
  });
565
- const showSearch = computed(() => toValue(form.fields).length > 0);
566
545
  onMounted(() => {
567
546
  if (props.immediateSearch ?? injectProps.immediateSearch) {
568
- search();
547
+ _search();
569
548
  }
570
549
  });
571
550
  return (_ctx, _cache) => {
572
551
  return openBlock(), createElementBlock("div", {
573
- class: "pro-table",
552
+ class: normalizeClass(["pro-table", _ctx.$attrs.class]),
574
553
  style: normalizeStyle(_ctx.$attrs.style)
575
554
  }, [
576
- showSearch.value ? (openBlock(), createBlock(unref(_sfc_main$7), {
555
+ showSearch.value ? (openBlock(), createBlock(unref(_sfc_main$a), {
577
556
  key: 0,
578
- component: _ctx.searchContainer
557
+ component: computedSearchFormConfig.value.container
579
558
  }, {
580
559
  default: withCtx(() => [
581
- renderSlot(_ctx.$slots, "search", {}, () => [
582
- createVNode(unref(SearchForm), mergeProps({
583
- form,
584
- cache: unref(cache)
585
- }, searchFormConfig, {
560
+ renderSlot(_ctx.$slots, "search-form", {}, () => [
561
+ unref(searchForm) ? (openBlock(), createBlock(SearchForm, mergeProps({
562
+ key: 0,
563
+ form: unref(searchForm)
564
+ }, computedSearchFormConfig.value, {
586
565
  onSearch: searchPage1st,
587
566
  onReset: reset
588
- }), null, 16, ["form", "cache"])
567
+ }), null, 16, ["form"])) : createCommentVNode("", true)
589
568
  ], true)
590
569
  ]),
591
570
  _: 3
592
571
  }, 8, ["component"])) : createCommentVNode("", true),
593
- unref(showControl) || Object.hasOwn(_ctx.$slots, "buttons") ? (openBlock(), createBlock(unref(_sfc_main$7), {
594
- key: 1,
595
- component: _ctx.controlContainer
596
- }, {
597
- default: withCtx(() => [
598
- Object.hasOwn(_ctx.$slots, "buttons") ? (openBlock(), createElementBlock("div", _hoisted_1, [
599
- renderSlot(_ctx.$slots, "buttons", {}, void 0, true)
600
- ])) : createCommentVNode("", true),
601
- unref(showControl) ? (openBlock(), createBlock(unref(Control), {
602
- key: 1,
603
- size: size.value,
604
- "onUpdate:size": _cache[0] || (_cache[0] = ($event) => size.value = $event),
605
- columns: mergeTableProps.value.columns,
606
- table: unref(table)
607
- }, null, 8, ["size", "columns", "table"])) : createCommentVNode("", true)
608
- ]),
609
- _: 3
610
- }, 8, ["component"])) : createCommentVNode("", true),
611
- createVNode(unref(_sfc_main$7), { component: _ctx.tableContainer }, {
572
+ createVNode(unref(_sfc_main$a), { component: _ctx.tableContainer }, {
612
573
  default: withCtx(() => [
574
+ createElementVNode("div", _hoisted_1, [
575
+ unref(buttonBarSlot) ? (openBlock(), createElementBlock("div", _hoisted_2, [
576
+ renderSlot(_ctx.$slots, "button-bar", {}, void 0, true)
577
+ ])) : createCommentVNode("", true),
578
+ unref(toolbarSlot) ? (openBlock(), createElementBlock("div", _hoisted_3, [
579
+ renderSlot(_ctx.$slots, "toolbar", {}, void 0, true)
580
+ ])) : createCommentVNode("", true),
581
+ computedControl.value.sizeControl ? (openBlock(), createElementBlock("div", _hoisted_4, [
582
+ createVNode(unref(SizeControl), {
583
+ size: unref(size),
584
+ "onUpdate:size": _cache[0] || (_cache[0] = ($event) => isRef(size) ? size.value = $event : null)
585
+ }, null, 8, ["size"])
586
+ ])) : createCommentVNode("", true),
587
+ computedControl.value.columnControl ? (openBlock(), createElementBlock("div", _hoisted_5, [
588
+ createVNode(unref(ColumnControl), {
589
+ columns: computedColumns.value,
590
+ table: props.table
591
+ }, null, 8, ["columns", "table"])
592
+ ])) : createCommentVNode("", true)
593
+ ]),
613
594
  renderSlot(_ctx.$slots, "table", {}, () => [
614
- createVNode(unref(Table), mergeProps(mergeTableProps.value, {
615
- columns: visibleColumns.value,
616
- class: "base-table",
617
- size: size.value
595
+ createVNode(unref(Table), mergeProps({ class: "pro-table-content" }, computedTableProps.value, {
596
+ size: unref(size),
597
+ loading: unref(loading),
598
+ columns: visibleComputedColumns.value,
599
+ "data-source": computedDataSource.value,
600
+ pagination: computedPagination.value,
601
+ onChange: onTableChange
618
602
  }), createSlots({ _: 2 }, [
619
- renderList(unref(tableSlots), (slot, name) => {
603
+ renderList(tableSlots, (_, name) => {
620
604
  return {
621
605
  name,
622
606
  fn: withCtx((scoped) => [
@@ -624,82 +608,138 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
624
608
  ])
625
609
  };
626
610
  })
627
- ]), 1040, ["columns", "size"])
611
+ ]), 1040, ["size", "loading", "columns", "data-source", "pagination"])
628
612
  ], true)
629
613
  ]),
630
614
  _: 3
631
615
  }, 8, ["component"])
632
- ], 4);
616
+ ], 6);
633
617
  };
634
618
  }
635
619
  });
636
- const Table_vue_vue_type_style_index_0_scoped_7ca35914_lang = "";
637
- const BaseTable = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-7ca35914"]]);
638
- const getDefaultPagination = () => ({ current: 1, pageSize: 10, total: 0 });
639
- const useTable = ({
640
- columns: initColumns = [],
641
- dataSource: initDataSource = [],
642
- showColumnKeys: initShowColumnKeys = void 0,
643
- pagination: initPagination = getDefaultPagination(),
644
- searchParam: initSearchParam = {},
645
- searchFields: initSearchFields = []
646
- }) => {
647
- const _initSearchParam = cloneDeep(unref(initSearchParam));
648
- const columns = ref(initColumns);
620
+ const BaseTable = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-6701f35a"]]);
621
+ const getDefaultPageParam = () => ({ current: 1, pageSize: 10, total: 0 });
622
+ const pageParamProperty = ["current", "pageSize", "total"];
623
+ const useTable = (params) => {
624
+ const {
625
+ columns: initColumns = [],
626
+ dataSource: initDataSource = [],
627
+ pageParam: initPageParam = getDefaultPageParam(),
628
+ searchParam: initSearchParam = {},
629
+ searchFields: initSearchFields = []
630
+ } = params;
631
+ const _initSearchParam = cloneDeep(toValue(initSearchParam));
632
+ const columns = ref([]);
633
+ columns.value = initColumns;
649
634
  const dataSource = ref(initDataSource);
650
- const showColumnKeys = ref(
651
- initShowColumnKeys ?? columns.value.map(
652
- (item, index) => {
653
- var _a;
654
- return item.key ?? ((_a = item.dataIndex) == null ? void 0 : _a.toString()) ?? index;
635
+ const pageParam = reactive(initPageParam);
636
+ const setPageParam = (pa) => {
637
+ let newPageParam = pa;
638
+ if (typeof pa === "function") {
639
+ newPageParam = pa(pageParam);
640
+ }
641
+ Object.assign(pageParam, pick(newPageParam, pageParamProperty));
642
+ };
643
+ const searchForm = useForm(initSearchParam, initSearchFields, true);
644
+ const resetQueryParams = () => {
645
+ Object.assign(pageParam, getDefaultPageParam());
646
+ searchForm.setFormData(cloneDeep(_initSearchParam));
647
+ };
648
+ const updaterMatch = (key, updater, options = {}) => {
649
+ if (!key) return;
650
+ const { all = typeof key === "function" } = options;
651
+ for (let i = 0; i < columns.value.length; i++) {
652
+ const columnItem = columns.value[i];
653
+ let matched = false;
654
+ if (typeof key === "function") {
655
+ matched = key(columnItem);
656
+ } else if (columnItem.key) {
657
+ matched = columnItem.key === key;
658
+ } else if (columnItem.dataIndex) {
659
+ const dataIndexKey = Array.isArray(columnItem.dataIndex) ? columnItem.dataIndex.join(".") : columnItem.dataIndex;
660
+ matched = dataIndexKey === key;
661
+ } else {
662
+ matched = key === i;
655
663
  }
656
- )
657
- );
658
- watch(columns, (val) => {
659
- showColumnKeys.value = val.map(
660
- (item, index) => {
661
- var _a;
662
- return item.key ?? ((_a = item.dataIndex) == null ? void 0 : _a.toString()) ?? index;
664
+ if (matched) {
665
+ updater({
666
+ column: columnItem,
667
+ columnIndex: i,
668
+ group: columns.value
669
+ });
670
+ if (!all) return;
663
671
  }
664
- );
665
- });
666
- const setShowColumnKeys = (val) => {
667
- showColumnKeys.value = val;
668
- };
669
- const pagination = ref(initPagination);
670
- const setPagination = (val) => {
671
- pagination.value = val;
672
+ }
672
673
  };
673
- const { formData, fields, setFormData, setField, getField } = useForm(
674
- initSearchParam,
675
- initSearchFields
676
- );
677
- const searchParam = formData;
678
- const searchFields = fields;
679
- const setSearchParam = setFormData;
680
- const setSearchField = setField;
681
- const getSearchField = getField;
682
- const resetQueryParams = () => {
683
- setPagination(getDefaultPagination());
684
- setSearchParam(cloneDeep(_initSearchParam));
674
+ const setColumn = (key, column, options) => {
675
+ if (!key || !column) return;
676
+ const { updateType = "merge", ...rest } = options || {};
677
+ updaterMatch(
678
+ key,
679
+ ({ column: preColumn, columnIndex, group }) => {
680
+ let value = column;
681
+ if (typeof column === "function") {
682
+ value = column(preColumn);
683
+ }
684
+ if (!value) return;
685
+ if (updateType === "rewrite") {
686
+ group[columnIndex] = value;
687
+ } else {
688
+ Object.assign(preColumn, value);
689
+ }
690
+ },
691
+ rest
692
+ );
685
693
  };
694
+ function deleteColumn(path, options) {
695
+ if (!path) return;
696
+ updaterMatch(
697
+ path,
698
+ ({ columnIndex, group }) => {
699
+ group.splice(columnIndex, 1);
700
+ },
701
+ options
702
+ );
703
+ }
704
+ function addColumns(path, newColumns, options, placement) {
705
+ if (newColumns.length === 0) return;
706
+ if (path) {
707
+ updaterMatch(
708
+ path,
709
+ ({ columnIndex, group }) => {
710
+ const index = placement === "after" ? columnIndex + 1 : columnIndex;
711
+ group.splice(index, 0, ...newColumns);
712
+ },
713
+ options
714
+ );
715
+ } else if (placement === "after") {
716
+ columns.value.push(...newColumns);
717
+ } else {
718
+ columns.value.unshift(...newColumns);
719
+ }
720
+ }
721
+ function appendColumn(path, column, options) {
722
+ const newColumns = Array.isArray(column) ? column : [column];
723
+ addColumns(path, newColumns, options, "after");
724
+ }
725
+ function prependColumn(path, column, options) {
726
+ const newColumns = Array.isArray(column) ? column : [column];
727
+ addColumns(path, newColumns, options, "before");
728
+ }
686
729
  return {
687
730
  columns,
688
731
  dataSource,
689
- pagination,
690
- showColumnKeys,
691
- searchParam,
692
- setSearchParam,
693
- searchFields,
694
- setSearchField,
695
- getSearchField,
696
- setShowColumnKeys,
697
- setPagination,
732
+ pageParam,
733
+ searchForm,
734
+ setColumn,
735
+ deleteColumn,
736
+ appendColumn,
737
+ prependColumn,
738
+ setPageParam,
698
739
  resetQueryParams
699
740
  };
700
741
  };
701
- const useTable$1 = useTable;
702
742
  export {
703
743
  BaseTable as default,
704
- useTable$1 as useTable
744
+ useTable
705
745
  };