From e37472805c3644f6ce61214f55d8c967585f1b29 Mon Sep 17 00:00:00 2001 From: kobeCristiano Date: Wed, 28 Mar 2018 15:12:03 +0800 Subject: [PATCH] =?UTF-8?q?[refactor]Toptips=EF=BC=9A=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E4=B8=BA=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=20(#169)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [improvement] Tab:升级到自定义组件 * fix: 去除冗余example代码 * [refactor] 重构badge为自定义组件 (#160) * fix: 去除tab组件使用对象入参方式,修改example用例 * refactor: 重构noticebar组件 * fix: 去除tab组件冗余属性字段 * refactor: 重构toptips为自定义组件 --- example/pages/toptips/index.js | 45 +++++++++-- example/pages/toptips/index.json | 5 +- example/pages/toptips/index.wxml | 20 ++++- packages/noticebar/index.js | 8 +- packages/tab/index.js | 19 +---- packages/tab/index.wxml | 6 +- packages/toptips/README.md | 132 +++++++++++++++++++++++++++---- packages/toptips/index.js | 97 +++++++++++++++-------- packages/toptips/index.json | 3 + packages/toptips/index.wxml | 4 +- 10 files changed, 259 insertions(+), 80 deletions(-) create mode 100644 packages/toptips/index.json diff --git a/example/pages/toptips/index.js b/example/pages/toptips/index.js index 62926a82..79f6d0e0 100644 --- a/example/pages/toptips/index.js +++ b/example/pages/toptips/index.js @@ -1,9 +1,44 @@ -var Zan = require('../../dist/index'); +const Toptips = require('../../dist/toptips/index'); -Page(Object.assign({}, Zan.TopTips, { - data: {}, +Page({ + data: { + content: '测试toptips', + duration: 2000, + $zanui: { + toptips: { + show: false + } + } + }, showTopTips() { - this.showZanTopTips('toptips的内容'); + this.setData({ + $zanui: { + toptips: { + show: true + } + } + }); + + setTimeout(() => { + this.setData({ + $zanui: { + toptips: { + show: false + } + } + }); + },this.data.duration); + }, + + showTopTips2() { + Toptips('测试内容'); + }, + + showTopTips3() { + Toptips({ + duration: 1000, + content: '测试时间1秒' + }) } -})); +}); diff --git a/example/pages/toptips/index.json b/example/pages/toptips/index.json index 3f45367d..a2099cd9 100644 --- a/example/pages/toptips/index.json +++ b/example/pages/toptips/index.json @@ -1,3 +1,6 @@ { - "navigationBarTitleText": "Toptips 顶部提示" + "navigationBarTitleText": "Toptips 顶部提示", + "usingComponents": { + "zan-toptips": "../../dist/toptips/index" + } } diff --git a/example/pages/toptips/index.wxml b/example/pages/toptips/index.wxml index bc84428d..8e40027f 100644 --- a/example/pages/toptips/index.wxml +++ b/example/pages/toptips/index.wxml @@ -6,9 +6,25 @@ + + + + + + + + - + diff --git a/packages/noticebar/index.js b/packages/noticebar/index.js index 4b0a8ca2..7c0c67f2 100644 --- a/packages/noticebar/index.js +++ b/packages/noticebar/index.js @@ -66,6 +66,11 @@ Component({ } }, + detached() { + const { timer } = this.data; + timer && clearTimeout(timer); + }, + ready() { this._init(); }, @@ -105,7 +110,6 @@ Component({ if (scrollable && wrapWidth < width) { const elapse = width / speed * 1000; - console.log(`delay: ${delay}`) const animation = wx.createAnimation({ duration: elapse, timeingFunction: 'linear', @@ -162,4 +166,4 @@ Component({ }); } } -}) \ No newline at end of file +}) diff --git a/packages/tab/index.js b/packages/tab/index.js index 37c9b6ab..23568383 100644 --- a/packages/tab/index.js +++ b/packages/tab/index.js @@ -20,31 +20,16 @@ Component({ }, selectedId: { type: [String, Number], - value: '', - observer(newVal) { - this.setData({ - currentTab: newVal - }); - } + value: '' } }, - data: { - currentTab: '' - }, - - attached() { - this.setData({ - currentTab: this.data.selectedId - }); - }, - methods: { _handleZanTabChange(e) { const selectedId = e.currentTarget.dataset.itemId; this.setData({ - currentTab: selectedId + selectedId }); console.info('[zan:tab:change] selectedId:', selectedId); diff --git a/packages/tab/index.wxml b/packages/tab/index.wxml index 60474ed1..1a52111e 100644 --- a/packages/tab/index.wxml +++ b/packages/tab/index.wxml @@ -10,7 +10,7 @@ >