kobeCristiano e37472805c [refactor]Toptips:升级为自定义组件 (#169)
* [improvement] Tab:升级到自定义组件

* fix: 去除冗余example代码

* [refactor] 重构badge为自定义组件 (#160)

* fix: 去除tab组件使用对象入参方式,修改example用例

* refactor: 重构noticebar组件

* fix: 去除tab组件冗余属性字段

* refactor: 重构toptips为自定义组件
2018-03-28 15:12:03 +08:00

74 lines
1.3 KiB
JavaScript

const FONT_COLOR = '#fff';
const BG_COLOR = '#e64340';
Component({
properties: {
content: String,
color: {
type: String,
value: FONT_COLOR
},
backgroundColor: {
type: String,
value: BG_COLOR
},
isShow: {
type: Boolean,
value: false
},
duration: {
type: Number,
value: 3000
}
},
methods: {
show() {
const duration = this.data.duration;
this._timer && clearTimeout(this._timer);
this.setData({
isShow: true
});
if (duration > 0 && duration !== Infinity) {
this._timer = setTimeout(() => {
this.hide();
}, duration);
}
},
hide() {
this._timer = clearTimeout(this._timer);
this.setData({
isShow: false
});
}
}
});
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;