refactor travel

This commit is contained in:
Timi
2025-12-13 18:44:37 +08:00
parent 880e702288
commit 69659a1746
37 changed files with 4154 additions and 400 deletions

View File

@ -0,0 +1,13 @@
{
"component": true,
"usingComponents": {
"t-tag": "tdesign-miniprogram/tag/tag",
"t-icon": "tdesign-miniprogram/icon/icon",
"t-input": "tdesign-miniprogram/input/input",
"t-button": "tdesign-miniprogram/button/button",
"t-dialog": "tdesign-miniprogram/dialog/dialog",
"t-navbar": "tdesign-miniprogram/navbar/navbar",
"t-loading": "tdesign-miniprogram/loading/loading"
},
"styleIsolation": "shared"
}

View File

@ -0,0 +1,308 @@
// pages/main/travel-detail/index.less
.detail-container {
width: 100vw;
min-height: 100vh;
box-sizing: border-box;
background: var(--theme-bg-page);
.content {
gap: 24rpx;
display: flex;
padding-top: 48rpx;
flex-direction: column;
.status-section {
display: flex;
padding: 16rpx 0;
justify-content: center;
}
.title-section {
padding: 24rpx;
text-align: center;
background: var(--theme-bg-card);
box-shadow: 0 2px 12px var(--theme-shadow-light);
.title {
color: var(--theme-text-primary);
font-size: 40rpx;
font-weight: bold;
line-height: 1.5;
}
}
.info-card,
.content-card,
.locations-card {
overflow: hidden;
background: var(--theme-bg-card);
box-shadow: 0 2px 12px var(--theme-shadow-light);
.card-title {
display: flex;
padding: 24rpx;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--theme-border-light);
.title-left {
gap: 12rpx;
display: flex;
align-items: center;
.icon {
color: var(--theme-primary);
}
.text {
color: var(--theme-text-primary);
font-size: 32rpx;
font-weight: bold;
}
}
.title-right {
gap: 16rpx;
display: flex;
align-items: center;
.icon-btn {
display: flex;
padding: 8rpx;
align-items: center;
justify-content: center;
transition: all .2s;
&:active {
transform: scale(1.1);
}
}
}
}
.info-list {
padding: 24rpx;
.info-item {
display: flex;
padding: 20rpx 0;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--theme-border-light);
&:last-child {
border-bottom: none;
}
.label {
gap: 12rpx;
flex: 1;
display: flex;
align-items: center;
.icon {
color: var(--theme-text-secondary);
}
.text {
color: var(--theme-text-secondary);
font-size: 28rpx;
}
}
.value {
color: var(--theme-text-primary);
font-size: 28rpx;
font-weight: 500;
}
}
}
.content-text {
color: var(--theme-text-primary);
padding: 24rpx;
font-size: 28rpx;
line-height: 1.8;
white-space: pre-wrap;
word-break: break-all;
}
.loading-container {
display: flex;
padding: 48rpx;
align-items: center;
justify-content: center;
}
.locations-list {
padding: 24rpx;
.location-item {
gap: 24rpx;
display: flex;
padding: 24rpx;
margin-bottom: 20rpx;
border-radius: 12rpx;
background: var(--theme-bg-page);
border: 1px solid var(--theme-border-light);
transition: all .3s;
&:last-child {
margin-bottom: 0;
}
&:active {
transform: scale(.98);
background: var(--theme-bg-card);
}
.location-icon {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
}
.location-content {
gap: 16rpx;
flex: 1;
display: flex;
overflow: hidden;
flex-direction: column;
.location-header {
display: flex;
align-items: center;
justify-content: space-between;
.location-title {
flex: 1;
color: var(--theme-text-primary);
overflow: hidden;
font-size: 30rpx;
font-weight: bold;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.location-description {
color: var(--theme-text-secondary);
font-size: 26rpx;
line-height: 1.6;
word-break: break-all;
}
.location-info {
gap: 24rpx;
display: flex;
flex-wrap: wrap;
.info-item {
gap: 8rpx;
display: flex;
align-items: center;
color: var(--theme-text-secondary);
font-size: 24rpx;
}
}
}
.location-arrow {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
}
}
}
.empty-state {
gap: 16rpx;
display: flex;
padding: 64rpx 24rpx;
align-items: center;
flex-direction: column;
justify-content: center;
.empty-text {
color: var(--theme-text-secondary);
font-size: 26rpx;
}
}
}
.time-card {
gap: 16rpx;
display: flex;
padding: 24rpx;
flex-direction: column;
background: var(--theme-bg-card);
box-shadow: 0 2px 12px var(--theme-shadow-light);
.time-item {
display: flex;
align-items: center;
justify-content: space-between;
.label {
color: var(--theme-text-secondary);
font-size: 24rpx;
}
.value {
color: var(--theme-text-secondary);
font-size: 24rpx;
}
}
}
.action-section {
gap: 24rpx;
display: flex;
padding: 24rpx 16rpx 48rpx 16rpx;
.edit-btn {
flex: 2;
}
.delete-btn {
flex: 1;
}
}
}
}
.delete-dialog-content {
gap: 32rpx;
display: flex;
flex-direction: column;
.delete-warning {
gap: 16rpx;
display: flex;
padding: 24rpx;
align-items: center;
border-radius: 12rpx;
flex-direction: column;
background: #FFF4F4;
.warning-text {
color: #E34D59;
font-size: 28rpx;
text-align: center;
}
}
.delete-confirm {
gap: 16rpx;
display: flex;
flex-direction: column;
.confirm-label {
color: var(--theme-text-primary);
font-size: 28rpx;
}
}
}

