refactor pages struct

This commit is contained in:
Timi
2026-01-28 14:11:54 +08:00
parent 8adc28ae9c
commit 965743be38
73 changed files with 234 additions and 176 deletions

View File

@@ -0,0 +1,16 @@
{
"component": true,
"usingComponents": {
"t-cell": "tdesign-miniprogram/cell/cell",
"t-rate": "tdesign-miniprogram/rate/rate",
"t-icon": "tdesign-miniprogram/icon/icon",
"t-input": "tdesign-miniprogram/input/input",
"t-button": "tdesign-miniprogram/button/button",
"t-empty": "tdesign-miniprogram/empty/empty",
"t-dialog": "tdesign-miniprogram/dialog/dialog",
"t-navbar": "tdesign-miniprogram/navbar/navbar",
"t-loading": "tdesign-miniprogram/loading/loading",
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group"
},
"styleIsolation": "shared"
}

View File

@@ -0,0 +1,150 @@
// pages/main/travel/location-detail/index.less
.travel-location-detail {
width: 100vw;
min-height: 100vh;
box-sizing: border-box;
.status-card {
padding: 64rpx 24rpx;
}
.content {
display: flex;
padding-top: 48rpx;
flex-direction: column;
padding-bottom: 128rpx;
.section {
margin-top: 32rpx;
> .title {
color: var(--theme-text-secondary);
padding: 0 32rpx;
font-size: 28rpx;
line-height: 64rpx;
}
&.title {
color: var(--theme-text-primary);
padding: 24rpx;
text-align: center;
margin-top: 24rpx;
background: var(--theme-bg-card);
box-shadow: 0 2px 12px var(--theme-shadow-light);
.title-text {
color: var(--theme-text-primary);
font-size: 40rpx;
font-weight: bold;
line-height: 1.5;
}
.subtitle {
color: var(--theme-text-secondary);
display: block;
font-size: 28rpx;
margin-top: 12rpx;
}
}
&.location {
.t-cell__title {
margin: 0;
}
.map {
padding: 0;
.instance {
width: 100%;
height: 520rpx;
.marker {
width: calc(var(--title-length) * 28rpx);
color: var(--theme-text-primary);
padding: 8rpx;
overflow: hidden;
font-size: 28rpx;
background: var(--theme-bg-card);
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, .15);
white-space: nowrap;
border-radius: 8rpx;
text-overflow: ellipsis;
}
}
}
}
&.media {
.media-grid {
gap: 16rpx;
display: grid;
grid-template-columns: repeat(3, 1fr);
.media-item {
width: 220rpx;
height: 220rpx;
overflow: hidden;
position: relative;
.thumbnail {
width: 100%;
height: 100%;
}
.video-container {
width: 100%;
height: 100%;
position: relative;
.thumbnail {
width: 100%;
height: 100%;
}
.play-icon {
top: 50%;
left: 50%;
color: rgba(255, 255, 255, .9);
position: absolute;
transform: translate(-50%, -50%);
}
}
}
}
}
&.navigate {
padding: 0 16rpx;
margin-top: 90rpx;
}
&.action {
gap: 24rpx;
display: flex;
padding: 0 16rpx;
.edit {
flex: 2;
}
.delete {
flex: 1;
}
}
}
}
}
.delete-dialog {
padding: 16rpx 0;
.tips {
color: var(--theme-text-secondary);
font-size: 28rpx;
line-height: 1.5;
margin-bottom: 24rpx;
}
}

View File

