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

import {
  showWebview
} from './util'

import {
10 11
  setStatusBarStyle,
  invoke
fxy060608's avatar
fxy060608 已提交
12 13
} from '../../bridge'

fxy060608's avatar
init v3  
fxy060608 已提交
14 15 16 17
import {
  registerPage
} from '../../framework/page'

fxy060608's avatar
fxy060608 已提交
18 19
import tabBar from '../../../../app-plus/service/framework/tab-bar'

fxy060608's avatar
fxy060608 已提交
20 21 22
import {
  navigate
} from '../../framework/navigator'
fxy060608's avatar
fxy060608 已提交
23

fxy060608's avatar
fxy060608 已提交
24 25 26 27
function _reLaunch ({
  path,
  query
}, callbackId) {
fxy060608's avatar
fxy060608 已提交
28 29 30 31 32
  const pages = getCurrentPages(true).slice(0)

  const routeOptions = __uniRoutes.find(route => route.path === path)

  if (routeOptions.meta.isTabBar) {
fxy060608's avatar
fxy060608 已提交
33
    tabBar.switchTab(path)
fxy060608's avatar
fxy060608 已提交
34 35 36
  }

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

  pages.forEach(page => {
    page.$remove()
    page.$getAppWebview().close('none')
  })

  setStatusBarStyle()
57
}
fxy060608's avatar
fxy060608 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71

export function reLaunch ({
  url
}, callbackId) {
  const urls = url.split('?')
  const path = urls[0]
  const query = parseQuery(urls[1] || '')
  navigate(path, function () {
    _reLaunch({
      path,
      query
    }, callbackId)
  })
}