diff --git a/components/notice-bar/index.js b/components/notice-bar/index.js deleted file mode 100644 index 87d35bb..0000000 --- a/components/notice-bar/index.js +++ /dev/null @@ -1,165 +0,0 @@ -import baseComponent from '../helpers/baseComponent' -import classNames from '../helpers/classNames' - -baseComponent({ - properties: { - prefixCls: { - type: String, - value: 'wux-notice-bar', - }, - icon: { - type: String, - value: null, - }, - content: { - type: String, - value: '', - }, - mode: { - type: String, - value: '', - }, - action: { - type: String, - value: null, - }, - loop: { - type: Boolean, - value: false, - }, - leading: { - type: Number, - value: 500, - }, - trailing: { - type: Number, - value: 1000, - }, - speed: { - type: Number, - value: 25, - }, - }, - data: { - animatedWidth: 0, - overflowWidth: 0, - visible: true, - }, - computed: { - classes: ['prefixCls', function(prefixCls) { - const wrap = classNames(prefixCls) - const hd = `${prefixCls}__hd` - const icon = `${prefixCls}__icon` - const bd = `${prefixCls}__bd` - const container = `${prefixCls}__marquee-container` - const marquee = `${prefixCls}__marquee` - const ft = `${prefixCls}__ft` - const action = `${prefixCls}__action` - - return { - wrap, - hd, - icon, - bd, - container, - marquee, - ft, - action, - } - }], - }, - observers: { - content() { - this.resetAnimation() - }, - }, - methods: { - clearMarqueeTimer() { - if (this.marqueeTimer) { - clearTimeout(this.marqueeTimer) - this.marqueeTimer = null - } - }, - startAnimation() { - this.clearMarqueeTimer() - const { loop, leading, trailing, speed } = this.data - const isLeading = this.data.animatedWidth === 0 - const timeout = isLeading ? leading : speed - const animate = () => { - let animatedWidth = this.data.animatedWidth + 1 - const isRoundOver = animatedWidth > this.data.overflowWidth - // 判断是否完成一次滚动 - if (isRoundOver) { - if (!loop) return - // 重置初始位置 - animatedWidth = 0 - } - // 判断是否等待一段时间后进行下一次滚动 - if (isRoundOver && trailing) { - this.triggerEvent('loop') - setTimeout(() => { - this.setData({ animatedWidth }) - this.marqueeTimer = setTimeout(animate, speed) - }, trailing) - } else { - this.setData({ animatedWidth }) - this.marqueeTimer = setTimeout(animate, speed) - - } - } - if (this.data.overflowWidth !== 0) { - this.marqueeTimer = setTimeout(animate, timeout) - } - }, - initAnimation(isForce) { - const { prefixCls } = this.data - const query = wx.createSelectorQuery().in(this) - query.select(`.${prefixCls}__marquee-container`).boundingClientRect() - query.select(`.${prefixCls}__marquee`).boundingClientRect() - query.exec((rects) => { - if (rects.filter((n) => !n).length) return - - const [container, text] = rects - const overflowWidth = text.width - container.width - if (this.data.overflowWidth !== overflowWidth || isForce) { - this.setData({ overflowWidth, animatedWidth: 0 }, () => { - // 当文本内容存在且长度可滚动时,才触发动画 - if (text.width > 0 && overflowWidth > 0) { - this.startAnimation() - } else { - this.startLoop() - } - }) - } - }) - }, - startLoop: function () { - this.clearMarqueeTimer() - this.marqueeTimer = setTimeout(() => { - this.triggerEvent('loop') - }, 3000) - }, - resetAnimation() { - this.initAnimation(true) - }, - stopAnimation() { - this.clearMarqueeTimer() - }, - onAction() { - if (this.data.mode === 'closable') { - this.clearMarqueeTimer() - this.setData({ visible: false }) - } - this.triggerEvent('click') - }, - onClick() { - this.triggerEvent('click') - }, - }, - ready() { - this.initAnimation() - }, - detached() { - this.clearMarqueeTimer() - }, -}) diff --git a/components/notice-bar/index.json b/components/notice-bar/index.json deleted file mode 100644 index fba482a..0000000 --- a/components/notice-bar/index.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "component": true -} \ No newline at end of file diff --git a/components/notice-bar/index.wxml b/components/notice-bar/index.wxml deleted file mode 100644 index 478a29c..0000000 --- a/components/notice-bar/index.wxml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - {{ content }} - - - - - - - - - - - \ No newline at end of file diff --git a/components/notice-bar/index.wxss b/components/notice-bar/index.wxss deleted file mode 100644 index 19cc41c..0000000 --- a/components/notice-bar/index.wxss +++ /dev/null @@ -1,52 +0,0 @@ -.wux-notice-bar { - background-color: #fefcec; - height: 72rpx; - overflow: hidden; - font-size: 28rpx; - line-height: 72rpx; - color: #f76a24; - display: -ms-flexbox; - display: flex; - padding: 0 20rpx -} -.wux-notice-bar__icon { - width: 30rpx; - height: 30rpx; - margin-right: 20rpx -} -.wux-notice-bar__action { - width: 30rpx; - height: 30rpx; - margin-left: 20rpx -} -.wux-notice-bar__hd { - display: -ms-flexbox; - display: flex; - margin-right: 8rpx; - -ms-flex-align: center; - align-items: center -} -.wux-notice-bar__bd { - -ms-flex: 1; - flex: 1; - width: 100%; - width: auto; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap -} -.wux-notice-bar__marquee-container { - overflow: hidden -} -.wux-notice-bar__marquee { - position: relative; - transform: translate3d(0,0,0); - white-space: nowrap; - display: inline-block -} -.wux-notice-bar__ft { - display: -ms-flexbox; - display: flex; - -ms-flex-align: center; - align-items: center -} \ No newline at end of file diff --git a/pages/article/hot-index/index.js b/pages/article/hot-index/index.js index f9c2716..2070713 100644 --- a/pages/article/hot-index/index.js +++ b/pages/article/hot-index/index.js @@ -155,8 +155,6 @@ Component({ this.fetchNoticeList() } this.setData({ content: this.data.noticeList[this.data.noticeIndex].title }) - this.notice = this.notice || this.selectComponent('#wux-notice-bar') - this.notice.resetAnimation() }, onClick: function(){ wx.navigateTo({ url: '/pages/html/notice/index?id=' + this.data.noticeList[this.data.noticeIndex].id }) diff --git a/pages/article/hot-index/index.json b/pages/article/hot-index/index.json index ebee684..4fb567e 100644 --- a/pages/article/hot-index/index.json +++ b/pages/article/hot-index/index.json @@ -8,7 +8,6 @@ "wux-col": "/components/col/index", "wux-grids": "/components/grids/index", "wux-grid": "/components/grid/index", - "wux-notice-bar": "/components/notice-bar/index", "wux-divider": "/components/divider/index", "wux-image": "/components/image/index", "refresh-view": "/components/refresher/index", diff --git a/pages/article/hot-index/index.wxml b/pages/article/hot-index/index.wxml index e9bd6be..42450a7 100644 --- a/pages/article/hot-index/index.wxml +++ b/pages/article/hot-index/index.wxml @@ -1,40 +1,5 @@ - - -