@tmagic/table 1.8.0-manmanyu.21 → 1.8.0-manmanyu.23

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,12 +1,13 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("@tmagic/design"), require("@tmagic/form"), require("@tmagic/utils")) : typeof define === "function" && define.amd ? define([
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("@tmagic/design"), require("@element-plus/icons-vue"), require("@tmagic/form"), require("@tmagic/utils")) : typeof define === "function" && define.amd ? define([
3
3
  "exports",
4
4
  "vue",
5
5
  "@tmagic/design",
6
+ "@element-plus/icons-vue",
6
7
  "@tmagic/form",
7
8
  "@tmagic/utils"
8
- ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.TMagicTable = {}, global.Vue, global._tmagic_design, global._tmagic_form, global._tmagic_utils));
9
- })(this, function(exports, vue, _tmagic_design, _tmagic_form, _tmagic_utils) {
9
+ ], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.TMagicTable = {}, global.Vue, global._tmagic_design, global._element_plus_icons_vue, global._tmagic_form, global._tmagic_utils));
10
+ })(this, function(exports, vue, _tmagic_design, _element_plus_icons_vue, _tmagic_form, _tmagic_utils) {
10
11
  Object.defineProperties(exports, {
11
12
  __esModule: { value: true },
12
13
  [Symbol.toStringTag]: { value: "Module" }
@@ -1919,8 +1920,124 @@
1919
1920
  return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
1920
1921
  }
1921
1922
  //#endregion
1923
+ //#region packages/table/src/actionHelpers.ts
1924
+ var display = (fuc, row) => {
1925
+ if (typeof fuc === "function") return fuc(row);
1926
+ if (typeof fuc === "boolean") return fuc;
1927
+ return true;
1928
+ };
1929
+ var disabled = (fuc, row) => {
1930
+ if (typeof fuc === "function") return fuc(row);
1931
+ if (typeof fuc === "boolean") return fuc;
1932
+ return false;
1933
+ };
1934
+ var formatActionText = (fuc, row) => {
1935
+ if (typeof fuc === "function") return fuc(row);
1936
+ return fuc;
1937
+ };
1938
+ //#endregion
1939
+ //#region packages/table/src/ActionButton.vue?vue&type=script&setup=true&lang.ts
1940
+ var _hoisted_1$3 = ["innerHTML"];
1941
+ //#endregion
1942
+ //#region packages/table/src/ActionButton.vue
1943
+ var ActionButton_default = /* @__PURE__ */ (0, vue.defineComponent)({
1944
+ name: "MTableActionButton",
1945
+ __name: "ActionButton",
1946
+ props: {
1947
+ action: {},
1948
+ row: {},
1949
+ index: {},
1950
+ btnClass: { default: "action-btn" },
1951
+ visible: {
1952
+ type: Boolean,
1953
+ default: true
1954
+ }
1955
+ },
1956
+ emits: ["click"],
1957
+ setup(__props, { emit: __emit }) {
1958
+ const props = __props;
1959
+ const emit = __emit;
1960
+ const onClick = () => emit("click", props.action, props.row, props.index);
1961
+ return (_ctx, _cache) => {
1962
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicTooltip), {
1963
+ placement: __props.action.tooltipPlacement || "top",
1964
+ disabled: !Boolean(__props.action.tooltip),
1965
+ content: __props.action.tooltip
1966
+ }, {
1967
+ default: (0, vue.withCtx)(() => [(0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
1968
+ class: (0, vue.normalizeClass)(__props.btnClass),
1969
+ link: "",
1970
+ size: "small",
1971
+ type: __props.action.buttonType || "primary",
1972
+ icon: __props.action.icon,
1973
+ disabled: (0, vue.unref)(disabled)(__props.action.disabled, __props.row),
1974
+ onClick
1975
+ }, {
1976
+ default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("span", { innerHTML: (0, vue.unref)(formatActionText)(__props.action.text, __props.row) }, null, 8, _hoisted_1$3)]),
1977
+ _: 1
1978
+ }, 8, [
1979
+ "class",
1980
+ "type",
1981
+ "icon",
1982
+ "disabled"
1983
+ ]), [[vue.vShow, __props.visible]])]),
1984
+ _: 1
1985
+ }, 8, [
1986
+ "placement",
1987
+ "disabled",
1988
+ "content"
1989
+ ]);
1990
+ };
1991
+ }
1992
+ });
1993
+ //#endregion
1994
+ //#region packages/table/src/ActionPopconfirm.vue
1995
+ var ActionPopconfirm_default = /* @__PURE__ */ (0, vue.defineComponent)({
1996
+ name: "MTableActionPopconfirm",
1997
+ __name: "ActionPopconfirm",
1998
+ props: {
1999
+ action: {},
2000
+ row: {},
2001
+ index: {},
2002
+ btnClass: { default: "action-btn" },
2003
+ visible: {
2004
+ type: Boolean,
2005
+ default: true
2006
+ }
2007
+ },
2008
+ emits: ["confirm"],
2009
+ setup(__props, { emit: __emit }) {
2010
+ const props = __props;
2011
+ const emit = __emit;
2012
+ const onConfirm = () => emit("confirm", props.action, props.row, props.index);
2013
+ return (_ctx, _cache) => {
2014
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicPopconfirm), {
2015
+ placement: "top",
2016
+ width: __props.action.popconfirmWidth,
2017
+ title: (0, vue.unref)(formatActionText)(__props.action.confirmText, __props.row) || "确定执行此操作?",
2018
+ onConfirm
2019
+ }, {
2020
+ reference: (0, vue.withCtx)(() => [(0, vue.createVNode)(ActionButton_default, {
2021
+ action: __props.action,
2022
+ row: __props.row,
2023
+ index: __props.index,
2024
+ "btn-class": __props.btnClass,
2025
+ visible: __props.visible
2026
+ }, null, 8, [
2027
+ "action",
2028
+ "row",
2029
+ "index",
2030
+ "btn-class",
2031
+ "visible"
2032
+ ])]),
2033
+ _: 1
2034
+ }, 8, ["width", "title"]);
2035
+ };
2036
+ }
2037
+ });
2038
+ //#endregion
1922
2039
  //#region packages/table/src/ActionsColumn.vue?vue&type=script&setup=true&lang.ts
