Skip to content

Commit defce70

Browse files
authored
Merge pull request #251 from blacksharksjc/main
fix: 修复pages.config.ts中tabbar属性无法正确合并到pages.json中的问题
2 parents df3db65 + 9dfd5ad commit defce70

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

packages/core/src/context.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,21 +446,19 @@ export class PageContext {
446446
private async genratePagesJSON() {
447447
const content = await fs.promises.readFile(this.resolvedPagesJSONPath, { encoding: 'utf-8' }).catch(() => '')
448448

449-
let pageJson = cjParse(content || '{}') as CommentObject
449+
const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = cjParse(content || '{}') as CommentObject
450450

451451
const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {}
452452

453-
pageJson = Object.assign(pageJson, {
454-
...others,
455-
})
453+
const pageJson = { ...others }
456454

457455
const currentPlatform = platform.toUpperCase()
458456

459457
// pages
460-
pageJson.pages = mergePlatformItems(pageJson?.pages as any, currentPlatform, this.pageMetaData, 'path')
458+
pageJson.pages = mergePlatformItems(oldPages as any, currentPlatform, this.pageMetaData, 'path')
461459

462460
// subPackages
463-
pageJson.subPackages = pageJson?.subPackages || new CommentArray<CommentObject>()
461+
pageJson.subPackages = oldSubPackages || new CommentArray<CommentObject>()
464462
const newSubPackages = new Map<string, SubPageMetaDatum>()
465463
for (const item of this.subPageMetaData) {
466464
newSubPackages.set(item.root, item)
@@ -480,18 +478,18 @@ export class PageContext {
480478
}
481479

482480
// tabbar
483-
const tabBar = await this.getTabBarMerged()
484-
if (tabBar) {
485-
const list = mergePlatformItems((pageJson?.tabBar as any)?.list as any, currentPlatform, tabBar.list!, 'pagePath')
486-
487-
if ((pageJson?.tabBar as any)?.list) {
488-
(pageJson!.tabBar as any)!.list = list
489-
}
490-
else {
491-
(pageJson as any).tabBar = (pageJson as any).tabBar || {};
492-
(pageJson as any).tabBar.list = list
481+
const { list, ...tabBarOthers } = (await this.getTabBarMerged()) || {}
482+
if (list) {
483+
const { list: oldList } = (oldTabBar as any) || {}
484+
const newList = mergePlatformItems(oldList, currentPlatform, list, 'pagePath')
485+
pageJson.tabBar = {
486+
...tabBarOthers, // 每次都直接更新除 list 外的其他属性
487+
list: newList,
493488
}
494489
}
490+
else {
491+
pageJson.tabBar = undefined // 直接清空,暂不支持 A 平台有 tabBar, B 平台无 tabBar 的情况。
492+
}
495493

496494
return pageJson
497495
}

0 commit comments

Comments
 (0)