-
-
Notifications
You must be signed in to change notification settings - Fork 28
fix: 修复pages.config.ts中tabbar属性无法正确合并到pages.json中的问题 #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughPreserves existing top-level page JSON properties (pages, subPackages, tabBar) when merging new page config; rebuilds pageJson from non-page/tabBar fields; merges pages and subPackages with prior values; introduces platform-aware tabBar merge that can preserve, update, or clear tabBar explicitly. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Builder as Builder/Plugin
participant Context as PageContext.mergePageMetaData
participant Old as existing pages JSON
participant Merge as mergePlatformItems / tabBarMerge
participant PageJson as new pageJson
Builder->>Context: provide new page config
Context->>Old: read top-level `oldPages`, `oldSubPackages`, `oldTabBar`
Context->>PageJson: build base from config "others" (no pages/tabBar)
Context->>Merge: merge pages using `oldPages` + new pages -> mergedPages
Merge-->>PageJson: assign mergedPages
Context->>Merge: for subPackages, use `oldSubPackages` or new CommentArray, then per-subpkg merge
Merge-->>PageJson: assign mergedSubPackages
Context->>Merge: merge tabBar -> { list, ...tabBarOthers }
alt merged tabBar produced
Merge-->>PageJson: apply merged `list` (platform-aware merge)
Context->>PageJson: copy `tabBarOthers` into pageJson.tabBar (merge/preserve)
else no tabBar produced
Context->>PageJson: set pageJson.tabBar = undefined %% explicit clear for unsupported platform cases
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/core/src/context.ts (1)
490-496: LGTM! The tabBar merge logic correctly preserves existing properties.The implementation correctly gives priority to properties already in
pageJson.tabBar, only copying additional properties from the mergedtabBarwhen they don't exist. This aligns with the stated priority of pages.json → pages.config.Consider improving type safety by reducing the use of
as any:- const { list: __, ...restTabBarProps } = tabBar - Object.keys(restTabBarProps).forEach((key) => { - if (!(key in (pageJson.tabBar as any))) { - (pageJson.tabBar as any)[key] = restTabBarProps[key] + const { list: __, ...restTabBarProps } = tabBar + Object.keys(restTabBarProps).forEach((key) => { + const tabBarObj = pageJson.tabBar as Record<string, any> + if (!(key in tabBarObj)) { + tabBarObj[key] = restTabBarProps[key as keyof typeof restTabBarProps] } })This consolidates the type assertions and makes the intent clearer.
|
谢谢你的PR, 确实是漏了。但是看了一下你的实现,感觉可以优化一下: // tabbar
const { list, ...tabBarOthers } = (await this.getTabBarMerged()) || {}
if (list) {
const { list: oldList } = (pageJson as any)?.tabBar || {}
const newList = mergePlatformItems(oldList, currentPlatform, list, 'pagePath');
(pageJson as any).tabBar = {
...tabBarOthers, // 每次都直接更新除 list 外的其他属性
list: newList,
}
}
else {
(pageJson as any).tabBar = undefined // 直接清空,暂不支持 A 平台有 tabBar, B 平台无 tabBar 的情况。
} |
Description 描述
问题现象
插件在合并tabbar配置时,出现丢失部分pages.config.(ts|mts|cts|js|cjs|mjs|json)中配置的tabbar属性,仅保留了list部分内容
问题示例
{ "tabbar": { "list": [{ "text": "首页", "iconPath": "static/images/tabbar/index.png", "selectedIconPath": "static/images/tabbar/index-active.png", "pagePath": "pages/index/index" }] } }修复结果
插件根据以下优先级合并tabbar额外属性:pages.json -> pages.config.(ts|mts|cts|js|cjs|mjs|json)。
根据上述示例配置,最终输出结果如下:
{ "tabbar": { "list": [{ "text": "首页", "iconPath": "static/images/tabbar/index.png", "selectedIconPath": "static/images/tabbar/index-active.png", "pagePath": "pages/index/index" }], color: "#999999", selectedColor: "#000000", } }Linked Issues 关联的 Issues
Additional context 额外上下文
Summary by CodeRabbit