'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {
  cached
} from 'uni-shared'
 
const pageFactory = Object.create(null)
 
export function definePage (name, createPageVueComponent) {
  pageFactory[name] = createPageVueComponent
}
 
export const getPageVueComponent = cached(function (pagePath) {
  return pageFactory[pagePath]()
})
 
export function createPage (pagePath, pageId, pageQuery, pageInstance) {
  if (!pageFactory[pagePath]) {
    console.error(`${pagePath} not found`)
  }
  const startTime = Date.now()
  const pageVm = new (getPageVueComponent(pagePath))({
    mpType: 'page',
    pageId,
    pagePath,
    pageQuery,
    pageInstance
  })
  if (process.env.NODE_ENV !== 'production') {
    console.log(`new ${pagePath}[${pageId}]:time(${Date.now() - startTime})`)
  }
  return pageVm
}