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

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

查看文件

@@ -0,0 +1,151 @@
<template>
<uni-tab style="flex: 1" :active-index="activeIndex" :tab-bar-height="40" @change="handleChange">
<uni-tab-content>
<view class="custom-panel custom-panel-emerald">
<text class="custom-panel-kicker">自定义 tab-bar</text>
<text class="custom-panel-title">精选</text>
<text class="custom-panel-desc">uni-tab-bar 使用 externalClass 覆盖了渐变背景和更低的高度,整体更像一条轻量导航条。</text>
</view>
</uni-tab-content>
<uni-tab-content>
<view class="custom-panel custom-panel-sand">
<text class="custom-panel-kicker">自定义 tab-bar</text>
<text class="custom-panel-title">趋势</text>
<text class="custom-panel-desc">这里只有一行文字,没有图标,适合内容频道或资讯场景里的轻型底部切换。</text>
</view>
</uni-tab-content>
<uni-tab-content>
<view class="custom-panel custom-panel-ink">
<text class="custom-panel-kicker">自定义 tab-bar</text>
<text class="custom-panel-title">我的</text>
<text class="custom-panel-desc">激活文字色改成绿色,同时每个 uni-tab-item 只有一行文本,更紧凑也更聚焦。</text>
</view>
</uni-tab-content>
<uni-tab-bar class="custom-tab-list-shell custom-tab-list-root">
<uni-tab-item>
<view class="custom-tab-cell">
<text class="custom-tab-label" :class="activeIndex == 0 ? 'custom-tab-label-active' : ''">精选</text>
</view>
</uni-tab-item>
<uni-tab-item>
<view class="custom-tab-cell">
<text class="custom-tab-label" :class="activeIndex == 1 ? 'custom-tab-label-active' : ''">趋势</text>
</view>
</uni-tab-item>
<uni-tab-item>
<view class="custom-tab-cell">
<text class="custom-tab-label" :class="activeIndex == 2 ? 'custom-tab-label-active' : ''">我的</text>
</view>
</uni-tab-item>
</uni-tab-bar>
</uni-tab>
</template>
<script setup lang="uts">
const activeIndex = ref<number>(0)
function syncNavigationBar(index : number) : void {
switch (index) {
case 0:
uni.setNavigationBarTitle({ title: '精选' })
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#dff3e8'
})
break
case 1:
uni.setNavigationBarTitle({ title: '趋势' })
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#f6ddbf'
})
break
case 2:
uni.setNavigationBarTitle({ title: '我的' })
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#dde7ea'
})
break
}
}
function handleChange(index : number) : void {
activeIndex.value = index
syncNavigationBar(index)
}
onLoad(() => {
syncNavigationBar(activeIndex.value)
})
</script>
<style>
.custom-panel {
flex: 1;
padding-top: 28px;
padding-right: 24px;
padding-bottom: 24px;
padding-left: 24px;
flex-direction: column;
justify-content: center;
}
.custom-panel-emerald {
background-color: #dff3e8;
}
.custom-panel-sand {
background-color: #f6ddbf;
}
.custom-panel-ink {
background-color: #dde7ea;
}
.custom-panel-kicker {
font-size: 12px;
color: rgba(34,51,59,0.56);
}
.custom-panel-title {
margin-top: 10px;
font-size: 30px;
color: #22333b;
}
.custom-panel-desc {
margin-top: 10px;
font-size: 15px;
line-height: 22px;
color: rgba(34,51,59,0.74);
}
.custom-tab-list-shell {
background-color: #f4efe6;
}
.custom-tab-list-root {
background: linear-gradient(to right, #f7d9a8, #c6ece3);
height: 40px;
border-top-width: 0px;
}
.custom-tab-cell {
width: 100%;
height: 100%;
flex-direction: row;
justify-content: center;
align-items: center;
}
.custom-tab-label {
font-size: 14px;
color: rgba(34,51,59,0.58);
}
.custom-tab-label-active {
color: #1d9f5f;
}
</style>

查看文件

@@ -0,0 +1,219 @@
<template>
<uni-tab style="flex: 1" :active-index="activeIndex" :tab-content-height-full="tabContentHeightFull" @change="handleChange">
<!-- 内容区域 -->
<uni-tab-content>
<!-- TODO 小程序下这些Class不生效,界面没有变黑! -->
<tabContent1 ref="tabContent1Ref" class="dark-tab-content dark-tab-content-home" />
</uni-tab-content>
<uni-tab-content>
<tabContent2 class="dark-tab-content dark-tab-content-api" />
</uni-tab-content>
<uni-tab-content>
<tabContent3 class="dark-tab-content dark-tab-content-css" />
</uni-tab-content>
<uni-tab-content>
<tabContent4 class="dark-tab-content dark-tab-content-template" />
</uni-tab-content>
<!-- 底部选项卡 -->
<uni-tab-bar class="dark-tab-list">
<!-- 图标高度24,文字字号10px,文字高度是12~14px,角标不能在图标的正右上角,需要向下偏移1px,避免角标画出tab-list之外) -->
<uni-tab-item>
<view class="first-tab-button" @click="handleFirstTabClick">
<view class="first-tab-animator">
<view class="first-tab-face"
:class="showBackToTop ? 'first-tab-default-hidden' : 'first-tab-default-visible'">
<image :src="activeIndex == 0 ? '/static/componentHL.png' : '/static/component.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 0 ? 'tab-label-active' : ''">首页</text>
</view>
<view class="first-tab-face"
:class="showBackToTop ? 'first-tab-backtop-visible' : 'first-tab-backtop-hidden'">
<text class="tab-arrow-icon" :class="activeIndex == 0 ? 'tab-arrow-icon-active' : ''">↑</text>
<text class="tab-label" :class="activeIndex == 0 ? 'tab-label-active' : ''">回到顶部</text>
</view>
</view>
</view>
</uni-tab-item>
<uni-tab-item badge-text="99+">
<image :src="activeIndex == 1 ? '/static/apiHL.png' : '/static/api.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 1 ? 'tab-label-active' : ''">API</text>
</uni-tab-item>
<uni-tab-item>
<image :src="activeIndex == 2 ? '/static/cssHL.png' : '/static/css.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 2 ? 'tab-label-active' : ''">CSS</text>
</uni-tab-item>
<uni-tab-item badge-text="">
<image :src="activeIndex == 3 ? '/static/templateHL.png' : '/static/template.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 3 ? 'tab-label-active' : ''">模板</text>
</uni-tab-item>
</uni-tab-bar>
</uni-tab>
</template>
<script setup lang="uts">
import tabContent1 from './tab-content1.uvue'
import tabContent2 from './tab-content2.uvue'
import tabContent3 from './tab-content3.uvue'
import tabContent4 from './tab-content4.uvue'
const TAB_CONTENT1_SCROLL_EVENT = 'uni-tab-bar-tab-content1-scroll'
const TAB_CONTENT1_SWITCH_OFFSET = 100
const tabContent1Ref = ref<ComponentPublicInstance | null>(null)
let tabContentHeightFull = false
// #ifdef MP
tabContentHeightFull = true
// #endif
const activeIndex = ref<number>(0)
const showBackToTop = ref<boolean>(false)
let lastTabContent1ScrollTop = 0
function handleTabContent1Scroll(scrollTop : number) : void {
lastTabContent1ScrollTop = scrollTop
if (activeIndex.value == 0) {
showBackToTop.value = scrollTop > TAB_CONTENT1_SWITCH_OFFSET
}
}
function handleFirstTabClick() : void {
if (activeIndex.value == 0 && showBackToTop.value) {
const tabContent1Instance = tabContent1Ref.value
if (tabContent1Instance != null) {
tabContent1Instance.$callMethod('scrollToTop')
}
}
}
function handleChange(index : number) : void {
activeIndex.value = index
if (index == 0) {
showBackToTop.value = lastTabContent1ScrollTop > TAB_CONTENT1_SWITCH_OFFSET
} else {
showBackToTop.value = false
}
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: '模板' })
break
}
}
onLoad(() => {
uni.$on(TAB_CONTENT1_SCROLL_EVENT, handleTabContent1Scroll)
})
onUnload(() => {
uni.$off(TAB_CONTENT1_SCROLL_EVENT, handleTabContent1Scroll)
})
</script>
<style>
.first-tab-button {
width: 100%;
height: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
}
.first-tab-animator {
width: 100%;
height: 100%;
position: relative;
flex-direction: column;
justify-content: center;
align-items: center;
}
.first-tab-face {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
flex-direction: column;
justify-content: center;
align-items: center;
transition-property: opacity, transform;
transition-duration: 220ms;
transition-timing-function: ease;
}
.first-tab-default-visible {
opacity: 1;
transform: translateY(0px);
}
.first-tab-default-hidden {
opacity: 0;
transform: translateY(8px);
}
.first-tab-backtop-visible {
opacity: 1;
transform: translateY(0px);
}
.first-tab-backtop-hidden {
opacity: 0;
transform: translateY(-8px);
}
.dark-tab-list {
background-color: #0f172a;
border-top-color: rgba(255,255,255,0.33);
}
.dark-tab-content {
background-color: #111827;
}
.dark-tab-content-home {
background-color: #111827;
}
.dark-tab-content-api {
background-color: #141c2f;
}
.dark-tab-content-css {
background-color: #102126;
}
.dark-tab-content-template {
background-color: #161a31;
}
.tab-icon-image {
height: 24px;
width: 24px;
}
.tab-arrow-icon {
line-height: 20px;
margin-bottom: 2px;
color: rgba(255,255,255,0.68);
}
.tab-arrow-icon-active {
color: #7ce0b8;
}
.tab-label {
font-size: 10px;
color: rgba(255,255,255,0.62);
}
.tab-label-active {
color: #f3f7fb;
}
</style>

