1 | import { version } from '../package.json'
|
2 | import Platform, { isSSR } from './plugins/Platform.js'
|
3 | import Screen from './plugins/Screen.js'
|
4 | import Dark from './plugins/Dark.js'
|
5 | import History from './history.js'
|
6 | import Lang from './lang.js'
|
7 | import Body from './body.js'
|
8 | import IconSet from './icon-set.js'
|
9 |
|
10 | const autoInstalled = [
|
11 | Platform, Screen, Dark
|
12 | ]
|
13 |
|
14 | export const queues = {
|
15 | server: [],
|
16 | takeover: []
|
17 | }
|
18 |
|
19 | export const $q = {
|
20 | version,
|
21 | config: {}
|
22 | }
|
23 |
|
24 | export default function (Vue, opts = {}) {
|
25 | if (this.__qInstalled === true) { return }
|
26 | this.__qInstalled = true
|
27 |
|
28 | const cfg = $q.config = Object.freeze(opts.config || {})
|
29 |
|
30 |
|
31 | Platform.install($q, queues)
|
32 | Body.install(queues, cfg)
|
33 | Dark.install($q, queues, cfg)
|
34 | Screen.install($q, queues, cfg)
|
35 | History.install(cfg)
|
36 | Lang.install($q, queues, opts.lang)
|
37 | IconSet.install($q, queues, opts.iconSet)
|
38 |
|
39 | if (isSSR === true) {
|
40 | Vue.mixin({
|
41 | beforeCreate () {
|
42 | this.$q = this.$root.$options.$q
|
43 | }
|
44 | })
|
45 | }
|
46 | else {
|
47 | Vue.prototype.$q = $q
|
48 | }
|
49 |
|
50 | opts.components && Object.keys(opts.components).forEach(key => {
|
51 | const c = opts.components[key]
|
52 | if (typeof c === 'function') {
|
53 | Vue.component(c.options.name, c)
|
54 | }
|
55 | })
|
56 |
|
57 | opts.directives && Object.keys(opts.directives).forEach(key => {
|
58 | const d = opts.directives[key]
|
59 | if (d.name !== undefined && d.unbind !== void 0) {
|
60 | Vue.directive(d.name, d)
|
61 | }
|
62 | })
|
63 |
|
64 | if (opts.plugins) {
|
65 | const param = { $q, queues, cfg }
|
66 | Object.keys(opts.plugins).forEach(key => {
|
67 | const p = opts.plugins[key]
|
68 | if (typeof p.install === 'function' && autoInstalled.includes(p) === false) {
|
69 | p.install(param)
|
70 | }
|
71 | })
|
72 | }
|
73 | }
|