This commit is contained in:
陈嘉涵 2018-08-11 21:29:02 +08:00
parent d6e1ed07ff
commit 5a9516c275
12 changed files with 142 additions and 205 deletions

30
dist/nav-bar/index.js vendored Normal file
View File

@ -0,0 +1,30 @@
'use strict';
Component({
externalClasses: ['custom-class', 'title-class'],
options: {
multipleSlots: true
},
properties: {
title: String,
leftText: String,
rightText: String,
leftArrow: Boolean,
fixed: Boolean,
zIndex: {
type: Number,
value: 1
}
},
methods: {
onTapLeft: function onTapLeft() {
this.triggerEvent('tap-left');
},
onTapRight: function onTapRight() {
this.triggerEvent('tap-right');
}
}
});

24
dist/nav-bar/index.wxml vendored Normal file
View File

@ -0,0 +1,24 @@
<view
class="custom-class van-nav-bar van-hairline--bottom {{ fixed ? 'van-nav-bar--fixed' : '' }}"
style="z-index: {{ zIndex }}"
>
<view class="van-nav-bar__left" bind:tap="onTapLeft">
<block wx:if="{{ leftArrow || leftText }}">
<van-icon
wx:if="{{ leftArrow }}"
name="arrow"
custom-class="van-nav-bar__arrow"
/>
<view wx:if="{{ leftText }}" class="van-nav-bar__text">{{ leftText }}</view>
</block>
<slot wx:else name="left" />
</view>
<view class="van-nav-bar__title title-class van-ellipsis">
<block wx:if="{{ title }}">{{ title }}</block>
<slot wx:else name="title" />
</view>
<view class="van-nav-bar__right" bind:tap="onTapRight">
<view wx:if="{{ rightText }}" class="van-nav-bar__text">{{ rightText }}</view>
<slot wx:else name="right" />
</view>
</view>

1
dist/nav-bar/index.wxss vendored Normal file
View File

@ -0,0 +1 @@
.van-nav-bar{height:46px;position:relative;-webkit-user-select:none;user-select:none;text-align:center;line-height:46px;background-color:#fff}.van-nav-bar__arrow{color:#38f;vertical-align:middle;-webkit-transform:rotate(180deg);transform:rotate(180deg)}.van-nav-bar__arrow+.van-nav-bar__text{margin-left:-20px;padding-left:25px}.van-nav-bar--fixed{top:0;left:0;width:100%;position:fixed}.van-nav-bar__title{margin:0 auto;max-width:60%;font-size:16px}.van-nav-bar__left,.van-nav-bar__right{bottom:0;font-size:14px;position:absolute}.van-nav-bar__left{left:15px}.van-nav-bar__right{right:15px}.van-nav-bar__text{color:#38f;margin:0 -15px;padding:0 15px;display:inline-block;vertical-align:middle}.van-nav-bar__text:active{background-color:#e8e8e8}

77
dist/notify/index.js vendored Normal file
View File

@ -0,0 +1,77 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Component({
properties: {
text: String,
color: {
type: String,
value: '#fff'
},
backgroundColor: {
type: String,
value: '#e64340'
},
duration: {
type: Number,
value: 3000
}
},
methods: {
show: function show() {
var _this = this;
var duration = this.data.duration;
clearTimeout(this.timer);
this.setData({
show: true
});
if (duration > 0 && duration !== Infinity) {
this.timer = setTimeout(function () {
_this.hide();
}, duration);
}
},
hide: function hide() {
clearTimeout(this.timer);
this.setData({
show: false
});
}
}
});
var defaultOptions = {
selector: '#van-notify',
duration: 3000
};
function Notify() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var pages = getCurrentPages();
var ctx = pages[pages.length - 1];
options = Object.assign({}, defaultOptions, parseParam(options));
var el = ctx.selectComponent(options.selector);
delete options.selector;
if (el) {
el.setData(_extends({}, options));
el.show();
}
}
function parseParam() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
return typeof params === 'object' ? params : { text: params };
}
module.exports = Notify;

3
dist/notify/index.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"component": true
}

6
dist/notify/index.wxml vendored Normal file
View File