1923
- var _hoisted_1$2 = ["innerHTML"];
2040
+ var _hoisted_1$2 = { class: "sub-actions" };
1924
2041
  //#endregion
1925
2042
  //#region packages/table/src/ActionsColumn.vue
1926
2043
  var ActionsColumn_default = /* @__PURE__ */ (0, vue.defineComponent)({
@@ -1935,23 +2052,13 @@
1935
2052
  index: {}
1936
2053
  },
1937
2054
  emits: ["after-action", "after-action-cancel"],
1938
- setup(__props, { emit: __emit }) {
2055
+ setup(__props, { expose: __expose, emit: __emit }) {
1939
2056
  const props = __props;
1940
- const emit = __emit;
1941
- const display = (fuc, row) => {
1942
- if (typeof fuc === "function") return fuc(row);
1943
- if (typeof fuc === "boolean") return fuc;
1944
- return true;
1945
- };
1946
- const disabled = (fuc, row) => {
1947
- if (typeof fuc === "function") return fuc(row);
1948
- if (typeof fuc === "boolean") return fuc;
1949
- return false;
1950
- };
1951
- const formatter = (fuc, row) => {
1952
- if (typeof fuc === "function") return fuc(row);
1953
- return fuc;
2057
+ const popoverVisible = (0, vue.ref)(false);
2058
+ const togglePopover = () => {
2059
+ popoverVisible.value = !popoverVisible.value;
1954
2060
  };
2061
+ const emit = __emit;
1955
2062
  const actionHandler = async (action, row, index) => {
1956
2063
  await action.before?.(row, index);
1957
2064
  if (action.type === "edit") props.editState[index] = cloneDeep(row);
@@ -1981,47 +2088,102 @@
1981
2088
  if (cancel) await cancel({ index });
1982
2089
  emit("after-action-cancel", { index });
1983
2090
  };
2091
+ __expose({
2092
+ actionHandler,
2093
+ save,
2094
+ cancel
2095
+ });
1984
2096
  return (_ctx, _cache) => {
1985
2097
  return (0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, null, [
1986
2098
  ((0, vue.openBlock)(true), (0, vue.createElementBlock)(vue.Fragment, null, (0, vue.renderList)(__props.config.actions, (action, actionIndex) => {
1987
- return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicTooltip), {
1988
- placement: action.tooltipPlacement || "top",
1989
- key: actionIndex,
1990
- disabled: !Boolean(action.tooltip),
1991
- content: action.tooltip
2099
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, { key: actionIndex }, [action.popconfirm ? ((0, vue.openBlock)(), (0, vue.createBlock)(ActionPopconfirm_default, {
2100
+ key: 0,
2101
+ action,
2102
+ row: __props.row,
2103
+ index: __props.index,
2104
+ visible: (0, vue.unref)(display)(action.display, __props.row) && !__props.editState[__props.index],
2105
+ onConfirm: actionHandler
2106
+ }, null, 8, [
2107
+ "action",
2108
+ "row",
2109
+ "index",
2110
+ "visible"
2111
+ ])) : action.type === "sub-actions" ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_design.TMagicPopover), {
2112
+ key: 1,
2113
+ visible: popoverVisible.value,
2114
+ "onUpdate:visible": _cache[0] || (_cache[0] = ($event) => popoverVisible.value = $event),
2115
+ trigger: "click",
2116
+ placement: action.subActionConfig?.placement || "bottom",
2117
+ width: action.subActionConfig?.popoverWidth,
2118
+ "popper-class": action.subActionConfig?.popoverClass,
2119
+ "destroy-on-close": action.subActionConfig?.popoverDestroyOnClose
1992
2120
  }, {
1993
- default: (0, vue.withCtx)(() => [(0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
2121
+ reference: (0, vue.withCtx)(() => [(0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
1994
2122
  class: "action-btn",
1995
2123
  link: "",
1996
2124
  size: "small",
1997
2125
  type: action.buttonType || "primary",
1998
- icon: action.icon,
1999
- disabled: disabled(action.disabled, __props.row),
2000
- onClick: ($event) => actionHandler(action, __props.row, __props.index)
2001
- }, {
2002
- default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("span", { innerHTML: formatter(action.text, __props.row) }, null, 8, _hoisted_1$2)]),
2003
- _: 2
2004
- }, 1032, [
2005
- "type",
2006
- "icon",
2007
- "disabled",
2008
- "onClick"
2009
- ]), [[vue.vShow, display(action.display, __props.row) && !__props.editState[__props.index]]])]),
2126
+ icon: popoverVisible.value ? (0, vue.unref)(_element_plus_icons_vue.ArrowDown) : (0, vue.unref)(_element_plus_icons_vue.ArrowRight),
2127
+ onClick: (0, vue.withModifiers)(togglePopover, ["stop"])
2128
+ }, null, 8, ["type", "icon"]), [[vue.vShow, action.subActionConfig?.items?.length && (0, vue.unref)(display)(action.display, __props.row) && !__props.editState[__props.index]]])]),
2129
+ default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("div", _hoisted_1$2, [((0, vue.openBlock)(true), (0, vue.createElementBlock)(vue.Fragment, null, (0, vue.renderList)(action.subActionConfig?.items, (subAction, subIndex) => {
2130
+ return (0, vue.openBlock)(), (0, vue.createElementBlock)(vue.Fragment, { key: subIndex }, [subAction.popconfirm ? ((0, vue.openBlock)(), (0, vue.createBlock)(ActionPopconfirm_default, {
2131
+ key: 0,
2132
+ action: subAction,
2133
+ row: __props.row,
2134
+ index: __props.index,
2135
+ "btn-class": "sub-action-btn",
2136
+ visible: (0, vue.unref)(display)(subAction.display, __props.row),
2137
+ onConfirm: actionHandler
2138
+ }, null, 8, [
2139
+ "action",
2140
+ "row",
2141
+ "index",
2142
+ "visible"
2143
+ ])) : ((0, vue.openBlock)(), (0, vue.createBlock)(ActionButton_default, {
2144
+ key: 1,
2145
+ action: subAction,
2146
+ row: __props.row,
2147
+ index: __props.index,
2148
+ "btn-class": "sub-action-btn",
2149
+ visible: (0, vue.unref)(display)(subAction.display, __props.row),
2150
+ onClick: actionHandler
2151
+ }, null, 8, [
2152
+ "action",
2153
+ "row",
2154
+ "index",
2155
+ "visible"
2156
+ ]))], 64);
2157
+ }), 128))])]),
2010
2158
  _: 2
2011
2159
  }, 1032, [
2160
+ "visible",
2012
2161
  "placement",
2013
- "disabled",
2014
- "content"
2015
- ]);
2162
+ "width",
2163
+ "popper-class",
2164
+ "destroy-on-close"
2165
+ ])) : ((0, vue.openBlock)(), (0, vue.createBlock)(ActionButton_default, {
2166
+ key: 2,
2167
+ action,
2168
+ row: __props.row,
2169
+ index: __props.index,
2170
+ visible: (0, vue.unref)(display)(action.display, __props.row) && !__props.editState[__props.index],
2171
+ onClick: actionHandler
2172
+ }, null, 8, [
2173
+ "action",
2174
+ "row",
2175
+ "index",
2176
+ "visible"
2177
+ ]))], 64);
2016
2178
  }), 128)),
