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

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 28 29
import {
  registerPage
} from '../../framework/page'

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

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

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

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