diff --git a/build/bin/build-entry.js b/build/bin/build-entry.js
index 2419df433..a976ee92e 100644
--- a/build/bin/build-entry.js
+++ b/build/bin/build-entry.js
@@ -51,7 +51,7 @@ ComponentNames.forEach(name => {
'Lazyload',
// services
- 'MessageBox',
+ 'Dialog',
'Toast',
'Indicator'
].indexOf(componentName) === -1) {
diff --git a/components.json b/components.json
index a11836bf4..1ed3e41c2 100644
--- a/components.json
+++ b/components.json
@@ -6,5 +6,6 @@
"cell": "./packages/cell/index.js",
"icon": "./packages/icon/index.js",
"cell-group": "./packages/cell-group/index.js",
- "popup": "./packages/popup/index.js"
+ "popup": "./packages/popup/index.js",
+ "dialog": "./packages/dialog/index.js"
}
diff --git a/docs/examples/dialog.md b/docs/examples/dialog.md
new file mode 100644
index 000000000..05fa69801
--- /dev/null
+++ b/docs/examples/dialog.md
@@ -0,0 +1,40 @@
+
+
+## Dialog组件
+
+### 基础用法
+
+:::demo
+```html
+alert
+
+confirm
+```
+:::
+
+### API
+
+| 参数 | 说明 | 类型 | 默认值 | 可选值 |
+|-----------|-----------|-----------|-------------|-------------|
+| title | 标题 | String | '' | |
+| message | 内容 | String | '' | |
diff --git a/docs/examples/popup.md b/docs/examples/popup.md
index e5ca59b0b..3778b530e 100644
--- a/docs/examples/popup.md
+++ b/docs/examples/popup.md
@@ -81,4 +81,4 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
-| value | 利用`v-model`绑定当前组件是否显示 | Boolean | '' | |
\ No newline at end of file
+| value | 利用`v-model`绑定当前组件是否显示 | Boolean | '' | |
diff --git a/docs/nav.config.json b/docs/nav.config.json
index 38c9aee7c..6046705d1 100644
--- a/docs/nav.config.json
+++ b/docs/nav.config.json
@@ -80,6 +80,10 @@
"path": "/popup",
"title": "Popup"
},
+ {
+ "path": "/dialog",
+ "title": "Dialog"
+ },
{
"path": "/swipe",
"title": "Swipe"
diff --git a/packages/dialog/CHANGELOG.md b/packages/dialog/CHANGELOG.md
new file mode 100644
index 000000000..e88c472b3
--- /dev/null
+++ b/packages/dialog/CHANGELOG.md
@@ -0,0 +1,8 @@
+## 0.0.2 (2017-01-20)
+
+* 改了bug A
+* 加了功能B
+
+## 0.0.1 (2017-01-10)
+
+* 第一版
diff --git a/packages/dialog/README.md b/packages/dialog/README.md
new file mode 100644
index 000000000..4c6172563
--- /dev/null
+++ b/packages/dialog/README.md
@@ -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)
diff --git a/packages/dialog/index.js b/packages/dialog/index.js
new file mode 100644
index 000000000..cb8dcd8d5
--- /dev/null
+++ b/packages/dialog/index.js
@@ -0,0 +1,3 @@
+import Dialog from './src/dialog.js';
+
+export default Dialog;
diff --git a/packages/dialog/package.json b/packages/dialog/package.json
new file mode 100644
index 000000000..7dbfa2900
--- /dev/null
+++ b/packages/dialog/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "<%= name %>",
+ "version": "<%= version %>",
+ "description": "<%= description %>",
+ "main": "./lib/index.js",
+ "author": "<%= author %>",
+ "license": "<%= license %>",
+ "devDependencies": {},
+ "dependencies": {}
+}
diff --git a/packages/dialog/src/dialog.js b/packages/dialog/src/dialog.js
new file mode 100644
index 000000000..bb08501b8
--- /dev/null
+++ b/packages/dialog/src/dialog.js
@@ -0,0 +1,98 @@
+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) {
+ let callback = currentDialog.callback;
+
+ if (typeof callback === 'function') {
+ callback(action);
+ }
+
+ if (currentDialog.resolve && action !== 'cancel') {
+ currentDialog.resolve(action);
+ } else {
+ currentDialog.reject(action);
+ }
+ }
+};
+
+var initInstance = () => {
+ instance = new DialogConstructor({
+ el: document.createElement('div')
+ });
+
+ instance.callback = defaultCallback;
+};
+
+var showNextDialog = () => {
+ if (!instance) {
+ initInstance();
+ }
+
+ if (!instance.value && dialogQueue.length > 0) {
+ currentDialog = dialogQueue.shift();
+
+ let options = currentDialog.options;
+
+ for (let prop in options) {
+ if (options.hasOwnProperty(prop)) {
+ instance[prop] = options[prop];
+ }
+ }
+ console.log(instance)
+
+ if (options.callback === undefined) {
+ instance.callback = defaultCallback;
+ }
+
+ document.body.appendChild(instance.$el);
+
+ Vue.nextTick(() => {
+ instance.value = true;
+ });
+ }
+};
+
+var DialogBox = options => {
+ console.log(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',
+ closeOnClickOverlay: false
+ }, options));
+};
+
+DialogBox.confirm = function(options) {
+ return DialogBox(merge({
+ type: 'confirm',
+ showCancelButton: true
+ }, options));
+};
+
+DialogBox.close = function() {
+ instance.value = false;
+ dialogQueue = [];
+ currentDialog = null;
+};
+
+export default DialogBox;
diff --git a/packages/dialog/src/dialog.vue b/packages/dialog/src/dialog.vue
new file mode 100644
index 000000000..62a1124c4
--- /dev/null
+++ b/packages/dialog/src/dialog.vue
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
diff --git a/packages/zanui/src/dialog.pcss b/packages/zanui/src/dialog.pcss
new file mode 100644
index 000000000..c6b2b4d48
--- /dev/null
+++ b/packages/zanui/src/dialog.pcss
@@ -0,0 +1,87 @@
+@import "./mixins/border_retina.pcss";
+
+@component-namespace o2 {
+ @component dialog-wrapper {
+ position: absolute;
+ }
+
+ @component dialog {
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ transform: translate3d(-50%, -50%, 0);
+ background-color: #fff;
+ width: 85%;
+ border-radius: 4px;
+ font-size: 16px;
+ overflow: hidden;
+ backface-visibility: hidden;
+ transition: .2s;
+
+ @descendent header {
+ padding: 15px 0 0;
+ }
+
+ @descendent content {
+ padding: 10px 20px 15px;
+ min-height: 36px;
+ position: relative;
+
+ &::after {
+ @mixin border-retina (bottom);
+ }
+ }
+
+ @descendent title {
+ text-align: center;
+ padding-left: 0;
+ margin-bottom: 0;
+ font-size: 16px;
+ color: #333;
+ }
+
+ @descendent message {
+ color: #999;
+ margin: 0;
+ text-align: center;
+ font-size: 14px;
+ line-height: 36px;
+ }
+
+ @descendent footer {
+ font-size: 14px;
+ overflow: hidden;
+ }
+
+ .is-twobtn {
+ .o2-dialog-btn {
+ width: 50%;
+ }
+
+ .o2-dialog-cancel {
+ &::after {
+ @mixin border-retina (right);
+ }
+ }
+ }
+
+ @descendent btn {
+ line-height: 40px;
+ border: 0;
+ background-color: #fff;
+ float: left;
+ box-sizing: border-box;
+ text-align: center;
+ position: relative;
+ }
+
+ @descendent cancel {
+ color: #333;
+ }
+
+ @descendent confirm {
+ color: #00C000;
+ width: 100%;
+ }
+ }
+}
diff --git a/packages/zanui/src/index.pcss b/packages/zanui/src/index.pcss
index 554cafe0f..64007adf1 100644
--- a/packages/zanui/src/index.pcss
+++ b/packages/zanui/src/index.pcss
@@ -3,6 +3,7 @@
*/
@import './button.pcss';
@import './cell.pcss';
+@import './dialog.pcss';
@import './field.pcss';
@import './icon.pcss';
@import './popup.pcss';
diff --git a/src/index.js b/src/index.js
index 42ea5ca67..b3dd83c70 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,6 +6,7 @@ import Cell from '../packages/cell/index.js';
import Icon from '../packages/icon/index.js';
import CellGroup from '../packages/cell-group/index.js';
import Popup from '../packages/popup/index.js';
+import Dialog from '../packages/dialog/index.js';
// zanui
import '../packages/zanui/src/index.pcss';
@@ -20,6 +21,7 @@ const install = function(Vue) {
Vue.component(Icon.name, Icon);
Vue.component(CellGroup.name, CellGroup);
Vue.component(Popup.name, Popup);
+ // Vue.component(Dialog.name, Dialog);
};
// auto install
@@ -37,5 +39,6 @@ module.exports = {
Cell,
Icon,
CellGroup,
- Popup
+ Popup,
+ Dialog
};
diff --git a/src/utils/merge.js b/src/utils/merge.js
index c0aa39a55..564a989a4 100644
--- a/src/utils/merge.js
+++ b/src/utils/merge.js
@@ -1,6 +1,6 @@
export default function(target, ...sources) {
- for (let i = 1, j = sources.length; i < j; i++) {
- let source = arguments[i] || {};
+ for (let i = 0; i < sources.length; i++) {
+ let source = sources[i] || {};
for (let prop in source) {
if (source.hasOwnProperty(prop)) {
let value = source[prop];