@tmagic/table 1.2.0-beta.1 → 1.2.0-beta.10

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,86 +1,41 @@
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, toDisplayString, resolveComponent, ref, computed, resolveDirective, resolveDynamicComponent } 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$1 = ["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
21
  emits: ["afterAction"],
34
22
  setup(__props, { emit }) {
35
23
  const props = __props;
36
24
  const display = (fuc, row) => {
37
25
  if (typeof fuc === "function") {
38
- return fuc.call(this, this, row);
26
+ return fuc(row);
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,16 +56,11 @@ 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
61
  emit("afterAction");
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;
@@ -118,28 +68,33 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
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$1)
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,39 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
174
129
  }
175
130
  });
176
131
 
177
- const _sfc_main$3 = defineComponent({
178
- components: { MForm },
132
+ const __default__$3 = defineComponent({
133
+ name: "MTableExpandColumn"
134
+ });
135
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
136
+ ...__default__$3,
179
137
  props: {
180
- config: {
181
- type: Object,
182
- default: () => ({}),
183
- required: true
184
- }
138
+ config: { default: () => ({}) }
139
+ },
140
+ setup(__props) {
141
+ return (_ctx, _cache) => {
142
+ return openBlock(), createBlock(unref(TMagicTableColumn), { type: "expand" }, {
143
+ default: withCtx((scope) => [
144
+ __props.config.table ? (openBlock(), createBlock(_sfc_main, {
145
+ key: 0,
146
+ "show-header": false,
147
+ columns: __props.config.table,
148
+ data: __props.config.prop && scope.row[__props.config.prop] || []
149
+ }, null, 8, ["columns", "data"])) : createCommentVNode("", true),
150
+ __props.config.form ? (openBlock(), createBlock(unref(MForm), {
151
+ key: 1,
152
+ config: __props.config.form,
153
+ "init-values": __props.config.values || __props.config.prop && scope.row[__props.config.prop] || {}
154
+ }, null, 8, ["config", "init-values"])) : createCommentVNode("", true)
155
+ ]),
156
+ _: 1
157
+ });
158
+ };
185
159
  }
186
160
  });
