Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
b04647ff
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b04647ff
编写于
8月 02, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 优化 tabBar 内项目展示顺序
上级
39686008
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
88 deletion
+108
-88
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+24
-21
pages/tabBar/CSS.uvue
pages/tabBar/CSS.uvue
+24
-21
pages/tabBar/component.uvue
pages/tabBar/component.uvue
+24
-21
pages/tabBar/generateMenu.uts
pages/tabBar/generateMenu.uts
+36
-25
未找到文件。
pages/tabBar/API.uvue
浏览文件 @
b04647ff
...
@@ -14,26 +14,29 @@
...
@@ -14,26 +14,29 @@
<uni-collapse>
<uni-collapse>
<uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
<uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
class="item">
class="item">
<view style='padding-left:18px;' v-for="page in menuItem.pages" :key="page!.path" class="uni-navigate-item"
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem!.id">
hover-class="is--active" @click="goPage(`/${page.path}`)">
<view v-if="childMenuItem.items.length==0" style="padding-left: 18px" class="uni-navigate-item"
<text class="uni-navigate-text" :class="{'left-win-active': leftWinActive === page.path && hasLeftWin}">{{
hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
page.style["navigationBarTitleText"]
<text class="uni-navigate-text" :class="{
}}</text>
'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin,
<image :src="arrowRightIcon" class="uni-icon-size"></image>
}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
</view>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
<uni-collapse style="width: 100%" v-for="childMenu in menuItem.children" :key="childMenu!.id">
</view>
<uni-collapse-item :title="childMenu.name" class="item"
<uni-collapse v-else style="width: 100%">
style="margin-bottom: 0;padding-left: 5px;padding-right: 5px;">
<uni-collapse-item :title="childMenuItem.name" class="item"
<view style='padding-left: 18px;' class="uni-navigate-item" hover-class="is--active"
style="margin-bottom: 0; padding-left: 5px; padding-right: 5px">
v-for="childPage in childMenu.pages" :key="childPage!.path" @click="goPage(`/${childPage.path}`)">
<view style="padding-left: 18px" class="uni-navigate-item" hover-class="is--active"
<text class="uni-navigate-text"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem!.path"
:class="{'left-win-active': leftWinActive === childPage.path && hasLeftWin}">{{
@click="goPage(`/${grandChildMenuItem.path}`)">
childPage.style["navigationBarTitleText"]
<text class="uni-navigate-text" :class="{
}}</text>
'left-win-active':
<image :src="arrowRightIcon" class="uni-icon-size"></image>
leftWinActive === grandChildMenuItem.path && hasLeftWin,
</view>
}">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
</uni-collapse-item>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</uni-collapse>
</view>
</uni-collapse-item>
</uni-collapse>
</template>
</uni-collapse-item>
</uni-collapse-item>
</uni-collapse>
</uni-collapse>
<view v-if="!hasLeftWin" ref="pop" @click="hidePop()" class="popup">
<view v-if="!hasLeftWin" ref="pop" @click="hidePop()" class="popup">
...
@@ -91,7 +94,7 @@
...
@@ -91,7 +94,7 @@
immediate: true,
immediate: true,
handler(newRoute) {
handler(newRoute) {
if (newRoute.matched.length) {
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) {
if (activeCategoryIndex > -1) {
this.$nextTick(() => {
this.$nextTick(() => {
((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
...
...
pages/tabBar/CSS.uvue
浏览文件 @
b04647ff
...
@@ -14,26 +14,29 @@
...
@@ -14,26 +14,29 @@
<uni-collapse>
<uni-collapse>
<uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
<uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
class="item">
class="item">
<view style='padding-left:18px;' v-for="page in menuItem.pages" :key="page!.path" class="uni-navigate-item"
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem!.id">
hover-class="is--active" @click="goPage(`/${page.path}`)">
<view v-if="childMenuItem.items.length==0" style="padding-left: 18px" class="uni-navigate-item"
<text class="uni-navigate-text" :class="{'left-win-active': leftWinActive === page.path && hasLeftWin}">{{
hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
page.style["navigationBarTitleText"]
<text class="uni-navigate-text" :class="{
}}</text>
'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin,
<image :src="arrowRightIcon" class="uni-icon-size"></image>
}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
</view>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
<uni-collapse style="width: 100%" v-for="childMenu in menuItem.children" :key="childMenu!.id">
</view>
<uni-collapse-item :title="childMenu.name" class="item"
<uni-collapse v-else style="width: 100%">
style="margin-bottom: 0;padding-left: 5px;padding-right: 5px;">
<uni-collapse-item :title="childMenuItem.name" class="item"
<view style='padding-left: 18px;' class="uni-navigate-item" hover-class="is--active"
style="margin-bottom: 0; padding-left: 5px; padding-right: 5px">
v-for="childPage in childMenu.pages" :key="childPage!.path" @click="goPage(`/${childPage.path}`)">
<view style="padding-left: 18px" class="uni-navigate-item" hover-class="is--active"
<text class="uni-navigate-text"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem!.path"
:class="{'left-win-active': leftWinActive === childPage.path && hasLeftWin}">{{
@click="goPage(`/${grandChildMenuItem.path}`)">
childPage.style["navigationBarTitleText"]
<text class="uni-navigate-text" :class="{
}}</text>
'left-win-active':
<image :src="arrowRightIcon" class="uni-icon-size"></image>
leftWinActive === grandChildMenuItem.path && hasLeftWin,
</view>
}">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
</uni-collapse-item>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</uni-collapse>
</view>
</uni-collapse-item>
</uni-collapse>
</template>
</uni-collapse-item>
</uni-collapse-item>
</uni-collapse>
</uni-collapse>
</view>
</view>
...
@@ -73,7 +76,7 @@
...
@@ -73,7 +76,7 @@
immediate: true,
immediate: true,
handler(newRoute) {
handler(newRoute) {
if (newRoute.matched.length) {
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) {
if (activeCategoryIndex > -1) {
this.$nextTick(() => {
this.$nextTick(() => {
((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex]).$callMethod('openCollapse', true)
((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex]).$callMethod('openCollapse', true)
...
...
pages/tabBar/component.uvue
浏览文件 @
b04647ff
...
@@ -14,26 +14,29 @@
...
@@ -14,26 +14,29 @@
<uni-collapse>
<uni-collapse>
<uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
<uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
class="item">
class="item">
<view style='padding-left:18px;' v-for="page in menuItem.pages" :key="page!.path" class="uni-navigate-item"
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem!.id">
hover-class="is--active" @click="goPage(`/${page.path}`)">
<view v-if="childMenuItem.items.length==0" style="padding-left: 18px" class="uni-navigate-item"
<text class="uni-navigate-text" :class="{'left-win-active': leftWinActive === page.path && hasLeftWin}">{{
hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
page.style["navigationBarTitleText"]
<text class="uni-navigate-text" :class="{
}}</text>
'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin,
<image :src="arrowRightIcon" class="uni-icon-size"></image>
}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
</view>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
<uni-collapse style="width: 100%" v-for="childMenu in menuItem.children" :key="childMenu!.id">
</view>
<uni-collapse-item :title="childMenu.name" class="item"
<uni-collapse v-else style="width: 100%">
style="margin-bottom: 0;padding-left: 5px;padding-right: 5px;">
<uni-collapse-item :title="childMenuItem.name" class="item"
<view style='padding-left: 18px;' class="uni-navigate-item" hover-class="is--active"
style="margin-bottom: 0; padding-left: 5px; padding-right: 5px">
v-for="childPage in childMenu.pages" :key="childPage!.path" @click="goPage(`/${childPage.path}`)">
<view style="padding-left: 18px" class="uni-navigate-item" hover-class="is--active"
<text class="uni-navigate-text"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem!.path"
:class="{'left-win-active': leftWinActive === childPage.path && hasLeftWin}">{{
@click="goPage(`/${grandChildMenuItem.path}`)">
childPage.style["navigationBarTitleText"]
<text class="uni-navigate-text" :class="{
}}</text>
'left-win-active':
<image :src="arrowRightIcon" class="uni-icon-size"></image>
leftWinActive === grandChildMenuItem.path && hasLeftWin,
</view>
}">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
</uni-collapse-item>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</uni-collapse>
</view>
</uni-collapse-item>
</uni-collapse>
</template>
</uni-collapse-item>
</uni-collapse-item>
</uni-collapse>
</uni-collapse>
...
@@ -93,7 +96,7 @@
...
@@ -93,7 +96,7 @@
immediate: true,
immediate: true,
handler(newRoute) {
handler(newRoute) {
if (newRoute.matched.length) {
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) {
if (activeCategoryIndex > -1) {
this.$nextTick(() => {
this.$nextTick(() => {
((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
...
...
pages/tabBar/generateMenu.uts
浏览文件 @
b04647ff
...
@@ -15,15 +15,17 @@ type PageGroup = {
...
@@ -15,15 +15,17 @@ type PageGroup = {
type Page = {
type Page = {
path : string,
path : string,
style : UTSJSONObject,
style : UTSJSONObject,
group ?: string | null
group ?: string | null
,
}
}
export type MenuItem = {
export type MenuItem = {
id : string,
id : string,
name : string,
name : string,
index : number,
index : number,
children : (MenuItem | null)[],
path : string,
pages : (Page | null)[]
style : UTSJSONObject,
group ?: string | null,
items : (MenuItem | null)[]
}
}
export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
...
@@ -37,6 +39,7 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
...
@@ -37,6 +39,7 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
let currentGroups : (Group | null)[] | null = groupTree
let currentGroups : (Group | null)[] | null = groupTree
const pageGroups : PageGroup[] = []
const pageGroups : PageGroup[] = []
groupIndexList.forEach((groupIndex, index) => {
groupIndexList.forEach((groupIndex, index) => {
// 跳过第一层 component API CSS
if (index > 0) {
if (index > 0) {
pageGroups.push({ id: currentGroups![groupIndex]!.id, name: currentGroups![groupIndex]!.name, index: groupIndex } as PageGroup)
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)[] {
...
@@ -60,27 +63,39 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
id: id.split('.').slice(-1)[0],
id: id.split('.').slice(-1)[0],
name,
name,
index: validIndex,
index: validIndex,
children: [] as (MenuItem | null)[],
path: '',
pages: [] as (Page | null)[]
style: {},
group: '',
items: [] as (MenuItem | null)[],
} as MenuItem
} as MenuItem
}
}
currentMenu = menuItemArr[validIndex]
currentMenu = menuItemArr[validIndex]
if (groupIndex < groupLength - 1) {
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) {
if (hasPageGroup) {
const pageIndex = lastGroup.index
const pageIndex = lastGroup.index
fill
PageArrayWithNull(currentMenu!.page
s, pageIndex)
fill
MenuArrayWithNull(currentMenu!.item
s, pageIndex)
if (currentMenu!.
page
s[pageIndex] == null) {
if (currentMenu!.
item
s[pageIndex] == null) {
currentMenu!.
pages[pageIndex] = page
currentMenu!.
items[pageIndex] = pageMenuItem
} else {
} else {
currentMenu!.
pages.push(page
)
currentMenu!.
items.push(pageMenuItem
)
}
}
} else {
} else {
currentMenu!.
pages.push(page
)
currentMenu!.
items.push(pageMenuItem
)
}
}
})
})
...
@@ -116,24 +131,15 @@ function fillMenuArrayWithNull(arr : (MenuItem | null)[], index : number) : void
...
@@ -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)[] {
function removeNullItem(arr : (MenuItem | null)[]) : (MenuItem | null)[] {
const res = arr.filter((item : MenuItem | null) : boolean => item !== null)
const res = arr.filter((item : MenuItem | null) : boolean => item !== null)
res.forEach(menuItem => {
res.forEach(menuItem => {
addSetTabBarPage(menuItem!)
addSetTabBarPage(menuItem!)
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
menuItem.children = removeNullItem(menuItem.children)
menuItem.items = removeNullItem(menuItem.items)
menuItem.pages = menuItem.pages.filter((item : Page | null) : boolean => item !== null)
// #endif
// #endif
// #ifndef APP-ANDROID
// #ifndef APP-ANDROID
menuItem!.children = removeNullItem(menuItem!.children)
menuItem!.items = removeNullItem(menuItem!.items)
menuItem!.pages = menuItem!.pages.filter((item : Page | null) : boolean => item !== null)
// #endif
// #endif
})
})
return res
return res
...
@@ -142,11 +148,16 @@ function removeNullItem(arr : (MenuItem | null)[]) : (MenuItem | null)[] {
...
@@ -142,11 +148,16 @@ function removeNullItem(arr : (MenuItem | null)[]) : (MenuItem | null)[] {
function addSetTabBarPage(menuItem : MenuItem) {
function addSetTabBarPage(menuItem : MenuItem) {
const { id, name } = menuItem
const { id, name } = menuItem
if (id == 'page' && name == '页面和路由' && !state.noMatchLeftWindow) {
if (id == 'page' && name == '页面和路由' && !state.noMatchLeftWindow) {
menuItem.pages.push({
menuItem.items.push({
id: 'set-tab-bar',
name: '设置 TabBar',
index: 0,
path: 'set-tab-bar',
path: 'set-tab-bar',
style: {
style: {
navigationBarTitleText: '设置 TabBar'
navigationBarTitleText: '设置 TabBar'
}
},
} as Page)
group: null,
items: []
} as MenuItem)
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录