Skip to content

Commit 3cdd771

Browse files
authored
ActionTimeline组件新增自定义icon位置的内容插槽。 #1846 (#1872)
* feat(ActionTimeline): ActionTimeline组件新增自定义icon位置的内容插槽,未传入时默认使用原方式,对现有使用不影响。#1846 * feat(ActionTimeline): 删除多余的console #1846
1 parent 18e63c4 commit 3cdd771

File tree

2 files changed

+117
-4
lines changed

2 files changed

+117
-4
lines changed

packages/devui-vue/devui/action-timeline/src/action-timeline.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export default defineComponent({
4848
<div class={timelineItemClass(index, parentIndex, actionData, item)}>
4949
<div class="vertical-list-item-top">
5050
<div class="vertical-list-item-top-left">
51-
<div class={itemIconClass(item, true)}>
51+
{ctx.slots.iconContent?.({ option: item }) || <div class={itemIconClass(item, true)}>
5252
{!item.icon && <div class="list-empty-icon-dot"></div>}
5353
<em class={itemIconClass(item)}></em>
54-
</div>
54+
</div>}
5555
<div class="vertical-list-item-top-left-title">{ctx.slots.title?.({ option: item })}</div>
5656
</div>
5757
<div class="dp-action-timeline-item-data">{item.createdAt}</div>
@@ -62,10 +62,10 @@ export default defineComponent({
6262
const renderHorizontalBody = (actionData: ActionData, parentIndex: number) =>
6363
actionData.actions?.map((item, index) => (
6464
<div class={timelineItemClass(index, parentIndex, actionData, item)}>
65-
<div class={itemIconClass(item, true)}>
65+
{ctx.slots.iconContent?.({ option: item }) || <div class={itemIconClass(item, true)}>
6666
{!item.icon && <div class="list-empty-icon-dot"></div>}
6767
<em class={itemIconClass(item)}></em>
68-
</div>
68+
</div>}
6969
<div class="dp-action-timeline-list-data">{ctx.slots.content?.({ option: item })}</div>
7070
<div class="dp-action-timeline-item-date">{item.createdAt}</div>
7171
{!(actionData.actions && data?.value && index === actionData.actions.length - 1 && parentIndex === data?.value?.length - 1) && (

packages/devui-vue/docs/components/action-timeline/index.md

+113
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,118 @@ export default defineComponent({
180180

181181
:::
182182

183+
### 自定义Icon位置的代码
184+
185+
icon区域想要自定义样式和事件,可以通过iconContent插槽实现。
186+
187+
:::demo
188+
189+
```vue
190+
<template>
191+
<d-action-timeline :data="timeData" :load-more-config="loadMoreConfig" layout="vertical" :show-tail-line="false">
192+
<template #title="page">
193+
<div>{{ page.option.action }}</div>
194+
</template>
195+
<template #content="page">
196+
<div class="custom-content">{{ page.option.actionContent }}</div>
197+
</template>
198+
<template #iconContent="page">
199+
<d-tooltip position="top" :content="page.option.iconDes">
200+
<div class="custom-icon">{{ page.option.icon }}</div>
201+
</d-tooltip>
202+
</template>
203+
</d-action-timeline>
204+
</template>
205+
206+
<script>
207+
import { defineComponent, reactive, ref } from 'vue';
208+
209+
export default defineComponent({
210+
setup() {
211+
const timeData = [
212+
{
213+
time: '2022-07-01',
214+
actions: [
215+
{
216+
action: '操作信息',
217+
actionContent: '操作内容1',
218+
createdAt: '2022-07-01T07:30:09.681Z',
219+
icon: 'A',
220+
iconDes: '该事件发生在2022-07-01 07:30:09,进行了操作内容1的调整',
221+
},
222+
{
223+
action: '操作信息',
224+
actionContent: '操作内容2',
225+
icon: 'B',
226+
createdAt: '2022/07/01 9:38:00',
227+
iconDes: '该事件发生在2022/07/01 9:38:00,进行了操作内容2的调整',
228+
},
229+
],
230+
},
231+
{
232+
time: '2022-06-30',
233+
actions: [
234+
{
235+
action: '操作信息',
236+
actionContent: '操作内容3',
237+
createdAt: '2022-06-30 21:39:25',
238+
icon: 'C',
239+
iconDes: '该事件发生在2022-06-30 21:39:25,进行了操作内容3的调整',
240+
},
241+
{
242+
action: '操作信息',
243+
actionContent: '操作内容4',
244+
createdAt: 'Fri Jun 30 2022 15:21:54 GMT+0800(中国标准时间)',
245+
icon: 'D',
246+
iconDes: '该事件发生在Fri Jun 30 2022 15:21:54,进行了操作内容4的调整',
247+
},
248+
{
249+
action: '操作信息',
250+
actionContent: '操作内容5',
251+
createdAt: 'Fri Jun 30 2022 15:21:54 GMT+0800(中国标准时间)',
252+
iconDes: '该事件发生在Fri Jun 30 2022 15:21:54,进行了操作内容5的调整',
253+
icon: 'E',
254+
},
255+
],
256+
},
257+
];
258+
const loadMoreConfig = {
259+
type: 'button',
260+
};
261+
return {
262+
timeData,
263+
loadMoreConfig,
264+
};
265+
},
266+
});
267+
</script>
268+
269+
<style scoped>
270+
.custom-content {
271+
background: #fff;
272+
box-shadow: var(--devui-shadow-length-base, 0 1px 4px 0) var(--devui-feedback-overlay-shadow, rgba(37, 43, 58, 0.16));
273+
border-radius: 4px;
274+
margin-left: 32px;
275+
margin-top: 12px;
276+
padding: 12px 20px;
277+
}
278+
.custom-icon {
279+
width: 24px;
280+
height: 24px;
281+
background: #abcdef;
282+
border-radius: 50%;
283+
line-height: 24px;
284+
text-align: center;
285+
color: #FFFFFF;
286+
position: relative;
287+
margin-right: 8px;
288+
z-index: 3;
289+
}
290+
</style>
291+
```
292+
293+
:::
294+
183295
### ActionTimeline 参数
184296

185297
| 参数名 | 类型 | 默认值 | 说明 |
@@ -203,6 +315,7 @@ export default defineComponent({
203315
| :------ | :----------------------- | :------------------------------------------- |
204316
| content | `{ option: ActionItem }` | 必选,内容区域插槽 |
205317
| title | `{ option: ActionItem }` | 标题区域插槽,横向布局时可选,纵向布局时必选 |
318+
| iconContent | `{ option: ActionItem }` | 可选,图标区域插槽 |
206319

207320
### 接口定义
208321

0 commit comments

Comments
 (0)