仿互站小程序
This commit is contained in:
127
vant/notice-bar/index.js
Normal file
127
vant/notice-bar/index.js
Normal file
@@ -0,0 +1,127 @@
|
||||
var t = function() {
|
||||
function t(t, i) {
|
||||
var e = [], n = !0, r = !1, a = void 0;
|
||||
try {
|
||||
for (var o, l = t[Symbol.iterator](); !(n = (o = l.next()).done) && (e.push(o.value),
|
||||
!i || e.length !== i); n = !0) ;
|
||||
} catch (t) {
|
||||
r = !0, a = t;
|
||||
} finally {
|
||||
try {
|
||||
!n && l.return && l.return();
|
||||
} finally {
|
||||
if (r) throw a;
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
return function(i, e) {
|
||||
if (Array.isArray(i)) return i;
|
||||
if (Symbol.iterator in Object(i)) return t(i, e);
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||
};
|
||||
}();
|
||||
|
||||
(0, require("../common/component").VantComponent)({
|
||||
props: {
|
||||
text: {
|
||||
type: [ String, Array ],
|
||||
value: ""
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
value: ""
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
value: ""
|
||||
},
|
||||
openType: {
|
||||
type: String,
|
||||
value: "navigate"
|
||||
},
|
||||
delay: {
|
||||
type: Number,
|
||||
value: 0
|
||||
},
|
||||
speed: {
|
||||
type: Number,
|
||||
value: 50
|
||||
},
|
||||
scrollable: {
|
||||
type: Boolean,
|
||||
value: !0
|
||||
},
|
||||
leftIcon: {
|
||||
type: String,
|
||||
value: ""
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
value: "#ed6a0c"
|
||||
},
|
||||
backgroundColor: {
|
||||
type: String,
|
||||
value: "#fffbe8"
|
||||
}
|
||||
},
|
||||
data: {
|
||||
show: !0,
|
||||
hasRightIcon: !1
|
||||
},
|
||||
watch: {
|
||||
text: function() {
|
||||
this.set({}, this.init);
|
||||
}
|
||||
},
|
||||
created: function() {
|
||||
this.data.mode && this.set({
|
||||
hasRightIcon: !0
|
||||
}), this.resetAnimation = wx.createAnimation({
|
||||
duration: 0,
|
||||
timingFunction: "linear"
|
||||
});
|
||||
},
|
||||
destroyed: function() {
|
||||
this.timer && clearTimeout(this.timer);
|
||||
},
|
||||
methods: {
|
||||
init: function() {
|
||||
var i = this;
|
||||
Promise.all([ this.getRect(".van-notice-bar__content"), this.getRect(".van-notice-bar__content-wrap") ]).then(function(e) {
|
||||
var n = t(e, 2), r = n[0], a = n[1];
|
||||
if (null != r && null != a && r.width && a.width) {
|
||||
var o = i.data, l = o.speed, s = o.scrollable, c = o.delay;
|
||||
if (s && a.width < r.width) {
|
||||
var u = r.width / l * 1e3;
|
||||
i.wrapWidth = a.width, i.contentWidth = r.width, i.duration = u, i.animation = wx.createAnimation({
|
||||
duration: u,
|
||||
timingFunction: "linear",
|
||||
delay: c
|
||||
}), i.scroll();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
scroll: function() {
|
||||
var t = this;
|
||||
this.timer && clearTimeout(this.timer), this.timer = null, this.set({
|
||||
animationData: this.resetAnimation.translateX(this.wrapWidth).step().export()
|
||||
}), setTimeout(function() {
|
||||
t.set({
|
||||
animationData: t.animation.translateX(-t.contentWidth).step().export()
|
||||
});
|
||||
}, 20), this.timer = setTimeout(function() {
|
||||
t.scroll();
|
||||
}, this.duration);
|
||||
},
|
||||
onClickIcon: function() {
|
||||
this.timer && clearTimeout(this.timer), this.timer = null, this.set({
|
||||
show: !1
|
||||
});
|
||||
},
|
||||
onClick: function(t) {
|
||||
this.$emit("click", t);
|
||||
}
|
||||
}
|
||||
});
|
13
vant/notice-bar/index.json
Normal file
13
vant/notice-bar/index.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"van-icon": "../icon/index",
|
||||
"forview": "/utils/forview/index",
|
||||
"van-loading": "/vant/loading/index",
|
||||
"van-dialog": "/vant/dialog/index",
|
||||
"van-button": "/vant/button/index",
|
||||
"van-popup": "/vant/popup/index",
|
||||
"van-tab": "/vant/tab/index",
|
||||
"van-tabs": "/vant/tabs/index"
|
||||
}
|
||||
}
|
12
vant/notice-bar/index.wxml
Normal file
12
vant/notice-bar/index.wxml
Normal file
@@ -0,0 +1,12 @@
|
||||
<view bind:tap="onClick" class="custom-class van-notice-bar {{hasRightIcon?'van-notice-bar--within-icon':''}} {{scrollable?'':'noscrollable'}}" style="color: {{color}}; background-color: {{backgroundColor}};" wx:if="{{show}}">
|
||||
<image class="van-notice-bar__left-icon" src="{{leftIcon}}" wx:if="{{leftIcon}}"></image>
|
||||
<view class="van-notice-bar__content-wrap">
|
||||
<view animation="{{animationData}}" class="van-notice-bar__content">
|
||||
<rich-text nodes="{{text}}"></rich-text>
|
||||
</view>
|
||||
</view>
|
||||
<van-icon bind:tap="onClickIcon" class="van-notice-bar__right-icon" name="cross" wx:if="{{mode==='closeable'}}"></van-icon>
|
||||
<navigator openType="{{openType}}" url="{{url}}" wx:if="{{mode==='link'}}">
|
||||
<van-icon class="van-notice-bar__right-icon" name="arrow"></van-icon>
|
||||
</navigator>
|
||||
</view>
|
56
vant/notice-bar/index.wxss
Normal file
56
vant/notice-bar/index.wxss
Normal file
@@ -0,0 +1,56 @@
|
||||
@import "../area/index.wxss";
|
||||
|
||||
.van-notice-bar {
|
||||
display: flex;
|
||||
height: 40px;
|
||||
padding: 0 15px;
|
||||
font-size: 14px;
|
||||
line-height: 24px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.van-notice-bar--within-icon {
|
||||
position: relative;
|
||||
padding-right: 40px;
|
||||
}
|
||||
|
||||
.van-notice-bar__left-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.van-notice-bar__right-icon {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 15px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.van-notice-bar__content-wrap {
|
||||
position: relative;
|
||||
height: 24px;
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.van-notice-bar__content {
|
||||
position: absolute;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.noscrollable .van-notice-bar__content {
|
||||
max-width: 100%;
|
||||
position: inherit;
|
||||
white-space: inherit;
|
||||
}
|
||||
|
||||
.noscrollable .van-notice-bar__content-wrap {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.noscrollable.van-notice-bar {
|
||||
height: auto;
|
||||
padding: 8px 10px;
|
||||
line-height: 20px;
|
||||
}
|
Reference in New Issue
Block a user