feat: xtable增加预览功能

This commit is contained in:
xingyu 2023-01-06 17:20:59 +08:00
parent 71d4c5ad78
commit ed30f06ae1
3 changed files with 36 additions and 1 deletions

View File

@ -4,3 +4,4 @@ import './dict'
import './html' import './html'
import './link' import './link'
import './img' import './img'
import './preview'

View File

@ -0,0 +1,34 @@
import { VXETable } from 'vxe-table'
import { ElImage, ElLink } from 'element-plus'
// 图片渲染
VXETable.renderer.add('XPreview', {
// 默认显示模板
renderDefault(_renderOpts, params) {
const { row, column } = params
if (row.type.indexOf('image/') === 0) {
return (
<ElImage
style="width: 80px; height: 50px"
src={row[column.field]}
key={row[column.field]}
preview-src-list={[row[column.field]]}
fit="contain"
lazy
></ElImage>
)
} else if (row.type.indexOf('video/') === 0) {
return (
<video>
<source src={row[column.field]}></source>
</video>
)
} else {
return (
<ElLink href={row[column.field]} target="_blank">
{row[column.field]}
</ElLink>
)
}
}
})

View File

@ -23,7 +23,7 @@ const crudSchemas = reactive<VxeCrudSchema>({
field: 'url', field: 'url',
table: { table: {
cellRender: { cellRender: {
name: 'XImg' name: 'XPreview'
} }
} }
}, },