-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
120 lines (105 loc) · 2.57 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import merge from "lodash/merge";
import DefaultTheme from "./plugins/themes/default.js";
import NButton from "./components/NButton";
import NIcon from "./components/NIcon";
import NGrid from "./components/NGrid";
import NFlex from "./components/NFlex";
import NInput from "./components/NInput";
import NContainer from "./components/NContainer";
import NHeader from "./components/NHeader";
import NAside from "./components/NAside";
import NMain from "./components/NMain";
import NFooter from "./components/NFooter";
import NTable from "./components/NTable";
import NSelect from "./components/NSelect";
// import NFlvPlayer from "./components/NFlvPlayer";
import NToast from "./components/NToast";
const components = {
NButton,
NIcon,
NGrid,
NFlex,
NInput,
NContainer,
NHeader,
NAside,
NMain,
NFooter,
NTable,
NSelect,
// NFlvPlayer,
NToast
};
/**
* Will extend the component with the merged classes added in the settings
* 将使用在设置中添加的合并类扩展组件
*/
function extendComponent(Vue, CurrentTheme, componentName) {
const themeSettings = CurrentTheme[componentName];
const themeDefaultSettings = DefaultTheme[componentName];
const newSettings = merge(themeDefaultSettings, themeSettings);
let {
props
} = components[componentName];
Object.keys(newSettings).forEach(key => {
const prop = {
default: () => newSettings[key]
};
props[key] = prop;
});
return Vue.extend({
...components[componentName],
...{
props
}
});
}
let currentToast;
export default {
install(Vue, args = {}) {
if (this.installed) {
return;
}
this.installed = true;
const CurrentTheme = {
...DefaultTheme,
...(args.theme || {})
};
const componentsToRegister = args.components || Object.keys(components);
componentsToRegister.forEach(componentName => {
Vue.component(
componentName,
extendComponent(Vue, CurrentTheme, componentName)
);
});
Vue.prototype.$toast = function (message, toastOptions) {
if (currentToast) {
currentToast.close();
}
currentToast = createToast({
Vue,
message,
propsData: toastOptions,
onClose: () => {
currentToast = null;
}
});
};
}
};
function createToast({
Vue,
message,
propsData,
onClose
}) {
let Constructor = Vue.extend(NToast);
let toast = new Constructor({
propsData
});
toast.$slots.default = [message];
toast.$mount();
toast.$on("close", onClose);
document.body.appendChild(toast.$el);
return toast;
}