@tmagic/table 1.7.2 → 1.7.4
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/dist/tmagic-table.js +38 -33
- package/dist/tmagic-table.umd.cjs +39 -35
- package/package.json +4 -3
- package/src/ActionsColumn.vue +22 -17
- package/src/Table.vue +3 -0
- package/src/TextColumn.vue +22 -11
- package/src/schema.ts +3 -1
- package/types/index.d.ts +7 -0
package/dist/tmagic-table.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { defineComponent, createElementBlock, openBlock, Fragment, withDirectives, renderList, createBlock, unref, withCtx, createVNode, createElementVNode, vShow, createTextVNode, resolveDynamicComponent, mergeProps, toHandlers, createCommentVNode, normalizeProps, toDisplayString,
|
|
1
|
+
import { defineComponent, createElementBlock, openBlock, Fragment, withDirectives, renderList, createBlock, unref, withCtx, createVNode, createElementVNode, vShow, createTextVNode, resolveDynamicComponent, mergeProps, toHandlers, createCommentVNode, normalizeProps, toDisplayString, computed, useTemplateRef, ref, resolveDirective, h } from 'vue';
|
|
2
2
|
import { cloneDeep } from 'lodash-es';
|
|
3
|
-
import { TMagicTooltip, TMagicButton, tMagicMessage, TMagicPopover,
|
|
3
|
+
import { TMagicTooltip, TMagicButton, tMagicMessage, TMagicPopover, TMagicTag, TMagicTable } from '@tmagic/design';
|
|
4
4
|
import { MForm, datetimeFormatter } from '@tmagic/form';
|
|
5
|
+
import { setValueByKeyPath } from '@tmagic/utils';
|
|
5
6
|
|
|
6
7
|
const _hoisted_1$2 = ["innerHTML"];
|
|
7
8
|
const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
@@ -17,7 +18,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
17
18
|
row: {},
|
|
18
19
|
index: {}
|
|
19
20
|
},
|
|
20
|
-
emits: ["after-action"],
|
|
21
|
+
emits: ["after-action", "after-action-cancel"],
|
|
21
22
|
setup(__props, { emit: __emit }) {
|
|
22
23
|
const props = __props;
|
|
23
24
|
const emit = __emit;
|
|
@@ -48,7 +49,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
48
49
|
const actionHandler = async (action, row, index) => {
|
|
49
50
|
await action.before?.(row, index);
|
|
50
51
|
if (action.type === "edit") {
|
|
51
|
-
props.editState[index] = row;
|
|
52
|
+
props.editState[index] = cloneDeep(row);
|
|
52
53
|
} else {
|
|
53
54
|
await action.handler?.(row, index);
|
|
54
55
|
}
|
|
@@ -57,28 +58,30 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
57
58
|
const save = async (index, config) => {
|
|
58
59
|
const action = config.actions?.find((item) => item.type === "edit")?.action;
|
|
59
60
|
if (!action) return;
|
|
60
|
-
const data = {};
|
|
61
|
-
const row = props.editState[index];
|
|
62
|
-
props.columns.filter((item) => item.type).forEach((column) => {
|
|
63
|
-
if (column.prop) {
|
|
64
|
-
data[column.prop] = row[column.prop];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
61
|
const res = await action({
|
|
68
|
-
data
|
|
62
|
+
data: props.editState[index],
|
|
63
|
+
index
|
|
69
64
|
});
|
|
70
65
|
if (res) {
|
|
71
66
|
if (res.ret === 0) {
|
|
72
67
|
tMagicMessage.success("保存成功");
|
|
73
68
|
props.editState[index] = void 0;
|
|
74
|
-
emit("after-action");
|
|
69
|
+
emit("after-action", { index });
|
|
75
70
|
} else {
|
|
76
71
|
tMagicMessage.error(res.msg || "保存失败");
|
|
77
72
|
}
|
|
78
73
|
} else {
|
|
79
74
|
props.editState[index] = void 0;
|
|
80
|
-
emit("after-action");
|
|
75
|
+
emit("after-action", { index });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const cancel = async (index, config) => {
|
|
79
|
+
props.editState[index] = void 0;
|
|
80
|
+
const cancel2 = config.actions?.find((item) => item.type === "edit")?.cancel;
|
|
81
|
+
if (cancel2) {
|
|
82
|
+
await cancel2({ index });
|
|
81
83
|
}
|
|
84
|
+
emit("after-action-cancel", { index });
|
|
82
85
|
};
|
|
83
86
|
return (_ctx, _cache) => {
|
|
84
87
|
return openBlock(), createElementBlock(
|
|
@@ -153,9 +156,9 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
153
156
|
{
|
|
154
157
|
class: "action-btn",
|
|
155
158
|
link: "",
|
|
156
|
-
type: "
|
|
159
|
+
type: "danger",
|
|
157
160
|
size: "small",
|
|
158
|
-
onClick: _cache[1] || (_cache[1] = ($event) => __props.
|
|
161
|
+
onClick: _cache[1] || (_cache[1] = ($event) => cancel(__props.index, __props.config))
|
|
159
162
|
},
|
|
160
163
|
{
|
|
161
164
|
default: withCtx(() => [..._cache[3] || (_cache[3] = [
|
|
@@ -356,31 +359,30 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
356
359
|
index: {}
|
|
357
360
|
},
|
|
358
361
|
setup(__props) {
|
|
362
|
+
const props = __props;
|
|
363
|
+
const formChangeHandler = (v, eventData) => {
|
|
364
|
+
if (eventData.changeRecords?.length) {
|
|
365
|
+
for (const record of eventData.changeRecords) {
|
|
366
|
+
if (record.propPath) {
|
|
367
|
+
setValueByKeyPath(record.propPath, record.value, props.editState[props.index]);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
359
372
|
return (_ctx, _cache) => {
|
|
360
|
-
const _component_m_form_container = resolveComponent("m-form-container");
|
|
361
373
|
return __props.config.type === "index" ? (openBlock(), createElementBlock(
|
|
362
374
|
"div",
|
|
363
375
|
_hoisted_1,
|
|
364
376
|
toDisplayString(__props.config.pageIndex && __props.config.pageSize ? __props.config.pageIndex * __props.config.pageSize + __props.index + 1 : __props.index + 1),
|
|
365
377
|
1
|
|
366
378
|
/* TEXT */
|
|
367
|
-
)) : __props.config.type && __props.editState[__props.index] ? (openBlock(), createBlock(unref(
|
|
379
|
+
)) : (__props.config.type || __props.config.editInlineFormConfig) && __props.editState[__props.index] ? (openBlock(), createBlock(unref(MForm), {
|
|
368
380
|
key: 1,
|
|
369
381
|
"label-width": "0",
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
prop: __props.config.prop,
|
|
375
|
-
rules: __props.config.rules,
|
|
376
|
-
config: __props.config,
|
|
377
|
-
name: __props.config.prop,
|
|
378
|
-
model: __props.editState[__props.index]
|
|
379
|
-
}, null, 8, ["prop", "rules", "config", "name", "model"])
|
|
380
|
-
]),
|
|
381
|
-
_: 1
|
|
382
|
-
/* STABLE */
|
|
383
|
-
}, 8, ["model"])) : __props.config.action === "actionLink" && __props.config.prop ? (openBlock(), createBlock(unref(TMagicButton), {
|
|
382
|
+
config: __props.config.editInlineFormConfig ?? [__props.config],
|
|
383
|
+
"init-values": __props.editState[__props.index],
|
|
384
|
+
onChange: formChangeHandler
|
|
385
|
+
}, null, 8, ["config", "init-values"])) : __props.config.action === "actionLink" && __props.config.prop ? (openBlock(), createBlock(unref(TMagicButton), {
|
|
384
386
|
key: 2,
|
|
385
387
|
link: "",
|
|
386
388
|
type: "primary",
|
|
@@ -480,6 +482,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
480
482
|
emits: [
|
|
481
483
|
"sort-change",
|
|
482
484
|
"after-action",
|
|
485
|
+
"after-action-cancel",
|
|
483
486
|
"select",
|
|
484
487
|
"select-all",
|
|
485
488
|
"selection-change",
|
|
@@ -510,7 +513,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
510
513
|
index: $index,
|
|
511
514
|
rowkeyName: props.rowkeyName,
|
|
512
515
|
editState: editState.value,
|
|
513
|
-
columns: props.columns
|
|
516
|
+
columns: props.columns,
|
|
517
|
+
onAfterAction: (payload) => emit("after-action", payload),
|
|
518
|
+
onAfterActionCancel: (payload) => emit("after-action-cancel", payload)
|
|
514
519
|
});
|
|
515
520
|
}
|
|
516
521
|
if (config.type === "popover") {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@tmagic/design'), require('@tmagic/form')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vue', '@tmagic/design', '@tmagic/form'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicTable = {}, global.Vue, global.design, global.form));
|
|
5
|
-
})(this, (function (exports, vue, design, form) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@tmagic/design'), require('@tmagic/form'), require('@tmagic/utils')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vue', '@tmagic/design', '@tmagic/form', '@tmagic/utils'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicTable = {}, global.Vue, global.design, global.form, global.utils));
|
|
5
|
+
})(this, (function (exports, vue, design, form, utils) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/** Detect free variable `global` from Node.js. */
|
|
8
8
|
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|
@@ -2042,7 +2042,7 @@
|
|
|
2042
2042
|
row: {},
|
|
2043
2043
|
index: {}
|
|
2044
2044
|
},
|
|
2045
|
-
emits: ["after-action"],
|
|
2045
|
+
emits: ["after-action", "after-action-cancel"],
|
|
2046
2046
|
setup(__props, { emit: __emit }) {
|
|
2047
2047
|
const props = __props;
|
|
2048
2048
|
const emit = __emit;
|
|
@@ -2073,7 +2073,7 @@
|
|
|
2073
2073
|
const actionHandler = async (action, row, index) => {
|
|
2074
2074
|
await action.before?.(row, index);
|
|
2075
2075
|
if (action.type === "edit") {
|
|
2076
|
-
props.editState[index] = row;
|
|
2076
|
+
props.editState[index] = cloneDeep(row);
|
|
2077
2077
|
} else {
|
|
2078
2078
|
await action.handler?.(row, index);
|
|
2079
2079
|
}
|
|
@@ -2082,28 +2082,30 @@
|
|
|
2082
2082
|
const save = async (index, config) => {
|
|
2083
2083
|
const action = config.actions?.find((item) => item.type === "edit")?.action;
|
|
2084
2084
|
if (!action) return;
|
|
2085
|
-
const data = {};
|
|
2086
|
-
const row = props.editState[index];
|
|
2087
|
-
props.columns.filter((item) => item.type).forEach((column) => {
|
|
2088
|
-
if (column.prop) {
|
|
2089
|
-
data[column.prop] = row[column.prop];
|
|
2090
|
-
}
|
|
2091
|
-
});
|
|
2092
2085
|
const res = await action({
|
|
2093
|
-
data
|
|
2086
|
+
data: props.editState[index],
|
|
2087
|
+
index
|
|
2094
2088
|
});
|
|
2095
2089
|
if (res) {
|
|
2096
2090
|
if (res.ret === 0) {
|
|
2097
2091
|
design.tMagicMessage.success("保存成功");
|
|
2098
2092
|
props.editState[index] = void 0;
|
|
2099
|
-
emit("after-action");
|
|
2093
|
+
emit("after-action", { index });
|
|
2100
2094
|
} else {
|
|
2101
2095
|
design.tMagicMessage.error(res.msg || "保存失败");
|
|
2102
2096
|
}
|
|
2103
2097
|
} else {
|
|
2104
2098
|
props.editState[index] = void 0;
|
|
2105
|
-
emit("after-action");
|
|
2099
|
+
emit("after-action", { index });
|
|
2100
|
+
}
|
|
2101
|
+
};
|
|
2102
|
+
const cancel = async (index, config) => {
|
|
2103
|
+
props.editState[index] = void 0;
|
|
2104
|
+
const cancel2 = config.actions?.find((item) => item.type === "edit")?.cancel;
|
|
2105
|
+
if (cancel2) {
|
|
2106
|
+
await cancel2({ index });
|
|
2106
2107
|
}
|
|
2108
|
+
emit("after-action-cancel", { index });
|
|
2107
2109
|
};
|
|
2108
2110
|
return (_ctx, _cache) => {
|
|
2109
2111
|
return vue.openBlock(), vue.createElementBlock(
|
|
@@ -2178,9 +2180,9 @@
|
|
|
2178
2180
|
{
|
|
2179
2181
|
class: "action-btn",
|
|
2180
2182
|
link: "",
|
|
2181
|
-
type: "
|
|
2183
|
+
type: "danger",
|
|
2182
2184
|
size: "small",
|
|
2183
|
-
onClick: _cache[1] || (_cache[1] = ($event) => __props.
|
|
2185
|
+
onClick: _cache[1] || (_cache[1] = ($event) => cancel(__props.index, __props.config))
|
|
2184
2186
|
},
|
|
2185
2187
|
{
|
|
2186
2188
|
default: vue.withCtx(() => [..._cache[3] || (_cache[3] = [
|
|
@@ -2381,31 +2383,30 @@
|
|
|
2381
2383
|
index: {}
|
|
2382
2384
|
},
|
|
2383
2385
|
setup(__props) {
|
|
2386
|
+
const props = __props;
|
|
2387
|
+
const formChangeHandler = (v, eventData) => {
|
|
2388
|
+
if (eventData.changeRecords?.length) {
|
|
2389
|
+
for (const record of eventData.changeRecords) {
|
|
2390
|
+
if (record.propPath) {
|
|
2391
|
+
utils.setValueByKeyPath(record.propPath, record.value, props.editState[props.index]);
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2384
2396
|
return (_ctx, _cache) => {
|
|
2385
|
-
const _component_m_form_container = vue.resolveComponent("m-form-container");
|
|
2386
2397
|
return __props.config.type === "index" ? (vue.openBlock(), vue.createElementBlock(
|
|
2387
2398
|
"div",
|
|
2388
2399
|
_hoisted_1,
|
|
2389
2400
|
vue.toDisplayString(__props.config.pageIndex && __props.config.pageSize ? __props.config.pageIndex * __props.config.pageSize + __props.index + 1 : __props.index + 1),
|
|
2390
2401
|
1
|
|
2391
2402
|
/* TEXT */
|
|
2392
|
-
)) : __props.config.type && __props.editState[__props.index] ? (vue.openBlock(), vue.createBlock(vue.unref(
|
|
2403
|
+
)) : (__props.config.type || __props.config.editInlineFormConfig) && __props.editState[__props.index] ? (vue.openBlock(), vue.createBlock(vue.unref(form.MForm), {
|
|
2393
2404
|
key: 1,
|
|
2394
2405
|
"label-width": "0",
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
prop: __props.config.prop,
|
|
2400
|
-
rules: __props.config.rules,
|
|
2401
|
-
config: __props.config,
|
|
2402
|
-
name: __props.config.prop,
|
|
2403
|
-
model: __props.editState[__props.index]
|
|
2404
|
-
}, null, 8, ["prop", "rules", "config", "name", "model"])
|
|
2405
|
-
]),
|
|
2406
|
-
_: 1
|
|
2407
|
-
/* STABLE */
|
|
2408
|
-
}, 8, ["model"])) : __props.config.action === "actionLink" && __props.config.prop ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
|
|
2406
|
+
config: __props.config.editInlineFormConfig ?? [__props.config],
|
|
2407
|
+
"init-values": __props.editState[__props.index],
|
|
2408
|
+
onChange: formChangeHandler
|
|
2409
|
+
}, null, 8, ["config", "init-values"])) : __props.config.action === "actionLink" && __props.config.prop ? (vue.openBlock(), vue.createBlock(vue.unref(design.TMagicButton), {
|
|
2409
2410
|
key: 2,
|
|
2410
2411
|
link: "",
|
|
2411
2412
|
type: "primary",
|
|
@@ -2505,6 +2506,7 @@
|
|
|
2505
2506
|
emits: [
|
|
2506
2507
|
"sort-change",
|
|
2507
2508
|
"after-action",
|
|
2509
|
+
"after-action-cancel",
|
|
2508
2510
|
"select",
|
|
2509
2511
|
"select-all",
|
|
2510
2512
|
"selection-change",
|
|
@@ -2535,7 +2537,9 @@
|
|
|
2535
2537
|
index: $index,
|
|
2536
2538
|
rowkeyName: props.rowkeyName,
|
|
2537
2539
|
editState: editState.value,
|
|
2538
|
-
columns: props.columns
|
|
2540
|
+
columns: props.columns,
|
|
2541
|
+
onAfterAction: (payload) => emit("after-action", payload),
|
|
2542
|
+
onAfterActionCancel: (payload) => emit("after-action-cancel", payload)
|
|
2539
2543
|
});
|
|
2540
2544
|
}
|
|
2541
2545
|
if (config.type === "popover") {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.7.
|
|
2
|
+
"version": "1.7.4",
|
|
3
3
|
"name": "@tmagic/table",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -44,8 +44,9 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"vue": "^3.5.24",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
|
-
"@tmagic/
|
|
48
|
-
"@tmagic/
|
|
47
|
+
"@tmagic/form": "1.7.4",
|
|
48
|
+
"@tmagic/utils": "1.7.4",
|
|
49
|
+
"@tmagic/design": "1.7.4"
|
|
49
50
|
},
|
|
50
51
|
"peerDependenciesMeta": {
|
|
51
52
|
"typescript": {
|
package/src/ActionsColumn.vue
CHANGED
|
@@ -32,14 +32,16 @@
|
|
|
32
32
|
class="action-btn"
|
|
33
33
|
v-show="editState[index]"
|
|
34
34
|
link
|
|
35
|
-
type="
|
|
35
|
+
type="danger"
|
|
36
36
|
size="small"
|
|
37
|
-
@click="
|
|
37
|
+
@click="cancel(index, config)"
|
|
38
38
|
>取消</TMagicButton
|
|
39
39
|
>
|
|
40
40
|
</template>
|
|
41
41
|
|
|
42
42
|
<script lang="ts" setup>
|
|
43
|
+
import { cloneDeep } from 'lodash-es';
|
|
44
|
+
|
|
43
45
|
import { TMagicButton, tMagicMessage, TMagicTooltip } from '@tmagic/design';
|
|
44
46
|
|
|
45
47
|
import { ColumnActionConfig, ColumnConfig } from './schema';
|
|
@@ -65,7 +67,10 @@ const props = withDefaults(
|
|
|
65
67
|
},
|
|
66
68
|
);
|
|
67
69
|
|
|
68
|
-
const emit = defineEmits
|
|
70
|
+
const emit = defineEmits<{
|
|
71
|
+
'after-action': [{ index: number }];
|
|
72
|
+
'after-action-cancel': [{ index: number }];
|
|
73
|
+
}>();
|
|
69
74
|
|
|
70
75
|
const display = (fuc: boolean | Function | undefined, row: any) => {
|
|
71
76
|
if (typeof fuc === 'function') {
|
|
@@ -97,7 +102,7 @@ const formatter = (fuc: string | Function | undefined, row: any) => {
|
|
|
97
102
|
const actionHandler = async (action: ColumnActionConfig, row: any, index: number) => {
|
|
98
103
|
await action.before?.(row, index);
|
|
99
104
|
if (action.type === 'edit') {
|
|
100
|
-
props.editState[index] = row;
|
|
105
|
+
props.editState[index] = cloneDeep(row);
|
|
101
106
|
} else {
|
|
102
107
|
await action.handler?.(row, index);
|
|
103
108
|
}
|
|
@@ -108,31 +113,31 @@ const save = async (index: number, config: ColumnConfig) => {
|
|
|
108
113
|
const action = config.actions?.find((item) => item.type === 'edit')?.action;
|
|
109
114
|
if (!action) return;
|
|
110
115
|
|
|
111
|
-
const data: any = {};
|
|
112
|
-
const row = props.editState[index];
|
|
113
|
-
props.columns
|
|
114
|
-
.filter((item) => item.type)
|
|
115
|
-
.forEach((column) => {
|
|
116
|
-
if (column.prop) {
|
|
117
|
-
data[column.prop] = row[column.prop];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
116
|
const res: any = await action({
|
|
122
|
-
data,
|
|
117
|
+
data: props.editState[index],
|
|
118
|
+
index,
|
|
123
119
|
});
|
|
124
120
|
|
|
125
121
|
if (res) {
|
|
126
122
|
if (res.ret === 0) {
|
|
127
123
|
tMagicMessage.success('保存成功');
|
|
128
124
|
props.editState[index] = undefined;
|
|
129
|
-
emit('after-action');
|
|
125
|
+
emit('after-action', { index });
|
|
130
126
|
} else {
|
|
131
127
|
tMagicMessage.error(res.msg || '保存失败');
|
|
132
128
|
}
|
|
133
129
|
} else {
|
|
134
130
|
props.editState[index] = undefined;
|
|
135
|
-
emit('after-action');
|
|
131
|
+
emit('after-action', { index });
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const cancel = async (index: number, config: ColumnConfig) => {
|
|
136
|
+
props.editState[index] = undefined;
|
|
137
|
+
const cancel = config.actions?.find((item) => item.type === 'edit')?.cancel;
|
|
138
|
+
if (cancel) {
|
|
139
|
+
await cancel({ index });
|
|
136
140
|
}
|
|
141
|
+
emit('after-action-cancel', { index });
|
|
137
142
|
};
|
|
138
143
|
</script>
|
package/src/Table.vue
CHANGED
|
@@ -73,6 +73,7 @@ const props = withDefaults(
|
|
|
73
73
|
const emit = defineEmits([
|
|
74
74
|
'sort-change',
|
|
75
75
|
'after-action',
|
|
76
|
+
'after-action-cancel',
|
|
76
77
|
'select',
|
|
77
78
|
'select-all',
|
|
78
79
|
'selection-change',
|
|
@@ -102,6 +103,8 @@ const cellRender = (config: ColumnConfig, { row = {}, $index }: any) => {
|
|
|
102
103
|
rowkeyName: props.rowkeyName,
|
|
103
104
|
editState: editState.value,
|
|
104
105
|
columns: props.columns,
|
|
106
|
+
onAfterAction: (payload: { index: number }) => emit('after-action', payload),
|
|
107
|
+
onAfterActionCancel: (payload: { index: number }) => emit('after-action-cancel', payload),
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
110
|
if (config.type === 'popover') {
|
package/src/TextColumn.vue
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
<div v-if="config.type === 'index'">
|
|
3
3
|
{{ config.pageIndex && config.pageSize ? config.pageIndex * config.pageSize + index + 1 : index + 1 }}
|
|
4
4
|
</div>
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
></m-form-container>
|
|
13
|
-
</TMagicForm>
|
|
5
|
+
<MForm
|
|
6
|
+
v-else-if="(config.type || config.editInlineFormConfig) && editState[index]"
|
|
7
|
+
label-width="0"
|
|
8
|
+
:config="config.editInlineFormConfig ?? [config]"
|
|
9
|
+
:init-values="editState[index]"
|
|
10
|
+
@change="formChangeHandler"
|
|
11
|
+
></MForm>
|
|
14
12
|
|
|
15
13
|
<TMagicButton
|
|
16
14
|
v-else-if="config.action === 'actionLink' && config.prop"
|
|
@@ -46,7 +44,10 @@
|
|
|
46
44
|
</template>
|
|
47
45
|
|
|
48
46
|
<script lang="ts" setup>
|
|
49
|
-
import { TMagicButton,
|
|
47
|
+
import { TMagicButton, TMagicTag, TMagicTooltip } from '@tmagic/design';
|
|
48
|
+
import { type ContainerChangeEventData, MForm } from '@tmagic/form';
|
|
49
|
+
import type { FormValue } from '@tmagic/form-schema';
|
|
50
|
+
import { setValueByKeyPath } from '@tmagic/utils';
|
|
50
51
|
|
|
51
52
|
import { ColumnConfig } from './schema';
|
|
52
53
|
import { formatter } from './utils';
|
|
@@ -55,7 +56,7 @@ defineOptions({
|
|
|
55
56
|
name: 'MTableColumn',
|
|
56
57
|
});
|
|
57
58
|
|
|
58
|
-
withDefaults(
|
|
59
|
+
const props = withDefaults(
|
|
59
60
|
defineProps<{
|
|
60
61
|
config: ColumnConfig;
|
|
61
62
|
editState?: any;
|
|
@@ -67,4 +68,14 @@ withDefaults(
|
|
|
67
68
|
editState: () => ({}),
|
|
68
69
|
},
|
|
69
70
|
);
|
|
71
|
+
|
|
72
|
+
const formChangeHandler = (v: FormValue, eventData: ContainerChangeEventData) => {
|
|
73
|
+
if (eventData.changeRecords?.length) {
|
|
74
|
+
for (const record of eventData.changeRecords) {
|
|
75
|
+
if (record.propPath) {
|
|
76
|
+
setValueByKeyPath(record.propPath, record.value, props.editState[props.index]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
70
81
|
</script>
|
package/src/schema.ts
CHANGED
|
@@ -31,7 +31,8 @@ export interface ColumnActionConfig {
|
|
|
31
31
|
handler?: (row: any, index: number) => Promise<any> | any;
|
|
32
32
|
before?: (row: any, index: number) => Promise<void> | void;
|
|
33
33
|
after?: (row: any, index: number) => Promise<void> | void;
|
|
34
|
-
action?: (data: { data: any }) => Promise<void> | void;
|
|
34
|
+
action?: (data: { data: any; index: number }) => Promise<void> | void;
|
|
35
|
+
cancel?: (data: { index: number }) => Promise<void> | void;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export interface ColumnConfig<T = any> {
|
|
@@ -52,6 +53,7 @@ export interface ColumnConfig<T = any> {
|
|
|
52
53
|
name?: string;
|
|
53
54
|
showHeader?: boolean;
|
|
54
55
|
table?: ColumnConfig[];
|
|
56
|
+
editInlineFormConfig?: FormConfig;
|
|
55
57
|
formatter?: 'datetime' | ((item: any, row: T, data: { index: number }) => any);
|
|
56
58
|
popover?: {
|
|
57
59
|
placement?:
|
package/types/index.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ interface ColumnActionConfig {
|
|
|
17
17
|
after?: (row: any, index: number) => Promise<void> | void;
|
|
18
18
|
action?: (data: {
|
|
19
19
|
data: any;
|
|
20
|
+
index: number;
|
|
21
|
+
}) => Promise<void> | void;
|
|
22
|
+
cancel?: (data: {
|
|
23
|
+
index: number;
|
|
20
24
|
}) => Promise<void> | void;
|
|
21
25
|
}
|
|
22
26
|
interface ColumnConfig<T = any> {
|
|
@@ -37,6 +41,7 @@ interface ColumnConfig<T = any> {
|
|
|
37
41
|
name?: string;
|
|
38
42
|
showHeader?: boolean;
|
|
39
43
|
table?: ColumnConfig[];
|
|
44
|
+
editInlineFormConfig?: FormConfig;
|
|
40
45
|
formatter?: 'datetime' | ((item: any, row: T, data: {
|
|
41
46
|
index: number;
|
|
42
47
|
}) => any);
|
|
@@ -95,6 +100,7 @@ declare const __VLS_export: _vue_runtime_core.DefineComponent<__VLS_Props, {
|
|
|
95
100
|
"expand-change": (...args: any[]) => void;
|
|
96
101
|
"cell-click": (...args: any[]) => void;
|
|
97
102
|
"after-action": (...args: any[]) => void;
|
|
103
|
+
"after-action-cancel": (...args: any[]) => void;
|
|
98
104
|
"select-all": (...args: any[]) => void;
|
|
99
105
|
"selection-change": (...args: any[]) => void;
|
|
100
106
|
}, string, _vue_runtime_core.PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
@@ -103,6 +109,7 @@ declare const __VLS_export: _vue_runtime_core.DefineComponent<__VLS_Props, {
|
|
|
103
109
|
"onExpand-change"?: ((...args: any[]) => any) | undefined;
|
|
104
110
|
"onCell-click"?: ((...args: any[]) => any) | undefined;
|
|
105
111
|
"onAfter-action"?: ((...args: any[]) => any) | undefined;
|
|
112
|
+
"onAfter-action-cancel"?: ((...args: any[]) => any) | undefined;
|
|
106
113
|
"onSelect-all"?: ((...args: any[]) => any) | undefined;
|
|
107
114
|
"onSelection-change"?: ((...args: any[]) => any) | undefined;
|
|
108
115
|
}>, {
|