@@ -2,13 +2,11 @@ import type { Recordable } from '@vben/types';
22
33import { h } from 'vue' ;
44
5- import { IconifyIcon } from '@vben/icons' ;
6- import { $te } from '@vben/locales' ;
75import { setupVbenVxeTable , useVbenVxeGrid } from '@vben/plugins/vxe-table' ;
8- import { get , isFunction , isString } from '@vben/utils' ;
6+ import { get } from '@vben/utils' ;
97
108import { objectOmit } from '@vueuse/core' ;
11- import { Button , Image , Popconfirm , Switch , Tag } from 'ant-design-vue' ;
9+ import { Button , Image , Switch , Tag } from 'ant-design-vue' ;
1210
1311import { $t } from '#/locales' ;
1412
@@ -121,138 +119,6 @@ setupVbenVxeTable({
121119 } ,
122120 } ) ;
123121
124- /**
125- * 注册表格的操作按钮渲染器
126- */
127- vxeUI . renderer . add ( 'CellOperation' , {
128- renderTableDefault ( { attrs, options, props } , { column, row } ) {
129- const defaultProps = { size : 'small' , type : 'link' , ...props } ;
130- let align = 'end' ;
131- switch ( column . align ) {
132- case 'center' : {
133- align = 'center' ;
134- break ;
135- }
136- case 'left' : {
137- align = 'start' ;
138- break ;
139- }
140- default : {
141- align = 'end' ;
142- break ;
143- }
144- }
145- const presets : Recordable < Recordable < any > > = {
146- delete : {
147- danger : true ,
148- text : $t ( 'common.delete' ) ,
149- } ,
150- edit : {
151- text : $t ( 'common.edit' ) ,
152- } ,
153- } ;
154- const operations : Array < Recordable < any > > = (
155- options || [ 'edit' , 'delete' ]
156- )
157- . map ( ( opt ) => {
158- if ( isString ( opt ) ) {
159- return presets [ opt ]
160- ? { code : opt , ...presets [ opt ] , ...defaultProps }
161- : {
162- code : opt ,
163- text : $te ( `common.${ opt } ` ) ? $t ( `common.${ opt } ` ) : opt ,
164- ...defaultProps ,
165- } ;
166- } else {
167- return { ...defaultProps , ...presets [ opt . code ] , ...opt } ;
168- }
169- } )
170- . map ( ( opt ) => {
171- const optBtn : Recordable < any > = { } ;
172- Object . keys ( opt ) . forEach ( ( key ) => {
173- optBtn [ key ] = isFunction ( opt [ key ] ) ? opt [ key ] ( row ) : opt [ key ] ;
174- } ) ;
175- return optBtn ;
176- } )
177- . filter ( ( opt ) => opt . show !== false ) ;
178-
179- function renderBtn ( opt : Recordable < any > , listen = true ) {
180- return h (
181- Button ,
182- {
183- ...props ,
184- ...opt ,
185- icon : undefined ,
186- onClick : listen
187- ? ( ) =>
188- attrs ?. onClick ?.( {
189- code : opt . code ,
190- row,
191- } )
192- : undefined ,
193- } ,
194- {
195- default : ( ) => {
196- const content = [ ] ;
197- if ( opt . icon ) {
198- content . push (
199- h ( IconifyIcon , { class : 'size-5' , icon : opt . icon } ) ,
200- ) ;
201- }
202- content . push ( opt . text ) ;
203- return content ;
204- } ,
205- } ,
206- ) ;
207- }
208-
209- function renderConfirm ( opt : Recordable < any > ) {
210- return h (
211- Popconfirm ,
212- {
213- getPopupContainer ( el ) {
214- return el . closest ( 'tbody' ) || document . body ;
215- } ,
216- placement : 'topLeft' ,
217- title : $t ( 'ui.actionTitle.delete' , [ attrs ?. nameTitle || '' ] ) ,
218- ...props ,
219- ...opt ,
220- icon : undefined ,
221- onConfirm : ( ) => {
222- attrs ?. onClick ?.( {
223- code : opt . code ,
224- row,
225- } ) ;
226- } ,
227- } ,
228- {
229- default : ( ) => renderBtn ( { ...opt } , false ) ,
230- description : ( ) =>
231- h (
232- 'div' ,
233- { class : 'truncate' } ,
234- $t ( 'ui.actionMessage.deleteConfirm' , [
235- row [ attrs ?. nameField || 'name' ] ,
236- ] ) ,
237- ) ,
238- } ,
239- ) ;
240- }
241-
242- const btns = operations . map ( ( opt ) =>
243- opt . code === 'delete' ? renderConfirm ( opt ) : renderBtn ( opt ) ,
244- ) ;
245- return h (
246- 'div' ,
247- {
248- class : 'flex table-operations' ,
249- style : { justifyContent : align } ,
250- } ,
251- btns ,
252- ) ;
253- } ,
254- } ) ;
255-
256122 // 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
257123 // vxeUI.formats.add
258124 } ,
0 commit comments