2017
2179
  (0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
2018
2180
  class: "action-btn",
2019
2181
  link: "",
2020
2182
  type: "primary",
2021
2183
  size: "small",
2022
- onClick: _cache[0] || (_cache[0] = ($event) => save(__props.index, __props.config))
2184
+ onClick: _cache[1] || (_cache[1] = ($event) => save(__props.index, __props.config))
2023
2185
  }, {
2024
- default: (0, vue.withCtx)(() => [..._cache[2] || (_cache[2] = [(0, vue.createTextVNode)("保存", -1)])]),
2186
+ default: (0, vue.withCtx)(() => [..._cache[3] || (_cache[3] = [(0, vue.createTextVNode)("保存", -1)])]),
2025
2187
  _: 1
2026
2188
  }, 512), [[vue.vShow, __props.editState[__props.index]]]),
2027
2189
  (0, vue.withDirectives)((0, vue.createVNode)((0, vue.unref)(_tmagic_design.TMagicButton), {
@@ -2029,9 +2191,9 @@
2029
2191
  link: "",
2030
2192
  type: "danger",
2031
2193
  size: "small",
2032
- onClick: _cache[1] || (_cache[1] = ($event) => cancel(__props.index, __props.config))
2194
+ onClick: _cache[2] || (_cache[2] = ($event) => cancel(__props.index, __props.config))
2033
2195
  }, {
2034
- default: (0, vue.withCtx)(() => [..._cache[3] || (_cache[3] = [(0, vue.createTextVNode)("取消", -1)])]),
2196
+ default: (0, vue.withCtx)(() => [..._cache[4] || (_cache[4] = [(0, vue.createTextVNode)("取消", -1)])]),
2035
2197
  _: 1
2036
2198
  }, 512), [[vue.vShow, __props.editState[__props.index]]])
