config.js 1.1 KB
Newer Older
1 2 3 4
export const uniConfig = Object.create(null)
export const uniRoutes = []

function parseRoutes (config) {
fxy060608's avatar
fxy060608 已提交
5
  uniRoutes.length = 0
6 7 8 9
  /* 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 已提交
10 11
    const isTabBar = tabBarList.indexOf(pagePath) !== -1
    const isQuit = isTabBar || (config.pages[0] === pagePath)
fxy060608's avatar
fxy060608 已提交
12
    const isNVue = !!config.page[pagePath].nvue
13 14 15
    uniRoutes.push({
      path: '/' + pagePath,
      meta: {
fxy060608's avatar
fxy060608 已提交
16
        isQuit,
fxy060608's avatar
fxy060608 已提交
17 18
        isTabBar,
        isNVue
fxy060608's avatar
fxy060608 已提交
19
      },
fxy060608's avatar
fxy060608 已提交
20
      window: config.page[pagePath].window || {}
21 22 23 24
    })
  })
}

fxy060608's avatar
fxy060608 已提交
25 26 27
export function registerConfig (config, {
  plus
}) {
28
  Object.assign(uniConfig, config)
fxy060608's avatar
fxy060608 已提交
29 30 31 32 33 34 35 36 37

  uniConfig.viewport = ''
  uniConfig.defaultFontSize = ''

  if (uniConfig.nvueCompiler === 'uni-app') {
    uniConfig.viewport = plus.screen.resolutionWidth
    uniConfig.defaultFontSize = uniConfig.viewport / 20
  }

38
  parseRoutes(uniConfig)
fxy060608's avatar
fxy060608 已提交
39 40 41 42

  if (process.env.NODE_ENV !== 'production') {
    console.log(`[uni-app] registerConfig`, uniConfig)
  }
43
}