Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
5027b56c
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6067
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
5027b56c
编写于
7月 04, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip: 通过 pages.json 文件生成 tabBar 目录
上级
994a8f77
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
578 addition
and
458 deletion
+578
-458
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+27
-87
pages/tabBar/CSS.uvue
pages/tabBar/CSS.uvue
+26
-78
pages/tabBar/component.uvue
pages/tabBar/component.uvue
+21
-73
pages/tabBar/generateMenu.uts
pages/tabBar/generateMenu.uts
+108
-0
target-pages.json
target-pages.json
+396
-220
未找到文件。
pages/tabBar/API.uvue
浏览文件 @
5027b56c
...
...
@@ -26,30 +26,29 @@
</uni-collapse>
<text>---------------</text>
<uni-collapse>
<template v-for="menuItem in menu" :key="menuItem.id">
<uni-collapse-item :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}`)">
<text class="uni-navigate-text">{{
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}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
</uni-collapse>
</uni-collapse-item>
</template>
</uni-collapse>
<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}`)">
<text class="uni-navigate-text">{{
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}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
</uni-collapse>
</uni-collapse-item>
</uni-collapse>
</view>
<!-- #ifdef APP -->
</scroll-view>
...
...
@@ -62,68 +61,9 @@
</template>
<script lang="uts">
import { pages } from '@/target-pages.json'
type PagesJsonPageGroup = {
id : string,
name : string
}
type PagesJsonPage = {
path : string,
style : UTSJSONObject,
group ?: PagesJsonPageGroup[] | null
}
type MenuItem = {
id : string,
name : string,
children : MenuItem[],
pages : PagesJsonPage[]
}
const menu : MenuItem[] = []
const menuKeyMap = new Map<string, number>()
// #ifdef APP-ANDROID
const apiPages = JSON.parse<PagesJsonPage[]>(JSON.stringify(pages))!.filter((page : PagesJsonPage) : boolean => page.path.startsWith('pages/API') && page.group !== null)
// #endif
// #ifdef WEB || APP-IOS
const apiPages = (pages as unknown as PagesJsonPage[]).filter(page => page.path.startsWith('pages/API') && page.group)
// #endif
apiPages.forEach(page => {
let currentArr : MenuItem[] = menu
let currentMenu : MenuItem | null = null
if (page.group !== null) {
page.group!.forEach((item, index) => {
const { id, name } = item
const ids = id.split('.')
const _id = ids[ids.length - 1]
if (!menuKeyMap.has(id)) {
menuKeyMap.set(id, currentArr.length)
currentArr.push({
id: _id,
name,
children: [] as MenuItem[],
pages: [] as PagesJsonPage[]
} as MenuItem)
if (_id == 'page' && name == '页面和路由') {
currentArr[currentArr.length - 1].pages.push({
path: 'set-tab-bar',
style: {
navigationBarTitleText: '设置 TabBar'
}
} as PagesJsonPage)
}
}
currentMenu = currentArr[menuKeyMap.get(id)!]
if (index < page.group!.length - 1) {
currentArr = currentArr[menuKeyMap.get(id)!].children as MenuItem[]
}
})
}
if (currentMenu !== null) {
(currentMenu as MenuItem).pages.push(page)
}
})
import { generateMenu } from './generateMenu.uts'
import { MenuItem } from './generateMenu.uts'
const menu = generateMenu('pages/API')
type Page = {
name : string
url : string
...
...
@@ -140,7 +80,7 @@
export default {
data() {
return {
menu: menu as
MenuItem
[],
menu: menu as
(MenuItem | null)
[],
list: [
{
id: 'global',
...
...
pages/tabBar/CSS.uvue
浏览文件 @
5027b56c
...
...
@@ -25,29 +25,28 @@
</uni-collapse>
<text>---------------</text>
<uni-collapse>
<template v-for="menuItem in menu" :key="menuItem.id">
<uni-collapse-item :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}`)">
<text class="uni-navigate-text">{{
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}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
</uni-collapse>
</uni-collapse-item>
</template>
<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}`)">
<text class="uni-navigate-text">{{
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}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
</uni-collapse>
</uni-collapse-item>
</uni-collapse>
</view>
<!-- #ifdef APP -->
...
...
@@ -56,60 +55,9 @@
</template>
<script lang="uts">
import { pages } from '@/target-pages.json'
type PagesJsonPageGroup = {
id : string,
name : string
}
type PagesJsonPage = {
path : string,
style : UTSJSONObject,
group ?: PagesJsonPageGroup[] | null
}
type MenuItem = {
id : string,
name : string,
children : MenuItem[],
pages : PagesJsonPage[]
}
const menu : MenuItem[] = []
const menuKeyMap = new Map<string, number>()
// #ifdef APP-ANDROID
const cssPages = JSON.parse<PagesJsonPage[]>(JSON.stringify(pages))!.filter((page : PagesJsonPage) : boolean => page.path.startsWith('pages/CSS') && page.group !== null)
// #endif
// #ifdef WEB || APP-IOS
const cssPages = (pages as unknown as PagesJsonPage[]).filter(page => page.path.startsWith('pages/CSS') && page.group)
// #endif
cssPages.forEach(page => {
let currentArr : MenuItem[] = menu
let currentMenu : MenuItem | null = null
if (page.group !== null) {
page.group!.forEach((item, index) => {
const { id, name } = item
const ids = id.split('.')
const _id = ids[ids.length - 1]
if (!menuKeyMap.has(id)) {
menuKeyMap.set(id, currentArr.length)
currentArr.push({
id: _id,
name,
children: [] as MenuItem[],
pages: [] as PagesJsonPage[]
} as MenuItem)
}
currentMenu = currentArr[menuKeyMap.get(id)!]
if (index < page.group!.length - 1) {
currentArr = currentArr[menuKeyMap.get(id)!].children as MenuItem[]
}
})
}
if (currentMenu !== null) {
(currentMenu as MenuItem).pages.push(page)
}
})
import { generateMenu } from './generateMenu.uts'
import { MenuItem } from './generateMenu.uts'
const menu = generateMenu('pages/CSS')
type Page = {
name : string
enable ?: boolean
...
...
@@ -125,7 +73,7 @@
export default {
data() {
return {
menu: menu as
MenuItem
[],
menu: menu as
(MenuItem | null)
[],
list: [
{
id: 'background',
...
...
pages/tabBar/component.uvue
浏览文件 @
5027b56c
...
...
@@ -26,28 +26,27 @@
<text>---------------</text>
<uni-collapse>
<
template v-for="menuItem in menu" :key="menuItem.id">
<uni-collapse-item :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}`)">
<text class="uni-navigate-text">{{
<
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}`)">
<text class="uni-navigate-text">{{
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}`)">
<text class="uni-navigate-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}`)">
<text class="uni-navigate-text">{{
childPage.style["navigationBarTitleText"]
}}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
</uni-collapse>
</uni-collapse-item>
</template>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
</uni-collapse>
</uni-collapse-item>
</uni-collapse>
<!-- #ifdef UNI-APP-X && APP -->
...
...
@@ -60,60 +59,9 @@
</template>
<script lang="uts">
import { pages } from '@/target-pages.json'
type PagesJsonPageGroup = {
id : string,
name : string
}
type PagesJsonPage = {
path : string,
style : UTSJSONObject,
group ?: PagesJsonPageGroup[] | null
}
type MenuItem = {
id : string,
name : string,
children : MenuItem[],
pages : PagesJsonPage[]
}
const menu : MenuItem[] = []
const menuKeyMap = new Map<string, number>()
// #ifdef APP-ANDROID
const componentPages = JSON.parse<PagesJsonPage[]>(JSON.stringify(pages))!.filter((page : PagesJsonPage) : boolean => page.path.startsWith('pages/component') && page.group !== null)
// #endif
// #ifdef WEB || APP-IOS
const componentPages = (pages as unknown as PagesJsonPage[]).filter(page => page.path.startsWith('pages/component') && page.group)
// #endif
componentPages.forEach(page => {
let currentArr : MenuItem[] = menu
let currentMenu : MenuItem | null = null
if (page.group !== null) {
page.group!.forEach((item, index) => {
const { id, name } = item
const ids = id.split('.')
const _id = ids[ids.length - 1]
if (!menuKeyMap.has(id)) {
menuKeyMap.set(id, currentArr.length)
currentArr.push({
id: _id,
name,
children: [] as MenuItem[],
pages: [] as PagesJsonPage[]
} as MenuItem)
}
currentMenu = currentArr[menuKeyMap.get(id)!]
if (index < page.group!.length - 1) {
currentArr = currentArr[menuKeyMap.get(id)!].children as MenuItem[]
}
})
}
if (currentMenu !== null) {
(currentMenu as MenuItem).pages.push(page)
}
})
import { generateMenu } from './generateMenu.uts'
import { MenuItem } from './generateMenu.uts'
const menu = generateMenu('pages/component')
// #ifdef UNI-APP-X && APP
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
// #endif
...
...
@@ -133,7 +81,7 @@
export default {
data() {
return {
menu: menu as
MenuItem
[],
menu: menu as
(MenuItem | null)
[],
list: [
{
id: 'view',
...
...
pages/tabBar/generateMenu.uts
0 → 100644
浏览文件 @
5027b56c
import { pages } from '@/target-pages.json'
type PageGroup = {
id: string,
name: string,
index: number | null
}
type Page = {
path: string,
style: UTSJSONObject,
group?: PageGroup[] | null
}
export type MenuItem = {
id: string,
name: string,
index: number,
children: (MenuItem | null)[],
pages: Page[]
}
export function generateMenu(tabBarType: string): (MenuItem | null)[] {
const 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 groupLength = page.group!.length
page.group!.forEach((group, groupIndex) => {
const { index, id, name } = group
const validIndex = isNumber(index) ? index! : menuItemArr.length
fillArrayWithNull(menuItemArr, validIndex)
if (menuItemArr[validIndex] == null) {
menuItemArr[validIndex] = {
id: id.split('.').slice(-1)[0],
name,
index: validIndex,
children: [] as (MenuItem | null)[],
pages: [] as Page[]
} as MenuItem
}
currentMenu = menuItemArr[validIndex]
if (groupIndex < groupLength - 1) {
menuItemArr = menuItemArr[validIndex]!.children as (MenuItem | null)[]
}
})
currentMenu!.pages.push(page)
})
return removeNullItem(res)
}
function hasPageGroup(value: PageGroup[] | null): boolean {
// #ifdef APP-ANDROID
return value !== null
// #endif
// #ifndef APP-ANDROID
return !!value
// #endif
}
function isNumber(value: number | null): boolean {
// #ifdef APP-ANDROID
return value !== null
// #endif
// #ifndef APP-ANDROID
return typeof value === 'number'
// #endif
}
function fillArrayWithNull(arr: (MenuItem | 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)
// #endif
// #ifndef APP-ANDROID
menuItem!.children = removeNullItem(menuItem!.children)
// #endif
})
return res
}
function addSetTabBarPage(menuItem: MenuItem) {
const { id, name } = menuItem
if (id == 'page' && name == '页面和路由') {
menuItem.pages.push({
path: 'set-tab-bar',
style: {
navigationBarTitleText: '设置 TabBar'
}
} as Page)
}
}
target-pages.json
浏览文件 @
5027b56c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录