Commit 6afee415a3a8007f13af57892d62759ffbcde5a5
1 parent
8b2e0f66
feat(table): Table operation columns support permission codes
Showing
2 changed files
with
38 additions
and
25 deletions
src/components/Table/src/components/TableAction.vue
@@ -25,16 +25,17 @@ | @@ -25,16 +25,17 @@ | ||
25 | </template> | 25 | </template> |
26 | <script lang="ts"> | 26 | <script lang="ts"> |
27 | import { defineComponent, PropType, computed, toRaw } from 'vue'; | 27 | import { defineComponent, PropType, computed, toRaw } from 'vue'; |
28 | - | ||
29 | import { MoreOutlined } from '@ant-design/icons-vue'; | 28 | import { MoreOutlined } from '@ant-design/icons-vue'; |
29 | + import { Divider } from 'ant-design-vue'; | ||
30 | + | ||
30 | import Icon from '/@/components/Icon/index'; | 31 | import Icon from '/@/components/Icon/index'; |
31 | import { ActionItem, TableActionType } from '/@/components/Table'; | 32 | import { ActionItem, TableActionType } from '/@/components/Table'; |
32 | import { PopConfirmButton } from '/@/components/Button'; | 33 | import { PopConfirmButton } from '/@/components/Button'; |
33 | - import { Divider } from 'ant-design-vue'; | ||
34 | import { Dropdown } from '/@/components/Dropdown'; | 34 | import { Dropdown } from '/@/components/Dropdown'; |
35 | 35 | ||
36 | import { useDesign } from '/@/hooks/web/useDesign'; | 36 | import { useDesign } from '/@/hooks/web/useDesign'; |
37 | import { useTableContext } from '../hooks/useTableContext'; | 37 | import { useTableContext } from '../hooks/useTableContext'; |
38 | + import { usePermission } from '/@/hooks/web/usePermission'; | ||
38 | 39 | ||
39 | import { propTypes } from '/@/utils/propTypes'; | 40 | import { propTypes } from '/@/utils/propTypes'; |
40 | import { ACTION_COLUMN_FLAG } from '../const'; | 41 | import { ACTION_COLUMN_FLAG } from '../const'; |
@@ -61,33 +62,42 @@ | @@ -61,33 +62,42 @@ | ||
61 | table = useTableContext(); | 62 | table = useTableContext(); |
62 | } | 63 | } |
63 | 64 | ||
65 | + const { hasPermission } = usePermission(); | ||
64 | const getActions = computed(() => { | 66 | const getActions = computed(() => { |
65 | - return (toRaw(props.actions) || []).map((action) => { | ||
66 | - const { popConfirm } = action; | ||
67 | - return { | ||
68 | - type: 'link', | ||
69 | - size: 'small', | ||
70 | - ...action, | ||
71 | - ...(popConfirm || {}), | ||
72 | - onConfirm: popConfirm?.confirm, | ||
73 | - onCancel: popConfirm?.cancel, | ||
74 | - enable: !!popConfirm, | ||
75 | - }; | ||
76 | - }); | 67 | + return (toRaw(props.actions) || []) |
68 | + .filter((action) => { | ||
69 | + return hasPermission(action.auth); | ||
70 | + }) | ||
71 | + .map((action) => { | ||
72 | + const { popConfirm } = action; | ||
73 | + return { | ||
74 | + type: 'link', | ||
75 | + size: 'small', | ||
76 | + ...action, | ||
77 | + ...(popConfirm || {}), | ||
78 | + onConfirm: popConfirm?.confirm, | ||
79 | + onCancel: popConfirm?.cancel, | ||
80 | + enable: !!popConfirm, | ||
81 | + }; | ||
82 | + }); | ||
77 | }); | 83 | }); |
78 | 84 | ||
79 | const getDropdownList = computed(() => { | 85 | const getDropdownList = computed(() => { |
80 | - return (toRaw(props.dropDownActions) || []).map((action, index) => { | ||
81 | - const { label, popConfirm } = action; | ||
82 | - return { | ||
83 | - ...action, | ||
84 | - ...popConfirm, | ||
85 | - onConfirm: popConfirm?.confirm, | ||
86 | - onCancel: popConfirm?.cancel, | ||
87 | - text: label, | ||
88 | - divider: index < props.dropDownActions.length - 1 ? props.divider : false, | ||
89 | - }; | ||
90 | - }); | 86 | + return (toRaw(props.dropDownActions) || []) |
87 | + .filter((action) => { | ||
88 | + return hasPermission(action.auth); | ||
89 | + }) | ||
90 | + .map((action, index) => { | ||
91 | + const { label, popConfirm } = action; | ||
92 | + return { | ||
93 | + ...action, | ||
94 | + ...popConfirm, | ||
95 | + onConfirm: popConfirm?.confirm, | ||
96 | + onCancel: popConfirm?.cancel, | ||
97 | + text: label, | ||
98 | + divider: index < props.dropDownActions.length - 1 ? props.divider : false, | ||
99 | + }; | ||
100 | + }); | ||
91 | }); | 101 | }); |
92 | 102 | ||
93 | const getAlign = computed(() => { | 103 | const getAlign = computed(() => { |
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 { RoleEnum } from '/@/enums/roleEnum'; | ||
2 | export interface ActionItem extends ButtonProps { | 3 | export interface ActionItem extends ButtonProps { |
3 | onClick?: Fn; | 4 | onClick?: Fn; |
4 | label: string; | 5 | label: string; |
@@ -7,6 +8,8 @@ export interface ActionItem extends ButtonProps { | @@ -7,6 +8,8 @@ export interface ActionItem extends ButtonProps { | ||
7 | popConfirm?: PopConfirm; | 8 | popConfirm?: PopConfirm; |
8 | disabled?: boolean; | 9 | disabled?: boolean; |
9 | divider?: boolean; | 10 | divider?: boolean; |
11 | + // Permission code | ||
12 | + auth?: RoleEnum | RoleEnum[] | string | string[]; | ||
10 | } | 13 | } |
11 | 14 | ||
12 | export interface PopConfirm { | 15 | export interface PopConfirm { |