'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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import {
  hasLifecycleHook,
  findExistsPageIndex
} from 'uni-helpers/index'
 
import {
  initEventChannel
} from 'uni-helpers/navigate-to'
 
const {
  invokeCallbackHandler: invoke
} = UniServiceJSBridge
 
function onAppRoute (type, {
  url,
  delta,
  events,
  exists,
  animationType,
  animationDuration,
  from = 'navigateBack',
  detail
} = {}) {
  const router = getApp().$router
  delete router.$eventChannel
  switch (type) {
    case 'redirectTo':
      if (exists === 'back') {
        const existsPageIndex = findExistsPageIndex(url)
        if (existsPageIndex !== -1) {
          const delta = (getCurrentPages().length - 1) - existsPageIndex
          if (delta > 0) {
            return onAppRoute('navigateBack', {
              delta
            })
          }
        }
      }
      router.replace({
        type,
        path: url
      })
      break
    case 'navigateTo':
      router.$eventChannel = initEventChannel(events)
      router.push({
        type,
        path: url,
        animationType,
        animationDuration
      })
      return {
        errMsg: type + ':ok',
        eventChannel: router.$eventChannel
      }
    case 'navigateBack':
      {
        let canBack = true
        const pages = getCurrentPages()
        if (pages.length) {
          const page = pages[pages.length - 1]
          if (hasLifecycleHook(page.$options, 'onBackPress') && page.__call_hook('onBackPress', {
            from
          }) === true) {
            canBack = false
          }
        }
        if (canBack) {
          if (delta > 1) {
            router._$delta = delta
          }
          router.go(-delta, {
            animationType,
            animationDuration
          })
        }
      }
      break
    case 'reLaunch':
      router.replace({
        type,
        path: url
      })
      break
    case 'switchTab':
      router.replace({
        type,
        path: url,
        params: {
          detail
        }
      })
      break
  }
  return {
    errMsg: type + ':ok'
  }
}
 
export function redirectTo (args) {
  return onAppRoute('redirectTo', args)
}
 
export function navigateTo (args) {
  return onAppRoute('navigateTo', args)
}
 
export function navigateBack (args) {
  return onAppRoute('navigateBack', args)
}
 
export function reLaunch (args) {
  return onAppRoute('reLaunch', args)
}
 
export function switchTab (args) {
  return onAppRoute('switchTab', args)
}
 
export function preloadPage ({
  url
}, callbackId) {
  const path = url.split('?')[0].replace(/\//g, '-')
  __uniConfig.__webpack_chunk_load__(path.substr(1)).then(() => {
    invoke(callbackId, {
      url,
      errMsg: 'preloadPage:ok'
    })
  }).catch(err => {
    invoke(callbackId, {
      url,
      errMsg: 'preloadPage:fail ' + err
    })
  })
}