查看文件

@@ -0,0 +1,143 @@
<template>
<uni-tab style="flex: 1" :active-index="activeIndex" :tab-content-height-full="true" @change="handleChange">
<uni-tab-content>
<tabContent1 />
</uni-tab-content>
<uni-tab-content>
<tabContent2 />
</uni-tab-content>
<uni-tab-content>
<tabContent3 />
</uni-tab-content>
<uni-tab-content>
<tabContent4 />
</uni-tab-content>
<uni-tab-bar style="border-top: 0px;background-color: rgba(0, 0, 0, 0);">
<uni-tab-item class="tab-bg">
<!-- <image :src="activeIndex == 0 ? '/static/componentHL.png' : '/static/component.png'" class="tab-icon-image"></image> -->
<text :class="activeIndex == 0 ? 'tab-label-active' : ''">🏠</text>
<text class="tab-label" :class="activeIndex == 0 ? 'tab-label-active' : ''">首页</text>
</uni-tab-item>
<uni-tab-item class="tab-bg">
<!-- <image :src="activeIndex == 1 ? '/static/apiHL.png' : '/static/api.png'" class="tab-icon-image"></image> -->
<text :class="activeIndex == 0 ? 'tab-label-active' : ''">💬</text>
<text class="tab-label" :class="activeIndex == 1 ? 'tab-label-active' : ''">消息</text>
</uni-tab-item>
<uni-tab-midbutton :width="106" :height="94">
<view class="floating-ball" hover-class="floating-ball-hover" :hover-stop-propagation="true" @click="handleMidButtonClick">
<view flatten class="floating-ball-plus" style="position: absolute;"></view>
<view flatten class="floating-ball-plus" style="position: absolute;transform: rotate(90deg);"></view>
</view>
<image class="notch-svg" src="/static/tab-bar-midbutton-notch.svg" mode="scaleToFill"></image>
</uni-tab-midbutton>
<uni-tab-item class="tab-bg">
<!-- <image :src="activeIndex == 2 ? '/static/cssHL.png' : '/static/css.png'" class="tab-icon-image"></image> -->
<text :class="activeIndex == 0 ? 'tab-label-active' : ''">🔔</text>
<text class="tab-label" :class="activeIndex == 2 ? 'tab-label-active' : ''">通知</text>
</uni-tab-item>
<uni-tab-item class="tab-bg" badge-text="8">
<!-- <image :src="activeIndex == 3 ? '/static/templateHL.png' : '/static/template.png'" class="tab-icon-image"></image> -->
<text :class="activeIndex == 0 ? 'tab-label-active' : ''">👤</text>
<text class="tab-label" :class="activeIndex == 3 ? 'tab-label-active' : ''">我的</text>
</uni-tab-item>
</uni-tab-bar>
<view class="tab-bg" style="width: 100%; height: var(--uni-safe-area-inset-bottom);position: absolute; bottom: 0;"></view> <!-- 因为要镂空,tabbar不能整体设背景色,只能加一个占位view覆盖安全区的颜色,-->
</uni-tab>
</template>
<script setup lang="uts">
import tabContent1 from './tab-content1.uvue'
import tabContent2 from './tab-content2.uvue'
import tabContent3 from './tab-content3.uvue'
import tabContent4 from './tab-content4.uvue'
const activeIndex = ref<number>(0)
const midButtonClickCount = ref<number>(0)
function handleChange(index : number) : void {
activeIndex.value = index
switch (index) {
case 0:
uni.setNavigationBarTitle({ title: '首页' })
break
case 1:
uni.setNavigationBarTitle({ title: '消息' })
break
case 2:
uni.setNavigationBarTitle({ title: '通知' })
break
case 3:
uni.setNavigationBarTitle({ title: '我的' })
break
}
}
function handleMidButtonClick() : void {
midButtonClickCount.value = midButtonClickCount.value + 1
uni.showToast({
title: '悬浮球点击 ' + midButtonClickCount.value + ' 次',
icon: 'none'
})
}
</script>
<style>
.tab-icon-image {
width: 24px;
height: 24px;
}
.tab-label {
font-size: 10px;
color: rgb(220, 220, 220);
}
.tab-label-active {
color: #FFFFFF;
}
.tab-bg {
background-color: #2196F3;
/* 宽度用transform调宽1点,不然在某些屏幕上,item之间会出现半像素的间隙 */
transform: scaleX(1.005);
/* margin-left: -1px; */
/* margin-right: -1px; */
}
.notch-svg {
width: 108px;
height: 50px;
position: absolute;
margin-left: -1px; /* 为了防止边线漏出半像素 */
margin-right: -1px; /* 为了防止边线漏出半像素 */
bottom: 0;
pointer-events: none; /* 不拦截点击。 TODO 鸿蒙上有bug,svg图仍然遮挡了点击区,导致加号的下半部分点不着*/
}
.floating-ball {
position: relative;
width: 70px;
height: 70px;
border-radius: 50%;
background-color: #ff5a24;
justify-content: center;
align-items: center;
border-width: 1px;
border-style: solid;
border-color: #ffffff;
box-shadow: 0px 4px 10px rgba(28, 98, 183, 0.16);
}
.floating-ball-hover {
opacity: 0.92;
transform: scale(0.96);
}
.floating-ball-plus {
background-color: #ffffff;
border-radius: 2px;
width: 40%;
height: 2px;
}
</style>

