Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
eb92c88c
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看板
提交
eb92c88c
编写于
7月 05, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip: 基于 modules.json 生成 tabBar 页面目录
上级
ef200a1a
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
773 addition
and
76 deletion
+773
-76
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+5
-5
pages/tabBar/CSS.uvue
pages/tabBar/CSS.uvue
+5
-5
pages/tabBar/component.uvue
pages/tabBar/component.uvue
+5
-5
pages/tabBar/generateMenu.uts
pages/tabBar/generateMenu.uts
+37
-8
target-pages.json
target-pages.json
+721
-53
未找到文件。
pages/tabBar/API.uvue
浏览文件 @
eb92c88c
...
...
@@ -29,19 +29,19 @@
<uni-collapse>
<uni-collapse-item v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem!.name"
class="item">
<view v-for="page in menuItem!.pages" :key="page.path" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${page.path}`)">
<view v-for="page in menuItem!.pages" :key="page
!
.path" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${page
!
.path}`)">
<text class="uni-navigate-text">{{
page.style["navigationBarTitleText"]
page
!
.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
<uni-collapse style="width: 100%" v-for="childMenu in menuItem!.children" :key="childMenu!.id">
<uni-collapse-item :title="childMenu!.name" class="item" style="margin-bottom: 0">
<view class="uni-navigate-item" hover-class="is--active" v-for="childPage in childMenu!.pages"
:key="childPage
.path" @click="goPage(`/${childPage
.path}`)">
:key="childPage
!.path" @click="goPage(`/${childPage!
.path}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
childPage
!
.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
...
...
pages/tabBar/CSS.uvue
浏览文件 @
eb92c88c
...
...
@@ -28,19 +28,19 @@
<uni-collapse>
<uni-collapse-item v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem!.name"
class="item">
<view v-for="page in menuItem!.pages" :key="page.path" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${page.path}`)">
<view v-for="page in menuItem!.pages" :key="page
!
.path" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${page
!
.path}`)">
<text class="uni-navigate-text">{{
page.style["navigationBarTitleText"]
page
!
.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
<uni-collapse style="width: 100%" v-for="childMenu in menuItem!.children" :key="childMenu!.id">
<uni-collapse-item :title="childMenu!.name" class="item" style="margin-bottom: 0">
<view class="uni-navigate-item" hover-class="is--active" v-for="childPage in childMenu!.pages"
:key="childPage
.path" @click="goPage(`/${childPage
.path}`)">
:key="childPage
!.path" @click="goPage(`/${childPage!
.path}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
childPage
!
.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
...
...
pages/tabBar/component.uvue
浏览文件 @
eb92c88c
...
...
@@ -28,19 +28,19 @@
<uni-collapse>
<uni-collapse-item v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem!.name"
class="item">
<view v-for="page in menuItem!.pages" :key="page.path" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${page.path}`)">
<view v-for="page in menuItem!.pages" :key="page
!
.path" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${page
!
.path}`)">
<text class="uni-navigate-text">{{
page.style["navigationBarTitleText"]
page
!
.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
<uni-collapse style="width: 100%" v-for="childMenu in menuItem!.children" :key="childMenu!.id">
<uni-collapse-item :title="childMenu!.name" class="item" style="margin-bottom: 0">
<view class="uni-navigate-item" hover-class="is--active" v-for="childPage in childMenu!.pages"
:key="childPage
.path" @click="goPage(`/${childPage
.path}`)">
:key="childPage
!.path" @click="goPage(`/${childPage!
.path}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
childPage
!
.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
...
...
pages/tabBar/generateMenu.uts
浏览文件 @
eb92c88c
...
...
@@ -17,22 +17,28 @@ export type MenuItem = {
name: string,
index: number,
children: (MenuItem | null)[],
pages:
Page
[]
pages:
(Page | null)
[]
}
export function generateMenu(tabBarType: string): (MenuItem | null)[] {
cons
t res: (MenuItem | null)[] = []
le
t res: (MenuItem | null)[] = []
const tabBarPages = JSON.parse<Page[]>(JSON.stringify(pages))!.filter((page: Page): boolean => page.path.startsWith(tabBarType) && hasPageGroup(page.group))
tabBarPages.forEach(page => {
let menuItemArr: (MenuItem | null)[] = res
let currentMenu: MenuItem | null = null
const lastGroup = page.group![page.group!.length - 1]
let hasPageGroup = false
if (page.path.endsWith(camelToDash(lastGroup.name)) && page.group!.length > 1) {
hasPageGroup = true
page.group!.pop()
}
const groupLength = page.group!.length
page.group!.forEach((group, groupIndex) => {
const { index, id, name } = group
const validIndex = isNumber(index) ? index! : menuItemArr.length
fillArrayWithNull(menuItemArr, validIndex)
fill
Menu
ArrayWithNull(menuItemArr, validIndex)
if (menuItemArr[validIndex] == null) {
menuItemArr[validIndex] = {
...
...
@@ -40,7 +46,7 @@ export function generateMenu(tabBarType: string): (MenuItem | null)[] {
name,
index: validIndex,
children: [] as (MenuItem | null)[],
pages: [] as
Page
[]
pages: [] as
(Page | null)
[]
} as MenuItem
}
...
...
@@ -50,9 +56,19 @@ export function generateMenu(tabBarType: string): (MenuItem | null)[] {
menuItemArr = menuItemArr[validIndex]!.children as (MenuItem | null)[]
}
})
currentMenu!.pages.push(page)
if (hasPageGroup) {
const pageIndex = isNumber(lastGroup.index) ? lastGroup.index! : currentMenu!.pages.length
fillPageArrayWithNull(currentMenu!.pages, pageIndex)
if (currentMenu!.pages[pageIndex] == null) {
currentMenu!.pages[pageIndex] = page
}else{
currentMenu!.pages.push(page)
}
} else {
currentMenu!.pages.push(page)
}
})
return removeNullItem(res)
}
...
...
@@ -74,7 +90,18 @@ function isNumber(value: number | null): boolean {
// #endif
}
function fillArrayWithNull(arr: (MenuItem | null)[], index: number): void {
function camelToDash(camelStr: string): string {
return camelStr.replace(/([A-Z])/g, '-$1').toLowerCase()
}
function fillMenuArrayWithNull(arr: (MenuItem | null)[], index: number): void {
const len = arr.length
for (let i = 0;i <= index - (len - 1);i++) {
arr.push(null)
}
}
function fillPageArrayWithNull(arr: (Page | null)[], index: number): void {
const len = arr.length
for (let i = 0;i <= index - (len - 1);i++) {
arr.push(null)
...
...
@@ -86,10 +113,12 @@ function removeNullItem(arr: (MenuItem | null)[]): (MenuItem | null)[] {
res.forEach(menuItem => {
addSetTabBarPage(menuItem!)
// #ifdef APP-ANDROID
menuItem!.children = removeNullItem(menuItem.children)
menuItem.children = removeNullItem(menuItem.children)
menuItem.pages = menuItem.pages.filter((item: Page | null): boolean => item !== null)
// #endif
// #ifndef APP-ANDROID
menuItem!.children = removeNullItem(menuItem!.children)
menuItem!.pages = menuItem!.pages.filter((item: Page | null): boolean => item !== null)
// #endif
})
return res
...
...
target-pages.json
浏览文件 @
eb92c88c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录