Skip to content

Commit e3daed5

Browse files
jasper-opsMoonofweisheng
authored andcommitted
feat: ✨ 增强notice-bar组件vertical模式下插槽的功能
1 parent 641ebd7 commit e3daed5

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

docs/component/notice-bar.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,18 @@ const onNext = (index: number) => {
109109

110110
1. `direction`传递`vertical`即可开启垂直滚动,目前仅支持一个方向的垂直滚动
111111
2. `text`为数组时才会进行滚动
112-
3. 垂直滚动时会提供`vertical-{index}`的插槽,`text`有几个成员就有几个这样的插槽,索引从 0 开始
113-
4. **插槽内容不应该改变高度,例如设置 height、padding 等可能改变高度的样式,否则会导致滚动不准确**
112+
3. 垂直滚动时会提供`vertical`的插槽,该插槽传递`{item: any, index: number}`
113+
4. <u>**插槽内容不应该改变高度,例如设置 height、padding 等可能改变高度的样式,否则会导致滚动不准确**</u>
114114

115115
```html
116-
<demo-block title="垂直滚动">
117-
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="textArray" :speed="0.5" :delay="3" custom-class="space" />
118-
<wd-notice-bar prefix="warn-bold" direction="vertical" text="只有一条消息不会滚动" :speed="0.5" :delay="3" custom-class="space" />
119-
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="['', '这是文本内容,index:1', '这是文本内容,index:2']" :speed="0.5" :delay="3">
120-
<template #vertical-0>
121-
<!-- 插槽内容不应该改变高度,例如设置height、padding等可能改变高度的样式,否则会导致滚动不准确 -->
122-
<view style="font-weight: 700">索引为0的插槽</view>
123-
</template>
124-
</wd-notice-bar>
125-
</demo-block>
116+
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="textArray" :speed="0.5" :delay="3" custom-class="space" />
117+
<wd-notice-bar prefix="warn-bold" direction="vertical" text="只有一条消息不会滚动" :speed="0.5" :delay="3" custom-class="space" />
118+
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="textArray" :speed="0.5" :delay="3">
119+
<template #vertical="{ item, index }">
120+
<!-- 插槽内容不应该改变高度,例如设置height、padding等可能改变高度的样式,否则会导致滚动不准确 -->
121+
<view style="font-weight: 700; text-decoration: underline">{{ index }}: {{ item }}</view>
122+
</template>
123+
</wd-notice-bar>
126124
```
127125

128126
## Attributes
@@ -150,11 +148,11 @@ const onNext = (index: number) => {
150148

151149
## Slot
152150

153-
| name | 说明 | 最低版本 |
154-
| ---------------- | -------------------- | -------- |
155-
| prefix | 前置图标 | - |
156-
| suffix | 后置插槽 | - |
157-
| vertical-\{index\} | 垂直滚动时提供的插槽 | - |
151+
| name | 说明 | 类型 | 最低版本 |
152+
| -------- | -------------------- | ---------------------------- | -------- |
153+
| prefix | 前置图标 | - | - |
154+
| suffix | 后置插槽 | - | - |
155+
| vertical | 垂直滚动时提供的插槽 | `{item: any, index: number}` | - |
158156

159157
## 外部样式类
160158

src/pages/noticeBar/Index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
<demo-block title="垂直滚动">
7272
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="textArray" :speed="0.5" :delay="3" custom-class="space" />
7373
<wd-notice-bar prefix="warn-bold" direction="vertical" text="只有一条消息不会滚动" :speed="0.5" :delay="3" custom-class="space" />
74-
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="['', '这是文本内容,index:1', '这是文本内容,index:2']" :speed="0.5" :delay="3">
75-
<template #vertical-0>
74+
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="textArray" :speed="0.5" :delay="3">
75+
<template #vertical="{ item, index }">
7676
<!-- 插槽内容不应该改变高度,例如设置height、padding等可能改变高度的样式,否则会导致滚动不准确 -->
77-
<view style="font-weight: 700">索引为0的插槽</view>
77+
<view style="font-weight: 700; text-decoration: underline">{{ index }}: {{ item }}</view>
7878
</template>
7979
</wd-notice-bar>
8080
</demo-block>

src/uni_modules/wot-design-uni/components/wd-notice-bar/wd-notice-bar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<slot v-else name="prefix"></slot>
99
<view class="wd-notice-bar__wrap">
1010
<view class="wd-notice-bar__content" :animation="animation" @transitionend="animationEnd">
11-
<template v-if="direction === 'vertical'">
12-
<slot v-for="(item, i) in textArray" :key="item" :name="`vertical-${i}`">
11+
<template v-if="isVertical">
12+
<slot v-for="(item, i) in textArray" :key="item" name="vertical" :item="item" :index="i">
1313
<view>{{ item }}</view>
1414
</slot>
15-
<slot v-if="textArray.length > 1" name="vertical-0">
15+
<slot v-if="textArray.length > 1" name="vertical" :item="textArray[0]" :index="0">
1616
<view>{{ textArray[0] }}</view>
1717
</slot>
1818
</template>

0 commit comments

Comments
 (0)