查看文件

@@ -0,0 +1,137 @@
<template>
<uni-tab style="flex: 1" :active-index="activeIndex" :tab-content-height-full="tabContentHeightFull" @change="handleChange">
<uni-tab-content>
<tabContent1 />
</uni-tab-content>
<uni-tab-content>
<tabContent2 />
</uni-tab-content>
<uni-tab-content>
<tabContent3 />
</uni-tab-content>
<uni-tab-content>
<tabContent4 />
</uni-tab-content>
<uni-tab-bar style="border-top: 0px;">
<uni-tab-item>
<image :src="activeIndex == 0 ? '/static/componentHL.png' : '/static/component.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 0 ? 'tab-label-active' : ''">组件</text>
</uni-tab-item>
<uni-tab-item badge-text="99+">
<image :src="activeIndex == 1 ? '/static/apiHL.png' : '/static/api.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 1 ? 'tab-label-active' : ''">API</text>
</uni-tab-item>
<uni-tab-midbutton :width="60" :height="60">
<view class="mid-button-shell">
<view class="mid-button-core" hover-class="mid-button-core-hover" :hover-stop-propagation="true"
@click="handleMidButtonClick">
<text class="mid-button-plus">+</text>
<text class="mid-button-label">发布</text>
</view>
</view>
</uni-tab-midbutton>
<uni-tab-item>
<image :src="activeIndex == 2 ? '/static/cssHL.png' : '/static/css.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 2 ? 'tab-label-active' : ''">CSS</text>
</uni-tab-item>
<uni-tab-item badge-text="">
<image :src="activeIndex == 3 ? '/static/templateHL.png' : '/static/template.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 3 ? 'tab-label-active' : ''">模板</text>
</uni-tab-item>
</uni-tab-bar>
</uni-tab>
</template>
<script setup lang="uts">
import tabContent1 from './tab-content1.uvue'
import tabContent2 from './tab-content2.uvue'
import tabContent3 from './tab-content3.uvue'
import tabContent4 from './tab-content4.uvue'
const activeIndex = ref<number>(0)
const midButtonClickCount = ref<number>(0)
let tabContentHeightFull = false
// #ifdef MP
tabContentHeightFull = true
// #endif
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: '模板' })
break
}
}
function handleMidButtonClick() : void {
midButtonClickCount.value = midButtonClickCount.value + 1
uni.showToast({
title: 'mid-button 点击 ' + midButtonClickCount.value + ' 次',
icon: 'none'
})
}
</script>
<style>
.tab-icon-image {
width: 24px;
height: 24px;
}
.tab-label {
font-size: 10px;
color: rgb(122, 126, 131);
}
.tab-label-active {
color: #007aff;
}
.mid-button-shell {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0);
}
.mid-button-core {
width: 52px;
height: 52px;
border-radius: 26px;
background-color: #ff7a18;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
/* box-shadow: 0px 6px 16px rgba(255, 122, 24, 0.22); */
}
.mid-button-core-hover {
transform: scale(0.96);
opacity: 0.92;
}
.mid-button-plus {
font-size: 22px;
line-height: 22px;
color: #ffffff;
}
.mid-button-label {
margin-top: 1px;
font-size: 9px;
color: #ffffff;
}
</style>

