refactor travel
This commit is contained in:
8
miniprogram/components/travel-location-popup/index.json
Normal file
8
miniprogram/components/travel-location-popup/index.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-popup": "tdesign-miniprogram/popup/popup",
|
||||
"t-tag": "tdesign-miniprogram/tag/tag"
|
||||
}
|
||||
}
|
||||
173
miniprogram/components/travel-location-popup/index.less
Normal file
173
miniprogram/components/travel-location-popup/index.less
Normal file
@ -0,0 +1,173 @@
|
||||
/* components/travel-location-popup/index.less */
|
||||
.detail-panel {
|
||||
width: 100%;
|
||||
height: 70vh;
|
||||
display: flex;
|
||||
border-radius: 16rpx 16rpx 0 0;
|
||||
flex-direction: column;
|
||||
|
||||
.detail-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
flex-direction: column;
|
||||
|
||||
> .header {
|
||||
display: flex;
|
||||
padding: 32rpx 32rpx 0 32rpx;
|
||||
flex-shrink: 0;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 24rpx;
|
||||
justify-content: space-between;
|
||||
|
||||
.info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
flex-direction: column;
|
||||
|
||||
.title-row {
|
||||
gap: 8rpx;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
align-items: center;
|
||||
margin-bottom: 8rpx;
|
||||
|
||||
.type-icon {
|
||||
color: var(--theme-wx);
|
||||
font-size: 36rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.title {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
.location {
|
||||
gap: 4rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.icon {
|
||||
color: var(--theme-wx);
|
||||
font-size: 28rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.text {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
font-size: 24rpx;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
gap: 16rpx;
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
|
||||
.indicator {
|
||||
color: var(--theme-wx);
|
||||
padding: 4rpx 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: bold;
|
||||
background: var(--theme-bg-journal);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.locations-swiper {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
|
||||
.swiper-item-wrapper {
|
||||
height: 100%;
|
||||
|
||||
.location-scroll {
|
||||
height: 100%;
|
||||
|
||||
.location-item {
|
||||
display: flex;
|
||||
padding: 0 32rpx 128rpx 32rpx;
|
||||
flex-direction: column;
|
||||
|
||||
.tags {
|
||||
gap: 12rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.description {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.items {
|
||||
gap: 8rpx;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
|
||||
.column {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.item {
|
||||
overflow: hidden;
|
||||
background: var(--theme-bg-card);
|
||||
margin-bottom: 8rpx;
|
||||
|
||||
&.thumbnail {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
&.video {
|
||||
position: relative;
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
top: 50%;
|
||||
left: 53%;
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
transform: translate(-50%, -50%);
|
||||
border-top: 16px solid transparent;
|
||||
border-left: 24px solid var(--theme-video-play);
|
||||
border-bottom: 16px solid transparent;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty {
|
||||
color: var(--td-text-color-placeholder);
|
||||
padding: 64rpx 0;
|
||||
font-size: 28rpx;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
141
miniprogram/components/travel-location-popup/index.ts
Normal file
141
miniprogram/components/travel-location-popup/index.ts
Normal file
@ -0,0 +1,141 @@
|
||||
// components/travel-location-popup/index.ts
|
||||
import { TravelLocation, TravelLocationTypeLabel, TravelLocationTypeIcon } from "../../types/Travel";
|
||||
import { TravelLocationApi } from "../../api/TravelLocationApi";
|
||||
import { MediaAttachExt, MediaAttachType } from "../../types/Attachment";
|
||||
import { MediaItem, MediaItemType } from "../../types/UI";
|
||||
import config from "../../config/index";
|
||||
import Toolkit from "../../utils/Toolkit";
|
||||
|
||||
interface TravelLocationPopupData {
|
||||
locations: TravelLocation[];
|
||||
currentLocationIndex: number;
|
||||
}
|
||||
|
||||
Component({
|
||||
properties: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
ids: {
|
||||
type: Array,
|
||||
value: []
|
||||
}
|
||||
},
|
||||
data: <TravelLocationPopupData>{
|
||||
locations: [],
|
||||
currentLocationIndex: 0,
|
||||
},
|
||||
observers: {
|
||||
async 'ids, visible'(ids: number[], visible: boolean) {
|
||||
if (visible && ids && 0 < ids.length) {
|
||||
wx.showLoading({ title: "加载中...", mask: true });
|
||||
try {
|
||||
const locations = await TravelLocationApi.getListByIds(ids);
|
||||
|
||||
locations.forEach(location => {
|
||||
location.typeLabel = location.type ? TravelLocationTypeLabel[location.type] : "";
|
||||
location.typeIcon = location.type ? TravelLocationTypeIcon[location.type] : "";
|
||||
|
||||
// 处理附件数据
|
||||
const attachments = location.items || [];
|
||||
const thumbItems = attachments.filter((item: any) => item.attachType === MediaAttachType.THUMB);
|
||||
|
||||
if (0 < thumbItems.length) {
|
||||
const mediaItems: MediaItem[] = thumbItems.map((thumbItem: any, index: number) => {
|
||||
const metadata = thumbItem.metadata;
|
||||
const ext = typeof thumbItem.ext === "string" ? JSON.parse(thumbItem.ext) : thumbItem.ext;
|
||||
const thumbURL = `${config.url}/attachment/read/${thumbItem.mongoId}`;
|
||||
const sourceURL = `${config.url}/attachment/read/${ext.sourceMongoId}`;
|
||||
return {
|
||||
type: ext.isVideo ? MediaItemType.VIDEO : MediaItemType.IMAGE,
|
||||
thumbURL,
|
||||
sourceURL,
|
||||
size: thumbItem.size || 0,
|
||||
attachmentId: thumbItem.id,
|
||||
width: metadata?.width,
|
||||
height: metadata?.height,
|
||||
originalIndex: index
|
||||
} as MediaItem;
|
||||
});
|
||||
|
||||
location.mediaItems = mediaItems;
|
||||
location.columnedItems = Toolkit.splitItemsIntoColumns(mediaItems, 3, (item) => {
|
||||
if (item.width && item.height && 0 < item.width) {
|
||||
return item.height / item.width;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.setData({
|
||||
locations,
|
||||
currentLocationIndex: 0,
|
||||
});
|
||||
wx.hideLoading();
|
||||
} catch (err: any) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: err.message || "加载失败",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
/** 关闭详情 */
|
||||
closeDetail() {
|
||||
this.triggerEvent("close");
|
||||
},
|
||||
/** swiper 切换事件 */
|
||||
onSwiperChange(e: WechatMiniprogram.SwiperChange) {
|
||||
this.setData({
|
||||
currentLocationIndex: e.detail.current
|
||||
});
|
||||
},
|
||||
/** 打开位置 */
|
||||
openLocation() {
|
||||
const location = this.data.locations[this.data.currentLocationIndex];
|
||||
if (location && location.lat && location.lng) {
|
||||
wx.openLocation({
|
||||
latitude: location.lat,
|
||||
longitude: location.lng,
|
||||
name: location.title || "地点",
|
||||
address: location.location || ""
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 预览媒体 */
|
||||
previewMedia(e: WechatMiniprogram.BaseEvent) {
|
||||
const locations = this.data.locations;
|
||||
if (!locations || locations.length === 0) {
|
||||
return;
|
||||
}
|
||||
const { itemIndex } = e.currentTarget.dataset;
|
||||
const location = locations[this.data.currentLocationIndex];
|
||||
const items = (location as any).mediaItems;
|
||||
if (!items || items.length === 0) {
|
||||
return;
|
||||
}
|
||||
const total = items.length;
|
||||
|
||||
const startIndex = Math.max(0, itemIndex - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = itemIndex - startIndex;
|
||||
|
||||
const sources = items.slice(startIndex, endIndex).map((item: MediaItem) => {
|
||||
return {
|
||||
url: item.sourceURL,
|
||||
type: item.type === MediaItemType.IMAGE ? "image" : "video"
|
||||
};
|
||||
}) as any;
|
||||
wx.previewMedia({
|
||||
current: newCurrentIndex,
|
||||
sources
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
69
miniprogram/components/travel-location-popup/index.wxml
Normal file
69
miniprogram/components/travel-location-popup/index.wxml
Normal file
@ -0,0 +1,69 @@
|
||||
<!-- components/travel-location-popup/index.wxml -->
|
||||
<t-popup
|
||||
class="popup"
|
||||
visible="{{visible}}"
|
||||
placement="bottom"
|
||||
bind:visible-change="closeDetail"
|
||||
>
|
||||
<view class="detail-panel">
|
||||
<view class="detail-content">
|
||||
<view class="header">
|
||||
<view class="info">
|
||||
<view class="title-row">
|
||||
<t-icon wx:if="{{locations[currentLocationIndex].typeIcon}}" class="type-icon" name="{{locations[currentLocationIndex].typeIcon}}" />
|
||||
<text class="title">{{locations[currentLocationIndex].title || '未命名地点'}}</text>
|
||||
</view>
|
||||
<view wx:if="{{locations[currentLocationIndex].location}}" class="location" catchtap="openLocation">
|
||||
<t-icon class="icon" name="location-filled" />
|
||||
<text class="text">{{locations[currentLocationIndex].location}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="actions">
|
||||
<view wx:if="{{locations.length > 1}}" class="indicator">
|
||||
{{currentLocationIndex + 1}}/{{locations.length}}
|
||||
</view>
|
||||
<t-icon name="close" catchtap="closeDetail" size="48rpx" />
|
||||
</view>
|
||||
</view>
|
||||
<swiper class="locations-swiper" current="{{currentLocationIndex}}" bindchange="onSwiperChange">
|
||||
<block wx:for="{{locations}}" wx:key="id">
|
||||
<swiper-item class="swiper-item-wrapper">
|
||||
<scroll-view scroll-y class="location-scroll">
|
||||
<view class="location-item">
|
||||
<view class="tags">
|
||||
<t-tag wx:if="{{item.typeLabel}}" theme="primary" variant="outline">
|
||||
{{item.typeLabel}}
|
||||
</t-tag>
|
||||
<t-tag wx:if="{{item.amount}}" theme="warning" variant="outline">
|
||||
¥{{item.amount}}
|
||||
</t-tag>
|
||||
<t-tag wx:if="{{item.score}}" theme="success" variant="outline">
|
||||
评分 {{item.score}}
|
||||
</t-tag>
|
||||
<t-tag wx:if="{{item.requireIdCard}}" theme="danger" variant="outline">
|
||||
需要身份证
|
||||
</t-tag>
|
||||
</view>
|
||||
<view wx:if="{{item.description}}" class="description">{{item.description}}</view>
|
||||
<view wx:if="{{item.columnedItems && item.columnedItems.length > 0}}" class="items">
|
||||
<view wx:for="{{item.columnedItems}}" wx:for-item="column" wx:for-index="columnIndex" wx:key="columnIndex" class="column">
|
||||
<block wx:for="{{column}}" wx:key="attachmentId" wx:for-item="media" wx:for-index="itemIndex">
|
||||
<image
|
||||
class="item thumbnail {{media.type === 1 ? 'video' : 'image'}}"
|
||||
src="{{media.thumbURL}}"
|
||||
mode="widthFix"
|
||||
catchtap="previewMedia"
|
||||
data-item-index="{{media.originalIndex}}"
|
||||
/>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{!item.description && (!item.columnedItems || item.columnedItems.length === 0)}}" class="empty">暂无详细说明</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</swiper-item>
|
||||
</block>
|
||||
</swiper>
|
||||
</view>
|
||||
</view>
|
||||
</t-popup>
|
||||
Reference in New Issue
Block a user