refactor journal-detail-popup

This commit is contained in:
Timi
2025-12-11 12:02:01 +08:00
parent 0379a1d3b5
commit 1bf655c0dc
13 changed files with 238 additions and 352 deletions

View File

@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-icon": "tdesign-miniprogram/icon/icon",
"t-popup": "tdesign-miniprogram/popup/popup"
}
}

View File

@ -0,0 +1,177 @@
/* components/journal-detail-panel/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;
flex-direction: column;
.title {
display: flex;
font-size: 32rpx;
font-weight: 600;
align-items: center;
.icon {
color: var(--theme-wx);
font-size: 48rpx;
margin-right: 8rpx;
}
.text {
width: calc(100% - 90rpx);
overflow: hidden;
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;
}
}
}
.journals-swiper {
flex: 1;
height: 100%;
.swiper-item-wrapper {
height: 100%;
.journal-item {
height: 100%;
display: flex;
flex-direction: column;
.header {
gap: 16rpx;
display: flex;
padding: 0 32rpx;
flex-shrink: 0;
align-items: center;
margin-bottom: 16rpx;
.portfolio {
color: #FFF;
width: 52rpx;
padding: 4rpx 8rpx;
font-size: 24rpx;
background: var(--theme-wx);
text-align: center;
font-weight: bold;
border-radius: 8rpx;
}
.location {
gap: 8rpx;
display: flex;
font-size: 24rpx;
flex-basis: 100%;
align-items: center;
.icon {
color: var(--theme-wx);
font-size: 32rpx;
}
.text {
font-size: 24rpx;
}
}
.datetime {
font-size: 28rpx;
font-weight: bold;
}
}
.idea {
display: block;
padding: 0 32rpx;
font-size: 28rpx;
line-height: 1.6;
flex-shrink: 0;
margin-bottom: 16rpx;
}
.items-scroll {
flex: 1;
height: 100%;
.items {
padding: 0 32rpx 128rpx 32rpx;
.wrapper {
column-gap: 8rpx;
column-count: 3;
padding-bottom: 128rpx;
.item {
overflow: hidden;
background: var(--theme-bg-card);
break-inside: avoid;
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;
}
}
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,146 @@
// components/journal-detail-panel/index.ts
import { Journal } from "../../types/Journal";
import config from "../../config/index";
import { MediaAttachExt, MediaAttachType } from "../../types/Attachment";
import { MediaItem, MediaItemType } from "../../types/UI";
import Time from "../../utils/Time";
interface JournalDetailPanelData {
journals: Journal[];
currentJournalIndex: number;
}
Component({
properties: {
visible: {
type: Boolean,
value: false
},
ids: {
type: Array,
value: []
},
mode: {
type: String,
value: "DATE"
}
},
data: <JournalDetailPanelData>{
journals: [],
currentJournalIndex: 0,
},
observers: {
async 'ids, visible'(ids: number[], visible: boolean) {
if (visible && ids && 0 < ids.length) {
wx.showLoading({ title: "加载中...", mask: true });
try {
const journals: Journal[] = await new Promise((resolve, reject) => {
wx.request({
url: `${config.url}/journal/list/ids`,
method: "POST",
header: {
Key: wx.getStorageSync("key")
},
data: ids,
success: (resp: any) => {
if (resp.data.code === 20000) {
resolve(resp.data.data);
} else {
reject(new Error(resp.data.message || "加载失败"));
}
},
fail: reject
});
}) || [];
journals.forEach(journal => {
journal.date = Time.toPassedDate(journal.createdAt);
journal.time = Time.toTime(journal.createdAt);
journal.datetime = Time.toPassedDateTime(journal.createdAt);
const thumbItems = journal.items?.filter((item) => item.attachType === MediaAttachType.THUMB);
if (!thumbItems) {
return;
}
const mediaItems: MediaItem[] = thumbItems.map((thumbItem) => {
const ext = thumbItem.ext = JSON.parse(thumbItem.ext!.toString()) as MediaAttachExt;
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
} as MediaItem;
});
journal.mediaItems = mediaItems;
})
this.setData({
journals,
currentJournalIndex: 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({
currentJournalIndex: e.detail.current
});
},
/** 打开位置 */
openLocation(e: WechatMiniprogram.BaseEvent) {
const { journalIndex } = e.currentTarget.dataset;
if (!journalIndex && this.properties.mode !== "LOCATION") {
return;
}
const journals = this.properties.journals as Journal[];
const journal = journals[journalIndex || 0];
if (journal.lat && journal.lng) {
wx.openLocation({
latitude: journal.lat,
longitude: journal.lng,
});
}
},
/** 预览媒体 */
previewMedia(e: WechatMiniprogram.BaseEvent) {
const journals = this.properties.journals as Journal[];
if (!journals || journals.length === 0) {
return;
}
const { itemIndex } = e.currentTarget.dataset;
const items = journals[this.data.currentJournalIndex].mediaItems!;
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) => {
return {
url: item.sourceURL,
type: item.type === 0 ? "image" : "video"
}
}) as any;
wx.previewMedia({
current: newCurrentIndex,
sources
})
}
}
});

View File

@ -0,0 +1,64 @@
<!-- components/journal-detail-panel/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 wx:if="{{mode === 'LOCATION'}}" class="title" catchtap="openLocation">
<t-icon wx:if="{{mode === 'LOCATION'}}" class="icon" name="location-filled" />
<text class="text">{{journals[currentJournalIndex].location}}</text>
</view>
<text wx:if="{{mode === 'DATE'}}" class="title">{{journals[currentJournalIndex].datetime}}</text>
</view>
<view class="actions">
<view wx:if="{{journals.length > 1}}" class="indicator">
{{currentJournalIndex + 1}}/{{journals.length}}
</view>
<t-icon name="close" catchtap="closeDetail" size="48rpx" />
</view>
</view>
<swiper class="journals-swiper" current="{{currentJournalIndex}}" bindchange="onSwiperChange">
<block wx:for="{{journals}}" wx:key="id">
<swiper-item class="swiper-item-wrapper">
<view class="journal-item">
<view class="header">
<view wx:if="{{item.type === 'PORTFOLIO'}}" class="portfolio">专拍</view>
<view
wx:if="{{item.location && mode === 'DATE'}}"
class="location"
catchtap="openLocation"
data-journal-index="{{currentJournalIndex}}"
>
<t-icon class="icon" name="location-filled" />
<text class="text">{{item.location}}</text>
</view>
<view wx:if="{{mode === 'LOCATION'}}" class="datetime">{{item.datetime}}</view>
</view>
<view wx:if="{{item.idea}}" class="idea">{{item.idea}}</view>
<scroll-view wx:if="{{item.mediaItems && item.mediaItems.length > 0}}" scroll-y class="items-scroll">
<view class="items">
<view class="wrapper">
<block wx:for="{{item.mediaItems}}" wx:key="mongoId" 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="{{itemIndex}}"
/>
</block>
</view>
</view>
</scroll-view>
</view>
</swiper-item>
</block>
</swiper>
</view>
</view>
</t-popup>