查看文件

@@ -0,0 +1,26 @@
const PAGE_PATHS = [
'/pages/uni-ui/tab-bar/tab-bar',
'/pages/uni-ui/tab-bar/tab-bar-dark',
'/pages/uni-ui/tab-bar/tab-bar-custom',
'/pages/uni-ui/tab-bar/tab-bar-midbutton',
'/pages/uni-ui/tab-bar/tab-bar-midbutton-notch'
]
describe('tab-bar', () => {
let page
async function launchPage(pagePath) {
page = await program.reLaunch(pagePath)
await page.waitFor('view')
await page.waitFor(1000)
}
it.each(PAGE_PATHS)('%s snapshot', async (pagePath) => {
await launchPage(pagePath)
const image = await program.screenshot({
fullPage: true
})
expect(image).toSaveImageSnapshot()
})
})

查看文件

@@ -0,0 +1,235 @@
<template>
<uni-tab style="flex: 1" :active-index="activeIndex" :tab-content-height-full="tabContentHeightFull" @change="handleChange">
<!-- 内容区域 -->
<uni-tab-content>
<tabContent1 ref="tabContent1Ref" />
</uni-tab-content>
<uni-tab-content>
<tabContent2 />
</uni-tab-content>
<uni-tab-content>
<tabContent3 />
</uni-tab-content>
<uni-tab-content>
<tabContent4 />
</uni-tab-content>
<!-- 底部选项卡 -->
<uni-tab-bar>
<!-- 图标高度24,文字字号10px,文字高度是12~14px,角标不能在图标的正右上角,需要向下偏移1px,避免角标画出tab-list之外) -->
<uni-tab-item>
<view class="first-tab-button" @click="handleFirstTabClick">
<view class="first-tab-animator">
<view class="first-tab-face"
:class="showBackToTop ? 'first-tab-default-hidden' : 'first-tab-default-visible'">
<image :src="activeIndex == 0 ? '/static/componentHL.png' : '/static/component.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 0 ? 'tab-label-active' : ''">首页</text>
</view>
<view class="first-tab-face"
:class="showBackToTop ? 'first-tab-backtop-visible' : 'first-tab-backtop-hidden'">
<text class="tab-arrow-icon" :class="activeIndex == 0 ? 'tab-arrow-icon-active' : ''">↑</text>
<text class="tab-label" :class="activeIndex == 0 ? 'tab-label-active' : ''">回到顶部</text>
</view>
</view>
</view>
</uni-tab-item>
<uni-tab-item :badge-text="apiTabBadgeText" :badge-class="apiTabBadgeClass"> <!-- 需要角标时使用 badge-text="99+" 详见 uni-badge 组件 -->
<image :src="activeIndex == 1 ? '/static/apiHL.png' : '/static/api.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 1 ? 'tab-label-active' : ''">API</text>
</uni-tab-item>
<uni-tab-item>
<image :src="activeIndex == 2 ? '/static/cssHL.png' : '/static/css.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 2 ? 'tab-label-active' : ''">CSS</text>
</uni-tab-item>
<uni-tab-item badge-text="">
<image :src="activeIndex == 3 ? '/static/templateHL.png' : '/static/template.png'" class="tab-icon-image"></image>
<text class="tab-label" :class="activeIndex == 3 ? 'tab-label-active' : ''">模板</text>
</uni-tab-item>
</uni-tab-bar>
</uni-tab>
</template>
<script setup lang="uts">
import tabContent1 from './tab-content1.uvue'
import tabContent2 from './tab-content-api.uvue'
// import tabContent2 from './tab-content2.uvue'
import tabContent3 from './tab-content3.uvue'
import tabContent4 from './tab-content4.uvue'
const TAB_CONTENT1_SCROLL_EVENT = 'uni-tab-bar-tab-content1-scroll'
const TAB_CONTENT1_SWITCH_OFFSET = 100 // 当 tab-content1 滚动超过这个距离(单位px)时显示回到顶部按钮,如需调节请自行定义
const TAB_CONTENT2_INDEX = 1
const tabContent1Ref = ref<ComponentPublicInstance | null>(null)
let tabContentHeightFull = false
// #ifdef MP
tabContentHeightFull = true
// #endif
// 当前激活的索引
const activeIndex = ref<number>(0)
const showBackToTop = ref<boolean>(false)
const apiTabBadgeText = ref<string>('99+')
const apiTabBadgeClass = ref<string.ClassString>('')
let lastTabContent1ScrollTop = 0
function updateTabContent2Badge(text : string, badgeClass : string.ClassString) : void {
apiTabBadgeText.value = text
apiTabBadgeClass.value = badgeClass
}
function setTabContent2BadgeNumber() : void {
updateTabContent2Badge('8', '')
}
function setTabContent2BadgeDot() : void {
updateTabContent2Badge('', '')
}
function clearTabContent2Badge() : void {
updateTabContent2Badge('0', '')
}
function setTabContent2BadgeClass() : void {
updateTabContent2Badge('NEW', 'api-tab-badge-custom')
}
function handleTabContent1Scroll(scrollTop : number) : void {
lastTabContent1ScrollTop = scrollTop
if (activeIndex.value == 0) {
showBackToTop.value = scrollTop > TAB_CONTENT1_SWITCH_OFFSET
}
}
function handleFirstTabClick() : void {
if (activeIndex.value == 0 && showBackToTop.value) {
const tabContent1Instance = tabContent1Ref.value
if (tabContent1Instance != null) {
tabContent1Instance.$callMethod('scrollToTop')
}
}
}
// 处理 tab 的切换
function handleChange(index : number) : void {
activeIndex.value = index
if (index == 0) {
showBackToTop.value = lastTabContent1ScrollTop > TAB_CONTENT1_SWITCH_OFFSET
} else {
showBackToTop.value = false
}
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: '模板' })
break
}
}
onLoad(() => {
uni.$on(TAB_CONTENT1_SCROLL_EVENT, handleTabContent1Scroll)
})
onUnload(() => {
uni.$off(TAB_CONTENT1_SCROLL_EVENT, handleTabContent1Scroll)
})
provide('tabContent2Index', TAB_CONTENT2_INDEX)
provide('tabContent2SetBadgeNumber', setTabContent2BadgeNumber)
provide('tabContent2SetBadgeDot', setTabContent2BadgeDot)
provide('tabContent2ClearBadge', clearTabContent2Badge)
provide('tabContent2SetBadgeClass', setTabContent2BadgeClass)
</script>
<style>
.api-tab-badge-custom {
background-color: #1f6feb;
color: #ffffff;
}
.first-tab-button {
width: 100%;
height: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
}
.first-tab-animator {
width: 100%;
height: 100%;
position: relative;
flex-direction: column;
justify-content: center;
align-items: center;
}
.first-tab-face {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
flex-direction: column;
justify-content: center;
align-items: center;
transition-property: opacity, transform;
transition-duration: 220ms;
transition-timing-function: ease;
}
.first-tab-default-visible {
opacity: 1;
transform: translateY(0px);
}
.first-tab-default-hidden {
opacity: 0;
transform: translateY(8px);
}
.first-tab-backtop-visible {
opacity: 1;
transform: translateY(0px);
}
.first-tab-backtop-hidden {
opacity: 0;
transform: translateY(-8px);
}
.tab-icon-image {
height: 24px;
width: 24px;
}
.tab-arrow-icon {
line-height: 20px;
margin-bottom: 2px;
}
.tab-arrow-icon-active {
color: #007aff;
}
.tab-label {
font-size: 10px;
color: rgb(122, 126, 131);
}
.tab-label-active {
color: #007aff;
}
.blue-dot{
background-color: #1f6feb;
}
</style>

