refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范

这个提交包含在:
wikiboss
2026-09-20 17:05:22 +08:00
父节点 de3cf8b870
当前提交 9fa1d1fbd0
共有 1679 个文件被更改,包括 204798 次插入 和 16817 次删除

查看文件

@@ -0,0 +1,238 @@
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;" enable-back-to-top="true">
<!-- #endif -->
<view class="uni-container" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
<view v-if="!hasLeftWin" class="uni-header-logo">
<image class="uni-header-image" src="/static/apiIndex.png"></image>
</view>
<view v-if="!hasLeftWin" class="uni-text-box">
<text class="hello-text">uni-app x API接口能力,文档详见:</text>
<uni-link class="hello-text" href="https://doc.dcloud.net.cn/uni-app-x/api/"
<!-- #ifndef MP -->
target="_blank"
<!-- #endif -->
>
https://doc.dcloud.net.cn/uni-app-x/api/
</uni-link>
</view>
<uni-collapse>
<uni-collapse-item ref="categoryRef" v-for="menuItem in menu" :key="menuItem.id" :title="menuItem.name"
class="uni-panel" title-wrap-class="component-collapse-title-wrap"
title-class="component-collapse-title" content-wrap-class="component-collapse-content-wrap"
arrow-class="component-collapse-arrow">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
<view v-if="childMenuItem.items.length==0" hover-class="is--active"
:class="{'uni-navigate-item':childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768}"
@click="goPage(`/${childMenuItem.path}`)">
<template v-if="childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768">
<text class="uni-navigate-text"
:class="{'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
<view class="right_arrow"></view>
</template>
</view>
<uni-collapse v-else style="width: 100%;border-top: 1px solid var(--border-color);">
<uni-collapse-item :title="childMenuItem.name" class="uni-panel"
style="margin-bottom: 0;" title-wrap-class="component-collapse-title-wrap component-collapse-sub-title-wrap"
title-class="component-collapse-title" content-wrap-class="component-collapse-content-wrap"
arrow-class="component-collapse-arrow">
<view class="uni-navigate-item component-collapse-sub-navigate-item" hover-class="is--active"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
@click="goPage(`/${grandChildMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active':
leftWinActive === grandChildMenuItem.path && hasLeftWin,
}">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
<view class="right_arrow"></view>
</view>
</uni-collapse-item>
</uni-collapse>
</template>
</uni-collapse-item>
</uni-collapse>
<!-- #ifdef MP || WEB -->
<view v-if="!hasLeftWin" ref="popRef" @click="hidePop()" class="popup" @touchmove.prevent="stopPropagation">
<!-- #endif -->
<!-- #ifndef MP || WEB -->
<view v-if="!hasLeftWin" ref="popRef" @click="hidePop()" class="popup">
<!-- #endif -->
<view style="width: 90%; background-color: white" @click.stop="stopClickPop">
<api-set-tabbar></api-set-tabbar>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
defineOptions({
styleIsolation: 'app'
})
const activeIndex = inject<Ref<number>>('tabBarCurrentIndex', ref(0))
const instance = getCurrentInstance()!.proxy!
import { generateMenu, MenuItem } from './generateMenu.uts'
const menuData = generateMenu('pages/API')
import { state } from '@/store/index.uts'
// Template refs
const popRef = ref<UniElement | null>(null)
const categoryRef = ref<ComponentPublicInstance[] | null>(null)
const menu = ref(menuData as MenuItem[])
const hasLeftWin = computed((): boolean => {
return !state.noMatchLeftWindow
})
const leftWinActive = computed((): string => {
return state.leftWinActive.slice(1)
})
const windowWidth = computed((): number => {
return uni.getWindowInfo().windowWidth
})
const isDarkMode = computed((): boolean => {
return state.isDarkMode
})
const netless = computed((): boolean => {
return state.netless
})
function showPop() {
const popElement = popRef.value
if (popElement != null) {
popElement.style.setProperty("display", "flex")
}
}
function goPage(url : string) {
if (url == '/set-tab-bar') {
showPop()
}else {
if (hasLeftWin.value) {
uni.reLaunch({ url })
} else {
uni.navigateTo({ url })
}
}
}
function hidePop() {
const popElement = popRef.value
if (popElement != null) {
popElement.style.setProperty("display", "none")
}
}
function stopClickPop(e : PointerEvent) {
e.stopPropagation() //点击到pop的非灰色区域,拦截点击事件
}
function stopPropagation() {
}
// #ifdef APP-HARMONY
watch(netless, (netlessValue) => {
if (netlessValue) {
menu.value = menu.value.filter(item => {
return !['unicloud'].includes(item.id)
})
}
}, { immediate: true })
// #endif
// #ifdef WEB
// Note: This watch is for web platform routing, keeping minimal getInstance usage for $route and $nextTick
watch(() => (instance as any).$route, (newRoute: any) => {
if (newRoute.matched.length) {
const activeCategoryIndex = menu.value.findIndex(menuItem => menuItem?.items.some(item => leftWinActive.value !== "" && leftWinActive.value === item?.path))
if (activeCategoryIndex > -1) {
nextTick(() => {
const categoryRefs = categoryRef.value
if (categoryRefs != null && categoryRefs[activeCategoryIndex] != null) {
categoryRefs[activeCategoryIndex].$callMethod('openCollapse', true)
}
})
}
}
}, { immediate: true })
// #endif
// #ifdef APP-ANDROID
const testOpenDialogPage = () => {
uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-5'
});
}
const testCloseDialogPage = () => {
uni.closeDialogPage();
}
defineExpose({
testOpenDialogPage,
testCloseDialogPage
})
// #endif
</script>
<style>
.popup {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
align-items: center;
justify-content: center;
display: none;
background-color: rgba(16, 16, 16, 0.5);
}
.right_arrow {
width: 8px;
height: 8px;
margin-left: 12px;
transform: rotate(-45deg);
border-right-width: 1px;
border-right-style: solid;
border-right-color: var(--arrow-color, #999999);
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-title-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-sub-title-wrap {
padding-left: 16px;
padding-right: 20px;
}
.component-collapse-title {
color: var(--text-color, #333333);
}
.component-collapse-content-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-arrow {
border-right-color: var(--arrow-color, #999999);
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-sub-navigate-item {
padding-right: 20px;
}
</style>

查看文件

@@ -0,0 +1,151 @@
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;" enable-back-to-top="true">
<!-- #endif -->
<view class="uni-container" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
<view v-if="!hasLeftWin" class="uni-header-logo">
<image class="uni-header-image" src="/static/cssIndex.png"></image>
</view>
<view v-if="!hasLeftWin" class="uni-text-box">
<text class="hello-text">uni-app x App平台支持的CSS,文档详见:</text>
<uni-link class="hello-text" href="https://doc.dcloud.net.cn/uni-app-x/css/"
<!-- #ifndef MP -->
target="_blank"
<!-- #endif -->
>
https://doc.dcloud.net.cn/uni-app-x/css/
</uni-link>
</view>
<uni-collapse>
<uni-collapse-item ref="categoryRef" v-for="menuItem in menu" :key="menuItem.id" :title="menuItem.name"
class="uni-panel" title-wrap-class="component-collapse-title-wrap"
title-class="component-collapse-title" content-wrap-class="component-collapse-content-wrap"
arrow-class="component-collapse-arrow">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
<view v-if="childMenuItem.items.length==0" class="uni-navigate-item"
hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin,
}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
<view class="right_arrow"></view>
</view>
<uni-collapse v-else style="width: 100%;border-top: 1px solid var(--border-color);">
<uni-collapse-item :title="childMenuItem.name" class="uni-panel"
style="margin-bottom: 0;" title-wrap-class="component-collapse-title-wrap component-collapse-sub-title-wrap"
title-class="component-collapse-title" content-wrap-class="component-collapse-content-wrap"
arrow-class="component-collapse-arrow">
<view class="uni-navigate-item component-collapse-sub-navigate-item" hover-class="is--active"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
@click="goPage(`/${grandChildMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active':
leftWinActive === grandChildMenuItem.path && hasLeftWin,
}">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
<view class="right_arrow"></view>
</view>
</uni-collapse-item>
</uni-collapse>
</template>
</uni-collapse-item>
</uni-collapse>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
defineOptions({
styleIsolation: 'app'
})
const activeIndex = inject<Ref<number>>('tabBarCurrentIndex', ref(0))
const instance = getCurrentInstance()!.proxy!
import { generateMenu, MenuItem } from './generateMenu.uts'
const menuData = generateMenu('pages/CSS')
import { state } from '@/store/index.uts'
// Template refs
const categoryRef = ref<ComponentPublicInstance[] | null>(null)
const menu = ref(menuData as MenuItem[])
const hasLeftWin = computed((): boolean => {
return !state.noMatchLeftWindow
})
const leftWinActive = computed((): string => {
return state.leftWinActive.slice(1)
})
const isDarkMode = computed((): boolean => {
return state.isDarkMode
})
function goPage(url : string) {
if (hasLeftWin.value) {
uni.reLaunch({ url })
} else {
uni.navigateTo({ url })
}
}
// #ifdef WEB
watch(() => (instance as any).$route, (newRoute: any) => {
if (newRoute && newRoute.matched.length) {
const activeCategoryIndex = menu.value.findIndex(menuItem => menuItem?.items.some(item => leftWinActive.value !== "" && leftWinActive.value === item?.path))
if (activeCategoryIndex > -1) {
nextTick(() => {
const categoryRefs = categoryRef.value
if (categoryRefs != null && categoryRefs[activeCategoryIndex] != null) {
categoryRefs[activeCategoryIndex].$callMethod('openCollapse', true)
}
})
}
}
}, { immediate: true })
// #endif
</script>
<style>
.right_arrow {
width: 8px;
height: 8px;
margin-left: 12px;
transform: rotate(-45deg);
border-right-width: 1px;
border-right-style: solid;
border-right-color: var(--arrow-color, #999999);
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-title-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-sub-title-wrap {
padding-left: 16px;
padding-right: 20px;
}
.component-collapse-title {
color: var(--text-color, #333333);
}
.component-collapse-content-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-arrow {
border-right-color: var(--arrow-color, #999999);
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-sub-navigate-item {
padding-right: 20px;
}
</style>

查看文件

@@ -0,0 +1,230 @@
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;" enable-back-to-top="true">
<!-- #endif -->
<view class="uni-container" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
<view v-if="!hasLeftWin" class="uni-header-logo">
<image class="uni-header-image" src="/static/componentIndex.png"></image>
</view>
<view v-if="!hasLeftWin" class="uni-text-box">
<text class="hello-text">uni-app x内置组件,文档详见:</text>
<uni-link class="hello-text" href="https://doc.dcloud.net.cn/uni-app-x/component/"
<!-- #ifndef MP -->
target="_blank"
<!-- #endif -->
>
https://doc.dcloud.net.cn/uni-app-x/component/
</uni-link>
</view>
<uni-collapse>
<uni-collapse-item ref="categoryRef" v-for="menuItem in menu" :key="menuItem.id" :title="menuItem.name"
:open="menuItem.id == 'view-container'" class="uni-panel" title-wrap-class="component-collapse-title-wrap"
title-class="component-collapse-title" content-wrap-class="component-collapse-content-wrap"
arrow-class="component-collapse-arrow">
<template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
<view v-if="childMenuItem.items.length==0" class="uni-navigate-item" hover-class="is--active"
@click="goPage(`/${childMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin,
}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
<view class="right_arrow"></view>
</view>
<uni-collapse v-else style="width: 100%;border-top: 1px solid var(--border-color);">
<uni-collapse-item :title="childMenuItem.name" class="uni-panel" style="margin-bottom: 0;"
title-wrap-class="component-collapse-title-wrap component-collapse-sub-title-wrap" title-class="component-collapse-title"
content-wrap-class="component-collapse-content-wrap" arrow-class="component-collapse-arrow">
<view class="uni-navigate-item component-collapse-sub-navigate-item" hover-class="is--active"
v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
@click="goPage(`/${grandChildMenuItem.path}`)">
<text class="uni-navigate-text" :class="{
'left-win-active':
leftWinActive === grandChildMenuItem.path && hasLeftWin,
}">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
<view class="right_arrow"></view>
</view>
</uni-collapse-item>
</uni-collapse>
</template>
</uni-collapse-item>
</uni-collapse>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
defineOptions({
styleIsolation: 'app'
})
const activeIndex = inject<Ref<number>>('tabBarCurrentIndex', ref(0))
const instance = getCurrentInstance()!.proxy!
import { generateMenu, MenuItem } from './generateMenu.uts'
const menuData = generateMenu('pages/component')
// #ifdef APP
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
// #endif
import { state } from '@/store/index.uts'
// Template refs
const categoryRef = ref<ComponentPublicInstance[] | null>(null)
const menu = ref(menuData as MenuItem[])
const pageHiden = ref(false)
const hasLeftWin = computed((): boolean => {
return !state.noMatchLeftWindow
})
const leftWinActive = computed((): string => {
return state.leftWinActive.slice(1)
})
const isDarkMode = computed((): boolean => {
return state.isDarkMode
})
const netless = computed((): boolean => {
return state.netless
})
function goPage(url : string) {
if (hasLeftWin.value) {
uni.reLaunch({ url })
} else {
uni.navigateTo({ url })
}
}
// #ifdef APP-HARMONY
watch(netless, (netlessValue) => {
if (netlessValue) {
menu.value = menu.value.filter(item => {
return !['unicloud'].includes(item.id)
})
}
}, { immediate: true })
// #endif
onReady(() => {
// #ifdef APP
if (process.env.NODE_ENV !== 'development') {
uni.getPrivacySetting({
success(res) {
if (res.needAuthorization) {
let cbId: number = 0
cbId = uni.onPrivacyAuthorizationChange(() => {
checkUpdate()
uni.offPrivacyAuthorizationChange(cbId)
})
} else {
checkUpdate()
}
}
})
}
// #endif
})
onPageShow(() => {
pageHiden.value = false
})
onHide(() => {
pageHiden.value = true
})
onBeforeUnmount(() => {
uni.showTabBar()?.catch(_ => { })
})
// #ifdef WEB
watch(() => (instance as any).$route, (newRoute: any) => {
if (newRoute && newRoute.matched.length) {
const routePath = newRoute.path.slice(1)
if (!routePath.startsWith('pages/component/')) {
return
}
const activeCategoryIndex = menu.value.findIndex(menuItem => menuItem?.items.some(item => routePath === item?.path))
if (activeCategoryIndex > -1) {
nextTick(() => {
const categoryRefs = categoryRef.value
if (categoryRefs != null && categoryRefs[activeCategoryIndex] != null) {
categoryRefs[activeCategoryIndex].$callMethod('openCollapse', true)
}
})
}
}
}, { immediate: true })
// #endif
function openPreviewImageTest() {
uni.previewImage({
urls: ['/static/test-image/logo.jpg'],
current: 0
})
}
function closePreviewImageTest() {
uni.closePreviewImage({})
}
defineExpose({
openPreviewImageTest,
closePreviewImageTest
})
</script>
<style>
/* web端适配暗黑主题 */
/* #ifdef WEB */
.uni-container.theme-dark {
min-height: calc(100vh - var(--uni-safe-area-inset-top));
}
/* #endif */
.right_arrow {
width: 8px;
height: 8px;
margin-left: 12px;
transform: rotate(-45deg);
border-right-width: 1px;
border-right-style: solid;
border-right-color: var(--arrow-color, #999999);
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-title-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-sub-title-wrap {
padding-left: 16px;
padding-right: 20px;
}
.component-collapse-title {
color: var(--text-color, #333333);
}
.component-collapse-content-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-arrow {
border-right-color: var(--arrow-color, #999999);
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-sub-navigate-item {
padding-right: 20px;
}
</style>

查看文件

@@ -0,0 +1,180 @@
import { pages, groups, subPackages } from '@/pages.json'
type Group = {
id : string,
name : string,
children : (Group | null)[] | null
}
type PageGroup = {
id : string,
name : string,
index : number
}
type Page = {
path : string,
style : UTSJSONObject,
group ?: string | null,
}
export type MenuItem = {
id : string,
name : string,
index : number,
path : string,
style : UTSJSONObject,
group ?: string | null,
items : MenuItem[]
}
subPackages.forEach(subPackage => {
(subPackage.pages as UTSJSONObject[]).forEach(page => {
(pages as Page[]).push({
path: `${subPackage.root}/${page.path}`,
style: page.style as UTSJSONObject,
group: page.group as string | 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))
let currentMenu : MenuItem | null = null
tabBarPages.forEach(page => {
let menuItemArr : MenuItem[] = res
const groupIndexList = page.group!.split(',').map((index : string) : number => parseInt(index))
let currentGroups : (Group | null)[] | null = groupTree
const pageGroups : PageGroup[] = []
groupIndexList.forEach((groupIndex, index) => {
// 跳过第一层 component API CSS
if (index > 0) {
pageGroups.push({ id: currentGroups![groupIndex]!.id, name: currentGroups![groupIndex]!.name, index: groupIndex } as PageGroup)
}
currentGroups = currentGroups![groupIndex]!.children
})
const lastGroup = pageGroups[pageGroups.length - 1]
let hasPageGroup = false
if (
(
page.path.endsWith(camelToDash(lastGroup.name)) ||
page.path.endsWith(camelToDash(lastGroup.name.replace('uni.', '')))
) &&
pageGroups.length > 1
) {
hasPageGroup = true
pageGroups.pop()
}
const groupLength = pageGroups.length
pageGroups.forEach((group, groupIndex) => {
const { index, id, name } = group
const validIndex = index
fillMenuArrayWithEmptyMenuItem(menuItemArr, validIndex)
if (menuItemArr[validIndex].name == 'empty') {
menuItemArr[validIndex] = {
id: id.split('.').slice(-1)[0],
name,
index: validIndex,
path: '',
style: {},
group: '',
items: [] as MenuItem[],
} as MenuItem
}
currentMenu = menuItemArr[validIndex]
if (groupIndex < groupLength - 1) {
menuItemArr = menuItemArr[validIndex].items
}
})
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[],
}
if (hasPageGroup && currentMenu != null) {
const pageIndex = lastGroup.index
fillMenuArrayWithEmptyMenuItem(currentMenu!.items, pageIndex)
if (currentMenu!.items[pageIndex].name == 'empty') {
currentMenu!.items[pageIndex] = pageMenuItem
} else {
currentMenu!.items.push(pageMenuItem)
}
} else {
currentMenu!.items.push(pageMenuItem)
}
})
return removeEmptyItem(res)
}
function hasPageGroup(value ?: string | null) : boolean {
// #ifdef APP-ANDROID
return value !== null
// #endif
// #ifndef APP-ANDROID
return !!value
// #endif
}
function camelToDash(camelStr: string): string {
// 将首字母转换为小写, 兼容类似 Base64 场景
camelStr = camelStr.charAt(0).toLowerCase() + camelStr.slice(1);
return camelStr.replace(/([A-Z])/g, '-$1').toLowerCase()
}
function fillMenuArrayWithEmptyMenuItem(arr : MenuItem[], index : number) : void {
const len = arr.length
for (let i = 0; i <= index - (len - 1); i++) {
arr.push({
id: '',
name: 'empty',
index: i,
path: '',
style: {},
group: '',
items: [] as MenuItem[],
} as MenuItem)
}
}
function removeEmptyItem(arr : MenuItem[]) : MenuItem[] {
const res = arr.filter((item : MenuItem) : boolean => item.name !== 'empty')
res.forEach(menuItem => {
addSetTabBarPage(menuItem)
// #ifdef APP-ANDROID
menuItem.items = removeEmptyItem(menuItem.items)
// #endif
// #ifndef APP-ANDROID
menuItem!.items = removeEmptyItem(menuItem!.items)
// #endif
})
return res
}
function addSetTabBarPage(menuItem : MenuItem) {
const { id, name } = menuItem
if (id == 'page' && name == '页面和路由') {
menuItem.items.push({
id: 'set-tab-bar',
name: '设置 TabBar',
index: 0,
path: 'set-tab-bar',
style: {
navigationBarTitleText: '设置 TabBar'
},
group: null,
items: []
} as MenuItem)
}
}

查看文件

@@ -0,0 +1,154 @@
<template>
<uni-tab class="tab-page-root" :style="{ height: tabPageHeight + 'px' }" :active-index="activeIndex" @change="handleChange">
<!-- 内容区域 -->
<view class="tab-content-stage">
<uni-tab-content>
<componenttab />
</uni-tab-content>
<uni-tab-content>
<apitab />
</uni-tab-content>
<uni-tab-content>
<csstab />
</uni-tab-content>
<uni-tab-content>
<uniuitab />
</uni-tab-content>
<uni-tab-content>
<templatetab />
</uni-tab-content>
</view>
<!-- 底部选项卡 -->
<uni-tab-bar :style="{ backgroundColor: tabBarBgColor }">
<!-- 图标高度24,文字字号10px。如需角标,在 <uni-tab-item> 上设置 badge-text="99+" -->
<uni-tab-item>
<image :src="activeIndex == 0 ? '/static/componentHL.png' : '/static/component.png'" class="tab-icon-image" flatten></image>
<text class="tab-label" :class="[activeIndex == 0 ? 'tab-label-active' : '', darkTextClass]" flatten>组件</text>
</uni-tab-item>
<uni-tab-item>
<image :src="activeIndex == 1 ? '/static/apiHL.png' : '/static/api.png'" class="tab-icon-image" flatten></image>
<text class="tab-label" :class="[activeIndex == 1 ? 'tab-label-active' : '', darkTextClass]" flatten>API</text>
</uni-tab-item>
<uni-tab-item>
<image :src="activeIndex == 2 ? '/static/cssHL.png' : '/static/css.png'" class="tab-icon-image" flatten></image>
<text class="tab-label" :class="[activeIndex == 2 ? 'tab-label-active' : '', darkTextClass]" flatten>CSS</text>
</uni-tab-item>
<uni-tab-item>
<image :src="activeIndex == 3 ? '/static/extuiHL.png' : '/static/extui.png'" class="tab-icon-image" flatten></image>
<text class="tab-label" :class="[activeIndex == 3 ? 'tab-label-active' : '', darkTextClass]" flatten>uni-ui</text>
</uni-tab-item>
<uni-tab-item>
<image :src="activeIndex == 4 ? '/static/templateHL.png' : '/static/template.png'" class="tab-icon-image" flatten></image>
<text class="tab-label" :class="[activeIndex == 4 ? 'tab-label-active' : '', darkTextClass]" flatten>模板</text>
</uni-tab-item>
</uni-tab-bar>
</uni-tab>
</template>
<script setup lang="uts">
import componenttab from './component.uvue'
import apitab from './API.uvue'
import csstab from './CSS.uvue'
import templatetab from './template.uvue'
import uniuitab from './uni-ui.uvue'
import { state } from '@/store/index.uts'
const tabPageHeight = ref<number>(uni.getWindowInfo().windowHeight)
const activeIndex = ref<number>(0)
const currentPage = getCurrentInstance()?.proxy?.$page
const darkTextClass = computed((): string => {
return state.isDarkMode ? 'tab-label-dark' : ''
})
const tabBarBgColor = computed((): string => {
return state.isDarkMode ? '#1F1F1F' : '#F8F8F8'
})
function syncAndroidNavigationStyle() : void {
// #ifdef APP-ANDROID
const pages = getCurrentPages()
if (pages.length == 0 || currentPage == null) {
return
}
currentPage.setPageStyle({
androidThreeButtonNavigationBackgroundColor: tabBarBgColor.value,
androidThreeButtonNavigationStyle: state.isDarkMode ? 'white' : 'black'
})
// #endif
}
function syncTabPageHeight() : void {
tabPageHeight.value = uni.getWindowInfo().windowHeight
}
watch((): boolean => state.isDarkMode, () => {
syncAndroidNavigationStyle()
})
onResize(() => {
syncTabPageHeight()
})
onReady(() => {
syncTabPageHeight()
syncAndroidNavigationStyle()
})
// uni-tab-item 点击后由 <uni-tab> 抛出 change 事件,携带新激活的索引
function handleChange(index : number) : void {
activeIndex.value = index
switch (index) {
case 0:
uni.setNavigationBarTitle({ title: '组件' })
break
case 1:
uni.setNavigationBarTitle({ title: 'API' })
break
case 2:
uni.setNavigationBarTitle({ title: 'CSS' })
break
case 3:
uni.setNavigationBarTitle({ title: 'uni-ui' })
break
case 4:
uni.setNavigationBarTitle({ title: '模板' })
break
}
}
</script>
<style>
.tab-page-root {
width: 100%;
flex: 1;
}
.tab-content-stage {
width: 100%;
flex: 1;
min-height: 0px;
display: flex;
flex-direction: column;
position: relative;
overflow: hidden;
}
.tab-icon-image {
height: 24px;
width: 24px;
}
.tab-label {
font-size: 10px;
color: rgb(122, 126, 131);
}
.tab-label-dark {
color: #CACACA;
}
.tab-label-active {
color: #007aff;
}
</style>

查看文件

@@ -0,0 +1,145 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isHarmony = platformInfo.startsWith('harmony')
const isApp = isAndroid || isIos || isHarmony
const PAGE_PATH = '/pages/tabBar/API'
const COMPONENT_PAGE_PATH = '/pages/tabBar/component'
const TAB_BAR_INDEX = 1
const DEFAULT_TAB_BAR_STYLE = {
color: '#7A7E83',
selectedColor: '#007AFF',
backgroundColor: '#F8F8F8',
borderStyle: 'black'
}
const DEFAULT_TAB_BAR_ITEM = {
visible: true,
index: TAB_BAR_INDEX,
text: '接口',
iconPath: '/static/api.png',
selectedIconPath: '/static/apiHL.png'
}
describe('tab bar api screenshot', () => {
if (!isApp) {
it('not support', () => {
expect(1).toBe(1)
})
return
}
let page
let screenShotOptions = { fullPage: true }
async function callUniMethod(method, options) {
return await program.callUniMethod(method, options)
}
async function ignoreUniMethodError(method, options) {
try {
await callUniMethod(method, options)
} catch (_) {}
}
async function resetTabBar() {
await ignoreUniMethodError('showTabBar')
await ignoreUniMethodError('removeTabBarBadge', { index: TAB_BAR_INDEX })
await ignoreUniMethodError('hideTabBarRedDot', { index: TAB_BAR_INDEX })
await ignoreUniMethodError('setTabBarStyle', DEFAULT_TAB_BAR_STYLE)
await ignoreUniMethodError('setTabBarItem', DEFAULT_TAB_BAR_ITEM)
await page.waitFor(500)
}
async function openPage(path = PAGE_PATH) {
page = await program.reLaunch(path)
await page.waitFor('view')
await resetTabBar()
}
async function screenshot() {
await page.waitFor(1000)
const image = await program.screenshot(screenShotOptions)
expect(image).toSaveImageSnapshot()
}
beforeAll(async () => {
const windowInfo = await program.callUniMethod('getWindowInfo')
screenShotOptions = {
deviceShot: true,
area: {
x: 0,
y: windowInfo.safeAreaInsets.top + 44
}
}
})
beforeEach(async () => {
await openPage()
})
afterEach(async () => {
await resetTabBar()
})
afterAll(async () => {
if (page != null) {
await resetTabBar()
}
})
it('set tab bar item text screenshot', async () => {
await callUniMethod('setTabBarItem', {
...DEFAULT_TAB_BAR_ITEM,
text: 'API'
})
await screenshot()
})
it('set tab bar item long title screenshot', async () => {
await callUniMethod('setTabBarItem', {
...DEFAULT_TAB_BAR_ITEM,
text: '超长标题内容超长标题内容超长标题内容超长标题测试',
iconPath: '',
selectedIconPath: ''
})
await screenshot()
})
it('set tab bar style screenshot', async () => {
await callUniMethod('setTabBarStyle', {
color: '#FFF',
selectedColor: '#007AFF',
backgroundColor: '#000000',
borderStyle: 'black'
})
await screenshot()
})
it('show tab bar red dot screenshot', async () => {
await callUniMethod('showTabBarRedDot', { index: TAB_BAR_INDEX })
await screenshot()
})
it('set tab bar badge screenshot', async () => {
await callUniMethod('setTabBarBadge', {
index: TAB_BAR_INDEX,
text: '1'
})
await screenshot()
})
it('hide tab bar screenshot', async () => {
await callUniMethod('hideTabBar')
await screenshot()
})
it('preview image dialogPage cover tab bar screenshot', async () => {
await openPage(COMPONENT_PAGE_PATH)
await screenshot()
await page.callMethod('openPreviewImageTest')
await screenshot()
await page.callMethod('closePreviewImageTest')
await page.waitFor(500)
})
})

查看文件

@@ -0,0 +1,501 @@
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;" enable-back-to-top="true">
<!-- #endif -->
<view class="uni-container" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
<view v-if="!hasLeftWin" class="uni-header-logo">
<image class="uni-header-image" src="/static/templateIndex.png"></image>
</view>
<view v-if="!hasLeftWin" class="uni-text-box">
<text class="hello-text">以下是部分模板示例,更多模板见插件市场:</text>
<uni-link class="hello-text" href="https://ext.dcloud.net.cn"
<!-- #ifndef MP -->
target="_blank"
<!-- #endif -->
>https://ext.dcloud.net.cn</uni-link>
</view>
<uni-collapse>
<template v-for="(item, index) in list" :key="item.id">
<uni-collapse-item v-if="item.pages.length > 0" class="uni-panel" :open="item.open" :title="item.name"
title-wrap-class="component-collapse-title-wrap" title-class="component-collapse-title"
content-wrap-class="component-collapse-content-wrap" arrow-class="component-collapse-arrow"
@change="syncCollapseState(index, $event as boolean)">
<view style="padding-left: 18px;" class="uni-navigate-item"
:hover-class="page.enable == false ? '' : 'is--active'" v-for="(page, key) in item.pages" :key="key"
@click="goDetailPage(page)">
<text class="uni-navigate-text"
:class="{'left-win-active': leftWinActive === getPageKey(page.url) && hasLeftWin,'text-disabled' : page.enable == false}">{{ page.name }}</text>
<view class="right_arrow"></view>
</view>
</uni-collapse-item>
<view v-else class="uni-panel">
<view hover-class="is--active" class="uni-panel-h" @click="triggerCollapse(index, item)">
<text class="uni-panel-text"
:class="item.enable == false || item.open == true ? 'text-disabled' : '',item.url == leftWinActive && item.pages.length == 0 ? 'left-win-active' : ''">{{ item.name }}</text>
<view class="right_arrow"></view>
</view>
</view>
</template>
</uni-collapse>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
// #ifdef VUE3-VAPOR && APP || WEB
import { generateMockList as generateListViewMockList } from '../template/long-list-perf/mock-data'
import { generateMockList as generateWaterflowMockList } from '../template/waterflow-perf/mock-data'
// #endif
defineOptions({
styleIsolation: 'app'
})
const activeIndex = inject<Ref<number>>('tabBarCurrentIndex', ref(0))
const instance = getCurrentInstance()?.proxy
type Page = {
name : string
enable ?: boolean
url : string
}
type ListItem = {
id : string
name : string
open : boolean
pages : Page[]
url ?: string
enable ?: boolean
}
import { state } from '@/store/index.uts'
const list = ref<ListItem[]>([
// #ifdef APP && VUE3-VAPOR
{
id: '4050',
url: '4050',
name: 'view和text性能测试',
open: false,
pages: [
{
name: '拍平示例',
url: '4050/4050'
},
{
name: '非拍平示例',
url: '4050/4050-no-flatten'
}
] as Page[],
},
{
id: '2000-image',
url: '2000-image',
name: 'image性能测试',
open: false,
pages: [] as Page[],
},
{
id: 'long-rich-text',
url: 'long-rich-text',
name: 'rich-text 5万字性能测试',
open: false,
pages: [] as Page[],
},
{
id: 'long-list-perf',
url: 'long-list-perf',
name: '死亡长列表',
open: false,
pages: [] as Page[],
},
{
id: 'waterflow-perf',
url: 'waterflow-perf',
name: 'waterflow滚动加载长列表',
open: false,
pages: [] as Page[],
},
// #endif
{
id: 'long-list',
url: 'long-list',
name: '左右滑动长列表',
open: false,
enable: true,
pages: [
// #ifdef WEB
{
name: '顶部 Banner 分栏信息流嵌套滚动',
url: 'banner-tabs-feed-nested-scroll'
},
// #endif
// #ifdef APP
{
name: '顶部 Banner 分栏长列表嵌套滚动',
url: 'banner-tabs-long-list-nested-scroll'
},
{
name: '顶部 Banner 瀑布流嵌套滚动',
url: 'banner-waterfall-nested-scroll'
},
// #endif
{
name: '带搜索框的分栏长列表',
url: 'search-header-long-list'
}
] as Page[],
},
{
id: 'news-feed-list',
url: 'news-feed-list',
name: '新闻资讯列表',
open: false,
pages: [] as Page[],
},
// #ifdef APP || WEB
{
id: 'list-delete-swipe-batch',
url: 'list-delete-swipe-batch',
name: '可侧滑删除和多选删除的列表',
open: false,
pages: [] as Page[],
},
// #endif
// #ifndef VUE3-VAPOR
{
id: 'batch-load-long-list',
url: 'batch-load-long-list',
name: '分批加载长列表',
open: false,
pages: [] as Page[],
},
{
id: 'recycle-long-list',
url: 'recycle-long-list',
name: '可回收复用长列表',
open: false,
pages: [] as Page[],
},
// #endif
{
id: 'swipe-tabs-underline',
url: 'swipe-tabs-underline',
name: '横滑分页标签栏',
open: false,
pages: [
{
name: '横滑分页标签栏(下划线指示)',
url: 'swipe-tabs-underline'
},
{
name: '横滑分页标签栏(字体缩放高亮)',
url: 'swipe-tabs-scale-highlight'
},
] as Page[],
},
{
id: 'scroll-collapse-navbar',
url: 'scroll-collapse-navbar',
name: '随滚动折叠的导航栏',
open: false,
pages: [] as Page[],
},
// #ifdef APP
{
id: 'pull-zoom-profile-page',
url: 'pull-zoom-profile-page',
name: '下拉缩放封面图的个人主页',
open: false,
pages: [] as Page[],
},
{
id: 'scroll-view-sticky-section',
url: 'scroll-view-sticky-section',
name: '自定义吸顶',
open: false,
pages: [] as Page[],
},
// #endif
{
id: 'keyboard-adjust',
url: 'keyboard-adjust',
name: '输入框上推示例',
open: false,
pages: [] as Page[],
},
{
id: 'scroll-fade-navbar',
url: 'scroll-fade-navbar',
name: '随滚动渐显的透明导航栏',
open: false,
pages: [] as Page[],
},
{
id: 'vertical-video-feed',
url: 'vertical-video-feed',
name: '竖滑切换的视频信息流',
open: false,
pages: [] as Page[],
},
// #ifndef MP
{
id: 'chat-stream-reply',
url: 'chat-stream-reply',
name: '流式回复聊天示例',
open: false,
pages: [] as Page[],
},
// #endif
{
id: 'draggable-half-modal',
url: 'draggable-half-modal',
name: '可拖拽关闭的半屏弹窗',
open: false,
pages: [] as Page[],
},
{
id: 'interstitial-poster',
url: 'interstitial-poster',
name: 'page-container 插屏海报',
open: false,
pages: [] as Page[],
},
{
id: 'swipe-card-stack',
url: 'swipe-card-stack',
name: '左右划走的卡片堆叠',
open: false,
pages: [] as Page[],
},
{
id: 'shopping-cart-animation',
url: 'shopping-cart-animation',
name: '购物车加购动画',
open: false,
pages: [] as Page[],
},
// #ifdef APP && !VUE3-VAPOR
{
id: 'calendar',
url: 'calendar',
name: '日历',
open: false,
pages: [] as Page[],
},
// #endif
// #ifdef MP || VUE3-VAPOR
{
id: 'calendar',
url: 'calendar-vapor',
name: '日历',
open: false,
pages: [] as Page[],
},
// #endif
// #ifdef APP || WEB
{
id: 'external-link-launch',
url: 'external-link-launch',
name: '唤起外部应用与链接',
open: false,
pages: [] as Page[],
},
// #endif
// #ifdef WEB
{
id: 'browser-built-in-elements',
url: 'browser-built-in-elements',
name: '浏览器内置元素示例',
open: false,
pages: [] as Page[],
},
// #endif
// #ifdef MP-WEIXIN
{
id: 'mp-custom-components-vant',
url: 'mp-custom-components-vant',
name: '微信小程序自定义组件接入(Vant)',
open: false,
pages: [] as Page[],
},
{
id: 'wxs-drag-interaction',
url: 'wxs-drag-interaction',
name: 'WXS 交互与拖拽示例',
open: false,
pages: [] as Page[],
},
// #endif
{
id: 'about',
url: 'about',
name: '关于',
open: false,
pages: [] as Page[],
}
] as ListItem[])
const hasLeftWin = computed(() : boolean => {
return !state.noMatchLeftWindow
})
const leftWinActive = computed(() : string => {
return state.leftWinActive.split('/')[3]
})
const isDarkMode = computed(() : boolean => {
return state.isDarkMode
})
const netless = computed(() : boolean => {
return state.netless
})
function getPageKey(url : string) : string {
if (url.indexOf('/pages/') == 0) {
const parts = url.split('/')
if (parts.length > 1) {
return parts[parts.length - 2]
}
}
return url
}
function resolvePageUrl(url : string) : string {
if (url.indexOf('platform') > -1 || url.indexOf('/pages/') == 0) {
return url
}
if (url.indexOf('/') > -1) {
return `/pages/template/${url}`
}
return `/pages/template/${url}/${url}`
}
function goDetailPage(e : Page) {
if (e.enable == false) {
uni.showToast({
icon: 'none',
title: '暂不支持',
})
return
}
const url = resolvePageUrl(e.url)
if (hasLeftWin.value) {
uni.reLaunch({ url })
} else {
uni.navigateTo({ url
,fail() {
console.log('页面跳转失败:' + url)
}
})
}
}
function triggerCollapse(index : number, item : ListItem) {
if (item.pages.length == 0) {
const page : Page = {
name: item.name,
enable: item.enable,
url: item.url!,
}
goDetailPage(page)
return
}
for (var i = 0; i < list.value.length; ++i) {
if (index == i) {
list.value[i].open = !list.value[i].open
} else {
list.value[i].open = false
}
}
}
function syncCollapseState(index : number, open : boolean) {
for (var i = 0; i < list.value.length; ++i) {
list.value[i].open = open && index == i
}
}
// #ifdef APP-HARMONY
watch(() => netless.value, (netless) => {
if (netless) {
list.value = list.value.filter(item => {
return !['news-feed-list'].includes(item.id)
})
}
}, { immediate: true })
// #endif
// #ifdef WEB
watch(() => (instance as any)?.$route, (newRoute) => {
if (newRoute && newRoute.matched.length) {
let path = newRoute.path.split('/')[3]
for (const item of list.value) {
if (Array.isArray(item.pages)) {
for (const page of item.pages) {
if (page.url && getPageKey(page.url) === path) {
item.open = true
}
}
}
}
}
}, { immediate: true })
// #endif
onMounted(() => {
// #ifdef VUE3-VAPOR && APP || WEB
// 预加载长列表数据
generateListViewMockList()
generateWaterflowMockList()
// #endif
// 预热网络,只发送head请求,预先完成dns解析和tcp握手,提升后续请求速度
uni.request({
url: 'https://unidemo.dcloud.net.cn', // 替换为实际请求的URL
method: 'HEAD',
success: (res) => {
// console.log('预热网络成功', res)
},
fail: (err) => {
// console.log('预热网络失败', err);
}
})
})
</script>
<style>
.uni-panel-h {
flex-direction: row;
align-items: center;
padding: 12px 18px;
}
.right_arrow {
width: 8px;
height: 8px;
margin-left: 12px;
transform: rotate(-45deg);
border-right-width: 1px;
border-right-style: solid;
border-right-color: var(--arrow-color, #999999);
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-title-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-title {
color: var(--text-color, #333333);
}
.component-collapse-content-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-arrow {
border-right-color: var(--arrow-color, #999999);
border-bottom-color: var(--arrow-color, #999999);
}
</style>

查看文件

@@ -0,0 +1,318 @@
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;" enable-back-to-top="true">
<!-- #endif -->
<view class="uni-container" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
<view v-if="!hasLeftWin" class="uni-header-logo">
<image class="uni-header-image" src="/static/extuiIndex.png"></image>
</view>
<view v-if="!hasLeftWin" class="uni-text-box">
<text class="hello-text">uni-ui x 扩展组件示例,文档详见:</text>
<uni-link class="hello-text" href="https://doc.dcloud.net.cn/uni-app-x/component/uni-ui-x"
<!-- #ifndef MP -->
target="_blank"
<!-- #endif -->
>
https://doc.dcloud.net.cn/uni-app-x/component/uni-ui-x
</uni-link>
</view>
<uni-collapse>
<template v-for="(item, index) in list" :key="item.id">
<uni-collapse-item v-if="item.pages.length > 0" class="uni-panel" :open="item.open" :title="item.name"
title-wrap-class="component-collapse-title-wrap" title-class="component-collapse-title"
content-wrap-class="component-collapse-content-wrap" arrow-class="component-collapse-arrow"
@change="syncCollapseState(index, $event as boolean)">
<view style="padding-left: 18px;" class="uni-navigate-item"
:hover-class="page.enable == false ? '' : 'is--active'" v-for="(page, key) in item.pages" :key="key"
@click="goDetailPage(page)">
<text class="uni-navigate-text"
:class="{'left-win-active': leftWinActive === getPageKey(page.url) && hasLeftWin,'text-disabled' : page.enable == false}">{{ page.name }}</text>
<view class="right_arrow"></view>
</view>
</uni-collapse-item>
<view v-else class="uni-panel">
<view hover-class="is--active" class="uni-panel-h" @click="triggerCollapse(index, item)">
<text class="uni-panel-text"
:class="{
'text-disabled': item.enable == false || item.open == true,
'left-win-active': getPageKey(item.url!) == leftWinActive && hasLeftWin
}">{{ item.name }}</text>
<view class="right_arrow"></view>
</view>
</view>
</template>
</uni-collapse>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
defineOptions({
styleIsolation: 'app'
})
const instance = getCurrentInstance()?.proxy
type Page = {
name : string
enable ?: boolean
url : string
}
type ListItem = {
id : string
name : string
open : boolean
pages : Page[]
url ?: string
enable ?: boolean
}
import { state } from '@/store/index.uts'
const list = ref<ListItem[]>([
{
id: 'badge',
name: 'uni-badge-view 数字角标',
open: false,
url: '/pages/uni-ui/badge-view/badge-view',
pages: [] as Page[]
},
{
id: 'collapse',
name: 'uni-collapse 折叠面板',
open: false,
url: '/pages/uni-ui/collapse/collapse',
pages: [] as Page[]
},
{
id: 'drag-cell',
name: 'uni-drag-cell 拖拽排序',
open: false,
url: '/pages/uni-ui/drag-cell/drag-cell',
pages: [] as Page[]
},
{
id: 'fab-button',
name: 'uni-fab-button 悬浮按钮',
open: false,
url: '/pages/uni-ui/fab-button/fab-button',
pages: [] as Page[]
},
{
id: 'index-bar',
name: 'uni-index-bar 索引栏',
open: false,
url: '/pages/uni-ui/index-bar/index-bar',
pages: [] as Page[]
},
{
id: 'link',
name: 'uni-link 链接',
open: false,
url: '/pages/uni-ui/link/link',
pages: [] as Page[]
},
{
id: 'nav-bar',
name: 'uni-nav-bar 导航栏',
open: false,
url: '/pages/uni-ui/nav-bar/nav-bar',
pages: [] as Page[]
},
{
id: 'number-box',
name: 'uni-number-box 数字输入框',
open: false,
url: '/pages/uni-ui/number-box/number-box',
pages: [] as Page[]
},
{
id: 'rate',
name: 'uni-rate 评分组件',
open: false,
url: '/pages/uni-ui/rate/rate',
pages: [] as Page[]
},
{
id: 'refresh-box',
name: 'uni-refresh-box 下拉刷新组件',
open: false,
url: '/pages/uni-ui/refresh-box/refresh-box',
pages: [] as Page[]
},
{
id: 'tab-bar',
name: 'uni-tab-bar 底部选项卡',
open: false,
pages: [
{
name: '默认样式',
url: '/pages/uni-ui/tab-bar/tab-bar'
},
{
name: '暗色风格',
url: '/pages/uni-ui/tab-bar/tab-bar-dark'
},
{
name: '自定义样式',
url: '/pages/uni-ui/tab-bar/tab-bar-custom'
},
{
name: '中间按钮',
url: '/pages/uni-ui/tab-bar/tab-bar-midbutton'
},
{
name: '中间按钮镂空',
url: '/pages/uni-ui/tab-bar/tab-bar-midbutton-notch'
}
] as Page[]
},
{
id: 'time-format',
name: 'uni-time-format 时间格式化',
open: false,
url: '/pages/uni-ui/time-format/time-format',
pages: [] as Page[]
},
] as ListItem[])
const hasLeftWin = computed(() : boolean => {
return !state.noMatchLeftWindow
})
const leftWinActive = computed(() : string => {
const parts = state.leftWinActive.split('/').filter((item) : boolean => {
return item.length > 0
})
return parts.length > 0 ? parts[parts.length - 1] : ''
})
const isDarkMode = computed(() : boolean => {
return state.isDarkMode
})
function getPageKey(url : string) : string {
const parts = url.split('/').filter((item) : boolean => {
return item.length > 0
})
return parts.length > 0 ? parts[parts.length - 1] : url
}
function goDetailPage(page : Page) {
if (page.enable == false) {
uni.showToast({
icon: 'none',
title: '暂不支持',
})
return
}
if (hasLeftWin.value) {
uni.reLaunch({ url: page.url })
} else {
uni.navigateTo({
url: page.url,
fail() {
console.log('页面跳转失败:' + page.url)
}
})
}
}
function triggerCollapse(index : number, item : ListItem) {
if (item.pages.length == 0) {
const page : Page = {
name: item.name,
enable: item.enable,
url: item.url!
}
goDetailPage(page)
return
}
for (let i = 0; i < list.value.length; i++) {
list.value[i].open = index == i ? !list.value[i].open : false
}
}
function syncCollapseState(index : number, open : boolean) {
for (let i = 0; i < list.value.length; i++) {
list.value[i].open = open && index == i
}
}
function syncActiveGroup(path : string) {
const matchedIndex = list.value.findIndex((item) : boolean => {
for (const page of item.pages) {
if (getPageKey(page.url) == path) {
return true
}
}
if (item.url != null && getPageKey(item.url!) == path) {
return true
}
return false
})
if (matchedIndex == -1) {
return
}
for (let i = 0; i < list.value.length; i++) {
list.value[i].open = matchedIndex == i && list.value[i].pages.length > 0
}
}
watch(() : string => leftWinActive.value, (path : string) => {
syncActiveGroup(path)
}, { immediate: true })
// #ifdef WEB
watch(() => (instance as any).$route, (newRoute) => {
if (newRoute && newRoute.matched.length) {
syncActiveGroup(newRoute.path.split('/')[3])
}
}, { immediate: true })
// #endif
</script>
<style>
.uni-panel-h {
flex-direction: row;
align-items: center;
padding: 12px 18px;
}
.uni-ui-navigate-item {
border-top-style: none;
}
.right_arrow {
width: 8px;
height: 8px;
margin-left: 12px;
transform: rotate(-45deg);
border-right-width: 1px;
border-right-style: solid;
border-right-color: var(--arrow-color, #999999);
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--arrow-color, #999999);
}
.component-collapse-title-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-title {
color: var(--text-color, #333333);
}
.component-collapse-content-wrap {
background-color: var(--list-background-color, #ffffff);
}
.component-collapse-arrow {
border-right-color: var(--arrow-color, #999999);
border-bottom-color: var(--arrow-color, #999999);
}
</style>