Commit 5fab267a69600fdf5d7a7f9e4d9fff859d09dede
1 parent
5637588f
feat(table-action): support `tooltip` option
为tableAction组件中的操作按钮增加tooltip配置 close: #848
Showing
4 changed files
with
31 additions
and
11 deletions
CHANGELOG.zh_CN.md
... | ... | @@ -3,6 +3,10 @@ |
3 | 3 | - **Axios** 新增`withToken`配置,用于控制请求是否携带 token |
4 | 4 | - **BasicUpload** 新增在预览 `Modal` 中删除文件时触发`preview-delete` 事件 |
5 | 5 | - **BasicUpload** `value` 支持 `v-model` 用法 |
6 | +- **Route 配置** | |
7 | + - 增加`ignoreRoute`用于在`ROUTE_MAPPING`或`BACK`权限模式下仅生成菜单 | |
8 | + - 增加`hidePathForChildren`配置,标识为子项目生成菜单时忽略本级`path` | |
9 | +- **TableAction** 新增`tooltip`配置,可以为按钮增加 tooltip 提示 | |
6 | 10 | |
7 | 11 | ### 🐛 Bug Fixes |
8 | 12 | ... | ... |
src/components/Table/src/components/TableAction.vue
1 | 1 | <template> |
2 | 2 | <div :class="[prefixCls, getAlign]" @click="onCellClick"> |
3 | 3 | <template v-for="(action, index) in getActions" :key="`${index}-${action.label}`"> |
4 | - <PopConfirmButton v-bind="action"> | |
5 | - <Icon :icon="action.icon" class="mr-1" v-if="action.icon" /> | |
6 | - {{ action.label }} | |
7 | - </PopConfirmButton> | |
4 | + <Tooltip v-bind="getTooltip(action.tooltip)"> | |
5 | + <PopConfirmButton v-bind="action"> | |
6 | + <Tooltip v-bind="getTooltip(action.tooltip)"> | |
7 | + <Icon :icon="action.icon" class="mr-1" v-if="action.icon" /> | |
8 | + {{ action.label }} | |
9 | + </Tooltip> | |
10 | + </PopConfirmButton> | |
11 | + </Tooltip> | |
8 | 12 | <Divider |
9 | 13 | type="vertical" |
10 | 14 | class="action-divider" |
... | ... | @@ -31,7 +35,7 @@ |
31 | 35 | <script lang="ts"> |
32 | 36 | import { defineComponent, PropType, computed, toRaw } from 'vue'; |
33 | 37 | import { MoreOutlined } from '@ant-design/icons-vue'; |
34 | - import { Divider } from 'ant-design-vue'; | |
38 | + import { Divider, Tooltip } from 'ant-design-vue'; | |
35 | 39 | import Icon from '/@/components/Icon/index'; |
36 | 40 | import { ActionItem, TableActionType } from '/@/components/Table'; |
37 | 41 | import { PopConfirmButton } from '/@/components/Button'; |
... | ... | @@ -39,13 +43,13 @@ |
39 | 43 | import { useDesign } from '/@/hooks/web/useDesign'; |
40 | 44 | import { useTableContext } from '../hooks/useTableContext'; |
41 | 45 | import { usePermission } from '/@/hooks/web/usePermission'; |
42 | - import { isBoolean, isFunction } from '/@/utils/is'; | |
46 | + import { isBoolean, isFunction, isString } from '/@/utils/is'; | |
43 | 47 | import { propTypes } from '/@/utils/propTypes'; |
44 | 48 | import { ACTION_COLUMN_FLAG } from '../const'; |
45 | 49 | |
46 | 50 | export default defineComponent({ |
47 | 51 | name: 'TableAction', |
48 | - components: { Icon, PopConfirmButton, Divider, Dropdown, MoreOutlined }, | |
52 | + components: { Icon, PopConfirmButton, Divider, Dropdown, MoreOutlined, Tooltip }, | |
49 | 53 | props: { |
50 | 54 | actions: { |
51 | 55 | type: Array as PropType<ActionItem[]>, |
... | ... | @@ -124,6 +128,16 @@ |
124 | 128 | return actionColumn?.align ?? 'left'; |
125 | 129 | }); |
126 | 130 | |
131 | + const getTooltip = computed(() => { | |
132 | + return (data) => { | |
133 | + if (isString(data)) { | |
134 | + return { title: data }; | |
135 | + } else { | |
136 | + return data; | |
137 | + } | |
138 | + }; | |
139 | + }); | |
140 | + | |
127 | 141 | function onCellClick(e: MouseEvent) { |
128 | 142 | if (!props.stopButtonPropagation) return; |
129 | 143 | const target = e.target as HTMLElement; |
... | ... | @@ -132,7 +146,7 @@ |
132 | 146 | } |
133 | 147 | } |
134 | 148 | |
135 | - return { prefixCls, getActions, getDropdownList, getAlign, onCellClick }; | |
149 | + return { prefixCls, getActions, getDropdownList, getAlign, onCellClick, getTooltip }; | |
136 | 150 | }, |
137 | 151 | }); |
138 | 152 | </script> | ... | ... |
src/components/Table/src/types/tableAction.ts
1 | 1 | import { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'; |
2 | +import { TooltipProps } from 'ant-design-vue/es/tooltip/Tooltip'; | |
2 | 3 | import { RoleEnum } from '/@/enums/roleEnum'; |
3 | 4 | export interface ActionItem extends ButtonProps { |
4 | 5 | onClick?: Fn; |
... | ... | @@ -12,6 +13,7 @@ export interface ActionItem extends ButtonProps { |
12 | 13 | auth?: RoleEnum | RoleEnum[] | string | string[]; |
13 | 14 | // 业务控制是否显示 |
14 | 15 | ifShow?: boolean | ((action: ActionItem) => boolean); |
16 | + tooltip?: string | TooltipProps; | |
15 | 17 | } |
16 | 18 | |
17 | 19 | export interface PopConfirm { | ... | ... |
src/views/demo/system/account/index.vue
... | ... | @@ -10,18 +10,18 @@ |
10 | 10 | :actions="[ |
11 | 11 | { |
12 | 12 | icon: 'clarity:info-standard-line', |
13 | - title: '查看用户详情', | |
13 | + tooltip: '查看用户详情', | |
14 | 14 | onClick: handleView.bind(null, record), |
15 | 15 | }, |
16 | 16 | { |
17 | 17 | icon: 'clarity:note-edit-line', |
18 | - title: '编辑用户资料', | |
18 | + tooltip: '编辑用户资料', | |
19 | 19 | onClick: handleEdit.bind(null, record), |
20 | 20 | }, |
21 | 21 | { |
22 | 22 | icon: 'ant-design:delete-outlined', |
23 | 23 | color: 'error', |
24 | - title: '删除此账号', | |
24 | + tooltip: '删除此账号', | |
25 | 25 | popConfirm: { |
26 | 26 | title: '是否确认删除', |
27 | 27 | confirm: handleDelete.bind(null, record), | ... | ... |