From 3167737b99bd35d2fbfaafb7ddfec1d12e471dc9 Mon Sep 17 00:00:00 2001 From: xlaoyu Date: Mon, 25 Jun 2018 20:17:09 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=20Toptips:=20=E4=BF=AE=E5=A4=8Dtoptips?= =?UTF-8?q?=E5=9C=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E5=BC=95=E5=85=A5=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8CbackgroundColor=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#318)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/toptips/README.md | 6 +++--- packages/toptips/index.js | 28 ++-------------------------- packages/toptips/index.wxml | 2 +- packages/toptips/toptips.js | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 packages/toptips/toptips.js diff --git a/packages/toptips/README.md b/packages/toptips/README.md index 1cea4418..53c036ba 100644 --- a/packages/toptips/README.md +++ b/packages/toptips/README.md @@ -30,11 +30,11 @@ Page({ // 使用命令式调用的方式,必须在 wxml 模板中声明组件id, // 默认我们使用了 zan-toptips, 如果使用者要更换,可以手动传入 - -const Toptips = require('path/to/zanui-weapp/dist/toptips/index'); +// 注意和 usingComponents 里引用的路径不一样 +const Toptips = require('path/to/zanui-weapp/dist/toptips/toptips'); Page({ customCallback() { - Toptips('只穿文案展示'); + Toptips('只传文案展示'); } }) diff --git a/packages/toptips/index.js b/packages/toptips/index.js index 0ace58b2..41e47c99 100644 --- a/packages/toptips/index.js +++ b/packages/toptips/index.js @@ -42,33 +42,9 @@ Component({ this._timer = clearTimeout(this._timer); this.setData({ - isShow: false + isShow: false, + backgroundColor: BG_COLOR }); } } }); - -function Toptips(options = {}) { - const pages = getCurrentPages(); - const ctx = pages[pages.length - 1]; - const defaultOptions = { - selector: '#zan-toptips', - duration: 3000 - }; - - options = Object.assign(defaultOptions, parseParam(options)); - - const $toptips = ctx.selectComponent(options.selector); - delete options.selector; - - $toptips.setData({ - ...options - }); - $toptips && $toptips.show(); -} - -function parseParam(params = '') { - return typeof params === 'object' ? params : { content: params }; -} - -module.exports = Toptips; diff --git a/packages/toptips/index.wxml b/packages/toptips/index.wxml index e293b276..bf1757cd 100644 --- a/packages/toptips/index.wxml +++ b/packages/toptips/index.wxml @@ -1 +1 @@ -{{ content }} +{{ content }} diff --git a/packages/toptips/toptips.js b/packages/toptips/toptips.js new file mode 100644 index 00000000..7915ad6b --- /dev/null +++ b/packages/toptips/toptips.js @@ -0,0 +1,25 @@ + +function Toptips(options = {}) { + const pages = getCurrentPages(); + const ctx = pages[pages.length - 1]; + const defaultOptions = { + selector: '#zan-toptips', + duration: 3000 + }; + + options = Object.assign(defaultOptions, parseParam(options)); + + const $toptips = ctx.selectComponent(options.selector); + delete options.selector; + + $toptips.setData({ + ...options + }); + $toptips && $toptips.show(); +} + +function parseParam(params = '') { + return typeof params === 'object' ? params : { content: params }; +} + +module.exports = Toptips; \ No newline at end of file