refactor pages struct
This commit is contained in:
13
miniprogram/pages/main/tabs/travel/index.json
Normal file
13
miniprogram/pages/main/tabs/travel/index.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-tag": "tdesign-miniprogram/tag/tag",
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group"
|
||||
},
|
||||
"styleIsolation": "shared",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
118
miniprogram/pages/main/tabs/travel/index.less
Normal file
118
miniprogram/pages/main/tabs/travel/index.less
Normal file
@ -0,0 +1,118 @@
|
||||
// pages/main/travel/index.less
|
||||
|
||||
.filter-menu {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
background: var(--theme-bg-overlay);
|
||||
|
||||
.content {
|
||||
z-index: 1000;
|
||||
position: fixed;
|
||||
background: var(--theme-bg-menu);
|
||||
box-shadow: 0 0 12px var(--theme-shadow-medium);
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.travels {
|
||||
width: 100vw;
|
||||
padding: 16rpx;
|
||||
box-sizing: border-box;
|
||||
padding-bottom: 120rpx;
|
||||
|
||||
.travel {
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 12px var(--theme-shadow-light);
|
||||
transition: all .3s;
|
||||
background: var(--theme-bg-card);
|
||||
margin-bottom: 24rpx;
|
||||
border-radius: 16rpx;
|
||||
|
||||
&:active {
|
||||
transform: scale(.98);
|
||||
box-shadow: 0 2px 8px var(--theme-shadow-light);
|
||||
}
|
||||
|
||||
.header {
|
||||
padding: 24rpx;
|
||||
border-bottom: 1px solid var(--theme-border-light);
|
||||
}
|
||||
|
||||
.body {
|
||||
padding: 24rpx;
|
||||
|
||||
.title {
|
||||
color: var(--theme-text-primary);
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 16rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.content {
|
||||
color: var(--theme-text-secondary);
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 24rpx;
|
||||
display: -webkit-box;
|
||||
overflow: hidden;
|
||||
-webkit-line-clamp: 2;
|
||||
text-overflow: ellipsis;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.meta {
|
||||
gap: 32rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.item {
|
||||
gap: 8rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.icon {
|
||||
color: var(--theme-text-secondary);
|
||||
}
|
||||
|
||||
.text {
|
||||
color: var(--theme-text-secondary);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.finished {
|
||||
color: var(--theme-text-secondary);
|
||||
padding: 32rpx 0;
|
||||
font-size: 24rpx;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.fab {
|
||||
right: 32rpx;
|
||||
width: 112rpx;
|
||||
bottom: 120rpx;
|
||||
height: 112rpx;
|
||||
display: flex;
|
||||
z-index: 9999;
|
||||
position: fixed;
|
||||
background: var(--theme-wx);
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
justify-content: center;
|
||||
box-shadow: 0 8px 24px rgba(102, 126, 234, .4);
|
||||
transition: all .3s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(.9);
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, .3);
|
||||
}
|
||||
}
|
||||
176
miniprogram/pages/main/tabs/travel/index.ts
Normal file
176
miniprogram/pages/main/tabs/travel/index.ts
Normal file
@ -0,0 +1,176 @@
|
||||
// pages/main/travel/index.ts
|
||||
|
||||
import Time from "../../../../utils/Time";
|
||||
import { TravelApi } from "../../../../api/TravelApi";
|
||||
import { Travel, TravelPage, TravelStatus, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TransportationTypeIcon } from "../../../../types/Travel";
|
||||
|
||||
interface TravelData {
|
||||
/** 分页参数 */
|
||||
page: TravelPage;
|
||||
/** 出行列表 */
|
||||
list: Travel[];
|
||||
/** 当前筛选状态 */
|
||||
currentStatus: TravelStatus | "ALL";
|
||||
/** 是否正在加载 */
|
||||
isFetching: boolean;
|
||||
/** 是否已加载完成 */
|
||||
isFinished: boolean;
|
||||
/** 是否显示筛选菜单 */
|
||||
isShowFilterMenu: boolean;
|
||||
/** 菜单位置 */
|
||||
menuTop: number;
|
||||
menuLeft: number;
|
||||
/** 状态标签映射 */
|
||||
statusLabels: typeof TravelStatusLabel;
|
||||
/** 状态图标映射 */
|
||||
statusIcons: typeof TravelStatusIcon;
|
||||
/** 交通类型标签映射 */
|
||||
transportLabels: typeof TransportationTypeLabel;
|
||||
/** 交通类型图标映射 */
|
||||
transportIcons: typeof TransportationTypeIcon;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: <TravelData>{
|
||||
page: {
|
||||
index: 0,
|
||||
size: 10
|
||||
},
|
||||
list: [],
|
||||
currentStatus: "ALL",
|
||||
isFetching: false,
|
||||
isFinished: false,
|
||||
isShowFilterMenu: false,
|
||||
menuTop: 0,
|
||||
menuLeft: 0,
|
||||
statusLabels: TravelStatusLabel,
|
||||
statusIcons: TravelStatusIcon,
|
||||
transportLabels: TransportationTypeLabel,
|
||||
transportIcons: TransportationTypeIcon
|
||||
},
|
||||
onLoad() {
|
||||
this.resetAndFetch();
|
||||
},
|
||||
onShow() {
|
||||
// 页面显示时刷新数据(从编辑页返回时)
|
||||
if (0 < this.data.list.length) {
|
||||
this.resetAndFetch();
|
||||
}
|
||||
},
|
||||
onHide() {
|
||||
this.setData({
|
||||
isShowFilterMenu: false
|
||||
});
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.resetAndFetch();
|
||||
wx.stopPullDownRefresh();
|
||||
},
|
||||
onReachBottom() {
|
||||
this.fetch();
|
||||
},
|
||||
/** 重置并获取数据 */
|
||||
resetAndFetch() {
|
||||
this.setData({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 10,
|
||||
equalsExample: this.data.currentStatus === "ALL" ? undefined : {
|
||||
status: this.data.currentStatus as TravelStatus
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
isFetching: false,
|
||||
isFinished: false
|
||||
});
|
||||
this.fetch();
|
||||
},
|
||||
/** 获取出行列表 */
|
||||
async fetch() {
|
||||
if (this.data.isFetching || this.data.isFinished) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({ isFetching: true });
|
||||
|
||||
try {
|
||||
const pageResult = await TravelApi.getList(this.data.page);
|
||||
const list = pageResult.list || [];
|
||||
|
||||
if (list.length === 0) {
|
||||
this.setData({ isFinished: true });
|
||||
return;
|
||||
}
|
||||
|
||||
// 格式化数据
|
||||
list.forEach(travel => {
|
||||
if (travel.travelAt) {
|
||||
travel.travelDate = Time.toDate(travel.travelAt);
|
||||
travel.travelTime = Time.toTime(travel.travelAt);
|
||||
}
|
||||
});
|
||||
|
||||
this.setData({
|
||||
page: {
|
||||
...this.data.page,
|
||||
index: this.data.page.index + 1
|
||||
},
|
||||
list: this.data.list.concat(list),
|
||||
isFinished: list.length < this.data.page.size
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("获取出行列表失败:", error);
|
||||
} finally {
|
||||
this.setData({ isFetching: false });
|
||||
}
|
||||
},
|
||||
/** 切换筛选菜单 */
|
||||
toggleFilterMenu() {
|
||||
if (!this.data.isShowFilterMenu) {
|
||||
// 打开菜单时计算位置
|
||||
const query = wx.createSelectorQuery();
|
||||
query.select(".filter-btn").boundingClientRect();
|
||||
query.exec((res) => {
|
||||
if (res[0]) {
|
||||
const { top, left, height } = res[0];
|
||||
this.setData({
|
||||
isShowFilterMenu: true,
|
||||
menuTop: top + height + 16,
|
||||
menuLeft: left
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 关闭菜单
|
||||
this.setData({
|
||||
isShowFilterMenu: false
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 阻止事件冒泡 */
|
||||
stopPropagation() {
|
||||
// 空函数,仅用于阻止事件冒泡
|
||||
},
|
||||
/** 筛选状态 */
|
||||
filterByStatus(e: WechatMiniprogram.BaseEvent) {
|
||||
const status = e.currentTarget.dataset.status as TravelStatus | "ALL";
|
||||
this.setData({
|
||||
currentStatus: status,
|
||||
isShowFilterMenu: false
|
||||
});
|
||||
this.resetAndFetch();
|
||||
},
|
||||
/** 新建出行 */
|
||||
toCreate() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/main/travel/editor/index"
|
||||
});
|
||||
},
|
||||
/** 查看详情 */
|
||||
toDetail(e: WechatMiniprogram.BaseEvent) {
|
||||
const { id } = e.currentTarget.dataset;
|
||||
wx.navigateTo({
|
||||
url: `/pages/main/travel/detail/index?id=${id}`
|
||||
});
|
||||
},
|
||||
});
|
||||
101
miniprogram/pages/main/tabs/travel/index.wxml
Normal file
101
miniprogram/pages/main/tabs/travel/index.wxml
Normal file
@ -0,0 +1,101 @@
|
||||
<!--pages/main/travel/index.wxml-->
|
||||
<view class="custom-navbar">
|
||||
<t-navbar title="出行计划" placeholder>
|
||||
<view slot="left" class="filter-btn" bind:tap="toggleFilterMenu">
|
||||
<t-icon name="filter" size="24px" />
|
||||
</view>
|
||||
</t-navbar>
|
||||
</view>
|
||||
|
||||
<!-- 筛选菜单 -->
|
||||
<view wx:if="{{isShowFilterMenu}}" class="filter-menu" catchtap="toggleFilterMenu">
|
||||
<t-cell-group
|
||||
class="content"
|
||||
theme="card"
|
||||
style="top: {{menuTop}}px; left: {{menuLeft}}px;"
|
||||
catchtap="stopPropagation"
|
||||
>
|
||||
<t-cell
|
||||
title="全部"
|
||||
leftIcon="bulletpoint"
|
||||
bind:tap="filterByStatus"
|
||||
data-status="ALL"
|
||||
rightIcon="{{currentStatus === 'ALL' ? 'check' : ''}}"
|
||||
/>
|
||||
<t-cell
|
||||
title="计划中"
|
||||
leftIcon="calendar"
|
||||
bind:tap="filterByStatus"
|
||||
data-status="PLANNING"
|
||||
rightIcon="{{currentStatus === 'PLANNING' ? 'check' : ''}}"
|
||||
/>
|
||||
<t-cell
|
||||
title="进行中"
|
||||
leftIcon="play-circle"
|
||||
bind:tap="filterByStatus"
|
||||
data-status="ONGOING"
|
||||
rightIcon="{{currentStatus === 'ONGOING' ? 'check' : ''}}"
|
||||
/>
|
||||
<t-cell
|
||||
title="已完成"
|
||||
leftIcon="check-circle"
|
||||
bind:tap="filterByStatus"
|
||||
data-status="COMPLETED"
|
||||
rightIcon="{{currentStatus === 'COMPLETED' ? 'check' : ''}}"
|
||||
/>
|
||||
</t-cell-group>
|
||||
</view>
|
||||
|
||||
<!-- 出行列表 -->
|
||||
<view class="travels">
|
||||
<!-- 空状态 -->
|
||||
<t-empty
|
||||
wx:if="{{!isFetching && list.length === 0}}"
|
||||
icon="travel"
|
||||
description="暂无出行计划"
|
||||
/>
|
||||
<!-- 列表内容 -->
|
||||
<view
|
||||
wx:for="{{list}}"
|
||||
wx:for-item="travel"
|
||||
wx:for-index="travelIndex"
|
||||
wx:key="id"
|
||||
class="travel"
|
||||
bind:tap="toDetail"
|
||||
data-id="{{travel.id}}"
|
||||
>
|
||||
<view class="header">
|
||||
<t-tag
|
||||
theme="{{travel.status === 'PLANNING' ? 'default' : travel.status === 'ONGOING' ? 'warning' : 'success'}}"
|
||||
variant="light"
|
||||
icon="{{statusIcons[travel.status]}}"
|
||||
>
|
||||
{{statusLabels[travel.status]}}
|
||||
</t-tag>
|
||||
</view>
|
||||
<view class="body">
|
||||
<view class="title">{{travel.title || '未命名出行'}}</view>
|
||||
<view wx:if="{{travel.content}}" class="content">{{travel.content}}</view>
|
||||
<view class="meta">
|
||||
<view wx:if="{{travel.travelDate}}" class="item">
|
||||
<t-icon name="time" size="16px" class="icon" />
|
||||
<text class="text">{{travel.travelDate}}</text>
|
||||
</view>
|
||||
<view wx:if="{{travel.days}}" class="item">
|
||||
<t-icon name="calendar" size="16px" class="icon" />
|
||||
<text class="text">{{travel.days}} 天</text>
|
||||
</view>
|
||||
<view wx:if="{{travel.transportationType}}" class="item">
|
||||
<t-icon name="{{transportIcons[travel.transportationType]}}" size="16px" class="icon" />
|
||||
<text class="text">{{transportLabels[travel.transportationType]}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 加载完成提示 -->
|
||||
<view wx:if="{{isFinished && 0 < list.length}}" class="finished">没有更多了</view>
|
||||
</view>
|
||||
<!-- 新建按钮 -->
|
||||
<view class="fab" bind:tap="toCreate">
|
||||
<t-icon name="add" size="24px" color="#fff" />
|
||||
</view>
|
||||
Reference in New Issue
Block a user