@ -0,0 +1,6 @@
<view
class="van-notify {{ show ? 'van-notify--show' : '' }}"
style="background-color:{{ backgroundColor }}"
>
{{ text }}
</view>

1
dist/notify/index.wxss vendored Normal file
View File

@ -0,0 +1 @@
.van-notify{top:0;opacity:0;width:100%;z-index:110;color:#fff;position:fixed;min-height:32px;line-height:2.3;font-size:14px;text-align:center;background-color:#e64340;-webkit-transition:all .4s ease;transition:all .4s ease;-webkit-transform:translateZ(0) translateY(-100%);transform:translateZ(0) translateY(-100%)}.van-notify--show{opacity:1;-webkit-transform:translateZ(0) translateY(0);transform:translateZ(0) translateY(0)}

38
dist/toast/index.js vendored
View File

@ -1,38 +0,0 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var DEFAULT_DATA = {
show: false,
message: '',
icon: '',
image: '',
mask: false
};
var SUPPORT_TYPE = ['loading', 'success', 'fail'];
Component({
data: _extends({}, DEFAULT_DATA),
methods: {
show: function show(options) {
var toastOptions = _extends({}, options);
var icon = options.icon || '';
var image = options.image || '';
if (SUPPORT_TYPE.indexOf(options.type) > -1) {
icon = options.type;
image = '';
}
this.setData(_extends({}, toastOptions, {
icon: icon,
image: image
}));
},
clear: function clear() {
this.setData(_extends({}, DEFAULT_DATA));
}
}
});

30
dist/toast/index.wxml vendored
View File

@ -1,30 +0,0 @@
<view
class="van-toast {{ !message ? 'van-toast--notitle' : '' }}"
wx:if="{{ show }}"
bindtap="clearZanToast"
>
<!-- icon 展示 -->
<block
wx:if="{{ icon || image }}"
>
<view
wx:if="{{ image }}"
class="van-toast__icon van-toast__icon-image"
style="background-image: url({{ image }});"
></view>
<view
wx:elif="{{ icon === 'loading' }}"
class="van-toast__icon van-toast__icon-loading"
>
<view class="van-loading"></view>
</view>
<van-icon
wx:else
type="{{ icon }}"
class="van-toast__icon"
></van-icon>
</block>
<!-- 文案展示 -->
<view wx:if="{{ message }}">{{ message }}</view>
</view>

View File

@ -1 +0,0 @@
.van-toast{position:fixed;top:35%;left:50%;-webkit-transform:translate3d(-50%,-50%,0);transform:translate3d(-50%,-50%,0);background:rgba(0,0,0,.7);color:#fff;font-size:14px;line-height:1.5em;margin:0 auto;box-sizing:border-box;padding:10px 18px;text-align:center;border-radius:4px;z-index:100}.van-toast--notitle{padding:18px}.van-toast__icon{display:block;width:40px;height:40px;line-height:40px;margin:0 auto;padding:12px 15px;font-size:38px;text-align:center}.van-toast__icon-loading{line-height:0}.van-loading{width:20px;height:20px;display:inline-block;vertical-align:middle;-webkit-animation:weuiLoading 1s steps(12,end) infinite;animation:weuiLoading 1s steps(12,end) infinite;background:transparent url(data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iciIgd2lkdGg9JzEyMHB4JyBoZWlnaHQ9JzEyMHB4JyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJub25lIiBjbGFzcz0iYmsiPjwvcmVjdD4KICAgIDxyZWN0IHg9JzQ2LjUnIHk9JzQwJyB3aWR0aD0nNycgaGVpZ2h0PScyMCcgcng9JzUnIHJ5PSc1JyBmaWxsPScjRTlFOUU5JwogICAgICAgICAgdHJhbnNmb3JtPSdyb3RhdGUoMCA1MCA1MCkgdHJhbnNsYXRlKDAgLTMwKSc+CiAgICA8L3JlY3Q+CiAgICA8cmVjdCB4PSc0Ni41JyB5PSc0MCcgd2lkdGg9JzcnIGhlaWdodD0nMjAnIHJ4PSc1JyByeT0nNScgZmlsbD0nIzk4OTY5NycKICAgICAgICAgIHRyYW5zZm9ybT0ncm90YXRlKDMwIDUwIDUwKSB0cmFuc2xhdGUoMCAtMzApJz4KICAgICAgICAgICAgICAgICByZXBlYXRDb3VudD0naW5kZWZpbml0ZScvPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyM5Qjk5OUEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSg2MCA1MCA1MCkgdHJhbnNsYXRlKDAgLTMwKSc+CiAgICAgICAgICAgICAgICAgcmV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ZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNDQkNCQ0InCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgyNDAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNEMkQyRDInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgyNzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNEQURBREEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMDAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNFMkUyRTInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0Pgo8L3N2Zz4=) no-repeat;background-size:100%}.van-toast__icon-loading .van-loading{width:40px;height:40px}.van-toast__icon-image{background-size:40px;background-position:center;background-repeat:no-repeat}

136
dist/toast/toast.js vendored
View File

@ -1,136 +0,0 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var TOAST_CONFIG_KEY = 'vant.__zanToastPageConfig';
var DEFAULT_SHOW_TOAST_TIME = 3000;
var timeoutData = {
timeoutId: 0,
toastCtx: null
};
var globalToastUserConfig = {};
// 获取页面上下文
function getPageCtx(pageCtx) {
var ctx = pageCtx;
if (!ctx) {
var pages = getCurrentPages();
ctx = pages[pages.length - 1];
}
return ctx;
}
// 获取当前页面的 toast 配置数据
function getPageToastConfig(pageCtx) {
var vantData = pageCtx.data.vant || {};
return vantData.__zanToastPageConfig || {};
}
// Toast 显示函数
function Toast(optionsOrMsg, pageCtx) {
// 参数格式化处理
// 如果是文字,默认为 message
var options = optionsOrMsg || {};
if (typeof optionsOrMsg === 'string') {
options = { message: optionsOrMsg };
}
var ctx = getPageCtx(pageCtx);
var pageToastUserSetting = getPageToastConfig(ctx);
var parsedOptions = _extends({}, globalToastUserConfig, pageToastUserSetting, options);
var toastCtx = ctx.selectComponent(parsedOptions.selector);
if (!toastCtx) {
console.error('无法找到对应的toast组件请于页面中注册并在 wxml 中声明 toast 自定义组件');
return;
}
if (timeoutData.timeoutId) {
Toast.clear();
}
toastCtx.show(_extends({}, parsedOptions, {
show: true
}));
var timeoutId = 0;
// toast 计时如果小于0就不会去关闭。
// 如果不传,就取默认值
var timeoutOption = parsedOptions.timeout || DEFAULT_SHOW_TOAST_TIME;
if (timeoutOption >= 0) {
timeoutId = setTimeout(function () {
toastCtx.clear();
}, timeoutOption);
}
timeoutData = {
timeoutId: timeoutId,
toastCtx: toastCtx
};
}
// 设置 toast 基础属性
Toast.setDefaultOptions = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'page';
var parsedDefaultOptions = {
selector: options.selector || '',
type: options.type || '',
icon: options.icon || '',
image: options.image || '',
timeout: options.timeout || DEFAULT_SHOW_TOAST_TIME
};
if (type === 'global') {
globalToastUserConfig = _extends({}, parsedDefaultOptions);
} else if (type === 'page') {
var _ctx$setData;
var ctx = getPageCtx();
ctx.setData((_ctx$setData = {}, _ctx$setData['' + TOAST_CONFIG_KEY] = parsedDefaultOptions, _ctx$setData));
}
};
// 重置 toast 基础属性
Toast.resetDefaultOptions = function () {
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'page';
if (type === 'global') {
globalToastUserConfig = {};
} else {
var _ctx$setData2;
var ctx = getPageCtx();
ctx.setData((_ctx$setData2 = {}, _ctx$setData2['' + TOAST_CONFIG_KEY] = {}, _ctx$setData2));
}
};
// 清理所有 toast
Toast.clear = function () {
clearTimeout(timeoutData.timeoutId);
try {
timeoutData.toastCtx && timeoutData.toastCtx.clear();
} catch (e) {}
timeoutData = {
timeoutId: 0,
toastCtx: null
};
};
// 显示 loading
Toast.loading = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
Toast(_extends({}, options, {
type: 'loading'
}));
};
module.exports = Toast;