refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,38 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/badge-view/badge-view'
|
||||
|
||||
describe('badge', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
await page.waitFor(1000)
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
})
|
||||
}
|
||||
|
||||
it('badge dynamic text value', async () => {
|
||||
expect(await page.data('data.dynamicBadgeText')).toBe('0')
|
||||
|
||||
await setPageData({
|
||||
dynamicBadgeText: '8'
|
||||
})
|
||||
expect(await page.data('data.dynamicBadgeText')).toBe('8')
|
||||
|
||||
await setPageData({
|
||||
dynamicBadgeText: ''
|
||||
})
|
||||
expect(await page.data('data.dynamicBadgeText')).toBe('')
|
||||
})
|
||||
|
||||
it('badge snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,214 @@
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<scroll-view style="flex: 1;padding: 20px 5px 5px;">
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
<view style="padding: 20px 5px 5px;">
|
||||
<!-- #endif -->
|
||||
<uni-badge-view text="99+" >
|
||||
<view style="width: 50px; height: 20px; background-color: green;"></view>
|
||||
</uni-badge-view>
|
||||
<!-- TODO 上面被注掉的代码,在Android上顶部被裁剪,但web上角标上部可以露出来不少,没有拉齐表现 -->
|
||||
<text class="page-title">Badge 组件演示</text>
|
||||
<!-- 动态badge -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">badge动态设置text属性:</text>
|
||||
<text class="label" style="margin-bottom: 10px;">输入0不显示badge,空字符串显示红点,输入其他显示文字</text>
|
||||
<input
|
||||
v-model="data.dynamicBadgeText"
|
||||
placeholder="输入badge text属性"
|
||||
class="demo-input"
|
||||
/>
|
||||
<uni-badge-view :text="data.dynamicBadgeText" >
|
||||
<view style="width: 20px;height: 20px;background-color: green;"></view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- 不显示badge -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">不显示badge:</text>
|
||||
<uni-badge-view text="0">
|
||||
<view style="width: 20px;height: 16px;background-color: green;"></view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- 不包裹内容 -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">不包裹内容的圆点:</text>
|
||||
<uni-badge-view text="">
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">不包裹内容的文字:</text>
|
||||
<uni-badge-view text="1" badge-style="align-self:flex-start;"/> <!-- 在flex方向为竖时,默认横向拉伸,需要设flex-start避免 -->
|
||||
</view>
|
||||
|
||||
<!-- 文字样式 -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">文字样式:</text>
|
||||
<uni-badge-view text="3" >
|
||||
<view style="width: 80px;">
|
||||
<text class="label">20px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- text为99+ -->
|
||||
<view style="margin-bottom: 10px;overflow: visible;"> <!-- 添加 overflow: visible 兼容内部宽度不够使角标被裁剪 -->
|
||||
<text class="label" style="margin-bottom: 10px;">99+是自己写的,不会自动计算max</text>
|
||||
<uni-badge-view text="99+" >
|
||||
<view style="width: 80px; background-color: #6c757d; ">
|
||||
<text style="color: white;">50px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<uni-badge-view text="99+" >
|
||||
<view style="width: 10px; height: 20px; background-color: green;"></view>
|
||||
</uni-badge-view>
|
||||
|
||||
<!-- 文字样式自定义badge-class -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">自定义badge-class(绿色badge):</text>
|
||||
<uni-badge-view text="NEW" badge-class="custom-badge-text">
|
||||
<view style="height: 20px; background-color: #ffc107; ">
|
||||
<text>20px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- 文字样式自定义badge-style -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">自定义样式badge-style(紫色badge):</text>
|
||||
<uni-badge-view text="HOT" badge-style="background-color: #6f42c1; color: yellow;">
|
||||
<view style="height: 20px; background-color: #dc3545; ">
|
||||
<text style="color: white;">20px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- 红点样式 -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">红点默认样式:</text>
|
||||
<uni-badge-view>
|
||||
<button size="mini">按钮</button>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- 空文字测试 -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">空文字(红点模式):</text>
|
||||
<uni-badge-view text="">
|
||||
<view style="height: 20px; background-color: #17a2b8; border-radius: 4px; ">
|
||||
<text style="color: white;">20px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
|
||||
<!-- 红点自定义badge-class -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">dot自定义badge-class(绿色badge):</text>
|
||||
<uni-badge-view badge-class="custom-badge-dot">
|
||||
<view style="height: 20px; background-color: #ffc107; ">
|
||||
<text>20px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<!-- 红点自定义badge-style -->
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">dot自定义badge-style(紫色badge):</text>
|
||||
<uni-badge-view badge-style="background-color: #6f42c1;">
|
||||
<view style="height: 20px; background-color: #dc3545; ">
|
||||
<text style="color: white;">20px区域</text>
|
||||
</view>
|
||||
</uni-badge-view>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">按钮中badge文字:</text>
|
||||
<!-- <button size="mini">按钮<uni-badge-view text="9"/></button> -->
|
||||
<!-- TODO Android的button不支持子组件,上述badge样式错乱。先遗留,等button用前端重构-->
|
||||
<view style="width: 150px; height: 30px; background-color: lightgray; border-radius: 4px; align-items: center; justify-content: center;flex-direction: row;">
|
||||
<text>按钮 </text>
|
||||
<uni-badge-view text="9"/>
|
||||
<!--
|
||||
上面加style="padding-top: 5px;" 会导致vue报错:
|
||||
[Vue warn]: Extraneous non-props attributes (style) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. \n at <UniBadgeView>\nat <View>\nat <View>\nat <View>\nat <Badge>\nat <AsyncComponentWrapper>\nat <PageBody>\nat <Page>\nat <Anonymous>\nat <Layout>\nat <App>
|
||||
app不报错。app也应该报错。
|
||||
本质是因为多根节点,不知道把style属性绑定到哪个根节点,需要指定,在组件的每个根节点上使用v-bind="$attrs"绑定所有属性过去
|
||||
-->
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 10px;">
|
||||
<text class="label" style="margin-bottom: 10px;">按钮中badge红点:</text>
|
||||
<view style="width: 150px; height: 30px; background-color: lightgray; border-radius: 4px; align-items: center; justify-content: center;flex-direction: row;">
|
||||
<text>按钮 </text>
|
||||
<uni-badge-view/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
dynamicBadgeText: string
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
dynamicBadgeText: "0"
|
||||
})
|
||||
|
||||
/* onReady(() => {
|
||||
console.log((getCurrentInstance()!.proxy!.$page as BasePage).$nativePage!.getDomJson());
|
||||
}) */
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: var(--text-color, #333333);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
|
||||
.demo-input {
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: var(--border-color, rgba(0, 0, 0, 0.06));
|
||||
border-radius: 4px;
|
||||
width: 200px;
|
||||
height: 24px;
|
||||
padding-left: 2px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
|
||||
.custom-badge-text {
|
||||
background-color: #28a745;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.custom-badge-dot {
|
||||
background-color: #28a745;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,33 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/collapse/collapse'
|
||||
|
||||
describe('collapse', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
});
|
||||
}
|
||||
|
||||
it('collapse accordion', async () => {
|
||||
expect(await page.data('data.lastEvent')).toBe('暂无交互')
|
||||
expect(await page.data('data.enableOpen')).toBe(true)
|
||||
|
||||
await setPageData({
|
||||
enableOpen: false
|
||||
})
|
||||
expect(await page.data('data.enableOpen')).toBe(false)
|
||||
})
|
||||
|
||||
it('collapse snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,470 @@
|
||||
<template>
|
||||
<scroll-view class="page">
|
||||
<view class="section">
|
||||
<text class="section-title">手风琴模式</text>
|
||||
<uni-collapse :accordion="true">
|
||||
<uni-collapse-item title="面板 A(默认展开)" :open="data.enableOpen" @change="onPanelAChange">
|
||||
<view class="content-box" @click="onPanelAClick">
|
||||
<text class="content-text">手风琴模式下,同时只会保持一个面板展开。点击当前标题会自动收起其他面板。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item title="面板 B" @change="onPanelBChange">
|
||||
<view id="panel-b" class="content-box">
|
||||
<text class="content-text">当前项展开时,其他已展开的项会自动收起。这里用于验证切换动画和事件回调。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item title="禁用项" :disabled="true">
|
||||
<view class="content-box">
|
||||
<text class="content-text">禁用状态下不会响应点击,也不会触发展开或收起。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">普通模式-可同时展开的分组折叠列表</text>
|
||||
<uni-collapse :accordion="false">
|
||||
<uni-collapse-item v-for="(group, index) in categoryGroups" :key="group.title" :title="group.title" @change="onCategoryChange(group.title, $event as boolean)">
|
||||
<view class="category-list">
|
||||
<view v-for="(item, itemIndex) in group.items" :key="item.title" class="category-list-item"
|
||||
:class="{'category-list-item--last': itemIndex == group.items.length - 1}">
|
||||
<text class="category-list-text">{{ item.title }}</text>
|
||||
<view class="category-list-arrow"></view>
|
||||
</view>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">externalClass 示例</text>
|
||||
<uni-collapse :accordion="false">
|
||||
<uni-collapse-item title="自定义标题文字" title-class="demo-title-emphasis">
|
||||
<view class="content-box">
|
||||
<text class="content-text">通过 title-class 可以覆盖 title 属性对应 text 组件的样式。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item title="自定义箭头样式" arrow-class="demo-arrow-large">
|
||||
<view class="content-box">
|
||||
<text class="content-text">通过 arrow-class 可以覆盖默认箭头 view 的尺寸、边框粗细和颜色。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item title="同时自定义标题和箭头" title-class="demo-title-accent" arrow-class="demo-arrow-accent">
|
||||
<view class="content-box">
|
||||
<text class="content-text">title-class 和 arrow-class 可以组合使用。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">具名插槽标题</text>
|
||||
<uni-collapse :accordion="false">
|
||||
<uni-collapse-item>
|
||||
<template #title="{ open, disabled }">
|
||||
<view class="slot-title-wrap">
|
||||
<view class="slot-title-icon" :class="{'slot-title-icon--open': open, 'slot-title-icon--disabled': disabled}"></view>
|
||||
<text class="slot-title-text" :class="{'slot-title-text--open': open, 'slot-title-text--disabled': disabled}">消息中心</text>
|
||||
<text class="slot-title-badge" :class="{'slot-title-badge--open': open}">{{ open ? 'OPEN' : 'CLOSE' }}</text>
|
||||
</view>
|
||||
</template>
|
||||
<view class="content-box">
|
||||
<text class="content-text">通过 #title 可以自定义标题区域结构,例如在文字前增加图标、状态徽标和辅助说明。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item>
|
||||
<template #title="{ open }">
|
||||
<view class="slot-title-wrap">
|
||||
<view class="slot-title-icon slot-title-icon--secondary" :class="{'slot-title-icon--open': open}"></view>
|
||||
<text class="slot-title-text" :class="{'slot-title-text--open': open}">设置中心</text>
|
||||
<text class="slot-title-note">{{ open ? '当前已展开' : '点击展开配置项' }}</text>
|
||||
</view>
|
||||
</template>
|
||||
<view class="content-box">
|
||||
<text class="content-text">具名插槽会透出 open 和 disabled 状态,方便你在标题区域里联动样式。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
</view>
|
||||
|
||||
<view class="section section-dark">
|
||||
<text class="section-title section-title-dark">暗黑模式 externalClass 示例</text>
|
||||
<view class="dark-tip">
|
||||
<text class="dark-tip-text">这个示例通过给 uni-collapse-item 传入 class 和 externalClass,分别定制内容区和标题区样式。</text>
|
||||
</view>
|
||||
<uni-collapse :accordion="false">
|
||||
<uni-collapse-item class="dark-collapse-item" title="暗色标题 A" :open="true" title-wrap-class="dark-title-wrap" title-class="dark-title-text" title-open-class="dark-title-text-open" content-wrap-class="dark-content-wrap" arrow-class="dark-arrow" arrow-open-class="dark-arrow-open">
|
||||
<view class="content-box dark-content-box">
|
||||
<text class="content-text dark-content-text">组件根节点通过 class 统一接入暗色卡片样式,标题背景、默认文字、展开态文字和箭头颜色通过 externalClass 传入。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item class="dark-collapse-item dark-collapse-item-strong" title="暗色标题 B" title-wrap-class="dark-title-wrap-strong" title-class="dark-title-text-strong" title-open-class="dark-title-text-open" content-wrap-class="dark-content-wrap" arrow-class="dark-arrow-strong" arrow-open-class="dark-arrow-open">
|
||||
<view class="content-box dark-content-box">
|
||||
<text class="content-text dark-content-text">你也可以继续组合不同的根容器 class、标题字重、箭头粗细和激活色样式。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
<uni-collapse-item class="dark-collapse-item dark-collapse-item-muted" title="暗色禁用项" :disabled="true" title-wrap-class="dark-title-wrap-muted" title-class="dark-title-text" title-disabled-class="dark-title-text-disabled" content-wrap-class="dark-content-wrap-muted" arrow-class="dark-arrow" arrow-disabled-class="dark-arrow-disabled">
|
||||
<view class="content-box dark-content-box dark-content-box-muted">
|
||||
<text class="content-text dark-content-text">禁用态默认通过透明度表达状态,外部依然可以继续指定禁用态文字和箭头颜色。</text>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
</view>
|
||||
|
||||
<view class="log-section">
|
||||
<text class="log-title">最近事件</text>
|
||||
<text class="log-text">{{ data.lastEvent }}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type CategoryItem = {
|
||||
title : string
|
||||
}
|
||||
|
||||
type CategoryGroup = {
|
||||
title : string,
|
||||
items : CategoryItem[]
|
||||
}
|
||||
|
||||
const categoryGroups : CategoryGroup[] = [
|
||||
{
|
||||
title: '分类1',
|
||||
items: [
|
||||
{ title: '分类1-item1' },
|
||||
{ title: '分类1-item2' },
|
||||
{ title: '分类1-item3' }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '分类2',
|
||||
items: [
|
||||
{ title: '分类2-item1' },
|
||||
{ title: '分类2-item2' },
|
||||
{ title: '分类2-item3' }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '分类3',
|
||||
items: [
|
||||
{ title: '分类3-item1' },
|
||||
{ title: '分类3-item2' },
|
||||
{ title: '分类3-item3' }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
type Data = {
|
||||
lastEvent: string,
|
||||
enableOpen: boolean
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
lastEvent: '暂无交互',
|
||||
enableOpen: true
|
||||
})
|
||||
|
||||
function updateEvent(panel : string, open : boolean) {
|
||||
const stateText = open ? '展开' : '收起'
|
||||
const message = `${panel}${stateText}`
|
||||
data.lastEvent = message
|
||||
console.log(`[collapse] ${message}`)
|
||||
}
|
||||
|
||||
function onPanelAChange(open : boolean) {
|
||||
updateEvent('面板 A ', open)
|
||||
}
|
||||
|
||||
function onPanelBChange(open : boolean) {
|
||||
updateEvent('面板 B ', open)
|
||||
}
|
||||
|
||||
function onCategoryChange(title : string, open : boolean) {
|
||||
updateEvent(`${title} `, open)
|
||||
}
|
||||
|
||||
const onPanelAClick = () => {
|
||||
console.log('onPanelAClick')
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
onPanelAClick
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 12px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background-color: var(--list-background-color, #ffffff);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
padding: 12px;
|
||||
font-size: 14px;
|
||||
color: var(--text-color, #333333);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.content-box {
|
||||
padding: 12px;
|
||||
background-color: var(--active-background-color, #f8fafc);
|
||||
}
|
||||
|
||||
.content-text {
|
||||
font-size: 13px;
|
||||
color: var(--text-color, #475569);
|
||||
opacity: 0.78;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.category-list {
|
||||
background-color: var(--active-background-color, #f8fafc);
|
||||
}
|
||||
|
||||
.category-list-item {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 18px;
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
border-bottom-color: var(--border-color, #e2e8f0);
|
||||
}
|
||||
|
||||
.category-list-item--last {
|
||||
border-bottom-width: 0px;
|
||||
}
|
||||
|
||||
.category-list-text {
|
||||
flex: 1;
|
||||
font-size: 13px;
|
||||
color: var(--text-color, #334155);
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.category-list-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, #94a3b8);
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
border-bottom-color: var(--arrow-color, #94a3b8);
|
||||
}
|
||||
|
||||
.demo-title-emphasis {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.demo-title-accent {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.demo-arrow-large {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-right-width: 2px;
|
||||
border-bottom-width: 2px;
|
||||
}
|
||||
|
||||
.demo-arrow-accent {
|
||||
border-right-color: #0f766e;
|
||||
border-bottom-color: #0f766e;
|
||||
border-right-width: 2px;
|
||||
border-bottom-width: 2px;
|
||||
}
|
||||
|
||||
.slot-title-wrap {
|
||||
flex: 1;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.slot-title-icon {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 5px;
|
||||
margin-right: 10px;
|
||||
background-color: #94a3b8;
|
||||
}
|
||||
|
||||
.slot-title-icon--secondary {
|
||||
background-color: #c084fc;
|
||||
}
|
||||
|
||||
.slot-title-icon--open {
|
||||
background-color: #2563eb;
|
||||
}
|
||||
|
||||
.slot-title-icon--disabled {
|
||||
background-color: #cbd5e1;
|
||||
}
|
||||
|
||||
.slot-title-text {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
color: var(--text-color, #1f2937);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.slot-title-text--open {
|
||||
color: #2563eb;
|
||||
}
|
||||
|
||||
.slot-title-text--disabled {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.slot-title-badge {
|
||||
padding: 4px 8px;
|
||||
border-radius: 10px;
|
||||
background-color: #e2e8f0;
|
||||
font-size: 11px;
|
||||
color: #475569;
|
||||
}
|
||||
|
||||
.slot-title-badge--open {
|
||||
background-color: #dbeafe;
|
||||
color: #1d4ed8;
|
||||
}
|
||||
|
||||
.slot-title-note {
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.section-dark {
|
||||
background-color: #111827;
|
||||
}
|
||||
|
||||
.section-title-dark {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.dark-collapse-item {
|
||||
background-color: #111827;
|
||||
}
|
||||
|
||||
.dark-collapse-item-strong {
|
||||
background-color: #0f172a;
|
||||
}
|
||||
|
||||
.dark-collapse-item-muted {
|
||||
background-color: #101826;
|
||||
}
|
||||
|
||||
.dark-tip {
|
||||
padding: 0px 12px 12px 12px;
|
||||
}
|
||||
|
||||
.dark-tip-text {
|
||||
font-size: 12px;
|
||||
color: #9ca3af;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.dark-content-box {
|
||||
background-color: #1f2937;
|
||||
}
|
||||
|
||||
.dark-content-wrap {
|
||||
background-color: #1f2937;
|
||||
}
|
||||
|
||||
.dark-content-text {
|
||||
color: #cbd5e1;
|
||||
}
|
||||
|
||||
.dark-content-box-muted {
|
||||
background-color: #182333;
|
||||
}
|
||||
|
||||
.dark-content-wrap-muted {
|
||||
background-color: #182333;
|
||||
}
|
||||
|
||||
.dark-title-wrap {
|
||||
background-color: #111827;
|
||||
}
|
||||
|
||||
.dark-title-wrap-strong {
|
||||
background-color: #0f172a;
|
||||
}
|
||||
|
||||
.dark-title-wrap-muted {
|
||||
background-color: #101826;
|
||||
}
|
||||
|
||||
.dark-title-text {
|
||||
color: #f8fafc;
|
||||
}
|
||||
|
||||
.dark-title-text-strong {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.dark-title-text-open {
|
||||
color: #60a5fa;
|
||||
}
|
||||
|
||||
.dark-title-text-disabled {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.dark-arrow {
|
||||
border-right-color: #cbd5e1;
|
||||
border-bottom-color: #cbd5e1;
|
||||
}
|
||||
|
||||
.dark-arrow-strong {
|
||||
border-right-color: #cbd5e1;
|
||||
border-bottom-color: #cbd5e1;
|
||||
border-right-width: 2px;
|
||||
border-bottom-width: 2px;
|
||||
}
|
||||
|
||||
.dark-arrow-open {
|
||||
border-right-color: #60a5fa;
|
||||
border-bottom-color: #60a5fa;
|
||||
}
|
||||
|
||||
.dark-arrow-disabled {
|
||||
border-right-color: #94a3b8;
|
||||
border-bottom-color: #94a3b8;
|
||||
}
|
||||
|
||||
.log-section {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
background-color: var(--list-background-color, #ffffff);
|
||||
}
|
||||
|
||||
.log-title {
|
||||
font-size: 13px;
|
||||
color: var(--text-color, #333333);
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.log-text {
|
||||
font-size: 13px;
|
||||
color: #2563eb;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,42 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/drag-cell/drag-cell'
|
||||
|
||||
describe('drag-cell', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view');
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
})
|
||||
}
|
||||
|
||||
it('drag-cell model value', async () => {
|
||||
expect(await page.data('data.tagList')).toEqual(['标签1', '标签2', '标签3', '标签4'])
|
||||
expect((await page.data('data.gridList3')).length).toBe(9)
|
||||
expect((await page.data('data.deleteList')).length).toBe(5)
|
||||
expect(await page.data('data.handleList')).toEqual(['微信支付', '支付宝', 'Apple Pay'])
|
||||
|
||||
await setPageData({
|
||||
tagList: ['新标签1', '新标签2'],
|
||||
deleteList: ['A', 'B', 'C'],
|
||||
imageList: ['https://example.com/a.png'],
|
||||
handleList: ['卡1', '卡2']
|
||||
})
|
||||
|
||||
expect(await page.data('data.tagList')).toEqual(['新标签1', '新标签2'])
|
||||
expect(await page.data('data.deleteList')).toEqual(['A', 'B', 'C'])
|
||||
expect(await page.data('data.imageList')).toEqual(['https://example.com/a.png'])
|
||||
expect(await page.data('data.handleList')).toEqual(['卡1', '卡2'])
|
||||
})
|
||||
|
||||
it('drag-cell snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,596 @@
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<scroll-view style="flex: 1; padding: 15px;">
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
<view style="padding: 15px;">
|
||||
<!-- #endif -->
|
||||
<text class="page-title">drag-cell 拖拽排序组件</text>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 1:标签拖拽排序</text>
|
||||
<text class="section-desc">长按标签后可拖拽排序,点击标签可拿到 item 和 index</text>
|
||||
<uni-drag-cell v-model="data.tagList" @change="onTagChange">
|
||||
<template #default="{ item, index }">
|
||||
<view class="tag-slot">
|
||||
<view class="tag-item" @click="clickItem(item as string, index as number)">
|
||||
<text class="tag-text">{{ item as string }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">当前顺序:{{ data.tagList.join(', ') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 2:宫格拖拽排序(3 列)</text>
|
||||
<text class="section-desc">长按宫格项后可拖拽排序</text>
|
||||
<uni-drag-cell v-model="data.gridList3" :column="3" @change="onGridChange">
|
||||
<template #default="{ item }">
|
||||
<view class="grid-slot">
|
||||
<view class="grid-item">
|
||||
<text class="grid-text">{{ (item as UTSJSONObject)['name'] }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">当前顺序:{{ getGridNames(data.gridList3) }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 3:列表拖拽排序(1 列)</text>
|
||||
<text class="section-desc">长按列表项后可拖拽排序</text>
|
||||
<uni-drag-cell v-model="data.gridList4" :column="1" @change="onGridChange">
|
||||
<template #default="{ item }">
|
||||
<view class="grid-slot-small">
|
||||
<view class="grid-item-small">
|
||||
<text class="grid-text-small">{{ (item as UTSJSONObject)['name'] }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">当前顺序:{{ getGridNames(data.gridList4) }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 4:可新增并删除的标签</text>
|
||||
<text class="section-desc">长按标签可排序,拖到底部可删除,点击 + 可输入并新增标签</text>
|
||||
<uni-drag-cell v-model="data.deleteList" :show-close="true" :show-append="true" @change="onDeleteChange">
|
||||
<template #default="{ item }">
|
||||
<view class="tag-slot">
|
||||
<view class="tag-item-delete">
|
||||
<text class="tag-text">{{ item as string }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<template #append>
|
||||
<view class="tag-slot">
|
||||
<view class="tag-item-add" @click="promptAddDeleteTag">
|
||||
<text class="tag-plus-text">+</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">当前顺序:{{ data.deleteList.join(', ') }}</text>
|
||||
<text class="result-text">剩余:{{ data.deleteList.length }} 项</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 5:带删除功能的图标宫格</text>
|
||||
<text class="section-desc">长按后可拖动图标宫格项,并支持拖到底部删除</text>
|
||||
<uni-drag-cell v-model="data.iconGridList" :column="3" :show-close="true" @change="onIconGridChange">
|
||||
<template #default="{ item }">
|
||||
<view class="icon-grid-slot">
|
||||
<view class="icon-grid-item">
|
||||
<view class="icon-box">
|
||||
<text class="icon-emoji">{{ (item as UTSJSONObject)['icon'] }}</text>
|
||||
</view>
|
||||
<text class="icon-label">{{ (item as UTSJSONObject)['label'] }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">当前顺序:{{ getIconNames(data.iconGridList) }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 6:九宫格图片选择</text>
|
||||
<text class="section-desc">点击 + 选择图片,支持拖拽排序,也支持拖到底部删除</text>
|
||||
<uni-drag-cell v-model="data.imageList" :column="3" :show-close="true"
|
||||
:show-append="data.imageList.length < maxImageCount" @change="onImageChange">
|
||||
<template #default="{ item, index }">
|
||||
<view class="image-grid-slot">
|
||||
<view class="image-grid-item" @click="previewImages(index as number)">
|
||||
<image class="image-grid-img" :src="item" mode="aspectFill"></image>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<template #append>
|
||||
<view class="image-grid-slot">
|
||||
<view class="image-grid-plus" @click="chooseImages">
|
||||
<text class="image-grid-plus-icon">+</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">已选择:{{ data.imageList.length }}/{{ maxImageCount }}</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">示例 7:手柄拖拽排序</text>
|
||||
<text class="section-desc">开启手柄模式后,不需要长按,只能拖动右侧手柄进行排序</text>
|
||||
<uni-drag-cell v-model="data.handleList" :column="1" :handle-mode="true" @change="onHandleListChange">
|
||||
<template #default="{ item, index }">
|
||||
<view class="handle-demo-slot">
|
||||
<view class="handle-demo-item">
|
||||
<text class="handle-demo-index">{{ (index as number) + 1 }}</text>
|
||||
<text class="handle-demo-text">{{ item as string }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<template #handle="{ item }">
|
||||
<view class="handle-demo-grip">
|
||||
<text class="handle-demo-grip-text">≡</text>
|
||||
</view>
|
||||
</template>
|
||||
</uni-drag-cell>
|
||||
<text class="result-text">当前顺序:{{ data.handleList.join(', ') }}</text>
|
||||
</view>
|
||||
|
||||
<view style="height: 50px;"></view>
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
const maxImageCount = 9
|
||||
|
||||
type Data = {
|
||||
tagList: string[],
|
||||
gridList3: UTSJSONObject[],
|
||||
gridList4: UTSJSONObject[],
|
||||
deleteList: string[],
|
||||
iconGridList: UTSJSONObject[],
|
||||
imageList: string[],
|
||||
handleList: string[]
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
tagList: ['标签1', '标签2', '标签3', '标签4'],
|
||||
gridList3: [
|
||||
{ name: '宫格1' },
|
||||
{ name: '宫格2' },
|
||||
{ name: '宫格3' },
|
||||
{ name: '宫格4' },
|
||||
{ name: '宫格5' },
|
||||
{ name: '宫格6' },
|
||||
{ name: '宫格7' },
|
||||
{ name: '宫格8' },
|
||||
{ name: '宫格9' }
|
||||
],
|
||||
gridList4: [
|
||||
{ name: '1' },
|
||||
{ name: '2' },
|
||||
{ name: '3' },
|
||||
{ name: '4' },
|
||||
{ name: '5' }
|
||||
],
|
||||
deleteList: ['标签A', '标签B', '标签C', '标签D', '标签E'],
|
||||
iconGridList: [
|
||||
{ icon: 'H', label: '首页' },
|
||||
{ icon: 'M', label: '消息' },
|
||||
{ icon: 'P', label: '我的' },
|
||||
{ icon: 'S', label: '设置' },
|
||||
{ icon: 'A', label: '相册' },
|
||||
{ icon: 'Y', label: '音乐' }
|
||||
],
|
||||
imageList: [],
|
||||
handleList: ['微信支付', '支付宝', 'Apple Pay']
|
||||
})
|
||||
|
||||
const clickItem = (item : string, index : number) => {
|
||||
uni.showToast({
|
||||
title: '点击了第 ' + (index + 1) + ' 项:' + item,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
const onTagChange = (list : string[]) => {
|
||||
console.log('tag list changed:', list)
|
||||
}
|
||||
|
||||
const onGridChange = (list : UTSJSONObject[]) => {
|
||||
console.log('grid list changed:', list)
|
||||
}
|
||||
|
||||
const onDeleteChange = (list : string[]) => {
|
||||
console.log('delete list changed:', list)
|
||||
}
|
||||
|
||||
const onIconGridChange = (list : UTSJSONObject[]) => {
|
||||
console.log('icon grid list changed:', list)
|
||||
}
|
||||
|
||||
const onImageChange = (list : string[]) => {
|
||||
console.log('image list changed:', list)
|
||||
}
|
||||
|
||||
const onHandleListChange = (list : string[]) => {
|
||||
console.log('handle list changed:', list)
|
||||
}
|
||||
|
||||
const promptAddDeleteTag = () => {
|
||||
uni.showModal({
|
||||
title: '新增标签',
|
||||
editable: true,
|
||||
placeholderText: '请输入标签内容',
|
||||
confirmText: '确定',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm != true) {
|
||||
return
|
||||
}
|
||||
const value = res.content != null ? res.content.trim() : ''
|
||||
if (value.length == 0) {
|
||||
uni.showToast({
|
||||
title: '标签内容不能为空',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
const nextList = data.deleteList.slice()
|
||||
nextList.push(value)
|
||||
data.deleteList = nextList
|
||||
onDeleteChange(data.deleteList)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const extractChooseImagePaths = (res : ChooseImageSuccess) : string[] => {
|
||||
const paths : string[] = []
|
||||
for (let i = 0; i < res.tempFilePaths.length; i++) {
|
||||
const path = res.tempFilePaths[i]
|
||||
if (path.length > 0) {
|
||||
paths.push(path)
|
||||
}
|
||||
}
|
||||
if (paths.length > 0) {
|
||||
return paths
|
||||
}
|
||||
for (let i = 0; i < res.tempFiles.length; i++) {
|
||||
const path = res.tempFiles[i].path
|
||||
if (path.length > 0) {
|
||||
paths.push(path)
|
||||
}
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
const chooseImages = () => {
|
||||
const remainCount = maxImageCount - data.imageList.length
|
||||
if (remainCount <= 0) {
|
||||
return
|
||||
}
|
||||
uni.chooseImage({
|
||||
count: remainCount,
|
||||
success: (res : ChooseImageSuccess) => {
|
||||
const selectedPaths = extractChooseImagePaths(res)
|
||||
if (selectedPaths.length == 0) {
|
||||
return
|
||||
}
|
||||
const nextList = data.imageList.slice()
|
||||
for (let i = 0; i < selectedPaths.length; i++) {
|
||||
if (nextList.length >= maxImageCount) {
|
||||
break
|
||||
}
|
||||
nextList.push(selectedPaths[i])
|
||||
}
|
||||
data.imageList = nextList
|
||||
onImageChange(data.imageList)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const previewImages = (index : number) => {
|
||||
if (index < 0 || index >= data.imageList.length) {
|
||||
return
|
||||
}
|
||||
uni.previewImage({
|
||||
urls: data.imageList,
|
||||
current: data.imageList[index]
|
||||
})
|
||||
}
|
||||
|
||||
const getGridNames = (list : UTSJSONObject[]) : string => {
|
||||
const names : string[] = []
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const value = list[i]['name']
|
||||
if (value != null) {
|
||||
names.push(value as string)
|
||||
}
|
||||
}
|
||||
return names.join(', ')
|
||||
}
|
||||
|
||||
const getIconNames = (list : UTSJSONObject[]) : string => {
|
||||
const names : string[] = []
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const value = list[i]['label']
|
||||
if (value != null) {
|
||||
names.push(value as string)
|
||||
}
|
||||
}
|
||||
return names.join(', ')
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
clickItem,
|
||||
promptAddDeleteTag,
|
||||
chooseImages,
|
||||
previewImages
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: var(--text-color, #333333);
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 30px;
|
||||
background-color: var(--list-background-color, #ffffff);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #007aff;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
font-size: 12px;
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.7;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.tag-slot {
|
||||
padding-right: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.tag-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #007aff;
|
||||
border-radius: 4px;
|
||||
padding: 8px 16px;
|
||||
}
|
||||
|
||||
.tag-text {
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.tag-item-delete {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #ff6b6b;
|
||||
border-radius: 4px;
|
||||
padding: 4px 16px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.tag-item-add {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #fff5f5;
|
||||
border-width: 1px;
|
||||
border-style: dashed;
|
||||
border-color: #ff6b6b;
|
||||
border-radius: 4px;
|
||||
padding: 4px 16px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.tag-plus-text {
|
||||
color: #ff6b6b;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.grid-slot {
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #28a745;
|
||||
border-radius: 8px;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.grid-text {
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.grid-slot-small {
|
||||
width: 90%;
|
||||
/* 避免scale放大1.12倍时被裁剪*/
|
||||
padding: 3px;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.grid-item-small {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #ffc107;
|
||||
border-radius: 8px;
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.grid-text-small {
|
||||
color: #333333;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.icon-grid-slot {
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.icon-grid-item {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.icon-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-color: #e9ecef;
|
||||
border-radius: 25px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.icon-emoji {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.icon-label {
|
||||
font-size: 12px;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.image-grid-slot {
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.image-grid-item {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 104px;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-grid-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.image-grid-plus {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 104px;
|
||||
background-color: #fafafa;
|
||||
border-width: 1px;
|
||||
border-style: dashed;
|
||||
border-color: #d9d9d9;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.image-grid-plus-icon {
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.handle-demo-slot {
|
||||
width: 100%;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.handle-demo-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
background-color: #f7f8fa;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: #e5e6eb;
|
||||
border-radius: 10px;
|
||||
padding: 16px 52px 16px 14px;
|
||||
}
|
||||
|
||||
.handle-demo-index {
|
||||
width: 24px;
|
||||
margin-right: 12px;
|
||||
color: #007aff;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.handle-demo-text {
|
||||
color: #333333;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.handle-demo-grip {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 56px;
|
||||
}
|
||||
|
||||
.handle-demo-grip-text {
|
||||
color: #999999;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
font-size: 12px;
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.7;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,109 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/fab-button/fab-button'
|
||||
|
||||
describe('fab-button', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
})
|
||||
|
||||
it('fab-button snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true,
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
|
||||
it('fab-button movable example swipe', async () => {
|
||||
await page.waitFor(500)
|
||||
|
||||
const startLeft = await page.data('data.left')
|
||||
const startTop = await page.data('data.top')
|
||||
const startX = startLeft + 22
|
||||
const startY = startTop + 22
|
||||
const endX = startX + 80
|
||||
const endY = startY + 60
|
||||
const el = await page.$('#move-fab')
|
||||
await el.touchstart({
|
||||
touches: [
|
||||
{
|
||||
identifier: 1,
|
||||
pageX: startX,
|
||||
pageY: startY,
|
||||
clientX: startX,
|
||||
clientY: startY,
|
||||
screenX: startX,
|
||||
screenY: startY,
|
||||
},
|
||||
],
|
||||
changedTouches: [
|
||||
{
|
||||
identifier: 1,
|
||||
pageX: startX,
|
||||
pageY: startY,
|
||||
clientX: startX,
|
||||
clientY: startY,
|
||||
screenX: startX,
|
||||
screenY: startY,
|
||||
},
|
||||
],
|
||||
})
|
||||
await page.waitFor(100)
|
||||
await el.touchmove({
|
||||
touches: [
|
||||
{
|
||||
identifier: 1,
|
||||
pageX: endX,
|
||||
pageY: endY,
|
||||
clientX: endX,
|
||||
clientY: endY,
|
||||
screenX: endX,
|
||||
screenY: endY,
|
||||
},
|
||||
],
|
||||
changedTouches: [
|
||||
{
|
||||
identifier: 1,
|
||||
pageX: endX,
|
||||
pageY: endY,
|
||||
clientX: endX,
|
||||
clientY: endY,
|
||||
screenX: endX,
|
||||
screenY: endY,
|
||||
},
|
||||
],
|
||||
})
|
||||
await page.waitFor(100)
|
||||
await el.touchend({
|
||||
touches: [
|
||||
{
|
||||
identifier: 1,
|
||||
pageX: endX,
|
||||
pageY: endY,
|
||||
clientX: endX,
|
||||
clientY: endY,
|
||||
screenX: endX,
|
||||
screenY: endY,
|
||||
},
|
||||
],
|
||||
changedTouches: [
|
||||
{
|
||||
identifier: 1,
|
||||
pageX: endX,
|
||||
pageY: endY,
|
||||
clientX: endX,
|
||||
clientY: endY,
|
||||
screenX: endX,
|
||||
screenY: endY,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await page.waitFor(100)
|
||||
const endLeft = await page.data('data.left')
|
||||
const endTop = await page.data('data.top')
|
||||
expect(Math.abs(endLeft - (startLeft + 80))).toBeLessThanOrEqual(2)
|
||||
expect(Math.abs(endTop - (startTop + 60))).toBeLessThanOrEqual(2)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,162 @@
|
||||
<template>
|
||||
<view style="flex: 1;position: relative;padding: 15px 15px 0 15px;">
|
||||
<text class="label first-label">标准uni-fab-button</text>
|
||||
<uni-fab-button></uni-fab-button>
|
||||
<text class="label">自定义fab样式</text>
|
||||
<uni-fab-button class="custom-class"></uni-fab-button>
|
||||
<text class="label">自定义plus样式</text>
|
||||
<uni-fab-button plus-class="custom-plus-class"></uni-fab-button>
|
||||
<text class="label">自定义fab和plus样式,变成一个16px的纯+</text>
|
||||
<uni-fab-button class="transparent" plus-class="black-plus"></uni-fab-button>
|
||||
<text class="label">可移动uni-fab-button</text>
|
||||
<view class="move-fab-placeholder">
|
||||
<view id="move-fab" class="move-fab" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="updateMoveData" @touchcancel="updateMoveData">
|
||||
<uni-fab-button></uni-fab-button>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="right-bottom"
|
||||
:class="rightBottomFabPressed ? 'fab-pressed' : ''"
|
||||
@touchstart="rightBottomFabPressed = true"
|
||||
@touchend="rightBottomFabPressed = false"
|
||||
@touchcancel="rightBottomFabPressed = false">
|
||||
<uni-fab-button @click="handleClick"></uni-fab-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
dx : number
|
||||
dy : number
|
||||
left : number
|
||||
top : number
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
dx: 0,
|
||||
dy: 0,
|
||||
left: 15,
|
||||
top: 47
|
||||
})
|
||||
let sx = 0
|
||||
let sy = 0
|
||||
let mx = 0
|
||||
let my = 0
|
||||
let baseLeft = 15
|
||||
let baseTop = 47
|
||||
const rightBottomFabPressed = ref(false)
|
||||
|
||||
function handleClick() {
|
||||
uni.showToast({
|
||||
title: '点击了右下角的fab',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
function updateMoveData() {
|
||||
data.left = baseLeft + mx
|
||||
data.top = baseTop + my
|
||||
data.dx = mx
|
||||
data.dy = my
|
||||
}
|
||||
|
||||
function updateMovePos(element : UniElement) {
|
||||
element.style.setProperty('position', 'fixed')
|
||||
element.style.setProperty('left', baseLeft + 'px')
|
||||
element.style.setProperty('top', baseTop + 'px')
|
||||
element.style.setProperty('transform', 'translate(' + mx + 'px,' + my + 'px)')
|
||||
}
|
||||
|
||||
function onTouchStart(e : UniTouchEvent) {
|
||||
sx = e.touches[0].clientX
|
||||
sy = e.touches[0].clientY
|
||||
updateMovePos(e.currentTarget as UniElement)
|
||||
}
|
||||
|
||||
function onTouchMove(e : UniTouchEvent) {
|
||||
mx = e.touches[0].clientX - sx + mx
|
||||
my = e.touches[0].clientY - sy + my
|
||||
sx = e.touches[0].clientX
|
||||
sy = e.touches[0].clientY
|
||||
updateMovePos(e.currentTarget as UniElement)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
uni.createSelectorQuery()
|
||||
.select('.move-fab-placeholder')
|
||||
.boundingClientRect((rect) => {
|
||||
if (rect != null) {
|
||||
const nodeInfo = rect as NodeInfo
|
||||
baseLeft = nodeInfo.left != null ? nodeInfo.left : baseLeft
|
||||
baseTop = nodeInfo.top != null ? nodeInfo.top : baseTop
|
||||
data.left = baseLeft
|
||||
data.top = baseTop
|
||||
}
|
||||
})
|
||||
.exec()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.label {
|
||||
color: var(--text-color, #333333);
|
||||
margin-top: 24px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.first-label {
|
||||
margin-top: 0;
|
||||
}
|
||||
.custom-class{
|
||||
background-color: green;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
.custom-plus-class {
|
||||
background-color: brown;
|
||||
width: 80%;
|
||||
height: 5px;
|
||||
border-radius: 0px;
|
||||
}
|
||||
.transparent {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background-color: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
.black-plus {
|
||||
background-color: black;
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
border-radius: 0px;
|
||||
}
|
||||
.move-fab-placeholder {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
.move-fab {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
.right-bottom {
|
||||
position: absolute;
|
||||
right: 44px;
|
||||
bottom: 44px;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
transform-origin: center center;
|
||||
transition-property: transform, opacity;
|
||||
transition-duration: 140ms;
|
||||
transition-timing-function: cubic-bezier(0.2, 0, 0.2, 1);
|
||||
}
|
||||
.fab-pressed {
|
||||
opacity: 0.9;
|
||||
transform: scale(0.95);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,361 @@
|
||||
export type CityItem = {
|
||||
name: string
|
||||
pinyin: string
|
||||
}
|
||||
|
||||
export type CityGroup = {
|
||||
index: string
|
||||
cities: CityItem[]
|
||||
}
|
||||
|
||||
export const cityGroups: CityGroup[] = [
|
||||
{
|
||||
index: 'A',
|
||||
cities: [
|
||||
{ name: '安庆', pinyin: 'anqing' },
|
||||
{ name: '安阳', pinyin: 'anyang' },
|
||||
{ name: '鞍山', pinyin: 'anshan' },
|
||||
{ name: '安顺', pinyin: 'anshun' },
|
||||
{ name: '安康', pinyin: 'ankang' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'B',
|
||||
cities: [
|
||||
{ name: '北京', pinyin: 'beijing' },
|
||||
{ name: '保定', pinyin: 'baoding' },
|
||||
{ name: '包头', pinyin: 'baotou' },
|
||||
{ name: '宝鸡', pinyin: 'baoji' },
|
||||
{ name: '滨州', pinyin: 'binzhou' },
|
||||
{ name: '本溪', pinyin: 'benxi' },
|
||||
{ name: '白城', pinyin: 'baicheng' },
|
||||
{ name: '白山', pinyin: 'baishan' },
|
||||
{ name: '百色', pinyin: 'baise' },
|
||||
{ name: '毕节', pinyin: 'bijie' },
|
||||
{ name: '巴中', pinyin: 'bazhong' },
|
||||
{ name: '北海', pinyin: 'beihai' },
|
||||
{ name: '蚌埠', pinyin: 'bengbu' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'C',
|
||||
cities: [
|
||||
{ name: '重庆', pinyin: 'chongqing' },
|
||||
{ name: '成都', pinyin: 'chengdu' },
|
||||
{ name: '长沙', pinyin: 'changsha' },
|
||||
{ name: '长春', pinyin: 'changchun' },
|
||||
{ name: '沧州', pinyin: 'cangzhou' },
|
||||
{ name: '常州', pinyin: 'changzhou' },
|
||||
{ name: '常德', pinyin: 'changde' },
|
||||
{ name: '承德', pinyin: 'chengde' },
|
||||
{ name: '赤峰', pinyin: 'chifeng' },
|
||||
{ name: '郴州', pinyin: 'chenzhou' },
|
||||
{ name: '池州', pinyin: 'chizhou' },
|
||||
{ name: '崇左', pinyin: 'chongzuo' },
|
||||
{ name: '楚雄', pinyin: 'chuxiong' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'D',
|
||||
cities: [
|
||||
{ name: '大连', pinyin: 'dalian' },
|
||||
{ name: '大庆', pinyin: 'daqing' },
|
||||
{ name: '大同', pinyin: 'datong' },
|
||||
{ name: '大理', pinyin: 'dali' },
|
||||
{ name: '丹东', pinyin: 'dandong' },
|
||||
{ name: '德州', pinyin: 'dezhou' },
|
||||
{ name: '德阳', pinyin: 'deyang' },
|
||||
{ name: '东莞', pinyin: 'dongguan' },
|
||||
{ name: '东营', pinyin: 'dongying' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'E',
|
||||
cities: [
|
||||
{ name: '鄂州', pinyin: 'ezhou' },
|
||||
{ name: '恩施', pinyin: 'enshi' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'F',
|
||||
cities: [
|
||||
{ name: '福州', pinyin: 'fuzhou' },
|
||||
{ name: '抚顺', pinyin: 'fushun' },
|
||||
{ name: '抚州', pinyin: 'fuzhou2' },
|
||||
{ name: '阜阳', pinyin: 'fuyang' },
|
||||
{ name: '阜新', pinyin: 'fuxin' },
|
||||
{ name: '佛山', pinyin: 'foshan' },
|
||||
{ name: '防城港', pinyin: 'fangchenggang' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'G',
|
||||
cities: [
|
||||
{ name: '广州', pinyin: 'guangzhou' },
|
||||
{ name: '贵阳', pinyin: 'guiyang' },
|
||||
{ name: '桂林', pinyin: 'guilin' },
|
||||
{ name: '赣州', pinyin: 'ganzhou' },
|
||||
{ name: '甘南', pinyin: 'gannan' },
|
||||
{ name: '固原', pinyin: 'guyuan' },
|
||||
{ name: '广安', pinyin: 'guangan' },
|
||||
{ name: '广元', pinyin: 'guangyuan' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'H',
|
||||
cities: [
|
||||
{ name: '哈尔滨', pinyin: 'haerbin' },
|
||||
{ name: '海口', pinyin: 'haikou' },
|
||||
{ name: '杭州', pinyin: 'hangzhou' },
|
||||
{ name: '合肥', pinyin: 'hefei' },
|
||||
{ name: '呼和浩特', pinyin: 'huhehaote' },
|
||||
{ name: '邯郸', pinyin: 'handan' },
|
||||
{ name: '汉中', pinyin: 'hanzhong' },
|
||||
{ name: '菏泽', pinyin: 'heze' },
|
||||
{ name: '衡水', pinyin: 'hengshui' },
|
||||
{ name: '衡阳', pinyin: 'hengyang' },
|
||||
{ name: '黑河', pinyin: 'heihe' },
|
||||
{ name: '淮安', pinyin: 'huaian' },
|
||||
{ name: '淮北', pinyin: 'huaibei' },
|
||||
{ name: '淮南', pinyin: 'huainan' },
|
||||
{ name: '黄冈', pinyin: 'huanggang' },
|
||||
{ name: '黄山', pinyin: 'huangshan' },
|
||||
{ name: '黄石', pinyin: 'huangshi' },
|
||||
{ name: '惠州', pinyin: 'huizhou' },
|
||||
{ name: '葫芦岛', pinyin: 'huludao' },
|
||||
{ name: '湖州', pinyin: 'huzhou' },
|
||||
{ name: '怀化', pinyin: 'huaihua' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'J',
|
||||
cities: [
|
||||
{ name: '济南', pinyin: 'jinan' },
|
||||
{ name: '济宁', pinyin: 'jining' },
|
||||
{ name: '吉林', pinyin: 'jilin' },
|
||||
{ name: '金华', pinyin: 'jinhua' },
|
||||
{ name: '锦州', pinyin: 'jinzhou' },
|
||||
{ name: '晋城', pinyin: 'jincheng' },
|
||||
{ name: '晋中', pinyin: 'jinzhong' },
|
||||
{ name: '荆门', pinyin: 'jingmen' },
|
||||
{ name: '荆州', pinyin: 'jingzhou' },
|
||||
{ name: '景德镇', pinyin: 'jingdezhen' },
|
||||
{ name: '九江', pinyin: 'jiujiang' },
|
||||
{ name: '揭壶', pinyin: 'jiehu' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'K',
|
||||
cities: [
|
||||
{ name: '昆明', pinyin: 'kunming' },
|
||||
{ name: '开封', pinyin: 'kaifeng' },
|
||||
{ name: '喀什', pinyin: 'kashi' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'L',
|
||||
cities: [
|
||||
{ name: '兰州', pinyin: 'lanzhou' },
|
||||
{ name: '拉萨', pinyin: 'lasa' },
|
||||
{ name: '来宾', pinyin: 'laibin' },
|
||||
{ name: '莱芜', pinyin: 'laiwu' },
|
||||
{ name: '廊坊', pinyin: 'langfang' },
|
||||
{ name: '乐山', pinyin: 'leshan' },
|
||||
{ name: '丽江', pinyin: 'lijiang' },
|
||||
{ name: '丽水', pinyin: 'lishui' },
|
||||
{ name: '连云港', pinyin: 'lianyungang' },
|
||||
{ name: '凉山', pinyin: 'liangshan' },
|
||||
{ name: '辽阳', pinyin: 'liaoyang' },
|
||||
{ name: '辽源', pinyin: 'liaoyuan' },
|
||||
{ name: '临沧', pinyin: 'lincang' },
|
||||
{ name: '临汾', pinyin: 'linfen' },
|
||||
{ name: '临沂', pinyin: 'linyi' },
|
||||
{ name: '柳州', pinyin: 'liuzhou' },
|
||||
{ name: '六安', pinyin: 'liuan' },
|
||||
{ name: '六盘水', pinyin: 'liupanshui' },
|
||||
{ name: '龙岩', pinyin: 'longyan' },
|
||||
{ name: '娄底', pinyin: 'loudi' },
|
||||
{ name: '泸州', pinyin: 'luzhou' },
|
||||
{ name: '洛阳', pinyin: 'luoyang' },
|
||||
{ name: '吕梁', pinyin: 'lvliang' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'M',
|
||||
cities: [
|
||||
{ name: '马鞍山', pinyin: 'maanshan' },
|
||||
{ name: '茂名', pinyin: 'maoming' },
|
||||
{ name: '眉山', pinyin: 'meishan' },
|
||||
{ name: '梅州', pinyin: 'meizhou' },
|
||||
{ name: '绵阳', pinyin: 'mianyang' },
|
||||
{ name: '牡丹江', pinyin: 'mudanjiang' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'N',
|
||||
cities: [
|
||||
{ name: '南京', pinyin: 'nanjing' },
|
||||
{ name: '南昌', pinyin: 'nanchang' },
|
||||
{ name: '南宁', pinyin: 'nanning' },
|
||||
{ name: '南充', pinyin: 'nanchong' },
|
||||
{ name: '南通', pinyin: 'nantong' },
|
||||
{ name: '南阳', pinyin: 'nanyang' },
|
||||
{ name: '内江', pinyin: 'neijiang' },
|
||||
{ name: '宁波', pinyin: 'ningbo' },
|
||||
{ name: '宁德', pinyin: 'ningde' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'P',
|
||||
cities: [
|
||||
{ name: '盘锦', pinyin: 'panjin' },
|
||||
{ name: '攀枝花', pinyin: 'panzhihua' },
|
||||
{ name: '平顶山', pinyin: 'pingdingshan' },
|
||||
{ name: '平凉', pinyin: 'pingliang' },
|
||||
{ name: '萍乡', pinyin: 'pingxiang' },
|
||||
{ name: '莆田', pinyin: 'putian' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'Q',
|
||||
cities: [
|
||||
{ name: '青岛', pinyin: 'qingdao' },
|
||||
{ name: '秦皇岛', pinyin: 'qinhuangdao' },
|
||||
{ name: '钦州', pinyin: 'qinzhou' },
|
||||
{ name: '齐齐哈尔', pinyin: 'qiqihaer' },
|
||||
{ name: '泉州', pinyin: 'quanzhou' },
|
||||
{ name: '曲靖', pinyin: 'qujing' },
|
||||
{ name: '衢州', pinyin: 'quzhou' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'R',
|
||||
cities: [
|
||||
{ name: '日照', pinyin: 'rizhao' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'S',
|
||||
cities: [
|
||||
{ name: '上海', pinyin: 'shanghai' },
|
||||
{ name: '沈阳', pinyin: 'shenyang' },
|
||||
{ name: '深圳', pinyin: 'shenzhen' },
|
||||
{ name: '石家庄', pinyin: 'shijiazhuang' },
|
||||
{ name: '三门峡', pinyin: 'sanmenxia' },
|
||||
{ name: '三明', pinyin: 'sanming' },
|
||||
{ name: '三亚', pinyin: 'sanya' },
|
||||
{ name: '汕头', pinyin: 'shantou' },
|
||||
{ name: '汕尾', pinyin: 'shanwei' },
|
||||
{ name: '商洛', pinyin: 'shangluo' },
|
||||
{ name: '商丘', pinyin: 'shangqiu' },
|
||||
{ name: '韶关', pinyin: 'shaoguan' },
|
||||
{ name: '绍兴', pinyin: 'shaoxing' },
|
||||
{ name: '邵阳', pinyin: 'shaoyang' },
|
||||
{ name: '朔州', pinyin: 'shuozhou' },
|
||||
{ name: '四平', pinyin: 'siping' },
|
||||
{ name: '遂宁', pinyin: 'suining' },
|
||||
{ name: '宿迁', pinyin: 'suqian' },
|
||||
{ name: '宿州', pinyin: 'suzhou2' },
|
||||
{ name: '苏州', pinyin: 'suzhou' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'T',
|
||||
cities: [
|
||||
{ name: '天津', pinyin: 'tianjin' },
|
||||
{ name: '太原', pinyin: 'taiyuan' },
|
||||
{ name: '台州', pinyin: 'taizhou' },
|
||||
{ name: '泰安', pinyin: 'taian' },
|
||||
{ name: '泰州', pinyin: 'taizhou2' },
|
||||
{ name: '唐山', pinyin: 'tangshan' },
|
||||
{ name: '铁岭', pinyin: 'tieling' },
|
||||
{ name: '铜川', pinyin: 'tongchuan' },
|
||||
{ name: '铜陵', pinyin: 'tongling' },
|
||||
{ name: '铜仁', pinyin: 'tongren' },
|
||||
{ name: '通化', pinyin: 'tonghua' },
|
||||
{ name: '通辽', pinyin: 'tongliao' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'W',
|
||||
cities: [
|
||||
{ name: '武汉', pinyin: 'wuhan' },
|
||||
{ name: '乌鲁木齐', pinyin: 'wulumuqi' },
|
||||
{ name: '无锡', pinyin: 'wuxi' },
|
||||
{ name: '威海', pinyin: 'weihai' },
|
||||
{ name: '潍坊', pinyin: 'weifang' },
|
||||
{ name: '渭南', pinyin: 'weinan' },
|
||||
{ name: '温州', pinyin: 'wenzhou' },
|
||||
{ name: '梧州', pinyin: 'wuzhou' },
|
||||
{ name: '芜湖', pinyin: 'wuhu' },
|
||||
{ name: '吴忠', pinyin: 'wuzhong' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'X',
|
||||
cities: [
|
||||
{ name: '西安', pinyin: 'xian' },
|
||||
{ name: '西宁', pinyin: 'xining' },
|
||||
{ name: '厦门', pinyin: 'xiamen' },
|
||||
{ name: '咸宁', pinyin: 'xianning' },
|
||||
{ name: '咸阳', pinyin: 'xianyang' },
|
||||
{ name: '湘潭', pinyin: 'xiangtan' },
|
||||
{ name: '湘西', pinyin: 'xiangxi' },
|
||||
{ name: '襄阳', pinyin: 'xiangyang' },
|
||||
{ name: '孝感', pinyin: 'xiaogan' },
|
||||
{ name: '新乡', pinyin: 'xinxiang' },
|
||||
{ name: '信阳', pinyin: 'xinyang' },
|
||||
{ name: '邢台', pinyin: 'xingtai' },
|
||||
{ name: '兴安盟', pinyin: 'xinganmeng' },
|
||||
{ name: '宣城', pinyin: 'xuancheng' },
|
||||
{ name: '许昌', pinyin: 'xuchang' },
|
||||
{ name: '徐州', pinyin: 'xuzhou' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'Y',
|
||||
cities: [
|
||||
{ name: '银川', pinyin: 'yinchuan' },
|
||||
{ name: '烟台', pinyin: 'yantai' },
|
||||
{ name: '延安', pinyin: 'yanan' },
|
||||
{ name: '延边', pinyin: 'yanbian' },
|
||||
{ name: '盐城', pinyin: 'yancheng' },
|
||||
{ name: '阳江', pinyin: 'yangjiang' },
|
||||
{ name: '阳泉', pinyin: 'yangquan' },
|
||||
{ name: '扬州', pinyin: 'yangzhou' },
|
||||
{ name: '宜宾', pinyin: 'yibin' },
|
||||
{ name: '宜昌', pinyin: 'yichang' },
|
||||
{ name: '宜春', pinyin: 'yichun' },
|
||||
{ name: '益阳', pinyin: 'yiyang' },
|
||||
{ name: '营口', pinyin: 'yingkou' },
|
||||
{ name: '永州', pinyin: 'yongzhou' },
|
||||
{ name: '榆林', pinyin: 'yulin' },
|
||||
{ name: '玉林', pinyin: 'yulin2' },
|
||||
{ name: '玉溪', pinyin: 'yuxi' },
|
||||
{ name: '岳阳', pinyin: 'yueyang' },
|
||||
{ name: '云浮', pinyin: 'yunfu' },
|
||||
]
|
||||
},
|
||||
{
|
||||
index: 'Z',
|
||||
cities: [
|
||||
{ name: '郑州', pinyin: 'zhengzhou' },
|
||||
{ name: '珠海', pinyin: 'zhuhai' },
|
||||
{ name: '湛江', pinyin: 'zhanjiang' },
|
||||
{ name: '张家界', pinyin: 'zhangjiajie' },
|
||||
{ name: '张家口', pinyin: 'zhangjiakou' },
|
||||
{ name: '张掖', pinyin: 'zhangye' },
|
||||
{ name: '漳州', pinyin: 'zhangzhou' },
|
||||
{ name: '昭通', pinyin: 'zhaotong' },
|
||||
{ name: '镇江', pinyin: 'zhenjiang' },
|
||||
{ name: '中山', pinyin: 'zhongshan' },
|
||||
{ name: '舟山', pinyin: 'zhoushan' },
|
||||
{ name: '周口', pinyin: 'zhoukou' },
|
||||
{ name: '株洲', pinyin: 'zhuzhou' },
|
||||
{ name: '驻马店', pinyin: 'zhumadian' },
|
||||
{ name: '遵义', pinyin: 'zunyi' },
|
||||
{ name: '自贡', pinyin: 'zigong' },
|
||||
{ name: '资阳', pinyin: 'ziyang' },
|
||||
]
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,31 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/index-bar/index-bar'
|
||||
|
||||
describe('index-bar', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
await page.waitFor(500)
|
||||
})
|
||||
|
||||
async function tapControlButton(index) {
|
||||
const buttons = await page.$$('.control-btn')
|
||||
expect(buttons.length).toBeGreaterThan(index)
|
||||
await buttons[index].tap()
|
||||
await page.waitFor(500)
|
||||
}
|
||||
|
||||
it('index-bar custom style and indexs snapshot', async () => {
|
||||
await tapControlButton(0)
|
||||
await tapControlButton(1)
|
||||
|
||||
expect(await page.data('data.useCustomStyle')).toBe(true)
|
||||
expect(await page.data('data.useCustomIndexs')).toBe(true)
|
||||
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,142 @@
|
||||
<template>
|
||||
<view style="flex: 1; flex-direction: column; position: relative;">
|
||||
<!-- 控制条 -->
|
||||
<view class="control-bar">
|
||||
<button class="control-btn" @click="toggleStyle">{{ data.useCustomStyle ? '默认样式' : '自定义样式' }}</button>
|
||||
<button class="control-btn" @click="toggleIndexs">{{ data.useCustomIndexs ? '根据数据设索引' : '自定义索引' }}</button>
|
||||
</view>
|
||||
<list-view ref="listRef" style="flex: 1;" class="city-list" :scroll-into-view="data.indexViewID">
|
||||
<sticky-section v-for="group in cityGroups" :key="group.index"
|
||||
<!-- #ifdef APP && VUE3-VAPOR -->
|
||||
:preload="true"
|
||||
<!-- #endif -->
|
||||
>
|
||||
<sticky-header :id="'idx-' + group.index">
|
||||
<view class="group-header">
|
||||
<text class="group-header-text">{{ group.index }}</text>
|
||||
</view>
|
||||
</sticky-header>
|
||||
<!-- 每个城市作为独立的 list-item -->
|
||||
<list-item v-for="city in group.cities" :key="city.pinyin" type="city">
|
||||
<view class="city-item">
|
||||
<text class="city-name">{{ city.name }}</text>
|
||||
</view>
|
||||
</list-item>
|
||||
</sticky-section>
|
||||
</list-view>
|
||||
<uni-index-bar
|
||||
:indexs="currentIndexs"
|
||||
:indicator-view-class="data.useCustomStyle ? 'custom-indicator' : ''"
|
||||
:indicator-text-class="data.useCustomStyle ? 'custom-indicator-text' : ''"
|
||||
:style="data.useCustomStyle ? 'color: aqua;' : ''"
|
||||
@select="onSelect">
|
||||
</uni-index-bar>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="uts" setup>
|
||||
import { cityGroups } from './cities.uts'
|
||||
|
||||
// 默认索引列表
|
||||
const defaultIndexs = cityGroups.map((g) : string => g.index).join('\n')
|
||||
// 自定义索引列表
|
||||
const customIndexs = '☆\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\n#'
|
||||
|
||||
type Data = {
|
||||
useCustomStyle: boolean
|
||||
useCustomIndexs: boolean
|
||||
indexViewID: string
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
useCustomStyle: false,
|
||||
useCustomIndexs: false,
|
||||
indexViewID: ""
|
||||
})
|
||||
|
||||
// 当前使用的索引
|
||||
const currentIndexs = computed(() : string => data.useCustomIndexs ? customIndexs : defaultIndexs)
|
||||
|
||||
const listRef = ref<UniListViewElement | null>(null)
|
||||
|
||||
const toggleStyle = () => {
|
||||
data.useCustomStyle = !data.useCustomStyle
|
||||
}
|
||||
|
||||
const toggleIndexs = () => {
|
||||
data.useCustomIndexs = !data.useCustomIndexs
|
||||
}
|
||||
|
||||
const onSelect = (index : string) => {
|
||||
const list = listRef.value
|
||||
if (list == null) {
|
||||
return
|
||||
}
|
||||
// console.log('选择了索引:', index)
|
||||
const childId = 'idx-' + index
|
||||
data.indexViewID = childId
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
currentIndexs,
|
||||
toggleStyle,
|
||||
toggleIndexs,
|
||||
onSelect
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.control-bar {
|
||||
flex-direction: row;
|
||||
padding: 10px;
|
||||
background-color: var(--background-color, #f5f5f5);
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.group-header {
|
||||
background-color: var(--background-color, #f5f5f5);
|
||||
padding-left: 16px;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.group-header-text {
|
||||
font-size: 14px;
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.7;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.city-list {
|
||||
background-color: var(--list-background-color, #ffffff);
|
||||
}
|
||||
|
||||
.city-item {
|
||||
padding-left: 16px;
|
||||
padding-top: 14px;
|
||||
padding-bottom: 14px;
|
||||
background-color: var(--list-background-color, #ffffff);
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-color: var(--border-color, #eeeeee);
|
||||
border-bottom-style: solid;
|
||||
}
|
||||
|
||||
.city-name {
|
||||
font-size: 16px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
|
||||
.custom-indicator {
|
||||
background-color: #007aff;
|
||||
}
|
||||
|
||||
.custom-indicator-text {
|
||||
color: #ffff00;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,32 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/link/link'
|
||||
|
||||
describe('link', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
})
|
||||
}
|
||||
|
||||
it('link state', async () => {
|
||||
expect(await page.data('data.lastEvent')).toBe('暂无事件')
|
||||
|
||||
await setPageData({
|
||||
lastEvent: 'error: empty href'
|
||||
})
|
||||
expect(await page.data('data.lastEvent')).toBe('error: empty href')
|
||||
})
|
||||
|
||||
it('link snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
120
mpuniapp/pages/uni-ui/link/link.uvue
普通文件
120
mpuniapp/pages/uni-ui/link/link.uvue
普通文件
@@ -0,0 +1,120 @@
|
||||
<template>
|
||||
<scroll-view class="page">
|
||||
<view class="section">
|
||||
<text class="section-title">基础用法</text>
|
||||
<view class="link-block">
|
||||
<uni-link href="https://uniapp.dcloud.net.cn" @error="onError">https://uniapp.dcloud.net.cn</uni-link>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">自定义样式</text>
|
||||
<view class="link-block">
|
||||
<uni-link href="https://doc.dcloud.net.cn/uni-app-x/" class="custom-link" @error="onError" >
|
||||
查看 uni-app x 文档
|
||||
</uni-link>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">target="_self" (默认)</text>
|
||||
<view class="link-block">
|
||||
<uni-link href="https://uniapp.dcloud.net.cn" target="_self" @error="onError" >
|
||||
在内置 webview 中打开
|
||||
</uni-link>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">target="_blank"</text>
|
||||
<view class="link-block">
|
||||
<uni-link href="https://uniapp.dcloud.net.cn" target="_blank" @error="onError" >
|
||||
使用外部浏览器打开
|
||||
</uni-link>
|
||||
</view>
|
||||
<text class="tip-text">APP 使用 openSchema 插件,小程序回退到内置 webview 打开,Web 打开新页签</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">target="_blank" 且 失败回退策略为复制URL</text>
|
||||
<view class="link-block">
|
||||
<uni-link href="https://uniapp.dcloud.net.cn" target="_blank" blankFallback="copy-link-modal" @error="onError" >
|
||||
使用外部浏览器打开
|
||||
</uni-link>
|
||||
</view>
|
||||
<text class="tip-text">使用外部浏览器打开失败时,回退为复制URL到剪贴板且弹框提示用户手动粘贴URL到浏览器</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">失败示例</text>
|
||||
<view class="link-block">
|
||||
<uni-link href="" @error="onError" >
|
||||
空链接(触发 error)
|
||||
</uni-link>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">最近事件</text>
|
||||
<text class="log-text">{{ data.lastEvent }}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
lastEvent: string
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
lastEvent: '暂无事件'
|
||||
})
|
||||
|
||||
function onError(message : string) {
|
||||
data.lastEvent = `error: ${message}`
|
||||
console.error(`[link] error: ${message}`)
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
onError
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
|
||||
.link-block {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.custom-link {
|
||||
color: #007aff;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.log-text {
|
||||
margin-top: 8px;
|
||||
font-size: 13px;
|
||||
color: #007aff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,17 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/nav-bar/nav-bar'
|
||||
|
||||
describe('nav-bar', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('scroll-view')
|
||||
})
|
||||
|
||||
it('nav-bar snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,125 @@
|
||||
<template>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle"></uni-nav-bar>
|
||||
<scroll-view style="flex: 1;padding-bottom: var(--uni-safe-area-inset-bottom);" :class="state.isDarkMode ? 'theme-dark' : 'theme-light'">
|
||||
<!-- 正常使用场景应把uni-nav-bar放在template的根节点,本示例为了演示多种导航栏效果把导航栏组件放到了scroll-view里了 -->
|
||||
<uni-nav-bar navigationBarTextStyle="black" title="黑色标题"></uni-nav-bar>
|
||||
<uni-nav-bar navigationBarTextStyle="white" title="青色背景白色标题" style="background-color: cyan;"></uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" title="下边带灰线" style="border-bottom: 0.5px #ccc solid;"></uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" hideDefaultBack title="隐藏左侧返回箭头"></uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" title="标题居左" mid-class="left-title"></uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" title="右边有按钮">
|
||||
<template #right>
|
||||
<text class="txt-button" @click="clickButton">⋯</text>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" title="右边有2个按钮" right-class="two-buttons">
|
||||
<template #right>
|
||||
<text class="txt-button" @click="clickButton">+</text>
|
||||
<text class="txt-button" @click="clickButton">⋯</text>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" title="左边有按钮">
|
||||
<template #left>
|
||||
<text class="txt-button" @click="clickButton">+</text>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle" title="左右各1个按钮">
|
||||
<template #left>
|
||||
<text class="txt-button" @click="clickButton">+</text>
|
||||
</template>
|
||||
<template #right>
|
||||
<text class="txt-button" @click="clickButton">⋯</text>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle">
|
||||
<template #mid>
|
||||
<text :style="{ color: navigationBarTextStyle }">插槽右箭头可以点</text>
|
||||
<text style="padding: 3px;font-size: 10px;" class="uni-theme-text" @click="clickButton">▼</text>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
<uni-nav-bar :navigationBarTextStyle="navigationBarTextStyle">
|
||||
<template #left>
|
||||
<text class="txt-button" @click="clickButton">+</text>
|
||||
</template>
|
||||
<template #mid>
|
||||
<input placeholder="左中右都是插槽,中间是input" style="border: #ccc 0.5px solid;"/>
|
||||
</template>
|
||||
<template #right>
|
||||
<text class="txt-button" @click="clickButton">⋯</text>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { state } from '@/store/index';
|
||||
|
||||
const navigationBarTextStyle = ref('black')
|
||||
|
||||
function clickButton() {
|
||||
uni.showToast({
|
||||
title: '点击了按钮'
|
||||
});
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
// Android平台如果在onShow前调用API,会设置上一个页面的导航栏颜色,所以放在onShow里设置颜色
|
||||
// #ifdef APP-ANDROID
|
||||
if (state.isDarkMode) {
|
||||
navigationBarTextStyle.value = 'white'
|
||||
// 本示例中导航栏的背景色和通用背景色不同,前景色无法遵守theme.json的设置,需要单独设颜色
|
||||
uni.setNavigationBarColor({
|
||||
"frontColor":"#ffffff",
|
||||
"backgroundColor":"#000000" //微信规范不可为空
|
||||
})
|
||||
} else {
|
||||
navigationBarTextStyle.value = 'black'
|
||||
// 本示例中导航栏的背景色和通用背景色不同,前景色无法遵守theme.json的设置,需要单独设颜色
|
||||
uni.setNavigationBarColor({
|
||||
"frontColor":"#000000",
|
||||
"backgroundColor":"#ffffff" //微信规范不可为空
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
watch((): boolean => state.isDarkMode, (newVal: boolean) => {
|
||||
if (newVal) {
|
||||
navigationBarTextStyle.value = 'white'
|
||||
// 本示例中导航栏的背景色和通用背景色不同,前景色无法遵守theme.json的设置,需要单独设颜色
|
||||
uni.setNavigationBarColor({
|
||||
"frontColor":"#ffffff",
|
||||
"backgroundColor":"#000000" //微信规范不可为空
|
||||
})
|
||||
} else {
|
||||
navigationBarTextStyle.value = 'black'
|
||||
// 本示例中导航栏的背景色和通用背景色不同,前景色无法遵守theme.json的设置,需要单独设颜色
|
||||
uni.setNavigationBarColor({
|
||||
"frontColor":"#000000",
|
||||
"backgroundColor":"#ffffff" //微信规范不可为空
|
||||
})
|
||||
}
|
||||
}
|
||||
// #ifndef APP-ANDROID
|
||||
// TODO Android在设置页面导航栏颜色后,后退页面,上一层页面的导航栏也被改了!原因是这个代码执行太早,activity还没创建好
|
||||
, { immediate: true }
|
||||
// #endif
|
||||
)
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.left-title{
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.two-buttons{
|
||||
width: 88px;
|
||||
}
|
||||
.txt-button{
|
||||
font-weight: bold;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
text-align: center;
|
||||
color: var(--text-color);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,49 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/number-box/number-box'
|
||||
|
||||
describe('number-box', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
});
|
||||
}
|
||||
|
||||
it('number-box model value', async () => {
|
||||
expect(await page.data('data.value1')).toBe(1)
|
||||
|
||||
await setPageData({
|
||||
value1: 2
|
||||
})
|
||||
expect(await page.data('data.value1')).toBe(2)
|
||||
|
||||
await setPageData({
|
||||
value1: 3
|
||||
})
|
||||
expect(await page.data('data.value1')).toBe(3)
|
||||
|
||||
expect(await page.data('data.value2')).toBe(10)
|
||||
|
||||
await setPageData({
|
||||
value2: 15
|
||||
})
|
||||
expect(await page.data('data.value2')).toBe(15)
|
||||
|
||||
await setPageData({
|
||||
value2: 8
|
||||
})
|
||||
expect(await page.data('data.value2')).toBe(8)
|
||||
})
|
||||
|
||||
it('number-box snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,164 @@
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<scroll-view style="flex: 1; padding: 15px;">
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
<view style="padding: 15px;">
|
||||
<!-- #endif -->
|
||||
<text class="page-title">NumberBox 数字输入框</text>
|
||||
|
||||
<!-- 基础用法 -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">基础用法:</text>
|
||||
<uni-number-box v-model="data.value1" @change="onChange" />
|
||||
<text class="hint">当前值:{{ data.value1 }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 设置最小值和最大值 -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">设置范围 (min=5, max=20):</text>
|
||||
<uni-number-box v-model="data.value2" :min="5" :max="20" />
|
||||
<text class="hint">当前值:{{ data.value2 }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 设置步长 -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">步长为5 (step=5):</text>
|
||||
<uni-number-box v-model="data.value3" :step="5" />
|
||||
<text class="hint">当前值:{{ data.value3 }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 小数步长 -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">小数步长 (step=0.1):</text>
|
||||
<uni-number-box v-model="data.value4" :step="0.1" :min="0" :max="10" />
|
||||
<text class="hint">当前值:{{ data.value4 }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 禁用状态 -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">禁用状态:</text>
|
||||
<uni-number-box :value="5" :disabled="true" />
|
||||
</view>
|
||||
|
||||
<!-- 自定义样式 btn-class -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">自定义按钮样式 (btn-class):</text>
|
||||
<uni-number-box v-model="data.value5" btn-class="custom-btn" />
|
||||
</view>
|
||||
|
||||
<!-- 自定义样式 input-class -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">自定义输入框样式 (input-class):</text>
|
||||
<uni-number-box v-model="data.value6" input-class="custom-input" />
|
||||
</view>
|
||||
|
||||
<!-- 自定义样式组合 -->
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text class="label">自定义样式组合 (蓝色主题):</text>
|
||||
<uni-number-box v-model="data.value7" btn-class="blue-btn" input-class="blue-input" icon-class="blue-icon" />
|
||||
</view>
|
||||
|
||||
<!-- 暗黑模式外观演示:此区域固定展示深色外观,不跟随系统主题 -->
|
||||
<view style="margin-bottom: 20px; background-color: #1a1a1a; padding: 15px; border-radius: 8px;">
|
||||
<text style="color: #fff; margin-bottom: 10px;">暗黑模式:</text>
|
||||
<uni-number-box v-model="data.value8" btn-class="dark-btn" input-class="dark-input" icon-class="dark-icon" />
|
||||
<text style="color: #999; margin-top: 5px;">当前值:{{ data.value8 }}</text>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
value1 : number
|
||||
value2 : number
|
||||
value3 : number
|
||||
value4 : number
|
||||
value5 : number
|
||||
value6 : number
|
||||
value7 : number
|
||||
value8 : number
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
value1: 1,
|
||||
value2: 10,
|
||||
value3: 0,
|
||||
value4: 0.5,
|
||||
value5: 1,
|
||||
value6: 1,
|
||||
value7: 1,
|
||||
value8: 1
|
||||
})
|
||||
|
||||
const onChange = (value : number) : void => {
|
||||
console.log('number-box change:', value)
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: var(--text-color, #333333);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.75;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.6;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.custom-btn {
|
||||
background-color: #28a745;
|
||||
}
|
||||
|
||||
.custom-input {
|
||||
background-color: #fff3cd;
|
||||
color: #856404;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.dark-btn {
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
.dark-input {
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.dark-icon {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.blue-btn {
|
||||
background-color: #007aff;
|
||||
}
|
||||
|
||||
.blue-input {
|
||||
background-color: #e8f4ff;
|
||||
color: #007aff;
|
||||
}
|
||||
|
||||
.blue-icon {
|
||||
background-color: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,43 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/rate/rate'
|
||||
|
||||
describe('rate', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('text')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
})
|
||||
}
|
||||
|
||||
it('rate model value', async () => {
|
||||
expect(await page.data('data.vModelRateValue')).toBe(0)
|
||||
expect(await page.data('data.rateValue')).toBe(0)
|
||||
|
||||
await setPageData({
|
||||
vModelRateValue: 2
|
||||
})
|
||||
expect(await page.data('data.vModelRateValue')).toBe(2)
|
||||
|
||||
await setPageData({
|
||||
vModelRateValue: 4
|
||||
})
|
||||
expect(await page.data('data.vModelRateValue')).toBe(4)
|
||||
|
||||
await setPageData({
|
||||
rateValue: 5
|
||||
})
|
||||
expect(await page.data('data.rateValue')).toBe(5)
|
||||
})
|
||||
|
||||
it('rate snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
129
mpuniapp/pages/uni-ui/rate/rate.uvue
普通文件
129
mpuniapp/pages/uni-ui/rate/rate.uvue
普通文件
@@ -0,0 +1,129 @@
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<scroll-view style="flex: 1;padding: 15px 15px 30px 15px;">
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
<view style="padding: 15px 15px 30px 15px;">
|
||||
<!-- #endif -->
|
||||
<text class="desc">评分组件用于商品评价打分、服务态度评价、用户满意度等场景。\n
|
||||
高性能模式仅有一个text组件,不可修改评分,适合长列表中显示的场景。\n
|
||||
普通模式可以通过点击星星进行评分,且专门调大字号、调宽间距以适合点击。
|
||||
</text>
|
||||
|
||||
<text class="title">只读评分文字</text>
|
||||
<text style="color: #ffca3e;">★★★★</text>
|
||||
|
||||
<text class="title">高性能:只读,不显示灰星,不支持小数</text>
|
||||
<uni-rate :value="3.6"/>
|
||||
<text class="title">只读,显示灰星</text>
|
||||
<uni-rate full readonly/>
|
||||
<text class="title">只读,小数4.3</text>
|
||||
<uni-rate full readonly :value="4.3"/>
|
||||
<text class="title">只读,value大于5超限测试</text>
|
||||
<uni-rate full readonly :value="100"/>
|
||||
<text class="title">只读,value小于0超限测试</text>
|
||||
<uni-rate full readonly :value="-1"/>
|
||||
<text class="title">未选中的星星为镂空状态" </text>
|
||||
<uni-rate full :value="3.5" :plain="true" star-class="tap-rate-star" star-active-class="tap-rate-star" />
|
||||
<text class="title">未选中的星星为实心且响应change事件</text>
|
||||
<uni-rate full star-class="tap-rate-star" star-active-class="tap-rate-star" @change="onRateChange" />
|
||||
<text class="title">响应点击并双向绑定响应式变量</text>
|
||||
<uni-rate full v-model="data.vModelRateValue" star-class="tap-rate-star" star-active-class="tap-rate-star" />
|
||||
<text>{{data.vModelRateValue}}</text>
|
||||
<text class="title">只读,不触发change" </text>
|
||||
<uni-rate readonly :value="5" @change="onRateChange" />
|
||||
<text class="title">高性能只读,自定义大小和颜色(style方式)</text>
|
||||
<uni-rate style="font-size: 32px" star-active-style="color:red" :value="4.6" />
|
||||
<!-- 仅高性能版,因为单层,可以在组件的style属性上写作用于text的样式。但规范的写法是使用star-active-style -->
|
||||
<text class="title">高性能只读,自定义间隔letter-space(class方式)" </text>
|
||||
<uni-rate :value="4" star-active-class="star-active-class"/>
|
||||
<text class="title">自定义默认颜色和选中颜色 class方式</text>
|
||||
<uni-rate :value="3" full star-class="custom-default tap-rate-star" star-active-class="custom-selected tap-rate-star"/>
|
||||
<text class="title">自定义默认颜色和选中颜色 style方式</text>
|
||||
<uni-rate :value="3" full star-style="color:lightgreen;letter-spacing:8px" star-active-style="color:green"/>
|
||||
<text class="title">只读,程序动态赋值,不触发change</text>
|
||||
<uni-rate :value="data.rateValue" @change="onRateChange"/>
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
vModelRateValue: number
|
||||
rateValue: number
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
vModelRateValue: 0,
|
||||
rateValue: 0
|
||||
})
|
||||
let interval = 0
|
||||
|
||||
/* onReady(() => {
|
||||
console.log(getCurrentInstance()!.proxy!.$page.$nativePage);
|
||||
}) */
|
||||
|
||||
function onRateChange(value: number) {
|
||||
console.log('onRateChange received value:', value, 'type:', typeof value)
|
||||
|
||||
// 检查值是否有效
|
||||
if (isNaN(value)) {
|
||||
console.error('Invalid value received:', value)
|
||||
uni.showToast({
|
||||
title: '无效值: ' + value,
|
||||
position: "bottom"
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: 'rate改变:' + value,
|
||||
position: "bottom"
|
||||
})
|
||||
}
|
||||
|
||||
// 动态赋值示例
|
||||
onMounted(() => {
|
||||
// 每2秒改变一次评分值
|
||||
interval = setInterval(() => {
|
||||
data.rateValue = Math.floor(Math.random() * 6) // 0-5之间的随机整数
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (interval != 0) {
|
||||
clearInterval(interval)
|
||||
}
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
onRateChange
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
.desc {
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
.custom-default{
|
||||
color:black
|
||||
}
|
||||
.custom-selected{
|
||||
color:red
|
||||
}
|
||||
.title{
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
.star-active-class{
|
||||
letter-spacing: 5px;
|
||||
}
|
||||
.tap-rate-star{
|
||||
font-size: 32px;
|
||||
letter-spacing: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,84 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/refresh-box/refresh-box'
|
||||
|
||||
describe('refresh-box', () => {
|
||||
let page
|
||||
const pullingSnapshotState = {
|
||||
listCount1: 5,
|
||||
pullingDistance1: 24,
|
||||
listCount2: 5,
|
||||
pullingDistance2: 60,
|
||||
listCount3: 5,
|
||||
refreshing3: true,
|
||||
pullingDistance3: 60,
|
||||
listCount4: 5,
|
||||
refreshing4: true,
|
||||
pullingDistance4: 36
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
})
|
||||
}
|
||||
|
||||
async function savePageSnapshot() {
|
||||
await page.waitFor(200)
|
||||
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
}
|
||||
|
||||
it('refresh-box state', async () => {
|
||||
expect(await page.data('data.listCount1')).toBe(3)
|
||||
expect(await page.data('data.refreshing1')).toBe(false)
|
||||
expect(await page.data('data.pullingDistance1')).toBe(0)
|
||||
expect(await page.data('data.listCount2')).toBe(3)
|
||||
expect(await page.data('data.refreshing2')).toBe(false)
|
||||
expect(await page.data('data.pullingDistance2')).toBe(0)
|
||||
expect(await page.data('data.listCount3')).toBe(3)
|
||||
expect(await page.data('data.refreshing3')).toBe(false)
|
||||
expect(await page.data('data.pullingDistance3')).toBe(0)
|
||||
expect(await page.data('data.listCount4')).toBe(3)
|
||||
expect(await page.data('data.refreshing4')).toBe(false)
|
||||
expect(await page.data('data.pullingDistance4')).toBe(0)
|
||||
|
||||
await setPageData({
|
||||
listCount1: 8,
|
||||
refreshing1: true,
|
||||
pullingDistance1: 45,
|
||||
listCount2: 4,
|
||||
pullingDistance2: 50,
|
||||
listCount3: 7,
|
||||
refreshing3: true,
|
||||
pullingDistance3: 60,
|
||||
listCount4: 6,
|
||||
refreshing4: true,
|
||||
pullingDistance4: 30
|
||||
})
|
||||
|
||||
expect(await page.data('data.listCount1')).toBe(8)
|
||||
expect(await page.data('data.refreshing1')).toBe(true)
|
||||
expect(await page.data('data.listCount2')).toBe(4)
|
||||
expect(await page.data('data.refreshing2')).toBe(false)
|
||||
expect(await page.data('data.listCount3')).toBe(7)
|
||||
expect(await page.data('data.refreshing3')).toBe(true)
|
||||
expect(await page.data('data.listCount4')).toBe(6)
|
||||
expect(await page.data('data.refreshing4')).toBe(true)
|
||||
})
|
||||
|
||||
it('refresh-box default snapshot', async () => {
|
||||
await savePageSnapshot()
|
||||
})
|
||||
|
||||
it('refresh-box pulling snapshot', async () => {
|
||||
await setPageData(pullingSnapshotState)
|
||||
await savePageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<view style="flex: 1;">
|
||||
<scroll-view
|
||||
style="flex: 1;"
|
||||
:refresher-enabled="true"
|
||||
:refresher-triggered="data.refreshing1"
|
||||
refresher-default-style="none"
|
||||
:refresher-threshold="45"
|
||||
refresher-max-drag-distance="200px"
|
||||
@refresherpulling="onRefresherpulling1"
|
||||
@refresherrefresh="onRefresherrefresh1"
|
||||
@refresherrestore="onRefresherrestore1"
|
||||
@refresherabort="onRefresherabort1"
|
||||
> <!-- TODO Android不支持bool属性,:refresher-enabled="true" 不能简写为 refresher-enabled -->
|
||||
<!-- 列表内容 -->
|
||||
<view v-for="i in data.listCount1" :key="i" class="content-item">
|
||||
<text class="text">item-{{ i }}</text>
|
||||
</view>
|
||||
|
||||
<!-- refresher 插槽使用 uni-refresh-box 组件 -->
|
||||
<uni-refresh-box
|
||||
slot="refresher"
|
||||
:pulling-distance="data.pullingDistance1"
|
||||
:refreshing="data.refreshing1"
|
||||
></uni-refresh-box> <!-- TODO web只认在组件外层使用slot="refresher",不支持组件内根元素使用-->
|
||||
</scroll-view>
|
||||
<text class="section-label">竖排暗黑自定义文字的下拉设置</text>
|
||||
<scroll-view
|
||||
style="flex: 1;background-color: black;"
|
||||
:refresher-enabled="true"
|
||||
:refresher-triggered="data.refreshing2"
|
||||
refresher-default-style="none"
|
||||
:refresher-threshold="45"
|
||||
refresher-max-drag-distance="200px"
|
||||
@refresherpulling="onRefresherpulling2"
|
||||
@refresherrefresh="onRefresherrefresh2"
|
||||
@refresherrestore="onRefresherrestore2"
|
||||
@refresherabort="onRefresherabort2"
|
||||
>
|
||||
<!-- 列表内容 -->
|
||||
<view v-for="i in data.listCount2" :key="i" class="content-item">
|
||||
<text class="text">item-{{ i }}</text>
|
||||
</view>
|
||||
|
||||
<!-- refresher 插槽使用 uni-refresh-box 组件 -->
|
||||
<uni-refresh-box
|
||||
slot="refresher"
|
||||
:pulling-distance="data.pullingDistance2"
|
||||
:refreshing="data.refreshing2"
|
||||
loading-class="loading-dark"
|
||||
text-class="text-dark"
|
||||
style="flex-direction: column;height: 46px;padding-top: 6px;"
|
||||
pulling-text="继续下拉可刷新"
|
||||
loosing-text="释放后会刷新"
|
||||
loading-text="奋力加载中..."
|
||||
></uni-refresh-box>
|
||||
</scroll-view>
|
||||
<text class="section-label">slot自定义下拉图标</text>
|
||||
<scroll-view
|
||||
style="flex: 1;"
|
||||
:refresher-enabled="true"
|
||||
:refresher-triggered="data.refreshing3"
|
||||
refresher-default-style="none"
|
||||
:refresher-threshold="45"
|
||||
refresher-max-drag-distance="200px"
|
||||
@refresherpulling="onRefresherpulling3"
|
||||
@refresherrefresh="onRefresherrefresh3"
|
||||
@refresherrestore="onRefresherrestore3"
|
||||
@refresherabort="onRefresherabort3"
|
||||
>
|
||||
<!-- 列表内容 -->
|
||||
<view v-for="i in data.listCount3" :key="i" class="content-item">
|
||||
<text class="text">item-{{ i }}</text>
|
||||
</view>
|
||||
|
||||
<!-- refresher 插槽使用 uni-refresh-box 组件 -->
|
||||
<uni-refresh-box
|
||||
slot="refresher"
|
||||
:pulling-distance="data.pullingDistance3"
|
||||
:refreshing="data.refreshing3"
|
||||
>
|
||||
<template #loading="{ state }">
|
||||
<image
|
||||
v-if="state == 2"
|
||||
src="https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/refresh-box-run.gif"
|
||||
style="width: 20px; height: 20px;"
|
||||
/> <!-- 刷新中的动图-->
|
||||
<image
|
||||
v-else
|
||||
src="https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/refresh-box-run.gif"
|
||||
style="width: 20px; height: 20px;"
|
||||
/> <!-- 非刷新中的图,可以和刷新中的图是一张,也可以分开-->
|
||||
</template>
|
||||
<!-- <image src="https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/refresh-box-run.gif" style="width:20px;height:20px;"></image> -->
|
||||
</uni-refresh-box>
|
||||
</scroll-view>
|
||||
<text class="section-label">无文字,纯loading</text>
|
||||
<scroll-view
|
||||
style="flex: 1;"
|
||||
:refresher-enabled="true"
|
||||
:refresher-triggered="data.refreshing4"
|
||||
refresher-default-style="none"
|
||||
:refresher-threshold="45"
|
||||
refresher-max-drag-distance="200px"
|
||||
@refresherpulling="onRefresherpulling4"
|
||||
@refresherrefresh="onRefresherrefresh4"
|
||||
@refresherrestore="onRefresherrestore4"
|
||||
@refresherabort="onRefresherabort4"
|
||||
>
|
||||
<!-- 列表内容 -->
|
||||
<view v-for="i in data.listCount4" :key="i" class="content-item">
|
||||
<text class="text">item-{{ i }}</text>
|
||||
</view>
|
||||
|
||||
<!-- refresher 插槽使用 uni-refresh-box 组件 -->
|
||||
<uni-refresh-box
|
||||
slot="refresher"
|
||||
:pulling-distance="data.pullingDistance4"
|
||||
:refreshing="data.refreshing4"
|
||||
pulling-text=""
|
||||
loosing-text=""
|
||||
loading-text=""
|
||||
loading-class="loading-big-font"
|
||||
></uni-refresh-box>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
listCount1: number
|
||||
refreshing1: boolean
|
||||
pullingDistance1: number
|
||||
listCount2: number
|
||||
refreshing2: boolean
|
||||
pullingDistance2: number
|
||||
listCount3: number
|
||||
refreshing3: boolean
|
||||
pullingDistance3: number
|
||||
listCount4: number
|
||||
refreshing4: boolean
|
||||
pullingDistance4: number
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
listCount1: 3,
|
||||
refreshing1: false,
|
||||
pullingDistance1: 0,
|
||||
listCount2: 3,
|
||||
refreshing2: false,
|
||||
pullingDistance2: 0,
|
||||
listCount3: 3,
|
||||
refreshing3: false,
|
||||
pullingDistance3: 0,
|
||||
listCount4: 3,
|
||||
refreshing4: false,
|
||||
pullingDistance4: 0
|
||||
})
|
||||
|
||||
function onRefresherpulling1(e: RefresherEvent) {
|
||||
data.pullingDistance1 = e.detail.dy
|
||||
}
|
||||
|
||||
function onRefresherrefresh1() {
|
||||
data.refreshing1 = true
|
||||
console.log('列表1 触发刷新')
|
||||
setTimeout(() => {
|
||||
data.listCount1 += 5
|
||||
data.refreshing1 = false
|
||||
console.log('列表1 刷新完成')
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
function onRefresherrestore1() {
|
||||
data.pullingDistance1 = 0
|
||||
}
|
||||
|
||||
function onRefresherabort1() {
|
||||
data.pullingDistance1 = 0
|
||||
}
|
||||
|
||||
function onRefresherpulling2(e: RefresherEvent) {
|
||||
data.pullingDistance2 = e.detail.dy
|
||||
}
|
||||
|
||||
function onRefresherrefresh2() {
|
||||
data.refreshing2 = true
|
||||
console.log('列表2 触发刷新')
|
||||
setTimeout(() => {
|
||||
data.listCount2 += 5
|
||||
data.refreshing2 = false
|
||||
console.log('列表2 刷新完成')
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
function onRefresherrestore2() {
|
||||
data.pullingDistance2 = 0
|
||||
}
|
||||
|
||||
function onRefresherabort2() {
|
||||
data.pullingDistance2 = 0
|
||||
}
|
||||
|
||||
function onRefresherpulling3(e: RefresherEvent) {
|
||||
data.pullingDistance3 = e.detail.dy
|
||||
}
|
||||
|
||||
function onRefresherrefresh3() {
|
||||
data.refreshing3 = true
|
||||
console.log('列表3 触发刷新')
|
||||
setTimeout(() => {
|
||||
data.listCount3 += 5
|
||||
data.refreshing3 = false
|
||||
console.log('列表3 刷新完成')
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
function onRefresherrestore3() {
|
||||
data.pullingDistance3 = 0
|
||||
}
|
||||
|
||||
function onRefresherabort3() {
|
||||
data.pullingDistance3 = 0
|
||||
}
|
||||
|
||||
function onRefresherpulling4(e: RefresherEvent) {
|
||||
data.pullingDistance4 = e.detail.dy
|
||||
}
|
||||
|
||||
function onRefresherrefresh4() {
|
||||
data.refreshing4 = true
|
||||
console.log('列表4 触发刷新')
|
||||
setTimeout(() => {
|
||||
data.listCount4 += 5
|
||||
data.refreshing4 = false
|
||||
console.log('列表4 刷新完成')
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
function onRefresherrestore4() {
|
||||
data.pullingDistance4 = 0
|
||||
}
|
||||
|
||||
function onRefresherabort4() {
|
||||
data.pullingDistance4 = 0
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.section-label {
|
||||
margin: 5px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
.content-item {
|
||||
margin: 5px 10px;
|
||||
}
|
||||
.text {
|
||||
color: var(--text-color, #333333);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.loading-dark{
|
||||
border-color:white;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
.text-dark{
|
||||
color: white;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.loading-big-font{
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
</style>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,37 @@
|
||||
const PAGE_PATH = '/pages/uni-ui/time-format/time-format'
|
||||
|
||||
describe('time-format', () => {
|
||||
let page
|
||||
|
||||
beforeEach(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('scroll-view')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({
|
||||
data: newData
|
||||
})
|
||||
}
|
||||
|
||||
it('time-format value', async () => {
|
||||
expect((await page.data('data.relativeDateTimeText')).length).toBe(19)
|
||||
|
||||
await setPageData({
|
||||
relativeDateTimeText: '2024-01-02 03:04:05'
|
||||
})
|
||||
expect(await page.data('data.relativeDateTimeText')).toBe('2024-01-02 03:04:05')
|
||||
|
||||
await setPageData({
|
||||
relativeDateTimeText: 'invalid'
|
||||
})
|
||||
expect(await page.data('data.relativeDateTimeText')).toBe('invalid')
|
||||
})
|
||||
|
||||
it('time-format snapshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,248 @@
|
||||
<template>
|
||||
<scroll-view class="page">
|
||||
<view class="section">
|
||||
<text class="section-title">当前时间不同格式</text>
|
||||
<view class="row">
|
||||
<text class="row-label">date</text>
|
||||
<uni-time-format :timestamp="data.currentTimestamp" format="date"></uni-time-format>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">time</text>
|
||||
<uni-time-format :timestamp="data.currentTimestamp" format="time"></uni-time-format>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">datetime</text>
|
||||
<uni-time-format :timestamp="data.currentTimestamp" format="datetime"></uni-time-format>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">输入时间动态计算相对时间</text>
|
||||
<view class="input-block">
|
||||
<text class="row-label">输入格式</text>
|
||||
<text class="tip-text">yyyy-mm-dd hh:mm:ss</text>
|
||||
<input
|
||||
class="datetime-input"
|
||||
v-model="data.relativeDateTimeText"
|
||||
placeholder="yyyy-mm-dd hh:mm:ss"
|
||||
/>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">输出相对时间</text>
|
||||
<uni-time-format :timestamp="inputRelativeTimestamp" format="relative"></uni-time-format>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">固定 5 分支示例(不随输入变化)</text>
|
||||
<view class="row">
|
||||
<text class="row-label">刚刚</text>
|
||||
<uni-time-format :timestamp="fixedJustNowTimestamp" format="relative"></uni-time-format>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">分钟前</text>
|
||||
<uni-time-format :timestamp="fixedFiveMinutesAgoTimestamp" format="relative"></uni-time-format>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">小时前</text>
|
||||
<uni-time-format :timestamp="fixedHourBranchTimestamp" format="relative"></uni-time-format>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">昨天 HH:mm</text>
|
||||
<uni-time-format :timestamp="fixedYesterdayTimestamp" format="relative"></uni-time-format>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">超过昨天</text>
|
||||
<uni-time-format :timestamp="fixedOlderThanYesterdayTimestamp" format="relative"></uni-time-format>
|
||||
</view>
|
||||
<text class="tip-text">固定示例基于页面打开时刻计算,不随输入变化。</text>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">秒级时间戳自动换算</text>
|
||||
<view class="row">
|
||||
<text class="row-label">timestamp(s)</text>
|
||||
<uni-time-format :timestamp="secondTimestamp" format="datetime"></uni-time-format>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">非法时间戳</text>
|
||||
<view class="row">
|
||||
<uni-time-format :timestamp="data.invalidTimestamp" format="datetime"></uni-time-format>
|
||||
</view>
|
||||
<text class="tip-text">非法时间会显示为空字符串。</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type Data = {
|
||||
currentTimestamp: number
|
||||
invalidTimestamp: number
|
||||
relativeDateTimeText: string
|
||||
}
|
||||
|
||||
const data = reactive<Data>({
|
||||
currentTimestamp: Date.now(),
|
||||
invalidTimestamp: NaN,
|
||||
relativeDateTimeText: ''
|
||||
})
|
||||
let timer : number | null = null
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1000
|
||||
const pageOpenTimestamp = Date.now()
|
||||
const pageOpenDate = new Date(pageOpenTimestamp)
|
||||
|
||||
function padZero(value : number) : string {
|
||||
return value < 10 ? `0${value}` : `${value}`
|
||||
}
|
||||
|
||||
function formatDateTimeText(date : Date) : string {
|
||||
return `${date.getFullYear()}-${padZero(date.getMonth() + 1)}-${padZero(date.getDate())} ${padZero(date.getHours())}:${padZero(date.getMinutes())}:${padZero(date.getSeconds())}`
|
||||
}
|
||||
|
||||
function toSafeInt(text : string) : number | null {
|
||||
const value = parseInt(text)
|
||||
if (isNaN(value)) {
|
||||
return null
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
function parseDateTimeText(text : string) : number | null {
|
||||
if (text.length != 19) {
|
||||
return null
|
||||
}
|
||||
if (text.substring(4, 5) != '-' || text.substring(7, 8) != '-' || text.substring(10, 11) != ' ' || text.substring(13, 14) != ':' || text.substring(16, 17) != ':') {
|
||||
return null
|
||||
}
|
||||
|
||||
const year = toSafeInt(text.substring(0, 4))
|
||||
const month = toSafeInt(text.substring(5, 7))
|
||||
const day = toSafeInt(text.substring(8, 10))
|
||||
const hours = toSafeInt(text.substring(11, 13))
|
||||
const minutes = toSafeInt(text.substring(14, 16))
|
||||
const seconds = toSafeInt(text.substring(17, 19))
|
||||
|
||||
if (year == null || month == null || day == null || hours == null || minutes == null || seconds == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
const date = new Date(year, month - 1, day, hours, minutes, seconds)
|
||||
if (date.getFullYear() != year || date.getMonth() != month - 1 || date.getDate() != day || date.getHours() != hours || date.getMinutes() != minutes || date.getSeconds() != seconds) {
|
||||
return null
|
||||
}
|
||||
return date.getTime()
|
||||
}
|
||||
|
||||
const pageOpenDateText = formatDateTimeText(pageOpenDate)
|
||||
data.relativeDateTimeText = pageOpenDateText
|
||||
|
||||
const inputRelativeTimestamp = computed(() : number => {
|
||||
const parsed = parseDateTimeText(data.relativeDateTimeText)
|
||||
if (parsed != null) {
|
||||
return parsed
|
||||
}
|
||||
return NaN
|
||||
})
|
||||
|
||||
const fixedDayStartTimestamp = new Date(
|
||||
pageOpenDate.getFullYear(),
|
||||
pageOpenDate.getMonth(),
|
||||
pageOpenDate.getDate()
|
||||
).getTime()
|
||||
|
||||
const fixedJustNowTimestamp = pageOpenTimestamp - 20 * 1000
|
||||
const fixedFiveMinutesAgoTimestamp = pageOpenTimestamp - 5 * 60 * 1000
|
||||
const fixedHourBranchTimestamp = (() : number => {
|
||||
const fiveHoursAgo = pageOpenTimestamp - 5 * 60 * 60 * 1000
|
||||
if (fiveHoursAgo >= fixedDayStartTimestamp) {
|
||||
return fiveHoursAgo
|
||||
}
|
||||
const oneHourAgo = pageOpenTimestamp - 60 * 60 * 1000
|
||||
if (oneHourAgo >= fixedDayStartTimestamp) {
|
||||
return oneHourAgo
|
||||
}
|
||||
return pageOpenTimestamp - 60 * 1000
|
||||
})()
|
||||
const fixedYesterdayTimestamp = fixedDayStartTimestamp - 50 * 60 * 1000
|
||||
const fixedOlderThanYesterdayTimestamp = fixedDayStartTimestamp - 2 * DAY_MS - 30 * 60 * 1000
|
||||
|
||||
const secondTimestamp = computed(() : number => {
|
||||
return Math.floor(data.currentTimestamp / 1000)
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
timer = setInterval(() => {
|
||||
data.currentTimestamp = Date.now()
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
const currentTimer = timer
|
||||
if (currentTimer != null) {
|
||||
clearInterval(currentTimer)
|
||||
timer = null
|
||||
}
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
inputRelativeTimestamp,
|
||||
secondTimestamp
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
|
||||
.input-block {
|
||||
margin-top: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.datetime-input {
|
||||
margin-top: 8px;
|
||||
margin-bottom: 6px;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: var(--border-color, #dddddd);
|
||||
height: 38px;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: var(--text-color, #333333);
|
||||
}
|
||||
|
||||
.row {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.row-label {
|
||||
font-size: 14px;
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--text-color, #333333);
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户