@tmagic/table 1.2.0-beta.2 → 1.2.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,24 @@
1
- import { defineComponent, resolveComponent, openBlock, createBlock, withCtx, createElementBlock, Fragment, renderList, withDirectives, vShow, createVNode, createTextVNode, createCommentVNode, toDisplayString, createElementVNode, resolveDirective } from 'vue';
1
+ import { defineComponent, openBlock, createBlock, unref, withCtx, createElementBlock, Fragment, renderList, withDirectives, createElementVNode, vShow, createVNode, createTextVNode, createCommentVNode, resolveDynamicComponent, normalizeProps, mergeProps, toDisplayString, resolveComponent, ref, computed, resolveDirective } from 'vue';
2
2
  import { cloneDeep } from 'lodash-es';
3
- import { ElMessage, ElMessageBox } from 'element-plus';
3
+ import { TMagicTableColumn, TMagicButton, tMagicMessage, TMagicPopover, TMagicForm, TMagicTag, getConfig, TMagicTable } from '@tmagic/design';
4
4
  import { MForm } from '@tmagic/form';
5
5
  import { datetimeFormatter } from '@tmagic/utils';
6
6
 
7
- const _hoisted_1$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
8
- const _hoisted_2$1 = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
7
+ const _hoisted_1$2 = ["innerHTML"];
8
+ const _hoisted_2$1 = /* @__PURE__ */ createTextVNode("\u4FDD\u5B58");
9
+ const _hoisted_3$1 = /* @__PURE__ */ createTextVNode("\u53D6\u6D88");
10
+ const __default__$4 = defineComponent({
11
+ name: "MTableActionsColumn"
12
+ });
9
13
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
10
- __name: "ActionsColumn",
14
+ ...__default__$4,
11
15
  props: {
12
- columns: {
13
- type: Array,
14
- require: true,
15
- default: () => []
16
- },
17
- config: {
18
- type: Object,
19
- require: true,
20
- default: () => {
21
- }
22
- },
23
- rowkeyName: {
24
- type: String,
25
- default: "c_id"
26
- },
27
- editState: {
28
- type: Object,
29
- default: () => {
30
- }
31
- }
16
+ columns: { default: () => [] },
17
+ config: { default: () => ({}) },
18
+ rowkeyName: { default: "c_id" },
19
+ editState: { default: () => [] }
32
20
  },
33
- emits: ["afterAction"],
21
+ emits: ["after-action"],
34
22
  setup(__props, { emit }) {
35
23
  const props = __props;
36
24
  const display = (fuc, row) => {
@@ -39,48 +27,15 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
39
27
  }
40
28
  return true;
41
29
  };
