mh-two-thousand-and-two
2024-04-12 3d2ec2fd0578d3ba0a414b0cc4e4a2ae60878596
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
import initVue from 'uni-core/vue'
 
import {
  initPolyfill
} from 'uni-core/service/plugins/polyfill'
 
import EventChannel from 'uni-helpers/EventChannel'
 
import {
  registerApp
} from '../app'
 
import {
  initData
} from './data'
 
import {
  initLifecycle
} from './lifecycle'
 
import {
  vdSyncCallbacks
} from '../subscribe-handlers/on-vd-sync-callback'
 
import {
  uniIdMixin
} from 'uni-shared'
 
export default {
  install (Vue, options) {
    initVue(Vue)
 
    initData(Vue)
    initLifecycle(Vue)
 
    initPolyfill(Vue)
 
    uniIdMixin(Vue)
 
    Vue.prototype.getOpenerEventChannel = function () {
      if (!this.$root.$scope.eventChannel) {
        this.$root.$scope.eventChannel = new EventChannel()
      }
      return this.$root.$scope.eventChannel
    }
 
    Object.defineProperty(Vue.prototype, '$page', {
      get () {
        return this.$root.$scope.$page
      }
    })
    // 兼容旧版本
    Object.defineProperty(Vue.prototype, '$mp', {
      get () {
        return {
          page: this.$root.$scope
        }
      }
    })
 
    const oldMount = Vue.prototype.$mount
    Vue.prototype.$mount = function mount (el, hydrating) {
      if (this.mpType === 'app') {
        this.$options.render = function () {}
        if (weex.config.preload) { // preload
          if (process.env.NODE_ENV !== 'production') {
            console.log('[uni-app] preload app-service.js')
          }
          const globalEvent = weex.requireModule('globalEvent')
          globalEvent.addEventListener('launchApp', () => {
            if (process.env.NODE_ENV !== 'production') {
              console.log('[uni-app] launchApp')
            }
            plus.updateConfigInfo && plus.updateConfigInfo()
            registerApp(this, Vue)
            oldMount.call(this, el, hydrating)
          })
          return
        }
        registerApp(this, Vue)
      }
      return oldMount.call(this, el, hydrating)
    }
 
    Vue.prototype.$nextTick = function nextTick (cb) {
      const renderWatcher = this._watcher
      const callback = typeof cb === 'function'
      const result = new Promise((resolve) => {
        if (
          renderWatcher &&
          this._$queue.find(watcher => renderWatcher === watcher)
        ) {
          vdSyncCallbacks.push(callback ? cb.bind(this) : resolve)
        } else {
          // $nextTick bind vm context
          Vue.nextTick(callback ? () => cb.call(this) : resolve)
        }
        callback && resolve()
      })
      return callback ? undefined : result
    }
  }
}