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