仿互站小程序
This commit is contained in:
27
vant/toast/index.js
Normal file
27
vant/toast/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
(0, require("../common/component").VantComponent)({
|
||||
props: {
|
||||
show: Boolean,
|
||||
mask: Boolean,
|
||||
message: String,
|
||||
forbidClick: Boolean,
|
||||
zIndex: {
|
||||
type: Number,
|
||||
value: 1e3
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
value: "text"
|
||||
},
|
||||
loadingType: {
|
||||
type: String,
|
||||
value: "circular"
|
||||
},
|
||||
position: {
|
||||
type: String,
|
||||
value: "middle"
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
noop: function() {}
|
||||
}
|
||||
});
|
15
vant/toast/index.json
Normal file
15
vant/toast/index.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"van-icon": "../icon/index",
|
||||
"van-loading": "../loading/index",
|
||||
"van-overlay": "../overlay/index",
|
||||
"van-transition": "../transition/index",
|
||||
"forview": "/utils/forview/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/toast/index.wxml
Normal file
12
vant/toast/index.wxml
Normal file
@@ -0,0 +1,12 @@
|
||||
<van-overlay mask="{{mask}}" show="{{show}}" zIndex="{{zIndex}}" wx:if="{{mask||forbidClick}}"></van-overlay>
|
||||
<van-transition customClass="van-toast__container" customStyle="z-index: {{zIndex}}" show="{{show}}">
|
||||
<view catch:touchmove="noop" class="van-toast van-toast--{{type==='text'?'text':'icon'}} van-toast--{{position}}">
|
||||
<text wx:if="{{type==='text'}}">{{message}}</text>
|
||||
<block wx:else>
|
||||
<van-loading color="white" customClass="van-toast__loading" type="{{loadingType}}" wx:if="{{type==='loading'}}"></van-loading>
|
||||
<van-icon class="van-toast__icon" name="{{type}}" wx:else></van-icon>
|
||||
<text class="van-toast__text" wx:if="{{message}}">{{message}}</text>
|
||||
</block>
|
||||
<slot></slot>
|
||||
</view>
|
||||
</van-transition>
|
56
vant/toast/index.wxss
Normal file
56
vant/toast/index.wxss
Normal file
@@ -0,0 +1,56 @@
|
||||
@import "../area/index.wxss";
|
||||
|
||||
.van-toast {
|
||||
display: flex;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
border-radius: 4px;
|
||||
word-break: break-all;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
box-sizing: initial;
|
||||
background-color: rgba(51,51,51,.88);
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.van-toast__container {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
max-width: 70%;
|
||||
width: fit-content;
|
||||
transform: translate(-50%,-50%);
|
||||
}
|
||||
|
||||
.van-toast--text {
|
||||
padding: 8px 12px;
|
||||
min-width: 96px;
|
||||
}
|
||||
|
||||
.van-toast--icon {
|
||||
width: 90px;
|
||||
padding: 15px;
|
||||
min-height: 90px;
|
||||
}
|
||||
|
||||
.van-toast--icon .van-toast__icon {
|
||||
font-size: 48px;
|
||||
}
|
||||
|
||||
.van-toast--icon .van-toast__text {
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
.van-toast__loading {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.van-toast--top {
|
||||
transform: translateY(-30vh);
|
||||
}
|
||||
|
||||
.van-toast--bottom {
|
||||
transform: translateY(30vh);
|
||||
}
|
57
vant/toast/toast.js
Normal file
57
vant/toast/toast.js
Normal file
@@ -0,0 +1,57 @@
|
||||
function e(e) {
|
||||
return (0, o.isObj)(e) ? e : {
|
||||
message: e
|
||||
};
|
||||
}
|
||||
|
||||
function t() {
|
||||
var e = getCurrentPages();
|
||||
return e[e.length - 1];
|
||||
}
|
||||
|
||||
function n(n) {
|
||||
var o = Object.assign({}, i, e(n)), s = (o.context || t()).selectComponent(o.selector);
|
||||
if (s) return delete o.context, delete o.selector, s.clear = function() {
|
||||
s.set({
|
||||
show: !1
|
||||
}), o.onClose && o.onClose();
|
||||
}, r.push(s), s.set(o), clearTimeout(s.timer), o.duration > 0 && (s.timer = setTimeout(function() {
|
||||
s.clear(), r = r.filter(function(e) {
|
||||
return e !== s;
|
||||
});
|
||||
}, o.duration)), s;
|
||||
console.warn("未找到 van-toast 节点,请确认 selector 及 context 是否正确");
|
||||
}
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: !0
|
||||
});
|
||||
|
||||
var o = require("../common/utils"), s = {
|
||||
type: "text",
|
||||
mask: !1,
|
||||
message: "",
|
||||
show: !0,
|
||||
zIndex: 1e3,
|
||||
duration: 3e3,
|
||||
position: "middle",
|
||||
forbidClick: !1,
|
||||
loadingType: "circular",
|
||||
selector: "#van-toast"
|
||||
}, r = [], i = Object.assign({}, s), c = function(t) {
|
||||
return function(o) {
|
||||
return n(Object.assign({
|
||||
type: t
|
||||
}, e(o)));
|
||||
};
|
||||
};
|
||||
|
||||
n.loading = c("loading"), n.success = c("success"), n.fail = c("fail"), n.clear = function() {
|
||||
r.forEach(function(e) {
|
||||
e.clear();
|
||||
}), r = [];
|
||||
}, n.setDefaultOptions = function(e) {
|
||||
Object.assign(i, e);
|
||||
}, n.resetDefaultOptions = function() {
|
||||
i = Object.assign({}, s);
|
||||
}, exports.default = n;
|
Reference in New Issue
Block a user