@@ -0,0 +1,273 @@
// pages/main/travel/location-detail/index.ts
import config from "../../../../config/index";
import { TravelLocationApi } from "../../../../api/TravelLocationApi";
import { TravelLocation, TravelLocationTypeIcon, TravelLocationTypeLabel } from "../../../../types/Travel";
import { MediaAttachType, PreviewImageMetadata } from "../../../../types/Attachment";
import { MapMarker, MediaItem, MediaItemType } from "../../../../types/UI";
import Toolkit from "../../../../utils/Toolkit";
interface TravelLocationView extends TravelLocation {
/** 媒体列表 */
mediaItems?: MediaItem[];
}
interface TravelLocationDetailData {
/** 地点详情 */
location: TravelLocationView | null;
/** 地点 ID */
locationId: string;
/** 出行 ID */
travelId: string;
/** 是否正在加载 */
isLoading: boolean;
/** 错误信息 */
errorMessage: string;
/** 地点类型标签映射 */
locationTypeLabels: typeof TravelLocationTypeLabel;
/** 地点类型图标映射 */
locationTypeIcons: typeof TravelLocationTypeIcon;
/** 媒体类型枚举 */
mediaItemTypeEnum: typeof MediaItemType;
/** 地图标记 */
mapMarkers: MapMarker[];
/** 删除对话框可见性 */
deleteDialogVisible: boolean;
/** 删除确认文本 */
deleteConfirmText: string;
}
Page({
data: <TravelLocationDetailData>{
location: null,
locationId: "",
travelId: "",
isLoading: true,
errorMessage: "",
locationTypeLabels: TravelLocationTypeLabel,
locationTypeIcons: TravelLocationTypeIcon,
mediaItemTypeEnum: {
...MediaItemType
},
mapMarkers: [],
deleteDialogVisible: false,
deleteConfirmText: ""
},
onLoad(options: any) {
const { id, travelId } = options;
if (id) {
this.setData({
locationId: id,
travelId: travelId || ""
});
this.fetchDetail(id);
} else {
wx.showToast({
title: "参数错误",
icon: "error"
});
setTimeout(() => {
wx.navigateBack();
}, 1500);
}
},
onShow() {
// 页面显示时刷新数据(从编辑页返回时)
if (this.data.locationId && !this.data.isLoading && this.data.location) {
this.fetchDetail(this.data.locationId);
}
},
/** 获取地点详情 */
async fetchDetail(id: string) {
this.setData({
isLoading: true,
errorMessage: ""
});
try {
const location = await TravelLocationApi.getDetail(id);
const thumbItems = (location.items || []).filter((item) => item.attachType === MediaAttachType.THUMB);
const mediaItems: MediaItem[] = [];
thumbItems.forEach((thumbItem) => {
try {
const metadata = (typeof thumbItem.metadata === "string" ? JSON.parse(thumbItem.metadata) : thumbItem.metadata) as PreviewImageMetadata;
const thumbURL = `${config.url}/attachment/read/${thumbItem.mongoId}`;
const sourceURL = `${config.url}/attachment/read/${metadata.sourceMongoId}`;
const isVideo = metadata.sourceMimeType?.startsWith("video/");
mediaItems.push({
type: isVideo ? MediaItemType.VIDEO : MediaItemType.IMAGE,
thumbURL,
sourceURL,
size: thumbItem.size || 0,
attachmentId: thumbItem.id!
});
} catch (parseError) {
console.warn("解析附件元数据失败", parseError);
}
});
// 构建地图标记
const mapMarkers: MapMarker[] = [];
if (location.lat !== undefined && location.lng !== undefined) {
mapMarkers.push({
id: 0,
latitude: location.lat,
longitude: location.lng,
width: 24,
height: 30,
customCallout: {
anchorY: -2,
anchorX: 0,
display: "ALWAYS"
}
});
}
this.setData({
location: {
...location,
mediaItems
},
travelId: location.travelId ? String(location.travelId) : this.data.travelId,
mapMarkers
});
} catch (error) {
console.error("获取地点详情失败:", error);
this.setData({
errorMessage: "加载失败,请稍后重试"
});
wx.showToast({
title: "加载失败",
icon: "error"
});
} finally {
this.setData({ isLoading: false });
}
},
/** 重新加载 */
retryFetch() {
if (this.data.locationId) {
this.fetchDetail(this.data.locationId);
}
},
/** 编辑地点 */
toEdit() {
const { location, travelId } = this.data;
if (location && location.id) {
wx.navigateTo({
url: `/pages/main/travel/location-editor/index?id=${location.id}&travelId=${travelId || location.travelId || ""}`
});
}
},
/** 出发(打开地图导航) */
navigate() {
const { location } = this.data;
if (location && location.lat !== undefined && location.lng !== undefined) {
wx.openLocation({
latitude: location.lat,
longitude: location.lng,
name: location.title || "目的地",
address: location.location || "",
scale: 15
});
} else {
wx.showToast({
title: "位置信息不完整",
icon: "error"
});
}
},
/** 预览媒体 */
preview(e: WechatMiniprogram.BaseEvent) {
const index = e.currentTarget.dataset.index;
const { location } = this.data;
if (!location || !location.mediaItems) {
return;
}
const sources = location.mediaItems.map(item => ({
url: item.sourceURL,
type: item.type
}));
const total = sources.length;
const startIndex = Math.max(0, index - 25);
const endIndex = Math.min(total, startIndex + 50);
const newCurrentIndex = index - startIndex;
wx.previewMedia({
current: newCurrentIndex,
sources: sources.slice(startIndex, endIndex) as WechatMiniprogram.MediaSource[]
});
},
/** 删除地点 */
deleteLocation() {
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.location || !this.data.location.id) {
return;
}
wx.showLoading({ title: "删除中...", mask: true });
try {
await TravelLocationApi.delete(this.data.location.id);
wx.showToast({
title: "删除成功",
icon: "success"
});
setTimeout(() => {
wx.navigateBack();
}, 1500);
} catch (error) {
// 错误已由 Network 类处理
} finally {
wx.hideLoading();
}
},
/** 返回 */
async goBack() {
Toolkit.async(() => wx.navigateBack()); // 微信 BUG需要延时
}
});

View File

