diff --git a/pages/tabBar/API.uvue b/pages/tabBar/API.uvue index 39a825f6ca69dd1dc26ee7fbc229ecb4b3fa26a8..00f66ca9be5771dfa1ad54fd65f83a360831ac87 100644 --- a/pages/tabBar/API.uvue +++ b/pages/tabBar/API.uvue @@ -14,26 +14,29 @@ - - {{ - page.style["navigationBarTitleText"] - }} - - - - - - {{ - childPage.style["navigationBarTitleText"] - }} - - - - + @@ -91,7 +94,7 @@ immediate: true, handler(newRoute) { if (newRoute.matched.length) { - const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.pages.some(page => this.leftWinActive && this.leftWinActive === page?.path)) + const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path)) if (activeCategoryIndex > -1) { this.$nextTick(() => { ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true) diff --git a/pages/tabBar/CSS.uvue b/pages/tabBar/CSS.uvue index 02bee0bb36337aacc73a17ccf6cb0dcb25ce3fa8..ec2589b7140933e071306acd0c3b594b8d35bfad 100644 --- a/pages/tabBar/CSS.uvue +++ b/pages/tabBar/CSS.uvue @@ -14,26 +14,29 @@ - - {{ - page.style["navigationBarTitleText"] - }} - - - - - - {{ - childPage.style["navigationBarTitleText"] - }} - - - - + @@ -73,7 +76,7 @@ immediate: true, handler(newRoute) { if (newRoute.matched.length) { - const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.pages.some(page => this.leftWinActive && this.leftWinActive === page?.path)) + const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path)) if (activeCategoryIndex > -1) { this.$nextTick(() => { ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex]).$callMethod('openCollapse', true) diff --git a/pages/tabBar/component.uvue b/pages/tabBar/component.uvue index b45129003c27acf019ff8c6077e9257bd701d5af..306e66d6e77ac98a7b758250748de2f497669134 100644 --- a/pages/tabBar/component.uvue +++ b/pages/tabBar/component.uvue @@ -14,26 +14,29 @@ - - {{ - page.style["navigationBarTitleText"] - }} - - - - - - {{ - childPage.style["navigationBarTitleText"] - }} - - - - + @@ -93,7 +96,7 @@ immediate: true, handler(newRoute) { if (newRoute.matched.length) { - const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.pages.some(page => this.leftWinActive && this.leftWinActive === page?.path)) + const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path)) if (activeCategoryIndex > -1) { this.$nextTick(() => { ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true) diff --git a/pages/tabBar/generateMenu.uts b/pages/tabBar/generateMenu.uts index 09d0dbbd2553f800224ed5862de511b98abd1f6c..268e74dbcb187d22e5ac1adfca1680efeffa36c8 100644 --- a/pages/tabBar/generateMenu.uts +++ b/pages/tabBar/generateMenu.uts @@ -15,15 +15,17 @@ type PageGroup = { type Page = { path : string, style : UTSJSONObject, - group ?: string | null + group ?: string | null, } export type MenuItem = { id : string, name : string, index : number, - children : (MenuItem | null)[], - pages : (Page | null)[] + path : string, + style : UTSJSONObject, + group ?: string | null, + items : (MenuItem | null)[] } export function generateMenu(tabBarType : string) : (MenuItem | null)[] { @@ -37,6 +39,7 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] { let currentGroups : (Group | null)[] | null = groupTree const pageGroups : PageGroup[] = [] groupIndexList.forEach((groupIndex, index) => { + // 跳过第一层 component API CSS if (index > 0) { pageGroups.push({ id: currentGroups![groupIndex]!.id, name: currentGroups![groupIndex]!.name, index: groupIndex } as PageGroup) } @@ -60,27 +63,39 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] { id: id.split('.').slice(-1)[0], name, index: validIndex, - children: [] as (MenuItem | null)[], - pages: [] as (Page | null)[] + path: '', + style: {}, + group: '', + items: [] as (MenuItem | null)[], } as MenuItem } currentMenu = menuItemArr[validIndex] if (groupIndex < groupLength - 1) { - menuItemArr = menuItemArr[validIndex]!.children as (MenuItem | null)[] + menuItemArr = menuItemArr[validIndex]!.items as (MenuItem | null)[] } }) + + const pageMenuItem : MenuItem = { + id: page.path, + name: page.style["navigationBarTitleText"] as string, + index: lastGroup.index, + path: page.path, + style: page.style, + group: page.group, + items: [] as (MenuItem | null)[], + } if (hasPageGroup) { const pageIndex = lastGroup.index - fillPageArrayWithNull(currentMenu!.pages, pageIndex) - if (currentMenu!.pages[pageIndex] == null) { - currentMenu!.pages[pageIndex] = page + fillMenuArrayWithNull(currentMenu!.items, pageIndex) + if (currentMenu!.items[pageIndex] == null) { + currentMenu!.items[pageIndex] = pageMenuItem } else { - currentMenu!.pages.push(page) + currentMenu!.items.push(pageMenuItem) } } else { - currentMenu!.pages.push(page) + currentMenu!.items.push(pageMenuItem) } }) @@ -116,24 +131,15 @@ function fillMenuArrayWithNull(arr : (MenuItem | null)[], index : number) : void } } -function fillPageArrayWithNull(arr : (Page | null)[], index : number) : void { - const len = arr.length - for (let i = 0; i <= index - (len - 1); i++) { - arr.push(null) - } -} - function removeNullItem(arr : (MenuItem | null)[]) : (MenuItem | null)[] { const res = arr.filter((item : MenuItem | null) : boolean => item !== null) res.forEach(menuItem => { addSetTabBarPage(menuItem!) // #ifdef APP-ANDROID - menuItem.children = removeNullItem(menuItem.children) - menuItem.pages = menuItem.pages.filter((item : Page | null) : boolean => item !== null) + menuItem.items = removeNullItem(menuItem.items) // #endif // #ifndef APP-ANDROID - menuItem!.children = removeNullItem(menuItem!.children) - menuItem!.pages = menuItem!.pages.filter((item : Page | null) : boolean => item !== null) + menuItem!.items = removeNullItem(menuItem!.items) // #endif }) return res @@ -142,11 +148,16 @@ function removeNullItem(arr : (MenuItem | null)[]) : (MenuItem | null)[] { function addSetTabBarPage(menuItem : MenuItem) { const { id, name } = menuItem if (id == 'page' && name == '页面和路由' && !state.noMatchLeftWindow) { - menuItem.pages.push({ + menuItem.items.push({ + id: 'set-tab-bar', + name: '设置 TabBar', + index: 0, path: 'set-tab-bar', style: { navigationBarTitleText: '设置 TabBar' - } - } as Page) + }, + group: null, + items: [] + } as MenuItem) } }