Skip to content

Commit 19d8e01

Browse files
committedJun 6, 2021
feat(table-img): support simple show mode and more props
改进TableImg组件,支持简单显示模式以及更多可配置的属性。
1 parent 50f94bf commit 19d8e01

File tree

2 files changed

+82
-18
lines changed

2 files changed

+82
-18
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
<template>
22
<div
33
:class="prefixCls"
4-
class="flex mx-auto items-center"
4+
class="flex items-center mx-auto"
55
v-if="imgList && imgList.length"
66
:style="getWrapStyle"
77
>
8-
<PreviewGroup>
9-
<template v-for="img in imgList" :key="img">
10-
<Image :width="size" :src="img" />
8+
<Badge :count="!showBadge || imgList.length == 1 ? 0 : imgList.length" v-if="simpleShow">
9+
<div class="img-div">
10+
<PreviewGroup>
11+
<template v-for="(img, index) in imgList" :key="img">
12+
<Image
13+
:width="size"
14+
:style="{
15+
display: index === 0 ? '' : 'none !important',
16+
}"
17+
:src="srcPrefix + img"
18+
/>
19+
</template>
20+
</PreviewGroup>
21+
</div>
22+
</Badge>
23+
<PreviewGroup v-else>
24+
<template v-for="(img, index) in imgList" :key="img">
25+
<Image
26+
:width="size"
27+
:style="{ 'margin-left': index === 0 ? 0 : margin }"
28+
:src="srcPrefix + img"
29+
/>
1130
</template>
1231
</PreviewGroup>
1332
</div>
@@ -17,24 +36,30 @@
1736
import { defineComponent, computed } from 'vue';
1837
import { useDesign } from '/@/hooks/web/useDesign';
1938
20-
import { Image } from 'ant-design-vue';
39+
import { Image, Badge } from 'ant-design-vue';
2140
import { propTypes } from '/@/utils/propTypes';
2241
2342
export default defineComponent({
2443
name: 'TableImage',
25-
components: { Image, PreviewGroup: Image.PreviewGroup },
44+
components: { Image, PreviewGroup: Image.PreviewGroup, Badge },
2645
props: {
2746
imgList: propTypes.arrayOf(propTypes.string),
2847
size: propTypes.number.def(40),
48+
// 是否简单显示(只显示第一张图片)
49+
simpleShow: propTypes.bool,
50+
// 简单模式下是否显示图片数量的badge
51+
showBadge: propTypes.bool.def(true),
52+
// 图片间距
53+
margin: propTypes.number.def(4),
54+
// src前缀,将会附加在imgList中每一项之前
55+
srcPrefix: propTypes.string.def(''),
2956
},
3057
setup(props) {
31-
const getWrapStyle = computed(
32-
(): CSSProperties => {
33-
const { size } = props;
34-
const s = `${size}px`;
35-
return { height: s, width: s };
36-
}
37-
);
58+
const getWrapStyle = computed((): CSSProperties => {
59+
const { size } = props;
60+
const s = `${size}px`;
61+
return { height: s, width: s };
62+
});
3863
3964
const { prefixCls } = useDesign('basic-table-img');
4065
return { prefixCls, getWrapStyle };
@@ -53,5 +78,9 @@
5378
border-radius: 2px;
5479
}
5580
}
81+
82+
.img-div {
83+
display: inline-grid;
84+
}
5685
}
5786
</style>

‎src/views/demo/table/CustomerCell.vue

+40-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,31 @@
77
{{ record.no }}
88
</Tag>
99
</template>
10+
<template #avatar="{ record }">
11+
<Avatar
12+
:size="60"
13+
:src="'http://api.btstu.cn/sjtx/api.php?lx=c1&format=images&id=' + record.id"
14+
/>
15+
</template>
1016
<template #img>
1117
<TableImg
12-
:imgList="['https://picsum.photos/id/66/346/216', 'https://picsum.photos/id/67/346/216']"
18+
:size="60"
19+
:simpleShow="true"
20+
:imgList="[
21+
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?1622962250222',
22+
'https://picsum.photos/id/66/346/216',
23+
'https://picsum.photos/id/67/346/216',
24+
]"
25+
/>
26+
</template>
27+
<template #imgs>
28+
<TableImg
29+
:size="60"
30+
:imgList="[
31+
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?1622962250222',
32+
'https://picsum.photos/id/66/346/216',
33+
'https://picsum.photos/id/67/346/216',
34+
]"
1335
/>
1436
</template>
1537

@@ -24,14 +46,20 @@
2446
<script lang="ts">
2547
import { defineComponent } from 'vue';
2648
import { BasicTable, useTable, BasicColumn, TableImg } from '/@/components/Table';
27-
import { Tag } from 'ant-design-vue';
49+
import { Tag, Avatar } from 'ant-design-vue';
2850
import { demoListApi } from '/@/api/demo/table';
2951
const columns: BasicColumn[] = [
3052
{
3153
title: 'ID',
3254
dataIndex: 'id',
3355
slots: { customRender: 'id' },
3456
},
57+
{
58+
title: '头像',
59+
dataIndex: 'avatar',
60+
width: 100,
61+
slots: { customRender: 'avatar' },
62+
},
3563
{
3664
title: '分类',
3765
dataIndex: 'category',
@@ -46,11 +74,18 @@
4674
width: 120,
4775
},
4876
{
49-
title: '头像',
77+
title: '图片列表1',
5078
dataIndex: 'img',
51-
width: 120,
79+
helpMessage: ['这是简单模式的图片列表', '只会显示一张在表格中', '但点击可预览多张图片'],
80+
width: 140,
5281
slots: { customRender: 'img' },
5382
},
83+
{
84+
title: '照片列表2',
85+
dataIndex: 'imgs',
86+
width: 160,
87+
slots: { customRender: 'imgs' },
88+
},
5489
{
5590
title: '地址',
5691
dataIndex: 'address',
@@ -70,7 +105,7 @@
70105
},
71106
];
72107
export default defineComponent({
73-
components: { BasicTable, TableImg, Tag },
108+
components: { BasicTable, TableImg, Tag, Avatar },
74109
setup() {
75110
const [registerTable] = useTable({
76111
title: '自定义列内容',

0 commit comments

Comments
 (0)