查看文件

@@ -0,0 +1,126 @@
<template>
<view class="content-page">
<text class="page-text">当前索引: {{ activeIndex }}</text>
<view class="panel-card">
<text class="panel-title">Tab 切换</text>
<button class="action-button primary-button" @click="switchToFirstTab">切换到第一个 tab-item</button>
</view>
<view class="panel-card">
<text class="panel-title">当前 tab-item 角标</text>
<button class="action-button" @click="setBadgeNumber">设置数字角标</button>
<button class="action-button" @click="setBadgeDot">设置红点角标</button>
<button class="action-button" @click="clearBadge">取消角标</button>
<button class="action-button accent-button" @click="setBadgeClass">自定义 badgeClass 样式</button>
<text class="panel-tip">当前操作目标 tab 索引: {{ currentTabItemIndex }}</text>
</view>
</view>
</template>
<script setup lang="uts">
import { inject, ref } from 'vue'
import { Ref } from 'vue'
// 从父组件注入当前激活的索引
const activeIndex = inject<Ref<number>>('uniTabBarCurrentIndex', ref(0))
const changeTab = inject<(index : number) => void>('uniTabBarChangeTab', (index : number) => {})
const currentTabItemIndex = inject<number>('tabContent2Index', 1)
const setCurrentBadgeNumber = inject<() => void>('tabContent2SetBadgeNumber', () => {})
const setCurrentBadgeDot = inject<() => void>('tabContent2SetBadgeDot', () => {})
const clearCurrentBadge = inject<() => void>('tabContent2ClearBadge', () => {})
const setCurrentBadgeClass = inject<() => void>('tabContent2SetBadgeClass', () => {})
function switchToFirstTab() : void {
changeTab(0)
}
function setBadgeNumber() : void {
setCurrentBadgeNumber()
}
function setBadgeDot() : void {
setCurrentBadgeDot()
}
function clearBadge() : void {
clearCurrentBadge()
}
function setBadgeClass() : void {
setCurrentBadgeClass()
}
</script>
<style>
.content-page {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
width: 100%;
height: 100%;
padding: 20px;
background-color: #fff5f5;
}
.panel-card {
display: flex;
flex-direction: column;
width: 100%;
padding: 16px;
margin-top: 16px;
border-radius: 14px;
background-color: #ffffff;
box-shadow: 0px 6px 16px rgba(229, 102, 102, 0.12);
}
.panel-title {
font-size: 18px;
font-weight: bold;
color: #333;
margin-bottom: 12px;
}
.panel-tip {
font-size: 14px;
color: #8a5a5a;
margin-top: 12px;
}
.action-button {
width: 100%;
height: 40px;
margin-top: 10px;
border-radius: 20px;
background-color: #ffffff;
border-width: 1px;
border-style: solid;
border-color: #f1c7c7;
color: #8d4b4b;
font-size: 15px;
}
.primary-button {
background-color: #ff8a8a;
border-color: #ff8a8a;
color: #ffffff;
}
.accent-button {
background-color: #ffe7c7;
border-color: #ffd18c;
color: #8a4d00;
}
.page-title {
font-size: 28px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.page-text {
font-size: 16px;
color: #666;
margin-bottom: 10px;
}
</style>

查看文件

@@ -0,0 +1,70 @@
<template>
<scroll-view class="content-page" :scroll-with-animation="true" :scroll-top="targetScrollTop"
@scroll="handleScroll" >
<view class="content-page-inner">
<text class="page-title">首页</text>
<text class="page-text">这是首页的内容</text>
<text class="page-text">当前索引: {{ activeIndex }}</text>
<text class="page-text">\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n点首页tab可滚动回顶部(mid-button示例无效)\n\n\n\n</text>
</view>
</scroll-view>
</template>
<script setup lang="uts">
const TAB_CONTENT1_SCROLL_EVENT = 'uni-tab-bar-tab-content1-scroll'
// 从父组件注入当前激活的索引
const activeIndex = inject<Ref<number>>('uniTabBarCurrentIndex', ref(0))
const currentScrollTop = ref<number>(0)
const targetScrollTop = ref<number>(0)
function handleScroll(event : UniScrollEvent) : void {
currentScrollTop.value = event.detail.scrollTop
uni.$emit(TAB_CONTENT1_SCROLL_EVENT, currentScrollTop.value)
}
function scrollToTop() : void {
targetScrollTop.value = currentScrollTop.value
nextTick(() => {
targetScrollTop.value = 0 //TODO 鸿蒙上这个动画太慢太慢了,比其他平台慢很多
})
}
onMounted(() => {
uni.$emit(TAB_CONTENT1_SCROLL_EVENT, 0)
})
defineExpose({
scrollToTop
})
</script>
<style>
.content-page {
width: 100%;
height: 100%;
background-color: #f5f5f5;
}
.content-page-inner {
width: 100%;
align-items: center;
flex-direction: column;
justify-content: flex-start;
padding: 20px;
padding-bottom: 50px;
}
.page-title {
font-size: 28px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.page-text {
font-size: 16px;
color: #666;
margin-bottom: 10px;
}
</style>

查看文件

@@ -0,0 +1,40 @@
<template>
<view class="content-page">
<text class="page-title">消息</text>
<text class="page-text">这是消息页的内容</text>
<text class="page-text">当前索引: {{ activeIndex }}</text>
</view>
</template>
<script setup lang="uts">
import { inject, ref } from 'vue'
import { Ref } from 'vue'
// 从父组件注入当前激活的索引
const activeIndex = inject<Ref<number>>('uniTabBarCurrentIndex', ref(0))
</script>
<style>
.content-page {
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
padding: 20px;
background-color: #fff5f5;
}
.page-title {
font-size: 28px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.page-text {
font-size: 16px;
color: #666;
margin-bottom: 10px;
}
</style>

查看文件

@@ -0,0 +1,40 @@
<template>
<view class="content-page">
<text class="page-title">通知</text>
<text class="page-text">这是通知页的内容</text>
<text class="page-text">当前索引: {{ activeIndex }}</text>
</view>
</template>
<script setup lang="uts">
import { inject, ref } from 'vue'
import { Ref } from 'vue'
// 从父组件注入当前激活的索引
const activeIndex = inject<Ref<number>>('uniTabBarCurrentIndex', ref(0))
</script>
<style>
.content-page {
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
padding: 20px;
background-color: #f5fff5;
}
.page-title {
font-size: 28px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.page-text {
font-size: 16px;
color: #666;
margin-bottom: 10px;
}
</style>

查看文件

@@ -0,0 +1,40 @@
<template>
<view class="content-page">
<text class="page-title">我的</text>
<text class="page-text">这是我的页面的内容</text>
<text class="page-text">当前索引: {{ activeIndex }}</text>
</view>
</template>
<script setup lang="uts">
import { inject, ref } from 'vue'
import { Ref } from 'vue'
// 从父组件注入当前激活的索引
const activeIndex = inject<Ref<number>>('uniTabBarCurrentIndex', ref(0))
</script>
<style>
.content-page {
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
padding: 20px;
background-color: #f5f5ff;
}
.page-title {
font-size: 28px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.page-text {
font-size: 16px;
color: #666;
margin-bottom: 10px;
}
</style>

查看文件

@@ -0,0 +1,38 @@
<template>
<view class="content-page">
<text class="page-title">图片</text>
<text class="page-text">这是图片页面的内容</text>
<text class="page-text">当前索引: {{ activeIndex }}</text>
</view>
</template>
<script setup lang="uts">
// 从父组件注入当前激活的索引
const activeIndex = inject<Ref<number>>('uniTabBarCurrentIndex', ref(0))
</script>
<style>
.content-page {
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
padding: 20px;
background-color: #f5f5ff;
}
.page-title {
font-size: 28px;
font-weight: bold;
color: #333;
margin-bottom: 20px;
}
.page-text {
font-size: 16px;
color: #666;
margin-bottom: 10px;
}
</style>