navigate-to.js 1.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
import {
  parseQuery
fxy060608's avatar
fxy060608 已提交
3 4
} from 'uni-shared'

5 6 7 8
import {
  ANI_SHOW,
  ANI_DURATION
} from '../../constants'
fxy060608's avatar
fxy060608 已提交
9

fxy060608's avatar
fxy060608 已提交
10 11 12 13
import {
  showWebview
} from './util'

fxy060608's avatar
fxy060608 已提交
14
import {
fxy060608's avatar
fxy060608 已提交
15 16
  setStatusBarStyle,
  invoke
fxy060608's avatar
fxy060608 已提交
17 18
} from '../../bridge'

fxy060608's avatar
init v3  
fxy060608 已提交
19 20 21 22 23 24 25 26 27
import {
  registerPage
} from '../../framework/page'

import {
  navigate
} from '../../framework/navigator'

function _navigateTo ({
fxy060608's avatar
fxy060608 已提交
28
  url,
fxy060608's avatar
init v3  
fxy060608 已提交
29 30
  path,
  query,
fxy060608's avatar
fxy060608 已提交
31 32
  animationType,
  animationDuration
fxy060608's avatar
fxy060608 已提交
33
}, callbackId) {
fxy060608's avatar
fxy060608 已提交
34 35 36
  UniServiceJSBridge.emit('onAppRoute', {
    type: 'navigateTo',
    path
fxy060608's avatar
fxy060608 已提交
37
  })
fxy060608's avatar
fxy060608 已提交
38

fxy060608's avatar
fxy060608 已提交
39
  showWebview(
fxy060608's avatar
init v3  
fxy060608 已提交
40
    registerPage({
fxy060608's avatar
fxy060608 已提交
41
      url,
fxy060608's avatar
fxy060608 已提交
42
      path,
fxy060608's avatar
fxy060608 已提交
43 44
      query,
      openType: 'navigate'
fxy060608's avatar
fxy060608 已提交
45 46
    }),
    animationType,
fxy060608's avatar
fxy060608 已提交
47
    animationDuration,
48
    () => {
fxy060608's avatar
fxy060608 已提交
49 50 51 52
      invoke(callbackId, {
        errMsg: 'navigateTo:ok'
      })
    }
fxy060608's avatar
fxy060608 已提交
53
  )
fxy060608's avatar
fxy060608 已提交
54
  setStatusBarStyle()
fxy060608's avatar
init v3  
fxy060608 已提交
55 56 57 58
}

export function navigateTo ({
  url,
fxy060608's avatar
fxy060608 已提交
59
  openType,
fxy060608's avatar
init v3  
fxy060608 已提交
60 61
  animationType,
  animationDuration
62
}, callbackId) {
fxy060608's avatar
init v3  
fxy060608 已提交
63
  const urls = url.split('?')
fxy060608's avatar
fxy060608 已提交
64 65
  const path = urls[0]
  const routeStyles = __uniRoutes.find(route => route.path === path).window
66
  const globalStyle = __uniConfig.window || {}
fxy060608's avatar
fxy060608 已提交
67 68 69 70 71
  if (!animationType) {
    animationType = routeStyles.animationType || globalStyle.animationType || ANI_SHOW
  }
  if (!animationDuration) {
    animationDuration = routeStyles.animationDuration || globalStyle.animationDuration || ANI_DURATION
72
  }
fxy060608's avatar
init v3  
fxy060608 已提交
73 74 75
  const query = parseQuery(urls[1] || '')
  navigate(path, function () {
    _navigateTo({
fxy060608's avatar
fxy060608 已提交
76
      url,
fxy060608's avatar
init v3  
fxy060608 已提交
77 78 79 80
      path,
      query,
      animationType,
      animationDuration
81
    }, callbackId)
fxy060608's avatar
fxy060608 已提交
82
  }, openType === 'appLaunch')
83
}