diff --git a/packages/uni-cli-shared/src/json/app/manifest/arguments.ts b/packages/uni-cli-shared/src/json/app/manifest/arguments.ts index e3de9a74bee6075e97f8d8d53d7e333d9a379051..a20917e5b83dd3b0edd2ffa0ac268ee85600d02f 100644 --- a/packages/uni-cli-shared/src/json/app/manifest/arguments.ts +++ b/packages/uni-cli-shared/src/json/app/manifest/arguments.ts @@ -2,16 +2,22 @@ export function initArguments( manifestJson: Record, 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]) } } diff --git a/packages/uni-cli-shared/src/json/app/pages/uniConfig.ts b/packages/uni-cli-shared/src/json/app/pages/uniConfig.ts index 06120041a55c386457e3768c8c5580434d4e3663..5999c498accc6d7786027325fc62b0c5303d4312 100644 --- a/packages/uni-cli-shared/src/json/app/pages/uniConfig.ts +++ b/packages/uni-cli-shared/src/json/app/pages/uniConfig.ts @@ -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 ) { 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 +}