config.js 2.5 KB
Newer Older
1
function parseRoutes (config) {
fxy060608's avatar
fxy060608 已提交
2
  __uniRoutes.length = 0
3 4 5 6
  /* eslint-disable no-mixed-operators */
  const tabBarList = (config.tabBar && config.tabBar.list || []).map(item => item.pagePath)

  Object.keys(config.page).forEach(function (pagePath) {
fxy060608's avatar
fxy060608 已提交
7 8
    const isTabBar = tabBarList.indexOf(pagePath) !== -1
    const isQuit = isTabBar || (config.pages[0] === pagePath)
fxy060608's avatar
fxy060608 已提交
9
    const isNVue = !!config.page[pagePath].nvue
fxy060608's avatar
fxy060608 已提交
10
    __uniRoutes.push({
11 12
      path: '/' + pagePath,
      meta: {
fxy060608's avatar
fxy060608 已提交
13
        isQuit,
fxy060608's avatar
fxy060608 已提交
14 15
        isTabBar,
        isNVue
fxy060608's avatar
fxy060608 已提交
16
      },
fxy060608's avatar
fxy060608 已提交
17
      window: config.page[pagePath].window || {}
18 19 20 21
    })
  })
}

fxy060608's avatar
fxy060608 已提交
22
export function registerConfig (config, Vue) {
fxy060608's avatar
fxy060608 已提交
23
  Object.assign(__uniConfig, config)
fxy060608's avatar
fxy060608 已提交
24

fxy060608's avatar
fxy060608 已提交
25 26
  __uniConfig.viewport = ''
  __uniConfig.defaultFontSize = ''
fxy060608's avatar
fxy060608 已提交
27

fxy060608's avatar
fxy060608 已提交
28 29
  if (__uniConfig.nvueCompiler === 'uni-app') {
    __uniConfig.viewport = plus.screen.resolutionWidth
Q
qiang 已提交
30
    __uniConfig.defaultFontSize = 16
fxy060608's avatar
fxy060608 已提交
31 32
  }

fxy060608's avatar
fxy060608 已提交
33
  parseRoutes(__uniConfig)
fxy060608's avatar
fxy060608 已提交
34 35

  if (process.env.NODE_ENV !== 'production') {
fxy060608's avatar
fxy060608 已提交
36
    console.log('[uni-app] registerConfig', __uniConfig)
fxy060608's avatar
fxy060608 已提交
37
  }
fxy060608's avatar
fxy060608 已提交
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
}

let isInitEntryPage = false

export function initEntryPage () {
  if (isInitEntryPage) {
    return
  }
  isInitEntryPage = true

  let entryPagePath
  let entryPageQuery

  const weexPlus = weex.requireModule('plus')

  if (weexPlus.getRedirectInfo) {
    const info = weexPlus.getRedirectInfo() || {}
    entryPagePath = info.path
    entryPageQuery = info.query ? ('?' + info.query) : ''
  } else {
    const argsJsonStr = plus.runtime.arguments
    if (!argsJsonStr) {
      return
    }
    try {
      const args = JSON.parse(argsJsonStr)
      entryPagePath = args.path || args.pathName
      entryPageQuery = args.query ? ('?' + args.query) : ''
    } catch (e) {}
  }

  if (!entryPagePath || entryPagePath === __uniConfig.entryPagePath) {
70 71 72
    if (entryPageQuery) {
      __uniConfig.entryPageQuery = entryPageQuery
    }
fxy060608's avatar
fxy060608 已提交
73 74 75 76 77 78
    return
  }

  const entryRoute = '/' + entryPagePath
  const routeOptions = __uniRoutes.find(route => route.path === entryRoute)
  if (!routeOptions) {
79
    console.error(`[uni-app] ${entryPagePath} not found...`)
fxy060608's avatar
fxy060608 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92
    return
  }

  if (!routeOptions.meta.isTabBar) {
    __uniConfig.realEntryPagePath = __uniConfig.realEntryPagePath || __uniConfig.entryPagePath
  }

  __uniConfig.entryPagePath = entryPagePath
  __uniConfig.entryPageQuery = entryPageQuery

  if (process.env.NODE_ENV !== 'production') {
    console.log(`[uni-app] entryPagePath(${entryPagePath + entryPageQuery})`)
  }
Q
qiang 已提交
93
}