View File

@ -0,0 +1,233 @@
// pages/main/travel-detail/index.ts
import Time from "../../../utils/Time";
import { TravelApi } from "../../../api/TravelApi";
import { TravelLocationApi } from "../../../api/TravelLocationApi";
import { Travel, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TravelLocation, TravelLocationTypeLabel, TravelLocationTypeIcon } from "../../../types/Travel";
interface TravelDetailData {
/** 旅行详情 */
travel: Travel | null;
/** 旅行 ID */
travelId: string;
/** 是否正在加载 */
isLoading: boolean;
/** 地点列表 */
locations: TravelLocation[];
/** 是否正在加载地点 */
isLoadingLocations: boolean;
/** 状态标签映射 */
statusLabels: typeof TravelStatusLabel;
/** 状态图标映射 */
statusIcons: typeof TravelStatusIcon;
/** 交通类型标签映射 */
transportLabels: typeof TransportationTypeLabel;
/** 地点类型标签映射 */
locationTypeLabels: typeof TravelLocationTypeLabel;
/** 地点类型图标映射 */
locationTypeIcons: typeof TravelLocationTypeIcon;
/** 删除对话框可见性 */
deleteDialogVisible: boolean;
/** 删除确认文本 */
deleteConfirmText: string;
}
Page({
data: <TravelDetailData>{
travel: null,
travelId: "",
isLoading: true,
locations: [],
isLoadingLocations: false,
statusLabels: TravelStatusLabel,
statusIcons: TravelStatusIcon,
transportLabels: TransportationTypeLabel,
locationTypeLabels: TravelLocationTypeLabel,
locationTypeIcons: TravelLocationTypeIcon,
deleteDialogVisible: false,
deleteConfirmText: ""
},
onLoad(options: any) {
const { id } = options;
if (id) {
this.setData({ travelId: id });
this.fetchDetail(id);
} else {
wx.showToast({
title: "参数错误",
icon: "error"
});
setTimeout(() => {
wx.navigateBack();
}, 1500);
}
},
onShow() {
// 页面显示时刷新地点列表(从编辑页返回时)
if (this.data.travelId && !this.data.isLoading) {
this.fetchLocations(this.data.travelId);
}
},
/** 获取旅行详情 */
async fetchDetail(id: string) {
this.setData({ isLoading: true });
try {
const travel = await TravelApi.getDetail(id);
// 格式化数据
if (travel.travelAt) {
travel.travelDate = Time.toDate(travel.travelAt);
travel.travelTime = Time.toTime(travel.travelAt);
}
// 格式化创建和更新时间
if (travel.createdAt) {
(travel as any).createdAtFormatted = Time.toDateTime(travel.createdAt);
}
if (travel.updatedAt) {
(travel as any).updatedAtFormatted = Time.toDateTime(travel.updatedAt);
}
this.setData({ travel });
// 获取地点列表
this.fetchLocations(id);
} catch (error) {
console.error("获取旅行详情失败:", error);
wx.showToast({
title: "加载失败",
icon: "error"
});
setTimeout(() => {
wx.navigateBack();
}, 1500);
} finally {
this.setData({ isLoading: false });
}
},
/** 获取地点列表 */
async fetchLocations(travelId: string) {
this.setData({ isLoadingLocations: true });
try {
const result = await TravelLocationApi.getList({
index: 0,
size: 100,
equalsExample: {
travelId: Number(travelId)
}
});
this.setData({ locations: result.list });
} catch (error) {
console.error("获取地点列表失败:", error);
} finally {
this.setData({ isLoadingLocations: false });
}
},
/** 编辑旅行 */
toEdit() {
const { travel } = this.data;
if (travel && travel.id) {
wx.navigateTo({
url: `/pages/main/travel-editor/index?id=${travel.id}`
});
}
},
/** 新增地点 */
toAddLocation() {
const { travel } = this.data;
if (travel && travel.id) {
wx.navigateTo({
url: `/pages/main/travel-location-editor/index?travelId=${travel.id}`
});
}
},
/** 编辑地点 */
toEditLocation(e: WechatMiniprogram.BaseEvent) {
const { id } = e.currentTarget.dataset;
const { travel } = this.data;
if (id && travel && travel.id) {
wx.navigateTo({
url: `/pages/main/travel-location-editor/index?id=${id}&travelId=${travel.id}`
});
}
},
/** 跳转地图 */
toMap() {
const { travel } = this.data;
if (travel && travel.id) {
wx.navigateTo({
url: `/pages/main/travel-location-map/index?travelId=${travel.id}`
});
}
},
/** 删除旅行 */
deleteTravel() {
this.setData({
deleteDialogVisible: true,
deleteConfirmText: ""
});
},
/** 取消删除 */
cancelDelete() {
this.setData({
deleteDialogVisible: false,
deleteConfirmText: ""
});
},
/** 确认删除 */
confirmDelete() {
const inputText = this.data.deleteConfirmText.trim();
if (inputText !== "确认删除") {
wx.showToast({
title: "输入不匹配",
icon: "error"
});
return;
}
this.setData({
deleteDialogVisible: false
});
this.executeDelete();
},
/** 执行删除 */
async executeDelete() {
if (!this.data.travel || !this.data.travel.id) return;
wx.showLoading({ title: "删除中...", mask: true });
try {
await TravelApi.delete(this.data.travel.id);
wx.showToast({
title: "删除成功",
icon: "success"
});
setTimeout(() => {
wx.navigateBack();
}, 1500);
} catch (error) {
// 错误已由 Network 类处理
} finally {
wx.hideLoading();
}
},
/** 返回 */
goBack() {
wx.navigateBack();
}
});

