Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
cb41b6db
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看板
提交
cb41b6db
编写于
8月 20, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
types: 优化 generate menu 类型
上级
eeb22317
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
50 addition
and
42 deletion
+50
-42
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+3
-3
pages/tabBar/CSS.uvue
pages/tabBar/CSS.uvue
+9
-9
pages/tabBar/component.uvue
pages/tabBar/component.uvue
+9
-9
pages/tabBar/generateMenu.uts
pages/tabBar/generateMenu.uts
+29
-21
未找到文件。
pages/tabBar/API.uvue
浏览文件 @
cb41b6db
...
...
@@ -12,9 +12,9 @@
:inWhiteList="true"></u-link>
</view>
<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">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem
!
.id">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
<view v-if="childMenuItem.items.length==0" style="padding-left: 18px;"
:class="{'uni-navigate-item':childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768}"
hover-class="is--active"
...
...
@@ -62,7 +62,7 @@
export default {
data() {
return {
menu: menu as
(MenuItem | null)
[],
menu: menu as
MenuItem
[],
arrowRightIcon: '/static/icons/arrow-right.png',
}
},
...
...
pages/tabBar/CSS.uvue
浏览文件 @
cb41b6db
...
...
@@ -12,9 +12,9 @@
:inWhiteList="true"></u-link>
</view>
<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">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem
!
.id">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
<view v-if="childMenuItem.items.length==0" style="padding-left: 18px" class="uni-navigate-item"
hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
...
...
@@ -26,7 +26,7 @@
<uni-collapse-item :title="childMenuItem.name" class="item"
style="margin-bottom: 0; padding-left: 5px; padding-right: 5px">
<view style="padding-left: 18px" class="uni-navigate-item" hover-class="is--active"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem
!
.path"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
@click="goPage(`/${grandChildMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active':
...
...
@@ -53,7 +53,7 @@
export default {
data() {
return {
menu: menu as
(MenuItem | null)
[],
menu: menu as
MenuItem
[],
arrowRightIcon: '/static/icons/arrow-right.png',
}
},
...
...
pages/tabBar/component.uvue
浏览文件 @
cb41b6db
...
...
@@ -12,9 +12,9 @@
:text="'https://uniapp.dcloud.io/uni-app-x/component/'" :inWhiteList="true"></u-link>
</view>
<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">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem
!
.id">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
<view v-if="childMenuItem.items.length==0" style="padding-left: 18px" class="uni-navigate-item"
hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
...
...
@@ -26,7 +26,7 @@
<uni-collapse-item :title="childMenuItem.name" class="item"
style="margin-bottom: 0; padding-left: 5px; padding-right: 5px">
<view style="padding-left: 18px" class="uni-navigate-item" hover-class="is--active"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem
!
.path"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
@click="goPage(`/${grandChildMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active':
...
...
@@ -60,7 +60,7 @@
export default {
data() {
return {
menu: menu as
(MenuItem | null)
[],
menu: menu as
MenuItem
[],
arrowRightIcon: '/static/icons/arrow-right.png' as string.ImageURIString,
pageHiden: false
}
...
...
pages/tabBar/generateMenu.uts
浏览文件 @
cb41b6db
...
...
@@ -25,15 +25,15 @@ export type MenuItem = {
path : string,
style : UTSJSONObject,
group ?: string | null,
items
: (MenuItem | null)
[]
items
: MenuItem
[]
}
export function generateMenu(tabBarType
: string) : (MenuItem | null)
[] {
let res
: (MenuItem | null)
[] = []
export function generateMenu(tabBarType
: string): MenuItem
[] {
let res
: MenuItem
[] = []
const tabBarPages = JSON.parse<Page[]>(JSON.stringify(pages))!.filter((page : Page) : boolean => page.path.startsWith(tabBarType) && hasPageGroup(page.group))
const groupTree = JSON.parse<(Group | null)[]>(JSON.stringify(groups))
tabBarPages.forEach(page => {
let menuItemArr
: (MenuItem | null)
[] = res
let menuItemArr
: MenuItem
[] = res
let currentMenu : MenuItem | null = null
const groupIndexList = page.group!.split(',').map((index : string) : number => parseInt(index))
let currentGroups : (Group | null)[] | null = groupTree
...
...
@@ -56,9 +56,9 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
const { index, id, name } = group
const validIndex = index
fillMenuArrayWith
Null
(menuItemArr, validIndex)
fillMenuArrayWith
EmptyMenuItem
(menuItemArr, validIndex)
if (menuItemArr[validIndex]
== null
) {
if (menuItemArr[validIndex]
.name == 'empty'
) {
menuItemArr[validIndex] = {
id: id.split('.').slice(-1)[0],
name,
...
...
@@ -66,14 +66,14 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
path: '',
style: {},
group: '',
items: [] as
(MenuItem | null)
[],
items: [] as
MenuItem
[],
} as MenuItem
}
currentMenu = menuItemArr[validIndex]
if (groupIndex < groupLength - 1) {
menuItemArr = menuItemArr[validIndex]
!.items as (MenuItem | null)[]
menuItemArr = menuItemArr[validIndex]
.items
}
})
...
...
@@ -84,12 +84,12 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
path: page.path,
style: page.style,
group: page.group,
items: [] as
(MenuItem | null)
[],
items: [] as
MenuItem
[],
}
if (hasPageGroup) {
const pageIndex = lastGroup.index
fillMenuArrayWith
Null
(currentMenu!.items, pageIndex)
if (currentMenu!.items[pageIndex]
== null
) {
fillMenuArrayWith
EmptyMenuItem
(currentMenu!.items, pageIndex)
if (currentMenu!.items[pageIndex]
.name == 'empty'
) {
currentMenu!.items[pageIndex] = pageMenuItem
} else {
currentMenu!.items.push(pageMenuItem)
...
...
@@ -99,7 +99,7 @@ export function generateMenu(tabBarType : string) : (MenuItem | null)[] {
}
})
return remove
Null
Item(res)
return remove
Empty
Item(res)
}
function hasPageGroup(value ?: string | null) : boolean {
...
...
@@ -124,22 +124,30 @@ function camelToDash(camelStr : string) : string {
return camelStr.replace(/([A-Z])/g, '-$1').toLowerCase()
}
function fillMenuArrayWith
Null(arr : (MenuItem | null)[], index : number)
: void {
function fillMenuArrayWith
EmptyMenuItem(arr: MenuItem[], index: number)
: void {
const len = arr.length
for (let i = 0; i <= index - (len - 1); i++) {
arr.push(null)
arr.push({
id: '',
name: 'empty',
index: i,
path: '',
style: {},
group: '',
items: [] as MenuItem[],
})
}
}
function remove
NullItem(arr : (MenuItem | null)[]) : (MenuItem | null)
[] {
const res = arr.filter((item
: MenuItem | null) : boolean => item !== null
)
function remove
EmptyItem(arr: MenuItem[]): MenuItem
[] {
const res = arr.filter((item
: MenuItem): boolean => item.name !== 'empty'
)
res.forEach(menuItem => {
addSetTabBarPage(menuItem
!
)
addSetTabBarPage(menuItem)
// #ifdef APP-ANDROID
menuItem.items = remove
Null
Item(menuItem.items)
menuItem.items = remove
Empty
Item(menuItem.items)
// #endif
// #ifndef APP-ANDROID
menuItem!.items = remove
Null
Item(menuItem!.items)
menuItem!.items = remove
Empty
Item(menuItem!.items)
// #endif
})
return res
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录