2037
2199
  ], 64);
@@ -2039,6 +2201,16 @@
2039
2201
  }
2040
2202
  });
2041
2203
  //#endregion
2204
+ //#region packages/table/src/componentHelpers.ts
2205
+ var resolveComponentProps = (config, row, index) => {
2206
+ if (typeof config.props === "function") return config.props(row, index) || {};
2207
+ return config.props || {};
2208
+ };
2209
+ var resolveComponentListeners = (config, row, index) => {
2210
+ if (typeof config.listeners === "function") return config.listeners(row, index) || {};
2211
+ return config.listeners || {};
2212
+ };
2213
+ //#endregion
2042
2214
  //#region packages/table/src/ComponentColumn.vue
2043
2215
  var ComponentColumn_default = /* @__PURE__ */ (0, vue.defineComponent)({
2044
2216
  name: "MTableColumn",
@@ -2049,17 +2221,8 @@
2049
2221
  index: {}
2050
2222
  },
2051
2223
  setup(__props) {
2052
- const props = __props;
2053
- const componentProps = (row, index) => {
2054
- if (typeof props.config.props === "function") return props.config.props(row, index) || {};
2055
- return props.config.props || {};
2056
- };
2057
- const componentListeners = (row, index) => {
2058
- if (typeof props.config.listeners === "function") return props.config.listeners(row, index) || {};
2059
- return props.config.listeners || {};
2060
- };
2061
2224
  return (_ctx, _cache) => {
2062
- return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(__props.config.component), (0, vue.mergeProps)(componentProps(__props.row, __props.index), (0, vue.toHandlers)(componentListeners(__props.row, __props.index))), null, 16);
2225
+ return (0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(__props.config.component), (0, vue.mergeProps)((0, vue.unref)(resolveComponentProps)(__props.config, __props.row, __props.index), (0, vue.toHandlers)((0, vue.unref)(resolveComponentListeners)(__props.config, __props.row, __props.index))), null, 16);
2063
2226
  };
2064
2227
  }
