Skip to content

Commit 6fc786d

Browse files
author
xuqingkai
committed
feat: ✨ Noticebar 通知栏新增支持click点击事件
1 parent b2ad637 commit 6fc786d

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

docs/component/notice-bar.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ const onNext = (index: number) => {
133133

134134
## Events
135135

136-
| 事件名称 | 说明 | 参数 | 最低版本 |
137-
| -------- | ---------------- | --------------- | -------- |
138-
| close | 关闭按钮点击时 | - | - |
139-
| next | 下一次滚动前触发 | index: `number` | - |
136+
| 事件名称 | 说明 | 参数 | 最低版本 |
137+
| -------- | ---------------- | ------------------------------------------------------------------------------ | -------- |
138+
| close | 关闭按钮点击时 | - | - |
139+
| next | 下一次滚动前触发 | index: `number` | - |
140+
| click | 点击时触发 | `{ text: string, index: number }`,其中`text`为当前文本,`index`为当前文本索引 | 1.2.16 |
140141

141142
## Slot
142143

src/pages/noticeBar/Index.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!--
22
* @Author: weisheng
33
* @Date: 2023-06-13 11:47:12
4-
* @LastEditTime: 2024-04-09 21:48:26
4+
* @LastEditTime: 2024-04-16 13:13:31
55
* @LastEditors: weisheng
66
* @Description:
7-
* @FilePath: /wot-design-uni/src/pages/noticeBar/Index.vue
7+
* @FilePath: \wot-design-uni\src\pages\noticeBar\Index.vue
88
* 记得注释
99
-->
1010
<template>
@@ -66,12 +66,12 @@
6666
</demo-block>
6767

6868
<demo-block title="多文本轮播">
69-
<wd-notice-bar :text="textArray" prefix="check-outline" @next="onNext" />
69+
<wd-notice-bar @click="handleClick" :text="textArray" prefix="check-outline" @next="onNext" />
7070
</demo-block>
7171

7272
<demo-block title="垂直滚动">
73-
<wd-notice-bar prefix="warn-bold" direction="vertical" :text="textArray" :delay="3" custom-class="space" />
74-
<wd-notice-bar prefix="warn-bold" direction="vertical" text="只有一条消息不会滚动" :delay="3" custom-class="space" />
73+
<wd-notice-bar @click="handleClick" prefix="warn-bold" direction="vertical" :text="textArray" :delay="3" custom-class="space" />
74+
<wd-notice-bar @click="handleClick" prefix="warn-bold" direction="vertical" text="只有一条消息不会滚动" :delay="3" custom-class="space" />
7575
</demo-block>
7676
</view>
7777
</page-wraper>
@@ -92,6 +92,10 @@ const onNext = (index: number) => {
9292
console.log('展示下一条,index: ', index)
9393
console.log('文本是:' + textArray.value[index])
9494
}
95+
96+
function handleClick(result: { text: string; index: number }) {
97+
console.log(result)
98+
}
9599
</script>
96100
<style lang="scss" scoped>
97101
:deep(.prefix) {

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<wd-icon v-if="prefix" custom-class="wd-notice-bar__prefix" size="18px" :name="prefix"></wd-icon>
44
<slot v-else name="prefix"></slot>
55
<view class="wd-notice-bar__wrap">
6-
<view class="wd-notice-bar__content" :style="animation" @transitionend="animationEnd">
6+
<view class="wd-notice-bar__content" :style="animation" @transitionend="animationEnd" @click="handleClick">
77
<template v-if="isVertical">
88
<view v-for="item in textArray" :key="item">{{ item }}</view>
99
<view v-if="textArray.length > 1">{{ textArray[0] }}</view>
@@ -28,14 +28,14 @@ export default {
2828

2929
<script lang="ts" setup>
3030
import { ref, watch, nextTick, computed, getCurrentInstance, type CSSProperties } from 'vue'
31-
import { getRect, isDef, objToStyle } from '../common/util'
31+
import { getRect, isArray, isDef, objToStyle } from '../common/util'
3232
import { noticeBarProps } from './types'
3333
3434
const $wrap = '.wd-notice-bar__wrap'
3535
const $content = '.wd-notice-bar__content'
3636
3737
const props = defineProps(noticeBarProps)
38-
const emit = defineEmits(['close', 'next'])
38+
const emit = defineEmits(['close', 'next', 'click'])
3939
4040
const wrapWidth = ref<number>(0)
4141
const show = ref<boolean>(true)
@@ -185,6 +185,19 @@ function animationEnd() {
185185
clearTimeout(timer)
186186
}, 20)
187187
}
188+
189+
function handleClick() {
190+
const result = isArray(props.text)
191+
? {
192+
index: currentIndex.value,
193+
text: props.text[currentIndex.value]
194+
}
195+
: {
196+
index: 0,
197+
text: props.text
198+
}
199+
emit('click', result)
200+
}
188201
</script>
189202

190203
<style lang="scss" scoped>

0 commit comments

Comments
 (0)