-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
79 lines (68 loc) · 1.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author liupeng ([email protected]) @kefong
*/
import Link from './components/link'
import View from './components/view'
var VueDialogConfig = {
_vlist:[],
_el: null,
_opt: null,
_to: null,
_component: function(name){
var component;
this._opt.routes.forEach(function(n){
if(name == n.name){
component = n.component;
}
});
return component;
}
}
function VueDialog(opt) {
VueDialogConfig._opt = opt;
}
VueDialog.install = function(Vue, options){
// 初始化必要组件
//Vue.component(view.name, view); //此组件需要在show窗口时再初始化
Vue.component(Link.name, Link);
// init
for (var property in options) {
VueDialogConfig._opt[property] = options[property];
}
// create [vue dialog package]
if(VueDialogConfig._el === null){
VueDialogConfig._el = document.createElement('div');
VueDialogConfig._el.className = 'kefong-vue-dialog-package';
document.body.appendChild(VueDialogConfig._el);
}
Vue.prototype.$_dialog = function(to){
var view = Vue.component('dialog-view', View);
var v = new view();
v.to = to;
v.component = VueDialogConfig._component(to.name);
VueDialogConfig._to = to;
//将每个弹出层都加到清单中
VueDialogConfig._vlist.push(v);
/**
* 关闭窗口
* 使用方法:this.$dialog.close();
*/
VueDialogConfig._to.close = function(){
//v.hide();
//关闭最后一个弹窗
VueDialogConfig._vlist.slice(-1)[0].hide();
}
VueDialogConfig._el.appendChild(v.$mount().$el);
}
Vue.prototype.$_hide = function(){
//将关闭的弹窗从列表中删除
VueDialogConfig._vlist.pop();
}
Object.defineProperty(Vue.prototype, '$dialog', {
get: function() {
return VueDialogConfig._to;
}
})
}
export default VueDialog;