View File

@ -0,0 +1,208 @@
<!--pages/main/travel-detail/index.wxml-->
<view class="custom-navbar">
<t-navbar title="旅行详情" leftArrow bind:go-back="goBack">
<view slot="right" class="edit-btn" bind:tap="toEdit">
<t-icon name="edit" size="24px" />
</view>
</t-navbar>
</view>
<view class="detail-container">
<!-- 加载状态 -->
<t-loading wx:if="{{isLoading}}" theme="dots" size="40rpx" />
<!-- 详情内容 -->
<view wx:if="{{!isLoading && travel}}" class="content">
<!-- 状态标签 -->
<view class="status-section">
<t-tag
size="large"
theme="{{travel.status === 'PLANNING' ? 'default' : travel.status === 'ONGOING' ? 'warning' : 'success'}}"
variant="light"
icon="{{statusIcons[travel.status]}}"
>
{{statusLabels[travel.status]}}
</t-tag>
</view>
<!-- 标题 -->
<view class="title-section">
<text class="title">{{travel.title || '未命名旅行'}}</text>
</view>
<!-- 基本信息 -->
<view class="info-card">
<view class="card-title">
<t-icon name="info-circle" size="20px" class="icon" />
<text class="text">基本信息</text>
</view>
<view class="info-list">
<view class="info-item">
<view class="label">
<t-icon name="time" size="18px" class="icon" />
<text class="text">出行时间</text>
</view>
<view class="value">{{travel.travelDate}} {{travel.travelTime}}</view>
</view>
<view wx:if="{{travel.days}}" class="info-item">
<view class="label">
<t-icon name="calendar" size="18px" class="icon" />
<text class="text">旅行天数</text>
</view>
<view class="value">{{travel.days}} 天</view>
</view>
<view wx:if="{{travel.transportationType}}" class="info-item">
<view class="label">
<t-icon name="{{travel.transportationType === 'PLANE' ? 'flight-takeoff' : travel.transportationType === 'TRAIN' ? 'map-route' : travel.transportationType === 'SELF_DRIVING' ? 'control-platform' : 'location'}}" size="18px" class="icon" />
<text class="text">交通方式</text>
</view>
<view class="value">{{transportLabels[travel.transportationType]}}</view>
</view>
</view>
</view>
<!-- 旅行内容 -->
<view wx:if="{{travel.content}}" class="content-card">
<view class="card-title">
<t-icon name="edit" size="20px" class="icon" />
<text class="text">详细说明</text>
</view>
<view class="content-text">{{travel.content}}</view>
</view>
<!-- 地点列表 -->
<view class="locations-card">
<view class="card-title">
<view class="title-left">
<t-icon name="location" size="20px" class="icon" />
<text class="text">地点列表</text>
</view>
<view class="title-right">
<view class="icon-btn" catch:tap="toMap">
<t-icon name="map" size="20px" color="#5E7CE0" />
</view>
<view class="icon-btn" catch:tap="toAddLocation">
<t-icon name="add" size="20px" color="#5E7CE0" />
</view>
</view>
</view>
<!-- 加载中 -->
<view wx:if="{{isLoadingLocations}}" class="loading-container">
<t-loading theme="dots" size="40rpx" />
</view>
<!-- 地点列表 -->
<view wx:elif="{{locations.length > 0}}" class="locations-list">
<view
wx:for="{{locations}}"
wx:key="id"
class="location-item"
bind:tap="toEditLocation"
data-id="{{item.id}}"
>
<view class="location-icon">
<t-icon name="{{locationTypeIcons[item.type]}}" size="24px" color="#5E7CE0" />
</view>
<view class="location-content">
<view class="location-header">
<text class="location-title">{{item.title || '未命名地点'}}</text>
<t-tag size="small" variant="light">{{locationTypeLabels[item.type]}}</t-tag>
</view>
<view wx:if="{{item.description}}" class="location-description">{{item.description}}</view>
<view class="location-info">
<view wx:if="{{item.location}}" class="info-item">
<t-icon name="location" size="14px" />
<text>{{item.location}}</text>
</view>
<view wx:if="{{item.amount}}" class="info-item">
<t-icon name="money-circle" size="14px" />
<text>¥{{item.amount}}</text>
</view>
<view wx:if="{{item.requireIdCard}}" class="info-item">
<t-icon name="user" size="14px" />
<text>需要身份证</text>
</view>
<view wx:if="{{item.score}}" class="info-item">
<t-icon name="star" size="14px" />
<text>必要度 {{item.score}}</text>
</view>
</view>
</view>
<view class="location-arrow">
<t-icon name="chevron-right" size="20px" color="#DCDCDC" />
</view>
</view>
</view>
<!-- 空状态 -->
<view wx:else class="empty-state">
<t-icon name="location" size="48px" color="#DCDCDC" />
<text class="empty-text">暂无地点信息</text>
</view>
</view>
<!-- 时间信息 -->
<view class="time-card">
<view class="time-item">
<text class="label">创建时间</text>
<text class="value">{{travel.createdAtFormatted || ''}}</text>
</view>
<view wx:if="{{travel.updatedAt && travel.updatedAt !== travel.createdAt}}" class="time-item">
<text class="label">更新时间</text>
<text class="value">{{travel.updatedAtFormatted || ''}}</text>
</view>
</view>
<!-- 操作按钮 -->
<view class="action-section">
<t-button
theme="danger"
variant="outline"
size="large"
icon="delete"
t-class="delete-btn"
bind:tap="deleteTravel"
>
删除
</t-button>
<t-button
theme="primary"
size="large"
icon="edit"
t-class="edit-btn"
bind:tap="toEdit"
>
编辑旅行计划
</t-button>
</view>
</view>
</view>
<!-- 删除确认对话框 -->
<t-dialog
visible="{{deleteDialogVisible}}"
title="删除旅行计划"
confirm-btn="删除"
cancel-btn="取消"
bind:confirm="confirmDelete"
bind:cancel="cancelDelete"
>
<view class="delete-dialog-content">
<view class="delete-warning">
<t-icon name="error-circle" size="48rpx" color="#E34D59" />
<text class="warning-text">删除后无法恢复,请谨慎操作!</text>
</view>
<view class="delete-confirm">
<text class="confirm-label">请输入"确认删除"以继续:</text>
<t-input
placeholder="请输入确认删除"
model:value="{{deleteConfirmText}}"
borderless="{{false}}"
/>
</view>
</view>
</t-dialog>