@@ -0,0 +1,157 @@
<!--pages/main/travel/location-detail/index.wxml-->
<view class="custom-navbar">
<t-navbar title="地点详情" leftArrow placeholder 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="travel-location-detail setting-bg">
<t-loading wx:if="{{isLoading}}" theme="dots" size="40rpx" />
<view wx:elif="{{errorMessage}}" class="status-card">
<t-empty icon="error-circle" description="{{errorMessage}}">
<t-button size="small" theme="primary" variant="outline" bind:tap="retryFetch">
重新加载
</t-button>
</t-empty>
</view>
<view wx:elif="{{!location}}" class="status-card">
<t-empty icon="location" description="暂无地点信息" />
</view>
<view wx:else class="content">
<!-- 标题 -->
<view class="section title">
<text class="title-text">{{location.title || '未命名地点'}}</text>
</view>
<!-- 位置信息 -->
<t-cell-group wx:if="{{location.lat !== undefined && location.lng !== undefined}}" class="section location">
<view slot="title" class="title">位置信息</view>
<t-cell
left-icon="{{locationTypeIcons[location.type]}}"
title="类型"
note="{{locationTypeLabels[location.type]}}"
/>
<t-cell class="map">
<map
slot="description"
class="instance"
latitude="{{location.lat}}"
longitude="{{location.lng}}"
markers="{{mapMarkers}}"
scale="15"
show-location
>
<cover-view slot="callout">
<cover-view class="marker" marker-id="0" style="--title-length: {{location.title.length}}">
{{location.title || '地点'}}
</cover-view>
</cover-view>
</map>
</t-cell>
<t-cell
left-icon="location"
title="{{location.location || '位置信息'}}"
arrow
bind:tap="navigate"
/>
</t-cell-group>
<!-- 基础信息 -->
<t-cell-group class="section info">
<view slot="title" class="title">基础信息</view>
<t-cell wx:if="{{location.amount !== undefined && location.amount !== null}}" left-icon="money" title="费用">
<view slot="note">¥{{location.amount}}</view>
</t-cell>
<t-cell left-icon="verify" title="身份证">
<view slot="note" class="{{location.requireIdCard ? 'red' : ''}}">
{{location.requireIdCard ? '需要' : '无需'}}
</view>
</t-cell>
<t-cell left-icon="calendar" title="预约">
<view slot="note" class="{{location.requireAppointment ? 'red' : ''}}">
{{location.requireAppointment ? '需要' : '无需'}}
</view>
</t-cell>
<t-cell wx:if="{{location.score !== undefined && location.score !== null}}" left-icon="star" title="评分">
<view slot="note">
<t-rate value="{{location.score}}" count="{{5}}" size="20px" readonly />
</view>
</t-cell>
<t-cell wx:if="{{location.importance !== undefined && location.importance !== null}}" left-icon="chart-bubble" title="重要程度">
<view slot="note">
<t-rate value="{{location.importance}}" count="{{5}}" size="20px" readonly />
</view>
</t-cell>
</t-cell-group>
<!-- 详细说明 -->
<t-cell-group wx:if="{{location.description}}" class="section">
<view slot="title" class="title">详细说明</view>
<t-cell title="{{location.description}}" />
</t-cell-group>
<!-- 照片/视频 -->
<t-cell-group wx:if="{{location.mediaItems && 0 < location.mediaItems.length}}" class="section media">
<view slot="title" class="title">照片视频</view>
<t-cell>
<view slot="title" class="media-grid">
<view
wx:for="{{location.mediaItems}}"
wx:key="attachmentId"
class="media-item"
bind:tap="preview"
data-index="{{index}}"
>
<image
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
src="{{item.thumbURL}}"
class="thumbnail"
mode="aspectFill"
></image>
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
<image src="{{item.thumbURL}}" class="thumbnail" mode="aspectFill"></image>
<t-icon class="play-icon" name="play-circle-filled" size="48px" />
</view>
</view>
</view>
</t-cell>
</t-cell-group>
<view class="section navigate">
<t-button theme="primary" size="large" icon="rocket" block bind:tap="navigate">
出发导航
</t-button>
</view>
<!-- 操作按钮 -->
<view class="section action">
<t-button
theme="danger"
variant="outline"
size="large"
icon="delete"
t-class="delete"
bind:tap="deleteLocation"
>
删除
</t-button>
<t-button theme="primary" size="large" icon="edit" t-class="edit" bind:tap="toEdit">
编辑地点
</t-button>
</view>
</view>
</view>
<t-dialog
visible="{{deleteDialogVisible}}"
title="删除地点"
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
cancel-btn="取消"
bind:confirm="confirmDelete"
bind:cancel="cancelDelete"
>
<view slot="content" class="delete-dialog">
<view class="tips">
<text>此地点的图片和视频也会同步删除,删除后无法恢复,请输入 "</text>
<text style="color: var(--theme-error)">确认删除</text>
<text>" 以继续</text>
</view>
<t-input placeholder="请输入:确认删除" model:value="{{deleteConfirmText}}" />
</view>
</t-dialog>