42
- const success = (msg, action, row) => {
43
- ElMessage.success(msg);
44
- action.after?.(row);
45
- };
46
- const error = (msg) => ElMessage.error(msg);
47
- const deleteAction = async (action, row) => {
48
- await ElMessageBox.confirm(`\u786E\u8BA4\u5220\u9664${row[action.name || "c_name"]}(${row[props.rowkeyName]})?`, "\u63D0\u793A", {
49
- confirmButtonText: "\u786E\u5B9A",
50
- cancelButtonText: "\u53D6\u6D88",
51
- type: "warning"
52
- });
53
- const res = await action.handler?.(row);
54
- if (res.ret === 0) {
55
- success("\u5220\u9664\u6210\u529F!", action, row);
56
- } else {
57
- error(res.msg || "\u5220\u9664\u5931\u8D25");
58
- }
59
- };
60
- const copyHandler = async (action, row) => {
61
- await ElMessageBox.confirm(`\u786E\u5B9A\u590D\u5236${row[action.name || "c_name"]}(${row.c_id})?`, "\u63D0\u793A", {
62
- confirmButtonText: "\u786E\u5B9A",
63
- cancelButtonText: "\u53D6\u6D88",
64
- type: "warning"
65
- });
66
- try {
67
- const res = await action.handler?.(row);
68
- if (res.ret === 0) {
69
- success("\u590D\u5236\u6210\u529F!", action, row);
70
- } else {
71
- error(`\u590D\u5236\u5931\u8D25!${res.msg}`);
72
- }
73
- } catch (e) {
74
- error("\u590D\u5236\u5931\u8D25!");
30
+ const formatter = (fuc, row) => {
31
+ if (typeof fuc === "function") {
32
+ return fuc(row);
75
33
  }
34
+ return fuc;
76
35
  };
77
36
  const actionHandler = async (action, row, index) => {
78
37
  await action.before?.(row);
79
- if (action.type === "delete") {
80
- await deleteAction(action, row);
81
- } else if (action.type === "copy") {
82
- await copyHandler(action, row);
83
- } else if (action.type === "edit") {
38
+ if (action.type === "edit") {
84
39
  props.editState[index] = row;
85
40
  } else {
86
41
  await action.handler?.(row);
@@ -101,45 +56,45 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
101
56
  });
102
57
  if (res) {
103
58
  if (res.ret === 0) {
104
- ElMessage.success("\u4FDD\u5B58\u6210\u529F");
59
+ tMagicMessage.success("\u4FDD\u5B58\u6210\u529F");
105
60
  props.editState[index] = void 0;
106
- emit("afterAction");
61
+ emit("after-action");
107
62
  } else {
108
- ElMessage.error({
109
- duration: 1e4,
110
- showClose: true,
111
- dangerouslyUseHTMLString: true,
112
- message: res.msg || "\u4FDD\u5B58\u5931\u8D25"
113
- });
63
+ tMagicMessage.error(res.msg || "\u4FDD\u5B58\u5931\u8D25");
114
64
  }
115
65
  } else {
116
66
  props.editState[index] = void 0;
117
- emit("afterAction");
67
+ emit("after-action");
118
68
  }
119
69
  };
120
70
  return (_ctx, _cache) => {
121
- const _component_el_button = resolveComponent("el-button");
122
- const _component_el_table_column = resolveComponent("el-table-column");
123
- return openBlock(), createBlock(_component_el_table_column, {
71
+ return openBlock(), createBlock(unref(TMagicTableColumn), {
124
72
  label: __props.config.label,
125
73
  width: __props.config.width,
126
74
  fixed: __props.config.fixed
127
75
  }, {
128
76
  default: withCtx((scope) => [
129
77
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.config.actions, (action, actionIndex) => {
130
- return withDirectives((openBlock(), createBlock(_component_el_button, {
131
- innerHTML: action.text,
78
+ return withDirectives((openBlock(), createBlock(unref(TMagicButton), {
132
79
  class: "action-btn",
133
80
  text: "",
134
81
  type: "primary",
135
82
  size: "small",
83
+ icon: action.icon,
136
84
  key: actionIndex,
137
85
  onClick: ($event) => actionHandler(action, scope.row, scope.$index)
138
- }, null, 8, ["innerHTML", "onClick"])), [
86
+ }, {
87
+ default: withCtx(() => [
88
+ createElementVNode("span", {
89
+ innerHTML: formatter(action.text, scope.row)
90
+ }, null, 8, _hoisted_1$2)
91
+ ]),
92
+ _: 2
93
+ }, 1032, ["icon", "onClick"])), [
139
94
  [vShow, display(action.display, scope.row) && !__props.editState[scope.$index]]
140
95
  ]);
141
96
  }), 128)),
142
- withDirectives(createVNode(_component_el_button, {
97
+ withDirectives(createVNode(unref(TMagicButton), {
143
98
  class: "action-btn",
144
99
  text: "",
145
100
  type: "primary",
@@ -147,13 +102,13 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
147
102
  onClick: ($event) => save(scope.$index, __props.config)
148
103
  }, {
149
104
  default: withCtx(() => [
150
- _hoisted_1$1
105
+ _hoisted_2$1
151
106
  ]),
152
107
  _: 2
153
108
  }, 1032, ["onClick"]), [
154
109
  [vShow, __props.editState[scope.$index]]
155
110
  ]),
156
- withDirectives(createVNode(_component_el_button, {
111
+ withDirectives(createVNode(unref(TMagicButton), {
157
112
  class: "action-btn",
158
113
  text: "",
159
114
  type: "primary",
@@ -161,7 +116,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
161
116
  onClick: ($event) => __props.editState[scope.$index] = void 0
162
117
  }, {
163
118
  default: withCtx(() => [
164
- _hoisted_2$1
119
+ _hoisted_3$1
165
120
  ]),
166
121
  _: 2
167
122
  }, 1032, ["onClick"]), [
@@ -174,49 +129,52 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
174
129
  }
175
130
  });
176
131
 
177
- const _sfc_main$3 = defineComponent({
178
- components: { MForm },
132
+ const _hoisted_1$1 = ["innerHTML"];
133
+ const __default__$3 = defineComponent({
134
+ name: "MTableExpandColumn"
135
+ });
136
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
137
+ ...__default__$3,
179
138
  props: {
180
- config: {
181
- type: Object,
182
- default: () => ({}),
183
- required: true
184
- }
139
+ config: { default: () => ({}) }
140
+ },
141
+ setup(__props) {
142
+ const props = __props;
143
+ const componentProps = (row) => {
144
+ if (typeof props.config.props === "function") {
145
+ return props.config.props(row) || {};
146
+ }
147
+ return props.config.props || {};
148
+ };
149
+ return (_ctx, _cache) => {
150
+ return openBlock(), createBlock(unref(TMagicTableColumn), { type: "expand" }, {
151
+ default: withCtx((scope) => [
152
+ __props.config.table ? (openBlock(), createBlock(_sfc_main, {
153
+ key: 0,
154
+ "show-header": false,
155
+ columns: __props.config.table,
156
+ data: __props.config.prop && scope.row[__props.config.prop] || []
157
+ }, null, 8, ["columns", "data"])) : createCommentVNode("", true),
158
+ __props.config.form ? (openBlock(), createBlock(unref(MForm), {
159
+ key: 1,
160
+ config: __props.config.form,
161
+ "init-values": __props.config.values || __props.config.prop && scope.row[__props.config.prop] || {}
162
+ }, null, 8, ["config", "init-values"])) : createCommentVNode("", true),
163
+ __props.config.expandContent ? (openBlock(), createElementBlock("div", {
164
+ key: 2,
165
+ innerHTML: __props.config.expandContent(scope.row, __props.config.prop)
166
+ }, null, 8, _hoisted_1$1)) : createCommentVNode("", true),
167
+ __props.config.component ? (openBlock(), createBlock(resolveDynamicComponent(__props.config.component), normalizeProps(mergeProps({ key: 3 }, componentProps(scope.row))), null, 16)) : createCommentVNode("", true)
168
+ ]),
169
+ _: 1
170
+ });
171
+ };
185
172
  }
186
173
  });
187
174
 
188
- const _export_sfc = (sfc, props) => {
189
- const target = sfc.__vccOpts || sfc;
190
- for (const [key, val] of props) {
191
- target[key] = val;
192
- }
193
- return target;
194
- };
195
-
196
- function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
197
- const _component_m_table = resolveComponent("m-table");
198
- const _component_m_form = resolveComponent("m-form");
199
- const _component_el_table_column = resolveComponent("el-table-column");
200
- return openBlock(), createBlock(_component_el_table_column, { type: "expand" }, {
201
- default: withCtx((scope) => [
202
- _ctx.config.table ? (openBlock(), createBlock(_component_m_table, {
203
- key: 0,
204
- "show-header": false,
205
- columns: _ctx.config.table,
206
- data: scope.row[_ctx.config.prop]
207
- }, null, 8, ["columns", "data"])) : createCommentVNode("", true),
208
- _ctx.config.form ? (openBlock(), createBlock(_component_m_form, {
209
- key: 1,
210
- config: _ctx.config.form,
211
- "init-values": _ctx.config.values || scope.row[_ctx.config.prop] || {}
212
- }, null, 8, ["config", "init-values"])) : createCommentVNode("", true)
213
- ]),
214
- _: 1
215
- });
216
- }
217
- const ExpandColumn = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
218
-
219
175
  const formatter = (item, row) => {
176
+ if (!item.prop)
177
+ return "";
220
178
  if (item.formatter) {
221
179
  if (item.formatter === "datetime") {
222
180
  item.formatter = (value) => datetimeFormatter(value);
@@ -231,359 +189,319 @@ const formatter = (item, row) => {
231
189
  }
232
190
  };
233
191
 
234
- const _sfc_main$2 = defineComponent({
192
+ const __default__$2 = defineComponent({
193
+ name: "MTablePopoverColumn"
194
+ });
195
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
196
+ ...__default__$2,
235
197
  props: {
236
- config: {
237
- type: Object,
238
- default: () => ({}),
239
- required: true
240
- }
198
+ config: { default: () => ({}) }
241
199
  },
242
- setup() {
243
- return {
244
- formatter
245
- };
246
- }
247
- });
248
-
249
- function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
250
- const _component_m_table = resolveComponent("m-table");
251
- const _component_el_button = resolveComponent("el-button");
252
- const _component_el_popover = resolveComponent("el-popover");
253
- const _component_el_table_column = resolveComponent("el-table-column");
254
- return openBlock(), createBlock(_component_el_table_column, {
255
- label: _ctx.config.label,
256
- width: _ctx.config.width,
257
- fixed: _ctx.config.fixed
258
- }, {
259
- default: withCtx((scope) => [
260
- createVNode(_component_el_popover, {
261
- placement: _ctx.config.popover.placement,
262
- width: _ctx.config.popover.width,
263
- trigger: _ctx.config.popover.trigger
200
+ setup(__props) {
201
+ return (_ctx, _cache) => {
202
+ return openBlock(), createBlock(unref(TMagicTableColumn), {
203
+ label: __props.config.label,
204
+ width: __props.config.width,
205
+ fixed: __props.config.fixed
264
206
  }, {
265
- reference: withCtx(() => [
266
- createVNode(_component_el_button, {
267
- text: "",
268
- type: "primary"
207
+ default: withCtx((scope) => [
208
+ __props.config.popover ? (openBlock(), createBlock(unref(TMagicPopover), {
209
+ key: 0,
210
+ placement: __props.config.popover.placement,
211
+ width: __props.config.popover.width,
212
+ trigger: __props.config.popover.trigger
269
213
  }, {
214
+ reference: withCtx(() => [
215
+ createVNode(unref(TMagicButton), {
216
+ text: "",
217
+ type: "primary"
218
+ }, {
219
+ default: withCtx(() => [
220
+ createTextVNode(toDisplayString(__props.config.text || unref(formatter)(__props.config, scope.row)), 1)
221
+ ]),
222
+ _: 2
223
+ }, 1024)
224
+ ]),
270
225
  default: withCtx(() => [
271
- createTextVNode(toDisplayString(_ctx.config.text || _ctx.formatter(_ctx.config, scope.row)), 1)
226
+ __props.config.popover.tableEmbed ? (openBlock(), createBlock(_sfc_main, {
227
+ key: 0,
228
+ "show-header": __props.config.showHeader,
229
+ columns: __props.config.table,
230
+ data: __props.config.prop && scope.row[__props.config.prop] || []
231
+ }, null, 8, ["show-header", "columns", "data"])) : createCommentVNode("", true)
272
232
  ]),
273
233
  _: 2
274
- }, 1024)
275
- ]),
276
- default: withCtx(() => [
277
- _ctx.config.popover.tableEmbed ? (openBlock(), createBlock(_component_m_table, {
278
- key: 0,
279
- "show-header": _ctx.config.showHeader,
280
- columns: _ctx.config.table,
281
- data: scope.row[_ctx.config.prop]
282
- }, null, 8, ["show-header", "columns", "data"])) : createCommentVNode("", true)
234
+ }, 1032, ["placement", "width", "trigger"])) : createCommentVNode("", true)
283
235
  ]),
284
- _: 2
285
- }, 1032, ["placement", "width", "trigger"])
286
- ]),
287
- _: 1
288
- }, 8, ["label", "width", "fixed"]);
289
- }
290
- const PopoverColumn = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
291
-
292
- const _sfc_main$1 = defineComponent({
293
- props: {
294
- config: {
295
- type: Object,
296
- default: () => ({}),
297
- required: true
298
- },
299
- editState: {
300
- type: Object,
301
- default: () => {
302
- }
303
- }
304
- },
305
- setup() {
306
- return {
307
- formatter
236
+ _: 1
237
+ }, 8, ["label", "width", "fixed"]);
308
238
  };
309
239
  }
310
240
  });
311
241
 
312
- const _hoisted_1 = ["href"];
313
- const _hoisted_2 = ["src"];
314
- const _hoisted_3 = ["href"];
315
- const _hoisted_4 = /* @__PURE__ */ createTextVNode("\u6269\u5C55\u914D\u7F6E");
316
- const _hoisted_5 = ["innerHTML"];
317
- function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
318
- const _component_m_form_container = resolveComponent("m-form-container");
319
- const _component_el_form = resolveComponent("el-form");
320
- const _component_el_button = resolveComponent("el-button");
321
- const _component_el_tooltip = resolveComponent("el-tooltip");
322
- const _component_el_tag = resolveComponent("el-tag");
323
- const _component_el_table_column = resolveComponent("el-table-column");
324
- return openBlock(), createBlock(_component_el_table_column, {
325
- "show-overflow-tooltip": "",
326
- label: _ctx.config.label,
327
- width: _ctx.config.width,
328
- fixed: _ctx.config.fixed,
329
- sortable: _ctx.config.sortable,
330
- prop: _ctx.config.prop
331
- }, {
332
- default: withCtx((scope) => [
333
- _ctx.config.type && _ctx.editState[scope.$index] ? (openBlock(), createBlock(_component_el_form, {
334
- key: 0,
335
- "label-width": "0",
336
- model: _ctx.editState[scope.$index]
337
- }, {
338
- default: withCtx(() => [
339
- createVNode(_component_m_form_container, {
340
- prop: _ctx.config.prop,
341
- rules: _ctx.config.rules,
342
- config: _ctx.config,
343
- name: _ctx.config.prop,
344
- model: _ctx.editState[scope.$index]
345
- }, null, 8, ["prop", "rules", "config", "name", "model"])
346
- ]),
347
- _: 2
348
- }, 1032, ["model"])) : _ctx.config.action === "actionLink" ? (openBlock(), createBlock(_component_el_button, {
349
- key: 1,
350
- text: "",
351
- type: "primary",
352
- onClick: ($event) => _ctx.config.handler(scope.row)
353
- }, {
354
- default: withCtx(() => [
355
- createTextVNode(toDisplayString(_ctx.formatter(_ctx.config, scope.row)), 1)
356
- ]),
357
- _: 2
358
- }, 1032, ["onClick"])) : _ctx.config.action === "img" ? (openBlock(), createElementBlock("a", {
359
- key: 2,
360
- target: "_blank",
361
- href: scope.row[_ctx.config.prop]
362
- }, [
363
- createElementVNode("img", {
364
- src: scope.row[_ctx.config.prop],
365
- height: "50"
366
- }, null, 8, _hoisted_2)
367
- ], 8, _hoisted_1)) : _ctx.config.action === "link" ? (openBlock(), createElementBlock("a", {
368
- key: 3,
369
- target: "_blank",
370
- href: scope.row[_ctx.config.prop],
371
- class: "keep-all"
372
- }, toDisplayString(scope.row[_ctx.config.prop]), 9, _hoisted_3)) : _ctx.config.action === "tip" ? (openBlock(), createBlock(_component_el_tooltip, {
373
- key: 4,
374
- placement: "left"
242
+ const _hoisted_1 = ["innerHTML"];
243
+ const _hoisted_2 = ["href"];
244
+ const _hoisted_3 = ["src"];
245
+ const _hoisted_4 = ["href"];
246
+ const _hoisted_5 = /* @__PURE__ */ createTextVNode("\u6269\u5C55\u914D\u7F6E");
247
+ const _hoisted_6 = ["innerHTML"];
248
+ const __default__$1 = defineComponent({
249
+ name: "MTableColumn"
250
+ });
251
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
252
+ ...__default__$1,
253
+ props: {
254
+ config: { default: () => ({}) },
255
+ editState: { default: () => ({}) }
256
+ },
257
+ setup(__props) {
258
+ return (_ctx, _cache) => {
259
+ const _component_m_form_container = resolveComponent("m-form-container");
260
+ const _component_el_tooltip = resolveComponent("el-tooltip");
261
+ return openBlock(), createBlock(unref(TMagicTableColumn), {
262
+ "show-overflow-tooltip": "",
263
+ label: __props.config.label,
264
+ width: __props.config.width,
265
+ fixed: __props.config.fixed,
266
+ sortable: __props.config.sortable,
267
+ prop: __props.config.prop
375
268
  }, {
376
- content: withCtx(() => [
377
- createElementVNode("div", null, toDisplayString(_ctx.formatter(_ctx.config, scope.row)), 1)
378
- ]),
379
- default: withCtx(() => [
380
- createVNode(_component_el_button, {
269
+ default: withCtx((scope) => [
270
+ __props.config.type && __props.editState[scope.$index] ? (openBlock(), createBlock(unref(TMagicForm), {
271
+ key: 0,
272
+ "label-width": "0",
273
+ model: __props.editState[scope.$index]
274
+ }, {
275
+ default: withCtx(() => [
276
+ createVNode(_component_m_form_container, {
277
+ prop: __props.config.prop,
278
+ rules: __props.config.rules,
279
+ config: __props.config,
280
+ name: __props.config.prop,
281
+ model: __props.editState[scope.$index]
282
+ }, null, 8, ["prop", "rules", "config", "name", "model"])
283
+ ]),
284
+ _: 2
285
+ }, 1032, ["model"])) : __props.config.action === "actionLink" && __props.config.prop ? (openBlock(), createBlock(unref(TMagicButton), {
286
+ key: 1,
381
287
  text: "",
382
- type: "primary"
288
+ type: "primary",
289
+ onClick: ($event) => __props.config.handler?.(scope.row)
383
290
  }, {
384
291
  default: withCtx(() => [
385
- _hoisted_4
292
+ createElementVNode("span", {
293
+ innerHTML: unref(formatter)(__props.config, scope.row)
294
+ }, null, 8, _hoisted_1)
386
295
  ]),
387
- _: 1
388
- })
389
- ]),
390
- _: 2
391
- }, 1024)) : _ctx.config.action === "tag" ? (openBlock(), createBlock(_component_el_tag, {
392
- key: 5,
393
- type: typeof _ctx.config.type === "function" ? _ctx.config.type(scope.row[_ctx.config.prop], scope.row) : _ctx.config.type,
394
- "close-transition": ""
395
- }, {
396
- default: withCtx(() => [
397
- createTextVNode(toDisplayString(_ctx.formatter(_ctx.config, scope.row)), 1)
296
+ _: 2
297
+ }, 1032, ["onClick"])) : __props.config.action === "img" && __props.config.prop ? (openBlock(), createElementBlock("a", {
298
+ key: 2,
299
+ target: "_blank",
300
+ href: scope.row[__props.config.prop]
301
+ }, [
302
+ createElementVNode("img", {
303
+ src: scope.row[__props.config.prop],
304
+ height: "50"
305
+ }, null, 8, _hoisted_3)
306
+ ], 8, _hoisted_2)) : __props.config.action === "link" && __props.config.prop ? (openBlock(), createElementBlock("a", {
307
+ key: 3,
308
+ target: "_blank",
309
+ href: scope.row[__props.config.prop],
310
+ class: "keep-all"
311
+ }, toDisplayString(scope.row[__props.config.prop]), 9, _hoisted_4)) : __props.config.action === "tip" ? (openBlock(), createBlock(_component_el_tooltip, {
312
+ key: 4,
313
+ placement: "left"
314
+ }, {
315
+ content: withCtx(() => [
316
+ createElementVNode("div", null, toDisplayString(unref(formatter)(__props.config, scope.row)), 1)
317
+ ]),
318
+ default: withCtx(() => [
319
+ createVNode(unref(TMagicButton), {
320
+ text: "",
321
+ type: "primary"
322
+ }, {
323
+ default: withCtx(() => [
324
+ _hoisted_5
325
+ ]),
326
+ _: 1
327
+ })
328
+ ]),
329
+ _: 2
330
+ }, 1024)) : __props.config.action === "tag" && __props.config.prop ? (openBlock(), createBlock(unref(TMagicTag), {
331
+ key: 5,
332
+ type: typeof __props.config.type === "function" ? __props.config.type(scope.row[__props.config.prop], scope.row) : __props.config.type,
333
+ "close-transition": ""
334
+ }, {
335
+ default: withCtx(() => [
336
+ createTextVNode(toDisplayString(unref(formatter)(__props.config, scope.row)), 1)
337
+ ]),
338
+ _: 2
339
+ }, 1032, ["type"])) : (openBlock(), createElementBlock("div", {
340
+ key: 6,
341
+ innerHTML: unref(formatter)(__props.config, scope.row)
342
+ }, null, 8, _hoisted_6))
398
343
  ]),
399
- _: 2
400
- }, 1032, ["type"])) : (openBlock(), createElementBlock("div", {
401
- key: 6,
402
- innerHTML: _ctx.formatter(_ctx.config, scope.row)
403
- }, null, 8, _hoisted_5))
404
- ]),
405
- _: 1
406
- }, 8, ["label", "width", "fixed", "sortable", "prop"]);
407
- }
408
- const TextColumn = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
344
+ _: 1
345
+ }, 8, ["label", "width", "fixed", "sortable", "prop"]);
346
+ };
347
+ }
348
+ });
409
349
 
410
- const _sfc_main = defineComponent({
411
- name: "m-table",
412
- components: { ExpandColumn, ActionsColumn: _sfc_main$4, PopoverColumn, TextColumn },
350
+ const __default__ = defineComponent({
351
+ name: "MTable"
352
+ });
353
+ const _sfc_main = /* @__PURE__ */ defineComponent({
354
+ ...__default__,
413
355
  props: {
414
- data: {
415
- type: Array,
416
- require: true
417
- },
418
- columns: {
419
- type: Array,
420
- require: true,
421
- default: () => []
422
- },
423
- spanMethod: {
424
- type: Function
425
- },
426
- loading: {
427
- type: Boolean,
428
- default: false
429
- },
430
- bodyHeight: {
431
- type: [String, Number]
432
- },
433
- showHeader: {
434
- type: Boolean,
435
- default: true
436
- },
437
- emptyText: {
438
- type: String
439
- },
440
- defaultExpandAll: {
441
- type: Boolean,
442
- default: false
443
- },
444
- rowkeyName: {
445
- type: String
446
- },
447
- border: {
448
- type: Boolean,
449
- default: false
450
- }
451
- },
452
- emits: ["sort-change", "afterAction", "select", "select-all", "selection-change"],
453
- data() {
454
- return {
455
- editState: []
456
- };
356
+ data: null,
357
+ columns: { default: () => [] },
358
+ spanMethod: null,
359
+ loading: { type: Boolean, default: false },
360
+ bodyHeight: null,
361
+ showHeader: { type: Boolean, default: true },
362
+ emptyText: null,
363
+ defaultExpandAll: { type: Boolean, default: false },
364
+ rowkeyName: null,
365
+ border: { type: Boolean, default: false }
457
366
  },
458
- computed: {
459
- tableData() {
460
- if (this.selectionColumn) {
461
- return this.data || [];
462
- }
463
- return cloneDeep(this.data) || [];
464
- },
465
- selectionColumn() {
466
- const column = this.columns.filter((item) => item.selection);
367
+ emits: [
368
+ "sort-change",
369
+ "after-action",
370
+ "select",
371
+ "select-all",
372
+ "selection-change",
373
+ "expand-change",
374
+ "cell-click"
375
+ ],
376
+ setup(__props, { expose, emit }) {
377
+ const props = __props;
378
+ const tMagicTable = ref();
379
+ const editState = ref([]);
380
+ const tableColumnComponent = getConfig("components").tableColumn;
381
+ const selectionColumn = computed(() => {
382
+ const column = props.columns.filter((item) => item.selection);
467
383
  return column.length ? column[0] : null;
468
- },
469
- hasBorder() {
470
- return typeof this.border !== "undefined" ? this.border : true;
471
- }
472
- },
473
- methods: {
474
- sortChange(data) {
475
- this.$emit("sort-change", data);
476
- },
477
- selectHandler(selection, row) {
478
- const column = this.selectionColumn;
384
+ });
385
+ const tableData = computed(() => {
386
+ if (selectionColumn.value) {
387
+ return props.data || [];
388
+ }
389
+ return cloneDeep(props.data) || [];
390
+ });
391
+ const hasBorder = computed(() => typeof props.border !== "undefined" ? props.border : true);
392
+ const sortChange = (data) => {
393
+ emit("sort-change", data);
394
+ };
395
+ const selectHandler = (selection, row) => {
396
+ const column = selectionColumn.value;
479
397
  if (!column) {
480
398
  return;
481
399
  }
482
400
  if (column.selection === "single") ;
483
- this.$emit("select", selection, row);
484
- },
485
- selectAllHandler(selection) {
486
- this.$emit("select-all", selection);
487
- },
488
- selectionChangeHandler(selection) {
489
- this.$emit("selection-change", selection);
490
- },
491
- toggleRowSelection(row, selected) {
492
- const table = this.$refs.table;
493
- table.toggleRowSelection.bind(table)(row, selected);
494
- },
495
- toggleRowExpansion(row, expanded) {
496
- const table = this.$refs.table;
497
- table.toggleRowExpansion.bind(table)(row, expanded);
498
- },
499
- clearSelection() {
500
- const table = this.$refs.table;
501
- table.clearSelection.bind(table)();
502
- },
503
- objectSpanMethod(data) {
504
- if (typeof this.spanMethod === "function") {
505
- return this.spanMethod(data);
401
+ emit("select", selection, row);
402
+ };
403
+ const selectAllHandler = (selection) => {
404
+ emit("select-all", selection);
405
+ };
406
+ const selectionChangeHandler = (selection) => {
407
+ emit("selection-change", selection);
408
+ };
409
+ const cellClickHandler = (...args) => {
410
+ emit("cell-click", ...args);
411
+ };
412
+ const expandChange = (...args) => {
413
+ emit("expand-change", ...args);
414
+ };
415
+ const toggleRowSelection = (row, selected) => {
416
+ tMagicTable.value?.toggleRowSelection(row, selected);
417
+ };
418
+ const toggleRowExpansion = (row, expanded) => {
419
+ tMagicTable.value?.toggleRowExpansion(row, expanded);
420
+ };
421
+ const clearSelection = () => {
422
+ tMagicTable.value?.clearSelection();
423
+ };
424
+ const objectSpanMethod = (data) => {
425
+ if (typeof props.spanMethod === "function") {
426
+ return props.spanMethod(data);
506
427
  }
507
428
  return () => ({
508
429
  rowspan: 0,
509
430
  colspan: 0
510
431
  });
511
- }
432
+ };
433
+ expose({
434
+ toggleRowSelection,
435
+ toggleRowExpansion,
436
+ clearSelection
437
+ });
438
+ return (_ctx, _cache) => {
439
+ const _directive_loading = resolveDirective("loading");
440
+ return withDirectives((openBlock(), createBlock(unref(TMagicTable), {
441
+ "tooltip-effect": "dark",
442
+ class: "m-table",
443
+ ref_key: "tMagicTable",
444
+ ref: tMagicTable,
445
+ data: unref(tableData),
446
+ "show-header": __props.showHeader,
447
+ "max-height": __props.bodyHeight,
448
+ "default-expand-all": __props.defaultExpandAll,
449
+ border: unref(hasBorder),
450
+ "row-key": __props.rowkeyName || "id",
451
+ "tree-props": { children: "children" },
452
+ "empty-text": __props.emptyText || "\u6682\u65E0\u6570\u636E",
453
+ "span-method": objectSpanMethod,
454
+ onSortChange: sortChange,
455
+ onSelect: selectHandler,
456
+ onSelectAll: selectAllHandler,
457
+ onSelectionChange: selectionChangeHandler,
458
+ onCellClick: cellClickHandler,
459
+ onExpandChange: expandChange
460
+ }, {
461
+ default: withCtx(() => [
462
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (item, columnIndex) => {
463
+ return openBlock(), createElementBlock(Fragment, null, [
464
+ item.type === "expand" ? (openBlock(), createBlock(_sfc_main$3, {
465
+ config: item,
466
+ key: columnIndex
467
+ }, null, 8, ["config"])) : item.selection ? (openBlock(), createBlock(resolveDynamicComponent(unref(tableColumnComponent).component), {
468
+ width: "40",
469
+ type: "selection",
470
+ key: columnIndex,
471
+ selectable: item.selectable
472
+ }, null, 8, ["selectable"])) : item.actions ? (openBlock(), createBlock(_sfc_main$4, {
473
+ columns: __props.columns,
474
+ config: item,
475
+ "rowkey-name": __props.rowkeyName,
476
+ "edit-state": editState.value,
477
+ key: columnIndex,
478
+ onAfterAction: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("after-action"))
479
+ }, null, 8, ["columns", "config", "rowkey-name", "edit-state"])) : item.type === "popover" ? (openBlock(), createBlock(_sfc_main$2, {
480
+ key: columnIndex,
481
+ config: item
482
+ }, null, 8, ["config"])) : (openBlock(), createBlock(_sfc_main$1, {
483
+ key: columnIndex,
484
+ config: item,
485
+ "edit-state": editState.value
486
+ }, null, 8, ["config", "edit-state"]))
487
+ ], 64);
488
+ }), 256))
489
+ ]),
490
+ _: 1
491
+ }, 8, ["data", "show-header", "max-height", "default-expand-all", "border", "row-key", "empty-text"])), [
492
+ [_directive_loading, __props.loading]
493
+ ]);
494
+ };
512
495
  }
513
496
  });
514
497
 
515
498
  const Table_vue_vue_type_style_index_0_lang = '';
516
499
 
517
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
518
- const _component_expand_column = resolveComponent("expand-column");
519
- const _component_el_table_column = resolveComponent("el-table-column");
520
- const _component_actions_column = resolveComponent("actions-column");
521
- const _component_popover_column = resolveComponent("popover-column");
522
- const _component_text_column = resolveComponent("text-column");
523
- const _component_el_table = resolveComponent("el-table");
524
- const _directive_loading = resolveDirective("loading");
525
- return withDirectives((openBlock(), createBlock(_component_el_table, {
526
- "tooltip-effect": "dark",
527
- class: "m-table",
528
- ref: "table",
529
- data: _ctx.tableData,
530
- "show-header": _ctx.showHeader,
531
- "max-height": _ctx.bodyHeight,
532
- "default-expand-all": _ctx.defaultExpandAll,
533
- border: _ctx.hasBorder,
534
- "row-key": _ctx.rowkeyName || "c_id",
535
- "tree-props": { children: "children" },
536
- "empty-text": _ctx.emptyText || "\u6682\u65E0\u6570\u636E",
537
- "span-method": _ctx.objectSpanMethod,
538
- onSortChange: _ctx.sortChange,
539
- onSelect: _ctx.selectHandler,
540
- onSelectAll: _ctx.selectAllHandler,
541
- onSelectionChange: _ctx.selectionChangeHandler
542
- }, {
543
- default: withCtx(() => [
544
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.columns, (item, columnIndex) => {
545
- return openBlock(), createElementBlock(Fragment, null, [
546
- item.type === "expand" ? (openBlock(), createBlock(_component_expand_column, {
547
- config: item,
548
- key: columnIndex
549
- }, null, 8, ["config"])) : item.selection ? (openBlock(), createBlock(_component_el_table_column, {
550
- type: "selection",
551
- key: columnIndex,
552
- width: "40",
553
- selectable: item.selectable
554
- }, null, 8, ["selectable"])) : item.actions ? (openBlock(), createBlock(_component_actions_column, {
555
- columns: _ctx.columns,
556
- config: item,
557
- "rowkey-name": _ctx.rowkeyName,
558
- "edit-state": _ctx.editState,
559
- key: columnIndex,
560
- onAfterAction: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("afterAction"))
561
- }, null, 8, ["columns", "config", "rowkey-name", "edit-state"])) : item.type === "popover" ? (openBlock(), createBlock(_component_popover_column, {
562
- key: columnIndex,
563
- config: item
564
- }, null, 8, ["config"])) : (openBlock(), createBlock(_component_text_column, {
565
- key: columnIndex,
566
- config: item,
567
- "edit-state": _ctx.editState
568
- }, null, 8, ["config", "edit-state"]))
569
- ], 64);
570
- }), 256))
571
- ]),
572
- _: 1
573
- }, 8, ["data", "show-header", "max-height", "default-expand-all", "border", "row-key", "empty-text", "span-method", "onSortChange", "onSelect", "onSelectAll", "onSelectionChange"])), [
574
- [_directive_loading, _ctx.loading]
575
- ]);
576
- }
577
- const Table = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
578
-
579
- const components = [Table];
580
500
  const index = {
581
501
  install(app) {
582
- components.forEach((component) => {
583
- app.component(component.name, component);
584
- });
502
+ app.component("m-table", _sfc_main);
585
503
  }
586
504
  };
587
505
 
588
- export { Table as MagicTable, index as default };
506
+ export { _sfc_main as MagicTable, index as default };
589
507
  //# sourceMappingURL=tmagic-table.mjs.map