提交 7bc8b318 编写于 作者: fxy060608's avatar fxy060608

fix(app): ensure entry page path when use condition (#2914#issuecomment-984422582)

上级 1f8688eb
......@@ -2,16 +2,22 @@ export function initArguments(
manifestJson: Record<string, any>,
pagesJson: UniApp.PagesJson
) {
const args = parseArguments(pagesJson)
if (args) {
manifestJson.plus.arguments = args
}
}
export function parseArguments(pagesJson: UniApp.PagesJson) {
if (process.env.NODE_ENV !== 'development') {
return
}
// 指定了入口
if (process.env.UNI_CLI_LAUNCH_PAGE_PATH) {
manifestJson.plus.arguments = JSON.stringify({
return JSON.stringify({
path: process.env.UNI_CLI_LAUNCH_PAGE_PATH,
query: process.env.UNI_CLI_LAUNCH_PAGE_QUERY,
})
return
}
const condition = pagesJson.condition
......@@ -24,6 +30,6 @@ export function initArguments(
if (current >= list.length) {
current = 0
}
manifestJson.plus.arguments = JSON.stringify(list[current])
return JSON.stringify(list[current])
}
}
......@@ -6,6 +6,7 @@ import {
getNVueFlexDirection,
getNVueStyleCompiler,
} from '../manifest'
import { parseArguments } from '../manifest/arguments'
import { getSplashscreen } from '../manifest/splashscreen'
interface AppUniConfig {
......@@ -24,6 +25,8 @@ interface AppUniConfig {
appname: string
compilerVersion: string
entryPagePath: string
entryPageQuery: string
realEntryPagePath: string
networkTimeout: {
request: number
connectSocket: number
......@@ -41,6 +44,7 @@ export function normalizeAppUniConfig(
manifestJson: Record<string, any>
) {
const { autoclose, alwaysShowBeforeRender } = getSplashscreen(manifestJson)
const config: AppUniConfig = {
pages: [],
globalStyle: pagesJson.globalStyle,
......@@ -57,7 +61,7 @@ export function normalizeAppUniConfig(
autoclose,
},
compilerVersion: process.env.UNI_COMPILER_VERSION,
entryPagePath: pagesJson.pages[0].path,
...parseEntryPagePath(pagesJson),
networkTimeout: normalizeNetworkTimeout(manifestJson.networkTimeout),
tabBar: pagesJson.tabBar,
locales: initLocales(path.join(process.env.UNI_INPUT_DIR, 'locale')),
......@@ -65,3 +69,36 @@ export function normalizeAppUniConfig(
// TODO 待支持分包
return JSON.stringify(config)
}
function parseEntryPagePath(pagesJson: UniApp.PagesJson) {
const res = {
entryPagePath: '',
entryPageQuery: '',
realEntryPagePath: '',
}
if (!pagesJson.pages.length) {
return res
}
res.entryPagePath = pagesJson.pages[0].path
const argsJsonStr = parseArguments(pagesJson)
if (argsJsonStr) {
try {
const args = JSON.parse(argsJsonStr)
const entryPagePath = args.path || args.pathName
const realEntryPagePath = res.entryPagePath
if (entryPagePath && realEntryPagePath !== entryPagePath) {
res.entryPagePath = entryPagePath
res.entryPageQuery = args.query ? '?' + args.query : ''
// non tabBar page
if (
!(pagesJson.tabBar?.list || []).find(
(page) => page.pagePath === entryPagePath
)
) {
res.realEntryPagePath = realEntryPagePath
}
}
} catch (e) {}
}
return res
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册