2065
2228
  });
@@ -2165,6 +2328,13 @@
2165
2328
  }
2166
2329
  });
2167
2330
  //#endregion
2331
+ //#region packages/table/src/formHelpers.ts
2332
+ var applyInlineEditChange = (target, eventData) => {
2333
+ if (eventData.changeRecords?.length) {
2334
+ for (const record of eventData.changeRecords) if (record.propPath) (0, _tmagic_utils.setValueByKeyPath)(record.propPath, record.value, target);
2335
+ }
2336
+ };
2337
+ //#endregion
2168
2338
  //#region packages/table/src/TextColumn.vue?vue&type=script&setup=true&lang.ts
2169
2339
  var _hoisted_1 = { key: 0 };
2170
2340
  var _hoisted_2 = ["innerHTML"];
@@ -2186,9 +2356,7 @@
2186
2356
  setup(__props) {
2187
2357
  const props = __props;
2188
2358
  const formChangeHandler = (v, eventData) => {
2189
- if (eventData.changeRecords?.length) {
2190
- for (const record of eventData.changeRecords) if (record.propPath) (0, _tmagic_utils.setValueByKeyPath)(record.propPath, record.value, props.editState[props.index]);
2191
- }
2359
+ applyInlineEditChange(props.editState[props.index], eventData);
2192
2360
  };
2193
2361
  return (_ctx, _cache) => {
2194
2362
  return __props.config.type === "index" ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1, (0, vue.toDisplayString)(__props.config.pageIndex && __props.config.pageSize ? __props.config.pageIndex * __props.config.pageSize + __props.index + 1 : __props.index + 1), 1)) : (__props.config.type || __props.config.editInlineFormConfig) && __props.editState[__props.index] ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_tmagic_form.MForm), {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.0-manmanyu.21",
2
+ "version": "1.8.0-manmanyu.23",
3
3
  "name": "@tmagic/table",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -37,6 +37,7 @@
37
37
  "url": "https://github.com/Tencent/tmagic-editor.git"
38
38
  },
39
39
  "dependencies": {
40
+ "@element-plus/icons-vue": "^2.3.2",
40
41
  "lodash-es": "^4.17.21"
41
42
  },
