vant components

This commit is contained in:
cookfront
2017-04-19 17:33:44 +08:00
commit 63c549d651
346 changed files with 25710 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
## 0.0.2 (2017-01-20)
* 改了bug A
* 加了功能B
## 0.0.1 (2017-01-10)
* 第一版
+26
View File
@@ -0,0 +1,26 @@
# @youzan/<%= name %>
!!! 请在此处填写你的文档最简单描述 !!!
[![version][version-image]][download-url]
[![download][download-image]][download-url]
[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square
[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square
[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %>
## Demo
## Usage
## API
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| className | 自定义额外类名 | string | '' | '' |
## License
[MIT](https://opensource.org/licenses/MIT)
+3
View File
@@ -0,0 +1,3 @@
import Dialog from './src/dialog.js';
export default Dialog;
+10
View File
@@ -0,0 +1,10 @@
{
"name": "@youzan/van-dialog",
"version": "0.0.1",
"description": "dialog component",
"main": "./index.js",
"author": "zhangmin <zhangmin@youzan.com>",
"license": "MIT",
"devDependencies": {},
"dependencies": {}
}
+102
View File
@@ -0,0 +1,102 @@
import Vue from 'vue';
import Dialog from './dialog.vue';
import merge from 'src/utils/merge';
const DialogConstructor = Vue.extend(Dialog);
let currentDialog;
let instance;
let dialogQueue = [];
const defaultCallback = action => {
if (currentDialog) {
const callback = currentDialog.callback;
if (typeof callback === 'function') {
callback(action);
}
if (currentDialog.resolve && action === 'confirm') {
currentDialog.resolve(action);
} else if (currentDialog.reject && action === 'cancel') {
currentDialog.reject(action);
}
}
};
const initInstance = () => {
instance = new DialogConstructor({
el: document.createElement('div')
});
instance.callback = defaultCallback;
};
const showNextDialog = () => {
if (!instance) {
initInstance();
}
if (!instance.value && dialogQueue.length > 0) {
currentDialog = dialogQueue.shift();
const options = currentDialog.options;
for (const prop in options) {
if (options.hasOwnProperty(prop)) {
instance[prop] = options[prop];
}
}
if (options.callback === undefined) {
instance.callback = defaultCallback;
}
document.body.appendChild(instance.$el);
Vue.nextTick(() => {
instance.value = true;
});
}
};
var DialogBox = options => {
return new Promise((resolve, reject) => { // eslint-disable-line
dialogQueue.push({
options: merge({}, options),
callback: options.callback,
resolve: resolve,
reject: reject
});
showNextDialog();
});
};
DialogBox.alert = function(options) {
return DialogBox(merge({
type: 'alert',
title: '',
message: '',
closeOnClickOverlay: false,
showCancelButton: false
}, options));
};
DialogBox.confirm = function(options) {
return DialogBox(merge({
type: 'confirm',
title: '',
message: '',
closeOnClickOverlay: true,
showCancelButton: true
}, options));
};
DialogBox.close = function() {
instance.value = false;
dialogQueue = [];
currentDialog = null;
};
export default DialogBox;
+83
View File
@@ -0,0 +1,83 @@
<template>
<transition name="dialog-bounce">
<div class="van-dialog-wrapper">
<div class="van-dialog" v-show="value">
<div class="van-dialog__header" v-if="title">
<div class="van-dialog__title" v-text="title"></div>
</div>
<div class="van-dialog__content" v-if="message">
<div class="van-dialog__message" :class="{ 'van-dialog__message--notitle': !title }" v-html="message"></div>
</div>
<div class="van-dialog__footer" :class="{ 'is-twobtn': showCancelButton && showConfirmButton }">
<button class="van-dialog__btn van-dialog__cancel" v-show="showCancelButton" @click="handleAction('cancel')">{{ cancelButtonText }}</button>
<button class="van-dialog__btn van-dialog__confirm" v-show="showConfirmButton" @click="handleAction('confirm')">{{ confirmButtonText }}</button>
</div>
</div>
</div>
</transition>
</template>
<script>
import Popup from 'src/mixins/popup';
const CANCEL_TEXT = '取消';
const CONFIRM_TEXT = '确认';
export default {
name: 'van-dialog',
mixins: [Popup],
props: {
overlay: {
default: true
},
closeOnClickOverlay: {
default: true
},
lockOnScroll: {
default: true
}
},
data() {
return {
title: '',
message: '',
type: '',
showConfirmButton: true,
showCancelButton: false,
confirmButtonText: CONFIRM_TEXT,
cancelButtonText: CANCEL_TEXT,
callback: null
};
},
methods: {
handleAction(action) {
this.value = false;
this.callback && this.callback(action);
},
close() {
if (this.closing) return;
this.closing = true;
this.value = false;
if (this.lockOnScroll) {
setTimeout(() => {
if (this.overlay && this.bodyOverflow !== 'hidden') {
document.body.style.overflow = this.bodyOverflow;
}
this.bodyOverflow = null;
}, 200);
}
this.opened = false;
this.doAfterClose();
}
}
};
</script>