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
import {
  findVmByVueId,
  initRefs
} from '../../../mp-weixin/runtime/wrapper/util'
 
export { initRefs }
 
export const mocks = ['__route__', '__webviewId__', '__nodeid__', '__nodeId__']
 
export const instances = Object.create(null)
 
export function isPage () {
  return this.__nodeid__ === 0 || this.__nodeId__ === 0
}
 
export function initRelation ({
  vuePid,
  mpInstance
}) {
  // triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
  const nodeId = (mpInstance.__nodeId__ || mpInstance.__nodeid__) + ''
  const webviewId = mpInstance.__webviewId__ + ''
 
  instances[webviewId + '_' + nodeId] = mpInstance.$vm
 
  this.triggerEvent('__l', {
    vuePid,
    nodeId,
    webviewId
  })
}
 
export function handleLink ({
  detail: {
    vuePid,
    nodeId,
    webviewId
  }
}) {
  const vm = instances[webviewId + '_' + nodeId]
  if (!vm) {
    return
  }
 
  let parentVm
 
  if (vuePid) {
    parentVm = findVmByVueId(this.$vm, vuePid)
  }
 
  if (!parentVm) {
    parentVm = this.$vm
  }
 
  vm.$parent = parentVm
  vm.$root = parentVm.$root
  parentVm.$children.push(vm)
 
  vm.__call_hook('created')
  vm.__call_hook('beforeMount')
  vm._isMounted = true
  vm.__call_hook('mounted')
  vm.__call_hook('onReady')
}