'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
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
import Vue from 'vue'
 
import {
  stringifyQuery
} from 'uni-shared/query'
 
import {
  initData,
  initHooks,
  initUnknownHooks,
  handleEvent,
  initBehaviors,
  initVueComponent,
  PAGE_EVENT_HOOKS
} from 'uni-wrapper/util'
 
import { handleLink, initBehavior } from '../../../mp-weixin/runtime/wrapper/util'
 
import {
  handleWrap,
  initSpecialMethods
} from './util'
 
const hooks = [
  'onShow',
  'onHide',
  'onUnload'
]
 
hooks.push(...PAGE_EVENT_HOOKS)
 
export default function parsePage (vuePageOptions) {
  const [VueComponent, vueOptions] = initVueComponent(Vue, vuePageOptions)
 
  const pageOptions = {
    mixins: initBehaviors(vueOptions, initBehavior),
    data: initData(vueOptions, Vue.prototype),
    onLoad (query) {
      const properties = this.props
 
      this.__query = query
      this.__options = {
        mpType: 'page',
        mpInstance: this,
        propsData: properties
      }
    },
    onReady () {
      // initChildVues(this)
      // 初始化 vue 实例
      this.$vm = new VueComponent(this.__options)
 
      // 触发首次 setData
      this.$vm.$mount()
 
      initSpecialMethods(this)
      this.$vm._isMounted = true
      this.$vm.__call_hook('mounted')
 
      // mounted => onLoad
      this.options = this.__query
      this.$vm.$mp.query = this.__query // 兼容 mpvue
      const copyQuery = Object.assign({}, this.__query)
      delete copyQuery.__id__
      this.$page = {
        fullPath: '/' + this.route + stringifyQuery(copyQuery)
      }
 
      this.$vm.__call_hook('onLoad', this.__query)
      this.$vm.__call_hook('onShow')
      setTimeout(() => {
        this.$vm.__call_hook('onReady')
      })
    },
    onUnload () {
      this.$vm.__call_hook('onUnload')
      this.$vm.$destroy()
    },
    // __r: handleRef,
    __e: handleEvent,
    __l: handleLink,
    __w: handleWrap,
    triggerEvent: function noop () {}
  }
 
  initHooks(pageOptions, hooks, vueOptions)
  initUnknownHooks(pageOptions, vueOptions, ['onReady'])
 
  if (Array.isArray(vueOptions.wxsCallMethods)) {
    vueOptions.wxsCallMethods.forEach(callMethod => {
      pageOptions[callMethod] = function (args) {
        return this.$vm[callMethod](args)
      }
    })
  }
 
  return pageOptions
}