42
43
  "devDependencies": {
@@ -46,9 +47,9 @@
46
47
  "peerDependencies": {
47
48
  "vue": "^3.5.38",
48
49
  "typescript": "^6.0.3",
49
- "@tmagic/design": "1.8.0-manmanyu.21",
50
- "@tmagic/form": "1.8.0-manmanyu.21",
51
- "@tmagic/utils": "1.8.0-manmanyu.21"
50
+ "@tmagic/design": "1.8.0-manmanyu.23",
51
+ "@tmagic/form": "1.8.0-manmanyu.23",
52
+ "@tmagic/utils": "1.8.0-manmanyu.23"
52
53
  },
53
54
  "peerDependenciesMeta": {
54
55
  "typescript": {
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <TMagicTooltip
3
+ :placement="action.tooltipPlacement || 'top'"
4
+ :disabled="!Boolean(action.tooltip)"
5
+ :content="action.tooltip"
6
+ >
7
+ <TMagicButton
8
+ v-show="visible"
9
+ :class="btnClass"
10
+ link
11
+ size="small"
12
+ :type="action.buttonType || 'primary'"
13
+ :icon="action.icon"
14
+ :disabled="disabled(action.disabled, row)"
15
+ @click="onClick"
16
+ >
17
+ <span v-html="formatter(action.text, row)"></span>
18
+ </TMagicButton>
19
+ </TMagicTooltip>
20
+ </template>
21
+
22
+ <script lang="ts" setup>
23
+ import { TMagicButton, TMagicTooltip } from '@tmagic/design';
24
+
25
+ import { disabled, formatActionText as formatter } from './actionHelpers';
26
+ import { ColumnActionConfig } from './schema';
27
+
28
+ defineOptions({
29
+ name: 'MTableActionButton',
30
+ });
31
+
32
+ const props = withDefaults(
33
+ defineProps<{
34
+ action: ColumnActionConfig;
35
+ row: any;
36
+ index: number;
37
+ btnClass?: string;
38
+ visible?: boolean;
39
+ }>(),
40
+ {
41
+ btnClass: 'action-btn',
42
+ visible: true,
43
+ },
44
+ );
45
+
46
+ const emit = defineEmits<{
47
+ click: [action: ColumnActionConfig, row: any, index: number];
48
+ }>();
49
+
50
+ const onClick = () => emit('click', props.action, props.row, props.index);
51
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <TMagicPopconfirm
3
+ placement="top"
4
+ :width="action.popconfirmWidth"
5
+ :title="formatter(action.confirmText, row) || '确定执行此操作?'"
6
+ @confirm="onConfirm"
7
+ >
8
+ <template #reference>
9
+ <ActionButton :action="action" :row="row" :index="index" :btn-class="btnClass" :visible="visible" />
10
+ </template>
11
+ </TMagicPopconfirm>
12
+ </template>
13
+
14
+ <script lang="ts" setup>
15
+ import { TMagicPopconfirm } from '@tmagic/design';
16
+
17
+ import ActionButton from './ActionButton.vue';
18
+ import { formatActionText as formatter } from './actionHelpers';
19
+ import { ColumnActionConfig } from './schema';
20
+
21
+ defineOptions({
22
+ name: 'MTableActionPopconfirm',
23
+ });
24
+
25
+ const props = withDefaults(
26
+ defineProps<{
27
+ action: ColumnActionConfig;
28
+ row: any;
29
+ index: number;
30
+ btnClass?: string;
31
+ visible?: boolean;
32
+ }>(),
33
+ {
34
+ btnClass: 'action-btn',
35
+ visible: true,
36
+ },
37
+ );
38
+
39
+ const emit = defineEmits<{
40
+ confirm: [action: ColumnActionConfig, row: any, index: number];
41
+ }>();
42
+
43
+ const onConfirm = () => emit('confirm', props.action, props.row, props.index);
44
+ </script>
@@ -1,23 +1,68 @@
1
1
  <template>
2
- <TMagicTooltip
3
- v-for="(action, actionIndex) in config.actions"
4
- :placement="action.tooltipPlacement || 'top'"
5
- :key="actionIndex"
6
- :disabled="!Boolean(action.tooltip)"
7
- :content="action.tooltip"
8
- >
9
- <TMagicButton
10
- v-show="display(action.display, row) && !editState[index]"
11
- class="action-btn"
12
- link
13
- size="small"
14
- :type="action.buttonType || 'primary'"
15
- :icon="action.icon"
16
- :disabled="disabled(action.disabled, row)"
17
- @click="actionHandler(action, row, index)"
18
- ><span v-html="formatter(action.text, row)"></span
19
- ></TMagicButton>
20
- </TMagicTooltip>
2
+ <template v-for="(action, actionIndex) in config.actions" :key="actionIndex">
3
+ <ActionPopconfirm
4
+ v-if="action.popconfirm"
5
+ :action="action"
6
+ :row="row"
7
+ :index="index"
8
+ :visible="display(action.display, row) && !editState[index]"
9
+ @confirm="actionHandler"
10
+ />
11
+
12
+ <TMagicPopover
13
+ v-else-if="action.type === 'sub-actions'"
14
+ v-model:visible="popoverVisible"
15
+ trigger="click"
16
+ :placement="action.subActionConfig?.placement || 'bottom'"
17
+ :width="action.subActionConfig?.popoverWidth"
18
+ :popper-class="action.subActionConfig?.popoverClass"
19
+ :destroy-on-close="action.subActionConfig?.popoverDestroyOnClose"
20
+ >
21
+ <template #reference>
22
+ <TMagicButton
23
+ v-show="action.subActionConfig?.items?.length && display(action.display, row) && !editState[index]"
24
+ class="action-btn"
25
+ link
26
+ size="small"
27
+ :type="action.buttonType || 'primary'"
28
+ :icon="popoverVisible ? ArrowDown : ArrowRight"
29
+ @click.stop="togglePopover"
30
+ ></TMagicButton>
31
+ </template>
32
+ <div class="sub-actions">
33
+ <template v-for="(subAction, subIndex) in action.subActionConfig?.items" :key="subIndex">
34
+ <ActionPopconfirm
35
+ v-if="subAction.popconfirm"
36
+ :action="subAction"
37
+ :row="row"
38
+ :index="index"
39
+ btn-class="sub-action-btn"
40
+ :visible="display(subAction.display, row)"
41
+ @confirm="actionHandler"
42
+ />
43
+
44
+ <ActionButton
45
+ v-else
46
+ :action="subAction"
47
+ :row="row"
48
+ :index="index"
49
+ btn-class="sub-action-btn"
50
+ :visible="display(subAction.display, row)"
51
+ @click="actionHandler"
52
+ />
53
+ </template>
54
+ </div>
55
+ </TMagicPopover>
56
+
57
+ <ActionButton
58
+ v-else
59
+ :action="action"
60
+ :row="row"
61
+ :index="index"
62
+ :visible="display(action.display, row) && !editState[index]"
63
+ @click="actionHandler"
64
+ />
65
+ </template>
21
66
 
22
67
  <TMagicButton
23
68
  class="action-btn"
@@ -40,10 +85,15 @@
40
85
  </template>
41
86
 
42
87
  <script lang="ts" setup>
88
+ import { ref } from 'vue';
89
+ import { ArrowDown, ArrowRight } from '@element-plus/icons-vue';
43
90
  import { cloneDeep } from 'lodash-es';
44
91
 
45
- import { TMagicButton, tMagicMessage, TMagicTooltip } from '@tmagic/design';
92
+ import { TMagicButton, tMagicMessage, TMagicPopover } from '@tmagic/design';
46
93
 
94
+ import ActionButton from './ActionButton.vue';
95
+ import { display } from './actionHelpers';
96
+ import ActionPopconfirm from './ActionPopconfirm.vue';
47
97
  import { ColumnActionConfig, ColumnConfig } from './schema';
48
98
 
49
99
  defineOptions({
@@ -67,38 +117,16 @@ const props = withDefaults(
67
117
  },
68
118
  );
69
119
 
120
+ const popoverVisible = ref(false);
121
+ const togglePopover = () => {
122
+ popoverVisible.value = !popoverVisible.value;
123
+ };
124
+
70
125
  const emit = defineEmits<{
71
126
  'after-action': [{ index: number }];
72
127
  'after-action-cancel': [{ index: number }];
73
128
  }>();
74
129
 
75
- const display = (fuc: boolean | Function | undefined, row: any) => {
76
- if (typeof fuc === 'function') {
77
- return fuc(row);
78
- }
79
- if (typeof fuc === 'boolean') {
80
- return fuc;
81
- }
82
- return true;
83
- };
84
-
85
- const disabled = (fuc: boolean | Function | undefined, row: any) => {
86
- if (typeof fuc === 'function') {
87
- return fuc(row);
88
- }
89
- if (typeof fuc === 'boolean') {
90
- return fuc;
91
- }
92
- return false;
93
- };
94
-
95
- const formatter = (fuc: string | Function | undefined, row: any) => {
96
- if (typeof fuc === 'function') {
97
- return fuc(row);
98
- }
99
- return fuc;
100
- };
101
-
102
130
  const actionHandler = async (action: ColumnActionConfig, row: any, index: number) => {
103
131
  await action.before?.(row, index);
104
132
  if (action.type === 'edit') {
@@ -140,4 +168,31 @@ const cancel = async (index: number, config: ColumnConfig) => {
140
168
  }
141
169
  emit('after-action-cancel', { index });
142
170
  };
171
+
172
+ defineExpose({
173
+ actionHandler,
174
+ save,
175
+ cancel,
176
+ });
143
177
  </script>
178
+
179
+ <style lang="scss">
180
+ .sub-actions {
181
+ display: flex;
182
+ flex-direction: column;
183
+ gap: 4px;
184
+ align-items: flex-start;
185
+
186
+ .sub-action-btn {
187
+ width: 100%;
188
+ }
189
+
190
+ .tmagic-design-button + .tmagic-design-button {
191
+ margin-left: 0;
192
+ }
193
+
194
+ .tmagic-design-button {
195
+ justify-content: flex-start;
196
+ }
197
+ }
198
+ </style>