@@ -16,114 +16,93 @@ export default defineComponent({
1616 type : Array as PropType < ActionItem [ ] > ,
1717 default : null ,
1818 } ,
19+
20+ moreText : {
21+ type : String as PropType < string > ,
22+ default : '更多' ,
23+ } ,
1924 } ,
2025 setup ( props ) {
26+ function renderButton ( action : ActionItem , index : number ) {
27+ const { disabled = false , label, icon, color = '' , type = 'link' } = action ;
28+ const button = (
29+ < Button type = { type } size = "small" disabled = { disabled } color = { color } { ...action } key = { index } >
30+ { ( ) => (
31+ < >
32+ { label }
33+ { icon && < Icon icon = { icon } /> }
34+ </ >
35+ ) }
36+ </ Button >
37+ ) ;
38+ return button ;
39+ }
40+
41+ function renderPopConfirm ( action : ActionItem , index : number ) {
42+ const { popConfirm = null } = action ;
43+ if ( ! popConfirm ) {
44+ return renderButton ( action , index ) ;
45+ }
46+ const {
47+ title,
48+ okText = '确定' ,
49+ cancelText = '取消' ,
50+ confirm = ( ) => { } ,
51+ cancel = ( ) => { } ,
52+ icon = '' ,
53+ } = popConfirm ;
54+ return (
55+ < Popconfirm
56+ key = { `P-${ index } ` }
57+ title = { title }
58+ onConfirm = { confirm }
59+ onCancel = { cancel }
60+ okText = { okText }
61+ cancelText = { cancelText }
62+ icon = { icon }
63+ >
64+ { ( ) => renderButton ( action , index ) }
65+ </ Popconfirm >
66+ ) ;
67+ }
68+
69+ const dropdownDefaultSLot = ( ) => (
70+ < Button type = "link" size = "small" >
71+ { {
72+ default : ( ) => (
73+ < >
74+ { props . moreText }
75+ < DownOutlined />
76+ </ >
77+ ) ,
78+ } }
79+ </ Button >
80+ ) ;
81+
2182 // 增加按钮的TYPE和COLOR
2283 return ( ) => {
2384 const { dropDownActions = [ ] , actions } = props ;
2485 return (
2586 < div class = { prefixCls } >
26- { actions &&
27- actions . length &&
28- actions . map ( ( action , index ) => {
29- const {
30- disabled = false ,
31- label,
32- icon,
33- color = '' ,
34- type = 'link' ,
35- popConfirm = null ,
36- } = action ;
37- const button = (
38- < Button
39- type = { type }
40- size = "small"
41- disabled = { disabled }
42- color = { color }
43- { ...action }
44- key = { index }
45- >
46- { ( ) => (
47- < >
48- { label }
49- { icon && < Icon icon = { icon } /> }
50- </ >
51- ) }
52- </ Button >
53- ) ;
54- if ( popConfirm !== null ) {
55- const {
56- title,
57- okText = '确定' ,
58- cancelText = '取消' ,
59- confirm = ( ) => { } ,
60- cancel = ( ) => { } ,
61- icon = '' ,
62- } = popConfirm ;
63- return (
64- < Popconfirm
65- key = { `P-${ index } ` }
66- title = { title }
67- onConfirm = { confirm }
68- onCancel = { cancel }
69- okText = { okText }
70- cancelText = { cancelText }
71- icon = { icon }
72- >
73- { ( ) => button }
74- </ Popconfirm >
75- ) ;
76- }
77- return button ;
78- } ) }
79- { dropDownActions && dropDownActions . length && (
87+ { actions ?. map ( ( action , index ) => {
88+ return renderPopConfirm ( action , index ) ;
89+ } ) }
90+ { dropDownActions ?. length && (
8091 < Dropdown >
8192 { {
82- default : ( ) => (
83- < Button type = "link" size = "small" >
84- { {
85- default : ( ) => (
86- < >
87- 更多
88- < DownOutlined />
89- </ >
90- ) ,
91- } }
92- </ Button >
93- ) ,
93+ default : dropdownDefaultSLot ,
9494 overlay : ( ) => {
9595 return (
9696 < Menu >
9797 { {
9898 default : ( ) => {
9999 return dropDownActions . map ( ( action , index ) => {
100- const {
101- disabled = false ,
102- label,
103- icon,
104- color = '' ,
105- type = 'link' ,
106- } = action ;
100+ const { disabled = false } = action ;
107101 return (
108102 < Menu . Item key = { `${ index } ` } disabled = { disabled } >
109- { ( ) => (
110- < Button
111- type = { type }
112- size = "small"
113- { ...action }
114- disabled = { disabled }
115- color = { color }
116- >
117- { {
118- default : ( ) => (
119- < >
120- { label }
121- { icon && < Icon icon = { icon } /> }
122- </ >
123- ) ,
124- } }
125- </ Button >
126- ) }
103+ { ( ) => {
104+ return renderPopConfirm ( action , index ) ;
105+ } }
127106 </ Menu . Item >
128107 ) ;
129108 } ) ;
0 commit comments