187
161
 
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
162
  const formatter = (item, row) => {
163
+ if (!item.prop)
164
+ return "";
220
165
  if (item.formatter) {
221
166
  if (item.formatter === "datetime") {
222
167
  item.formatter = (value) => datetimeFormatter(value);
@@ -231,359 +176,303 @@ const formatter = (item, row) => {
231
176
  }
232
177
  };
233
178
 
234
- const _sfc_main$2 = defineComponent({
179
+ const __default__$2 = defineComponent({
180
+ name: "MTablePopoverColumn"
181
+ });
182
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
183
+ ...__default__$2,
235
184
  props: {
236
- config: {
237
- type: Object,
238
- default: () => ({}),
239
- required: true
240
- }
185
+ config: { default: () => ({}) }
241
186
  },
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
187
+ setup(__props) {
188
+ return (_ctx, _cache) => {
189
+ return openBlock(), createBlock(unref(TMagicTableColumn), {
190
+ label: __props.config.label,
191
+ width: __props.config.width,
192
+ fixed: __props.config.fixed
264
193
  }, {
265
- reference: withCtx(() => [
266
- createVNode(_component_el_button, {
267
- text: "",
268
- type: "primary"
194
+ default: withCtx((scope) => [
195
+ __props.config.popover ? (openBlock(), createBlock(unref(TMagicPopover), {
196
+ key: 0,
197
+ placement: __props.config.popover.placement,
198
+ width: __props.config.popover.width,
199
+ trigger: __props.config.popover.trigger
269
200
  }, {
201
+ reference: withCtx(() => [
202
+ createVNode(unref(TMagicButton), {
203
+ text: "",
204
+ type: "primary"
205
+ }, {
206
+ default: withCtx(() => [
207
+ createTextVNode(toDisplayString(__props.config.text || unref(formatter)(__props.config, scope.row)), 1)
208
+ ]),
209
+ _: 2
210
+ }, 1024)
211
+ ]),
270
212
  default: withCtx(() => [
271
- createTextVNode(toDisplayString(_ctx.config.text || _ctx.formatter(_ctx.config, scope.row)), 1)
213
+ __props.config.popover.tableEmbed ? (openBlock(), createBlock(_sfc_main, {
214
+ key: 0,
215
+ "show-header": __props.config.showHeader,
216
+ columns: __props.config.table,
217
+ data: __props.config.prop && scope.row[__props.config.prop] || []
218
+ }, null, 8, ["show-header", "columns", "data"])) : createCommentVNode("", true)
272
219
  ]),
273
220
  _: 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)
221
+ }, 1032, ["placement", "width", "trigger"])) : createCommentVNode("", true)
283
222
  ]),
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
223
+ _: 1
224
+ }, 8, ["label", "width", "fixed"]);
308
225
  };
309
226
  }
310
227
  });
311
228
 
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"
229
+ const _hoisted_1 = ["innerHTML"];
230
+ const _hoisted_2 = ["href"];
231
+ const _hoisted_3 = ["src"];
232
+ const _hoisted_4 = ["href"];
233
+ const _hoisted_5 = /* @__PURE__ */ createTextVNode("\u6269\u5C55\u914D\u7F6E");
234
+ const _hoisted_6 = ["innerHTML"];
235
+ const __default__$1 = defineComponent({
236
+ name: "MTableColumn"
237
+ });
238
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
239
+ ...__default__$1,
240
+ props: {
241
+ config: { default: () => ({}) },
242
+ editState: { default: () => ({}) }
243
+ },
244
+ setup(__props) {
245
+ return (_ctx, _cache) => {
246
+ const _component_m_form_container = resolveComponent("m-form-container");
247
+ const _component_el_tooltip = resolveComponent("el-tooltip");
248
+ return openBlock(), createBlock(unref(TMagicTableColumn), {
249
+ "show-overflow-tooltip": "",
250
+ label: __props.config.label,
251
+ width: __props.config.width,
252
+ fixed: __props.config.fixed,
253
+ sortable: __props.config.sortable,
254
+ prop: __props.config.prop
375
255
  }, {
376
- content: withCtx(() => [
377
- createElementVNode("div", null, toDisplayString(_ctx.formatter(_ctx.config, scope.row)), 1)
378
- ]),
379
- default: withCtx(() => [
380
- createVNode(_component_el_button, {
256
+ default: withCtx((scope) => [
257
+ __props.config.type && __props.editState[scope.$index] ? (openBlock(), createBlock(unref(TMagicForm), {
258
+ key: 0,
259
+ "label-width": "0",
260
+ model: __props.editState[scope.$index]
261
+ }, {
262
+ default: withCtx(() => [
263
+ createVNode(_component_m_form_container, {
264
+ prop: __props.config.prop,
265
+ rules: __props.config.rules,
266
+ config: __props.config,
267
+ name: __props.config.prop,
268
+ model: __props.editState[scope.$index]
269
+ }, null, 8, ["prop", "rules", "config", "name", "model"])
270
+ ]),
271
+ _: 2
272
+ }, 1032, ["model"])) : __props.config.action === "actionLink" && __props.config.prop ? (openBlock(), createBlock(unref(TMagicButton), {
273
+ key: 1,
381
274
  text: "",
382
- type: "primary"
275
+ type: "primary",
276
+ onClick: ($event) => __props.config.handler?.(scope.row)
383
277
  }, {
384
278
  default: withCtx(() => [
385
- _hoisted_4
279
+ createElementVNode("span", {
280
+ innerHTML: unref(formatter)(__props.config, scope.row)
281
+ }, null, 8, _hoisted_1)
386
282
  ]),
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)
283
+ _: 2
284
+ }, 1032, ["onClick"])) : __props.config.action === "img" && __props.config.prop ? (openBlock(), createElementBlock("a", {
285
+ key: 2,
286
+ target: "_blank",
287
+ href: scope.row[__props.config.prop]
288
+ }, [
289
+ createElementVNode("img", {
290
+ src: scope.row[__props.config.prop],
291
+ height: "50"
292
+ }, null, 8, _hoisted_3)
293
+ ], 8, _hoisted_2)) : __props.config.action === "link" && __props.config.prop ? (openBlock(), createElementBlock("a", {
294
+ key: 3,
295
+ target: "_blank",
296
+ href: scope.row[__props.config.prop],
297
+ class: "keep-all"
298
+ }, toDisplayString(scope.row[__props.config.prop]), 9, _hoisted_4)) : __props.config.action === "tip" ? (openBlock(), createBlock(_component_el_tooltip, {
299
+ key: 4,
300
+ placement: "left"
301
+ }, {
302
+ content: withCtx(() => [
303
+ createElementVNode("div", null, toDisplayString(unref(formatter)(__props.config, scope.row)), 1)
304
+ ]),
305
+ default: withCtx(() => [
306
+ createVNode(unref(TMagicButton), {
307
+ text: "",
308
+ type: "primary"
309
+ }, {
310
+ default: withCtx(() => [
311
+ _hoisted_5
312
+ ]),
313
+ _: 1
314
+ })
315
+ ]),
316
+ _: 2
317
+ }, 1024)) : __props.config.action === "tag" && __props.config.prop ? (openBlock(), createBlock(unref(TMagicTag), {
318
+ key: 5,
319
+ type: typeof __props.config.type === "function" ? __props.config.type(scope.row[__props.config.prop], scope.row) : __props.config.type,
320
+ "close-transition": ""
321
+ }, {
322
+ default: withCtx(() => [
323
+ createTextVNode(toDisplayString(unref(formatter)(__props.config, scope.row)), 1)
324
+ ]),
325
+ _: 2
326
+ }, 1032, ["type"])) : (openBlock(), createElementBlock("div", {
327
+ key: 6,
328
+ innerHTML: unref(formatter)(__props.config, scope.row)
329
+ }, null, 8, _hoisted_6))
398
330
  ]),
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]]);
331
+ _: 1
332
+ }, 8, ["label", "width", "fixed", "sortable", "prop"]);
333
+ };
334
+ }
335
+ });
409
336
 
410
- const _sfc_main = defineComponent({
411
- name: "m-table",
412
- components: { ExpandColumn, ActionsColumn: _sfc_main$4, PopoverColumn, TextColumn },
337
+ const __default__ = defineComponent({
338
+ name: "MTable"
339
+ });
340
+ const _sfc_main = /* @__PURE__ */ defineComponent({
341
+ ...__default__,
413
342
  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
- }
343
+ data: null,
344
+ columns: { default: () => [] },
345
+ spanMethod: null,
346
+ loading: { type: Boolean, default: false },
347
+ bodyHeight: null,
348
+ showHeader: { type: Boolean, default: true },
349
+ emptyText: null,
350
+ defaultExpandAll: { type: Boolean, default: false },
351
+ rowkeyName: null,
352
+ border: { type: Boolean, default: false }
451
353
  },
452
354
  emits: ["sort-change", "afterAction", "select", "select-all", "selection-change"],
453
- data() {
454
- return {
455
- editState: []
456
- };
457
- },
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);
355
+ setup(__props, { expose, emit }) {
356
+ const props = __props;
357
+ const tMagicTable = ref();
358
+ const editState = ref([]);
359
+ const tableColumnComponent = getConfig("components").tableColumn;
360
+ const selectionColumn = computed(() => {
361
+ const column = props.columns.filter((item) => item.selection);
467
362
  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;
363
+ });
364
+ const tableData = computed(() => {
365
+ if (selectionColumn.value) {
366
+ return props.data || [];
367
+ }
368
+ return cloneDeep(props.data) || [];
369
+ });
370
+ const hasBorder = computed(() => typeof props.border !== "undefined" ? props.border : true);
371
+ const sortChange = (data) => {
372
+ emit("sort-change", data);
373
+ };
374
+ const selectHandler = (selection, row) => {
375
+ const column = selectionColumn.value;
479
376
  if (!column) {
480
377
  return;
481
378
  }
482
379
  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);
380
+ emit("select", selection, row);
381
+ };
382
+ const selectAllHandler = (selection) => {
383
+ emit("select-all", selection);
384
+ };
385
+ const selectionChangeHandler = (selection) => {
386
+ emit("selection-change", selection);
387
+ };
388
+ const toggleRowSelection = (row, selected) => {
389
+ tMagicTable.value?.toggleRowSelection(row, selected);
390
+ };
391
+ const toggleRowExpansion = (row, expanded) => {
392
+ tMagicTable.value?.toggleRowExpansion(row, expanded);
393
+ };
394
+ const clearSelection = () => {
395
+ tMagicTable.value?.clearSelection();
396
+ };
397
+ const objectSpanMethod = (data) => {
398
+ if (typeof props.spanMethod === "function") {
399
+ return props.spanMethod(data);
506
400
  }
507
401
  return () => ({
508
402
  rowspan: 0,
509
403
  colspan: 0
510
404
  });
511
- }
405
+ };
406
+ expose({
407
+ toggleRowSelection,
408
+ toggleRowExpansion,
409
+ clearSelection
410
+ });
411
+ return (_ctx, _cache) => {
412
+ const _directive_loading = resolveDirective("loading");
413
+ return withDirectives((openBlock(), createBlock(unref(TMagicTable), {
414
+ "tooltip-effect": "dark",
415
+ class: "m-table",
416
+ ref_key: "tMagicTable",
417
+ ref: tMagicTable,
418
+ data: unref(tableData),
419
+ "show-header": __props.showHeader,
420
+ "max-height": __props.bodyHeight,
421
+ "default-expand-all": __props.defaultExpandAll,
422
+ border: unref(hasBorder),
423
+ "row-key": __props.rowkeyName || "c_id",
424
+ "tree-props": { children: "children" },
425
+ "empty-text": __props.emptyText || "\u6682\u65E0\u6570\u636E",
426
+ "span-method": objectSpanMethod,
427
+ onSortChange: sortChange,
428
+ onSelect: selectHandler,
429
+ onSelectAll: selectAllHandler,
430
+ onSelectionChange: selectionChangeHandler
431
+ }, {
432
+ default: withCtx(() => [
433
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (item, columnIndex) => {
434
+ return openBlock(), createElementBlock(Fragment, null, [
435
+ item.type === "expand" ? (openBlock(), createBlock(_sfc_main$3, {
436
+ config: item,
437
+ key: columnIndex
438
+ }, null, 8, ["config"])) : item.selection ? (openBlock(), createBlock(resolveDynamicComponent(unref(tableColumnComponent).component), {
439
+ width: "40",
440
+ type: "selection",
441
+ key: columnIndex,
442
+ selectable: item.selectable
443
+ }, null, 8, ["selectable"])) : item.actions ? (openBlock(), createBlock(_sfc_main$4, {
444
+ columns: __props.columns,
445
+ config: item,
446
+ "rowkey-name": __props.rowkeyName,
447
+ "edit-state": editState.value,
448
+ key: columnIndex,
449
+ onAfterAction: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("afterAction"))
450
+ }, null, 8, ["columns", "config", "rowkey-name", "edit-state"])) : item.type === "popover" ? (openBlock(), createBlock(_sfc_main$2, {
451
+ key: columnIndex,
452
+ config: item
453
+ }, null, 8, ["config"])) : (openBlock(), createBlock(_sfc_main$1, {
454
+ key: columnIndex,
455
+ config: item,
456
+ "edit-state": editState.value
457
+ }, null, 8, ["config", "edit-state"]))
458
+ ], 64);
459
+ }), 256))
460
+ ]),
461
+ _: 1
462
+ }, 8, ["data", "show-header", "max-height", "default-expand-all", "border", "row-key", "empty-text"])), [
463
+ [_directive_loading, __props.loading]
464
+ ]);
465
+ };
512
466
  }
513
467
  });
514
468
 
515
469
  const Table_vue_vue_type_style_index_0_lang = '';
516
470
 
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
471
  const index = {
581
472
  install(app) {
582
- components.forEach((component) => {
583
- app.component(component.name, component);
584
- });
473
+ app.component("m-table", _sfc_main);
585
474
  }
586
475
  };
587
476
 
588
- export { Table as MagicTable, index as default };
477
+ export { _sfc_main as MagicTable, index as default };
589
478
  //# sourceMappingURL=tmagic-table.mjs.map