init
This commit is contained in:
54
fuintUniapp/components/toptips/index.js
Normal file
54
fuintUniapp/components/toptips/index.js
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
var FONT_COLOR = '#fff';
|
||||
var 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: function show() {
|
||||
var _this = this;
|
||||
|
||||
var duration = this.data.duration;
|
||||
|
||||
|
||||
this._timer && clearTimeout(this._timer);
|
||||
this.setData({
|
||||
isShow: true
|
||||
});
|
||||
|
||||
if (duration > 0 && duration !== Infinity) {
|
||||
this._timer = setTimeout(function () {
|
||||
_this.hide();
|
||||
}, duration);
|
||||
}
|
||||
},
|
||||
hide: function hide() {
|
||||
this._timer = clearTimeout(this._timer);
|
||||
|
||||
this.setData({
|
||||
isShow: false,
|
||||
backgroundColor: BG_COLOR
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
3
fuintUniapp/components/toptips/index.json
Normal file
3
fuintUniapp/components/toptips/index.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"component": true
|
||||
}
|
||||
1
fuintUniapp/components/toptips/index.wxml
Normal file
1
fuintUniapp/components/toptips/index.wxml
Normal file
@@ -0,0 +1 @@
|
||||
<view class="zan-toptips {{ isShow ? 'zan-toptips--show' : '' }}" style="background-color:{{ backgroundColor }}">{{ content }}</view>
|
||||
1
fuintUniapp/components/toptips/index.wxss
Normal file
1
fuintUniapp/components/toptips/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
.zan-toptips{display:block;position:fixed;-webkit-transform:translateZ(0) translateY(-100%);width:100%;min-height:32px;top:0;line-height:2.3;font-size:14px;text-align:center;color:#fff;background-color:#e64340;z-index:110;opacity:0;-webkit-transition:all .4s ease;transition:all .4s ease}.zan-toptips--show{-webkit-transform:translateZ(0) translateY(0);opacity:1}
|
||||
28
fuintUniapp/components/toptips/toptips.js
Normal file
28
fuintUniapp/components/toptips/toptips.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
function Toptips() {
|
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
|
||||
var pages = getCurrentPages();
|
||||
var ctx = pages[pages.length - 1];
|
||||
var defaultOptions = {
|
||||
selector: '#zan-toptips',
|
||||
duration: 3000
|
||||
};
|
||||
|
||||
options = Object.assign(defaultOptions, parseParam(options));
|
||||
|
||||
var $toptips = ctx.selectComponent(options.selector);
|
||||
delete options.selector;
|
||||
|
||||
$toptips.setData(Object.assign({}, options));
|
||||
$toptips && $toptips.show();
|
||||
}
|
||||
|
||||
function parseParam() {
|
||||
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
||||
|
||||
return typeof params === 'object' ? params : { content: params };
|
||||
}
|
||||
|
||||
module.exports = Toptips;
|
||||
Reference in New Issue
Block a user