提交 34e27b2c 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

wip: 通过 json 文件生成部分 tabBar 页面目录

上级 22d5663f
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1;background-color: #f8f8f8;" enable-back-to-top="true"> <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
<!-- #endif --> <!-- #endif -->
<view class="uni-container"> <view class="uni-container">
<view class="uni-header-logo"> <view class="uni-header-logo">
...@@ -24,6 +24,32 @@ ...@@ -24,6 +24,32 @@
</uni-collapse-item> </uni-collapse-item>
</template> </template>
</uni-collapse> </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>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -36,6 +62,61 @@ ...@@ -36,6 +62,61 @@
</template> </template>
<script lang="uts"> <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)
}
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)
}
})
console.log('menu', menu)
type Page = { type Page = {
name : string name : string
url : string url : string
...@@ -52,6 +133,7 @@ ...@@ -52,6 +133,7 @@
export default { export default {
data() { data() {
return { return {
menu: menu as MenuItem[],
list: [ list: [
{ {
id: 'global', id: 'global',
...@@ -206,13 +288,13 @@ ...@@ -206,13 +288,13 @@
name: 'showToast轻提示框', name: 'showToast轻提示框',
url: 'toast', url: 'toast',
api: ["showToast"] api: ["showToast"]
} }
// #ifdef APP // #ifdef APP
,{ , {
name: '主题切换', name: '主题切换',
url: 'theme-change', url: 'theme-change',
api: ["setAppTheme","onOsThemeChange","offOsThemeChange","onAppThemeChange","offAppThemeChange"] api: ["setAppTheme", "onOsThemeChange", "offOsThemeChange", "onAppThemeChange", "offAppThemeChange"]
} }
// #endif // #endif
] as Page[], ] as Page[],
}, },
...@@ -292,14 +374,14 @@ ...@@ -292,14 +374,14 @@
{ {
name: "打电话", name: "打电话",
url: "make-phone-call", url: "make-phone-call",
}, },
{ {
name: "剪贴板", name: "剪贴板",
url: "clipboard", url: "clipboard",
}, },
{ {
name: "监听罗盘数据", name: "监听罗盘数据",
url: "on-compass-change", url: "on-compass-change",
}, },
// #endif // #endif
/* /*
...@@ -423,18 +505,18 @@ ...@@ -423,18 +505,18 @@
{ {
name: '获取当前位置', name: '获取当前位置',
url: 'get-location', url: 'get-location',
}, },
// #ifdef WEB // #ifdef WEB
{ {
name: "使用地图查看位置", name: "使用地图查看位置",
url: "open-location", url: "open-location",
}, },
{ {
name: "使用地图选择位置", name: "使用地图选择位置",
url: "choose-location", url: "choose-location",
}, },
// #endif // #endif
/* /*
{ {
name: "地图搜索", name: "地图搜索",
url: "map-search", url: "map-search",
...@@ -500,24 +582,24 @@ ...@@ -500,24 +582,24 @@
url: 'facial-recognition-verify', url: 'facial-recognition-verify',
} }
] as Page[], ] as Page[],
}, },
{ {
id: 'ad', id: 'ad',
name: '广告', name: '广告',
pages: [ pages: [
{ {
name: '激励视频广告', name: '激励视频广告',
url: 'rewarded-video-ad', url: 'rewarded-video-ad',
} }
/* { /* {
id: "full-screen-video-ad", id: "full-screen-video-ad",
url: "full-screen-video-ad", url: "full-screen-video-ad",
name: "全屏视频广告", name: "全屏视频广告",
enable: false, enable: false,
pages: [] as Page[] pages: [] as Page[]
}, */ }, */
] as Page[], ] as Page[],
}, },
// #endif // #endif
{ {
id: "payment", id: "payment",
...@@ -534,7 +616,7 @@ ...@@ -534,7 +616,7 @@
url: "request-payment-uni-pay", url: "request-payment-uni-pay",
} }
] as Page[], ] as Page[],
}, },
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
{ {
id: 'permission-listener', id: 'permission-listener',
...@@ -593,6 +675,9 @@ ...@@ -593,6 +675,9 @@
url, url,
}) })
}, },
goPage(url : string) {
uni.navigateTo({ url })
},
showPop: function () { showPop: function () {
(this.$refs["pop"] as UniElement).style.setProperty("display", "flex") (this.$refs["pop"] as UniElement).style.setProperty("display", "flex")
}, },
......
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1;background-color: #f8f8f8;" enable-back-to-top="true"> <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
<!-- #endif --> <!-- #endif -->
<view class="uni-container"> <view class="uni-container">
<view class="uni-header-logo"> <view class="uni-header-logo">
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<uni-collapse> <uni-collapse>
<template v-for="item in list" :key="item.id"> <template v-for="item in list" :key="item.id">
<uni-collapse-item :title="item.name" class="item"> <uni-collapse-item :title="item.name" class="item">
<view class="uni-navigate-item" :hover-class="page.enable == false?'':'is--active'" <view class="uni-navigate-item" :hover-class="page.enable == false ? '' : 'is--active'"
v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(page)"> v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(page)">
<text class="uni-navigate-text" <text class="uni-navigate-text"
:class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text> :class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
...@@ -23,6 +23,32 @@ ...@@ -23,6 +23,32 @@
</uni-collapse-item> </uni-collapse-item>
</template> </template>
</uni-collapse> </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>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -30,6 +56,62 @@ ...@@ -30,6 +56,62 @@
</template> </template>
<script lang="uts"> <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)
}
})
console.log('menu', menu)
type Page = { type Page = {
name : string name : string
enable ?: boolean enable ?: boolean
...@@ -45,6 +127,7 @@ ...@@ -45,6 +127,7 @@
export default { export default {
data() { data() {
return { return {
menu: menu as MenuItem[],
list: [ list: [
{ {
id: 'background', id: 'background',
...@@ -103,10 +186,10 @@ ...@@ -103,10 +186,10 @@
{ {
name: 'border属性复合示例', name: 'border属性复合示例',
url: '/pages/CSS/border/complex-border/complex-border', url: '/pages/CSS/border/complex-border/complex-border',
}, },
{ {
name: 'border动态修改样式', name: 'border动态修改样式',
url: '/pages/CSS/border/dynamic-border' url: '/pages/CSS/border/dynamic-border'
}, },
] as Page[], ] as Page[],
}, },
...@@ -277,10 +360,10 @@ ...@@ -277,10 +360,10 @@
{ {
name: 'overflow', name: 'overflow',
url: '/pages/CSS/overflow/overflow', url: '/pages/CSS/overflow/overflow',
}, },
{ {
name: 'overflow-visible-event', name: 'overflow-visible-event',
url: '/pages/CSS/overflow/overflow-visible-event' url: '/pages/CSS/overflow/overflow-visible-event'
} }
] as Page[], ] as Page[],
}, },
...@@ -357,16 +440,16 @@ ...@@ -357,16 +440,16 @@
url: '/pages/CSS/transition/transition', url: '/pages/CSS/transition/transition',
}, },
] as Page[], ] as Page[],
}, },
{ {
id: 'pointer-events', id: 'pointer-events',
name: 'pointer-events', name: 'pointer-events',
pages: [ pages: [
{ {
name: 'pointer-events', name: 'pointer-events',
url: '/pages/CSS/pointer-events/pointer-events', url: '/pages/CSS/pointer-events/pointer-events',
}, },
] as Page[], ] as Page[],
}, },
{ {
id: 'variable', id: 'variable',
...@@ -398,6 +481,9 @@ ...@@ -398,6 +481,9 @@
url, url,
}) })
}, },
goPage(url : string) {
uni.navigateTo({ url })
},
}, },
} }
</script> </script>
......
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1; background-color: #f8f8f8;" enable-back-to-top="true"> <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
<!-- #endif --> <!-- #endif -->
<view class="uni-container"> <view class="uni-container">
<view class="uni-header-logo"> <view class="uni-header-logo">
...@@ -22,6 +22,32 @@ ...@@ -22,6 +22,32 @@
</view> </view>
</uni-collapse-item> </uni-collapse-item>
</template> </template>
</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>
<!-- #ifdef UNI-APP-X && APP --> <!-- #ifdef UNI-APP-X && APP -->
...@@ -34,6 +60,61 @@ ...@@ -34,6 +60,61 @@
</template> </template>
<script lang="uts"> <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)
}
})
console.log('menu', menu)
// #ifdef UNI-APP-X && APP // #ifdef UNI-APP-X && APP
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update' import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
// #endif // #endif
...@@ -53,6 +134,7 @@ ...@@ -53,6 +134,7 @@
export default { export default {
data() { data() {
return { return {
menu: menu as MenuItem[],
list: [ list: [
{ {
id: 'view', id: 'view',
...@@ -66,14 +148,14 @@ ...@@ -66,14 +148,14 @@
}, },
{ {
name: 'swiper', name: 'swiper',
}, },
// #ifdef WEB // #ifdef WEB
{ {
name: 'movable-view' name: 'movable-view'
}, },
{ {
name: 'cover-view' name: 'cover-view'
}, },
// #endif // #endif
{ {
name: 'list-view', name: 'list-view',
...@@ -83,14 +165,14 @@ ...@@ -83,14 +165,14 @@
}, },
{ {
name: 'sticky-section', name: 'sticky-section',
}, },
// #ifdef APP // #ifdef APP
{ {
name: 'nested-scroll-header', name: 'nested-scroll-header',
}, },
{ {
name: 'nested-scroll-body', name: 'nested-scroll-body',
}, },
// #endif // #endif
] as Page[], ] as Page[],
}, },
...@@ -125,17 +207,17 @@ ...@@ -125,17 +207,17 @@
}, },
{ {
name: 'input', name: 'input',
}, },
// #ifdef WEB // #ifdef WEB
{ {
name: 'editor', name: 'editor',
}, },
{ {
name: 'label', name: 'label',
}, },
{ {
name: 'picker', name: 'picker',
}, },
// #endif // #endif
{ {
name: 'picker-view', name: 'picker-view',
...@@ -182,8 +264,8 @@ ...@@ -182,8 +264,8 @@
enable: false, enable: false,
}, */ }, */
] as Page[], ] as Page[],
}, },
// #ifdef WEB // #ifdef WEB
{ {
id: 'map', id: 'map',
name: '地图', name: '地图',
...@@ -193,22 +275,22 @@ ...@@ -193,22 +275,22 @@
} }
] as Page[] ] as Page[]
}, },
// #endif // #endif
// #ifdef APP || WEB // #ifdef APP || WEB
{ {
id: 'canvas', id: 'canvas',
name: '画布', name: '画布',
pages: [ pages: [
{ {
name: 'canvas', name: 'canvas',
url: '/pages/component/canvas/canvas', url: '/pages/component/canvas/canvas',
}, },
{ {
name: 'ball', name: 'ball',
url: '/pages/component/canvas/ball', url: '/pages/component/canvas/ball',
} }
] as Page[] ] as Page[]
}, },
// #endif // #endif
{ {
id: 'web-view', id: 'web-view',
...@@ -257,22 +339,22 @@ ...@@ -257,22 +339,22 @@
pages: [ pages: [
{ {
name: '通用属性', name: '通用属性',
url: '/pages/component/general-attribute/general-attribute', url: '/pages/component/public-properties/public-properties',
enable: true, enable: true,
}, },
{ {
name: '通用事件', name: '通用事件',
url: '/pages/component/general-event/general-event', url: '/pages/component/public-events/public-events',
enable: true, enable: true,
}, },
{ {
name: 'touch事件', name: 'touch事件',
url: '/pages/component/general-event/touch-event', url: '/pages/component/public-events/touch-events',
enable: true, enable: true,
}, },
{ {
name: 'Transition事件', name: 'Transition事件',
url: '/pages/component/general-event/transition-event', url: '/pages/component/public-events/transition-events',
enable: true, enable: true,
}, },
] as Page[], ] as Page[],
...@@ -298,9 +380,12 @@ ...@@ -298,9 +380,12 @@
uni.navigateTo({ uni.navigateTo({
url, url,
}) })
} },
goPage(url : string) {
uni.navigateTo({ url })
},
// #ifdef UNI-APP-X && APP // #ifdef UNI-APP-X && APP
, upgradePopupShow() { upgradePopupShow() {
console.log('upgradePopup show'); console.log('upgradePopup show');
if (!this.pageHiden) { if (!this.pageHiden) {
uni.hideTabBar()?.catch(_ => { }) uni.hideTabBar()?.catch(_ => { })
...@@ -316,16 +401,16 @@ ...@@ -316,16 +401,16 @@
// #ifdef UNI-APP-X && APP // #ifdef UNI-APP-X && APP
checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance) checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
// #endif // #endif
}, },
onLoad() { onLoad() {
// console.log("component page onLoad") // console.log("component page onLoad")
}, },
onShow() { onShow() {
// console.log("component page onShow") // console.log("component page onShow")
this.pageHiden = false this.pageHiden = false
}, },
onHide() { onHide() {
// console.log("component page onHide") // console.log("component page onHide")
this.pageHiden = true this.pageHiden = true
}, },
beforeUnmount() { beforeUnmount() {
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册