fix travel style
This commit is contained in:
17
miniprogram/pages/main/travel-location-detail/index.json
Normal file
17
miniprogram/pages/main/travel-location-detail/index.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-tag": "tdesign-miniprogram/tag/tag",
|
||||
"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"
|
||||
}
|
||||
144
miniprogram/pages/main/travel-location-detail/index.less
Normal file
144
miniprogram/pages/main/travel-location-detail/index.less
Normal file
@ -0,0 +1,144 @@
|
||||
// pages/main/travel-location-detail/index.less
|
||||
.travel-location-detail {
|
||||
width: 100vw;
|
||||
min-height: 100vh;
|
||||
background: var(--theme-bg-page);
|
||||
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;
|
||||
}
|
||||
|
||||
&.status {
|
||||
display: flex;
|
||||
margin-top: 24rpx;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
&.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;
|
||||
}
|
||||
|
||||
.mini-map {
|
||||
width: 100%;
|
||||
height: 520rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&.media {
|
||||
|
||||
.media-grid {
|
||||
gap: 16rpx;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
.media-item {
|
||||
width: 100%;
|
||||
height: 200rpx;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border-radius: 12rpx;
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
&.action {
|
||||
gap: 24rpx;
|
||||
display: flex;
|
||||
padding: 24rpx 16rpx 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;
|
||||
}
|
||||
}
|
||||
291
miniprogram/pages/main/travel-location-detail/index.ts
Normal file
291
miniprogram/pages/main/travel-location-detail/index.ts
Normal file
@ -0,0 +1,291 @@
|
||||
// pages/main/travel-location-detail/index.ts
|
||||
|
||||
import Time from "../../../utils/Time";
|
||||
import config from "../../../config/index";
|
||||
import { TravelLocationApi } from "../../../api/TravelLocationApi";
|
||||
import { TravelLocation, TravelLocationTypeIcon, TravelLocationTypeLabel } from "../../../types/Travel";
|
||||
import { MediaAttachExt, MediaAttachType } from "../../../types/Attachment";
|
||||
import { MediaItem, MediaItemType } from "../../../types/UI";
|
||||
import Toolkit from "../../../utils/Toolkit";
|
||||
|
||||
interface TravelLocationView extends TravelLocation {
|
||||
/** 首次出行时间 */
|
||||
firstTravelTime?: string;
|
||||
/** 最近出行时间 */
|
||||
lastTravelTime?: string;
|
||||
/** 媒体列表 */
|
||||
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: WechatMiniprogram.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 extStr = thumbItem.ext ? thumbItem.ext.toString() : "";
|
||||
if (!extStr) {
|
||||
return;
|
||||
}
|
||||
const ext = JSON.parse(extStr) as MediaAttachExt;
|
||||
const thumbURL = `${config.url}/attachment/read/${thumbItem.mongoId}`;
|
||||
const sourceURL = `${config.url}/attachment/read/${ext.sourceMongoId}`;
|
||||
mediaItems.push({
|
||||
type: ext.isVideo ? MediaItemType.VIDEO : MediaItemType.IMAGE,
|
||||
thumbURL,
|
||||
sourceURL,
|
||||
size: thumbItem.size || 0,
|
||||
attachmentId: thumbItem.id!
|
||||
});
|
||||
} catch (parseError) {
|
||||
console.warn("解析附件扩展信息失败", parseError);
|
||||
}
|
||||
});
|
||||
|
||||
// 构建地图标记
|
||||
const mapMarkers: WechatMiniprogram.MapMarker[] = [];
|
||||
if (location.lat !== undefined && location.lng !== undefined) {
|
||||
mapMarkers.push({
|
||||
id: 0,
|
||||
latitude: location.lat,
|
||||
longitude: location.lng,
|
||||
width: 30,
|
||||
height: 30,
|
||||
callout: {
|
||||
content: location.title || "地点",
|
||||
display: "ALWAYS",
|
||||
padding: 10,
|
||||
borderRadius: 5,
|
||||
bgColor: "#FFFFFF",
|
||||
color: "#333333",
|
||||
fontSize: 12,
|
||||
textAlign: "center"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log(mediaItems);
|
||||
|
||||
this.setData({
|
||||
location: {
|
||||
...location,
|
||||
mediaItems,
|
||||
firstTravelTime: location.firstTraveledAt ? Time.toDateTime(location.firstTraveledAt) : "",
|
||||
lastTravelTime: location.lastTraveledAt ? Time.toDateTime(location.lastTraveledAt) : ""
|
||||
},
|
||||
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: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
|
||||
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,需要延时
|
||||
}
|
||||
});
|
||||
165
miniprogram/pages/main/travel-location-detail/index.wxml
Normal file
165
miniprogram/pages/main/travel-location-detail/index.wxml
Normal file
@ -0,0 +1,165 @@
|
||||
<!--pages/main/travel-location-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="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 status">
|
||||
<t-tag size="large" theme="primary" variant="light" icon="{{locationTypeIcons[location.type]}}">
|
||||
{{locationTypeLabels[location.type]}}
|
||||
</t-tag>
|
||||
</view>
|
||||
<!-- 标题 -->
|
||||
<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 class="map">
|
||||
<map
|
||||
slot="description"
|
||||
class="mini-map"
|
||||
latitude="{{location.lat}}"
|
||||
longitude="{{location.lng}}"
|
||||
markers="{{mapMarkers}}"
|
||||
scale="15"
|
||||
show-location
|
||||
></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 ? 'warning' : ''}}">
|
||||
{{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 class="section">
|
||||
<view slot="title" class="title">出行记录</view>
|
||||
<t-cell left-icon="flag" title="首次出行">
|
||||
<view slot="note">{{location.firstTravelTime || '未记录'}}</view>
|
||||
</t-cell>
|
||||
<t-cell left-icon="calendar-1" title="最近出行">
|
||||
<view slot="note">{{location.lastTravelTime || '未记录'}}</view>
|
||||
</t-cell>
|
||||
<t-cell left-icon="chart" title="累计次数">
|
||||
<view slot="note">{{location.travelCount || 0}} 次</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 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>
|
||||
Reference in New Issue
Block a user