Compare commits
11 Commits
980d0e1431
...
f837c4d4d9
| Author | SHA1 | Date | |
|---|---|---|---|
| f837c4d4d9 | |||
| 3a8f7b0f19 | |||
| dc71590bd9 | |||
| 0cdef54954 | |||
| fc6edcb5ab | |||
| 61171a6df7 | |||
| 501745d937 | |||
| 1bf655c0dc | |||
| 0379a1d3b5 | |||
| 861ae8baff | |||
| 2cb8f16ccc |
@ -7,10 +7,8 @@
|
||||
flex-direction: column;
|
||||
|
||||
.year {
|
||||
color: var(--theme-text-secondary);
|
||||
display: flex;
|
||||
padding: 16rpx 32rpx;
|
||||
background: transparent;
|
||||
align-items: center;
|
||||
margin-bottom: 24rpx;
|
||||
justify-content: space-between;
|
||||
@ -52,16 +50,16 @@
|
||||
.months {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
padding-bottom: 256rpx;
|
||||
padding-bottom: 210rpx;
|
||||
|
||||
.month {
|
||||
padding: 0 32rpx;
|
||||
|
||||
.title {
|
||||
color: var(--theme-text);
|
||||
font-size: 28rpx;
|
||||
font-size: 32rpx;
|
||||
margin-top: 32rpx;
|
||||
font-weight: 600;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.days {
|
||||
|
||||
@ -1,116 +0,0 @@
|
||||
// components/journal-detail-panel/index.ts
|
||||
|
||||
interface JournalInfo {
|
||||
id: number;
|
||||
date: string;
|
||||
time: string;
|
||||
lat?: number;
|
||||
lng?: number;
|
||||
location?: string;
|
||||
idea?: string;
|
||||
items: Array<{
|
||||
type: number;
|
||||
thumbURL: string;
|
||||
sourceURL: string;
|
||||
mongoId: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
interface JournalDetailPanelData {
|
||||
currentJournalIndex: number;
|
||||
}
|
||||
|
||||
Component({
|
||||
properties: {
|
||||
// 是否显示
|
||||
visible: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
// 标题(如 "2024 年 1 月 1 日" 或位置名称)
|
||||
title: {
|
||||
type: String,
|
||||
value: ""
|
||||
},
|
||||
// 日记列表
|
||||
journals: {
|
||||
type: Array,
|
||||
value: []
|
||||
},
|
||||
// 是否显示标题位置图标
|
||||
showLocationIcon: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
// 是否显示每条日记的日期
|
||||
showJournalDate: {
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
// 是否显示每条日记的位置
|
||||
showJournalLocation: {
|
||||
type: Boolean,
|
||||
value: true
|
||||
}
|
||||
},
|
||||
|
||||
data: <JournalDetailPanelData>{
|
||||
currentJournalIndex: 0,
|
||||
},
|
||||
|
||||
observers: {
|
||||
'journals, visible'(journals: JournalInfo[], visible: boolean) {
|
||||
if (visible && journals && journals.length > 0) {
|
||||
// 显示时重置索引和 margin
|
||||
this.setData({
|
||||
currentJournalIndex: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
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;
|
||||
const journals = this.properties.journals as JournalInfo[];
|
||||
const journal = journals[journalIndex];
|
||||
if (journal.lat && journal.lng) {
|
||||
wx.openLocation({
|
||||
latitude: journal.lat,
|
||||
longitude: journal.lng,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** 预览媒体 */
|
||||
previewMedia(e: WechatMiniprogram.BaseEvent) {
|
||||
const { mediaIndex } = e.currentTarget.dataset;
|
||||
const journals = this.properties.journals as JournalInfo[];
|
||||
if (!journals || journals.length === 0) return;
|
||||
|
||||
// 使用当前 swiper 的索引
|
||||
const journal = journals[this.data.currentJournalIndex];
|
||||
const sources = journal.items.map((item: any) => ({
|
||||
url: item.sourceURL,
|
||||
type: item.type === 0 ? "image" : "video"
|
||||
}));
|
||||
|
||||
wx.previewMedia({
|
||||
current: mediaIndex,
|
||||
sources: sources as WechatMiniprogram.MediaSource[]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -12,12 +12,12 @@
|
||||
overflow: hidden;
|
||||
flex-direction: column;
|
||||
|
||||
.header {
|
||||
> .header {
|
||||
display: flex;
|
||||
padding: 32rpx 32rpx 0 32rpx;
|
||||
flex-shrink: 0;
|
||||
margin-bottom: 24rpx;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 24rpx;
|
||||
justify-content: space-between;
|
||||
|
||||
.info {
|
||||
@ -30,13 +30,19 @@
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
align-items: center;
|
||||
margin-bottom: 8rpx;
|
||||
|
||||
.icon {
|
||||
color: var(--theme-wx);
|
||||
font-size: 48rpx;
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
|
||||
.text {
|
||||
width: calc(100% - 90rpx);
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,9 +56,9 @@
|
||||
color: var(--theme-wx);
|
||||
padding: 4rpx 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 12rpx;
|
||||
font-weight: bold;
|
||||
background: var(--theme-bg-journal);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,14 +75,24 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.journal-header {
|
||||
.header {
|
||||
gap: 16rpx;
|
||||
display: flex;
|
||||
padding: 0 32rpx;
|
||||
flex-wrap: wrap;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
align-items: baseline;
|
||||
|
||||
.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;
|
||||
@ -95,14 +111,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
.date {
|
||||
flex: 1;
|
||||
.datetime {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 24rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
146
miniprogram/components/journal-detail-popup/index.ts
Normal file
146
miniprogram/components/journal-detail-popup/index.ts
Normal 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
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -9,10 +9,11 @@
|
||||
<view class="detail-content">
|
||||
<view class="header">
|
||||
<view class="info">
|
||||
<view wx:if="{{title}}" class="title">
|
||||
<t-icon wx:if="{{showLocationIcon}}" class="icon" name="location-filled" />
|
||||
<text>{{title}}</text>
|
||||
<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">
|
||||
@ -25,9 +26,10 @@
|
||||
<block wx:for="{{journals}}" wx:key="id">
|
||||
<swiper-item class="swiper-item-wrapper">
|
||||
<view class="journal-item">
|
||||
<view class="journal-header">
|
||||
<view class="header">
|
||||
<view wx:if="{{item.type === 'PORTFOLIO'}}" class="portfolio">专拍</view>
|
||||
<view
|
||||
wx:if="{{item.location && showJournalLocation}}"
|
||||
wx:if="{{item.location && mode === 'DATE'}}"
|
||||
class="location"
|
||||
catchtap="openLocation"
|
||||
data-journal-index="{{currentJournalIndex}}"
|
||||
@ -35,19 +37,19 @@
|
||||
<t-icon class="icon" name="location-filled" />
|
||||
<text class="text">{{item.location}}</text>
|
||||
</view>
|
||||
<view wx:if="{{showJournalDate}}" class="date">{{item.date}}</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.items && item.items.length > 0}}" scroll-y class="items-scroll">
|
||||
<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.items}}" wx:key="mongoId" wx:for-item="media" wx:for-index="mediaIndex">
|
||||
<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-media-index="{{mediaIndex}}"
|
||||
data-item-index="{{itemIndex}}"
|
||||
/>
|
||||
</block>
|
||||
</view>
|
||||
@ -26,7 +26,7 @@
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="label">版本:</text>
|
||||
<text>1.5.1</text>
|
||||
<text>1.5.2</text>
|
||||
</view>
|
||||
<view class="item copyright">
|
||||
<text>{{copyright}}</text>
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-radio": "tdesign-miniprogram/radio/radio",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar"
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-radio-group": "tdesign-miniprogram/radio-group/radio-group"
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,14 @@
|
||||
width: 100%;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
&.type {
|
||||
display: flex;
|
||||
|
||||
.radio {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
&.time {
|
||||
display: flex;
|
||||
|
||||
@ -103,9 +111,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
.progress {
|
||||
.uploading {
|
||||
width: 100%;
|
||||
margin-top: 1rem;
|
||||
|
||||
.progress {
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.text {
|
||||
color: var(--theme-text-secondary);
|
||||
display: flex;
|
||||
font-size: .8rem;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
|
||||
.ctrl {
|
||||
|
||||
@ -3,6 +3,8 @@ import Events from "../../../utils/Events";
|
||||
import Time from "../../../utils/Time";
|
||||
import Toolkit from "../../../utils/Toolkit";
|
||||
import config from "../../../config/index";
|
||||
import { JournalType } from "../../../types/Journal";
|
||||
import IOSize, { Unit } from "../../../utils/IOSize";
|
||||
|
||||
enum MediaItemType {
|
||||
IMAGE,
|
||||
@ -28,10 +30,16 @@ interface JournalEditorData {
|
||||
idea: string;
|
||||
date: string;
|
||||
time: string;
|
||||
type: JournalType;
|
||||
mediaList: MediaItem[];
|
||||
location?: Location;
|
||||
qqMapSDK?: any;
|
||||
isAuthLocation: boolean;
|
||||
uploaded: string;
|
||||
uploadTotal: string;
|
||||
uploadSpeed: string;
|
||||
uploadProgress: number;
|
||||
isSubmitting: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@ -39,15 +47,18 @@ Page({
|
||||
idea: "",
|
||||
date: "2025-06-28",
|
||||
time: "16:00",
|
||||
type: JournalType.NORMAL,
|
||||
mediaList: [],
|
||||
location: undefined,
|
||||
submitText: "提交",
|
||||
isAuthLocation: false,
|
||||
uploaded: "0",
|
||||
uploadTotal: "0 MB",
|
||||
uploadSpeed: "0 MB / s",
|
||||
uploadProgress: 0,
|
||||
isSubmitting: false,
|
||||
submitProgress: 0,
|
||||
mediaItemTypeEnum: {
|
||||
...MediaItemType
|
||||
},
|
||||
isAuthLocation: false
|
||||
}
|
||||
},
|
||||
async onLoad() {
|
||||
// 授权定位
|
||||
@ -97,6 +108,10 @@ Page({
|
||||
});
|
||||
});
|
||||
},
|
||||
onChangeType(e: any) {
|
||||
const { value } = e.detail;
|
||||
this.setData({ type: value });
|
||||
},
|
||||
async chooseLocation() {
|
||||
const location = await wx.chooseLocation({});
|
||||
this.setData({
|
||||
@ -153,14 +168,22 @@ Page({
|
||||
})
|
||||
},
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
wx.previewMedia({
|
||||
current: e.currentTarget.dataset.index,
|
||||
sources: this.data.mediaList.map(item => {
|
||||
const itemIndex = e.currentTarget.dataset.index;
|
||||
const total = this.data.mediaList.length;
|
||||
|
||||
const startIndex = Math.max(0, itemIndex - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = itemIndex - startIndex;
|
||||
|
||||
const sources = this.data.mediaList.slice(startIndex, endIndex).map(item => {
|
||||
return {
|
||||
url: item.path,
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
} as WechatMiniprogram.MediaSource;
|
||||
})
|
||||
});
|
||||
wx.previewMedia({
|
||||
current: newCurrentIndex,
|
||||
sources
|
||||
});
|
||||
},
|
||||
deleteMedia(e: WechatMiniprogram.BaseEvent) {
|
||||
@ -179,16 +202,15 @@ Page({
|
||||
submit() {
|
||||
const handleFail = () => {
|
||||
wx.showToast({ title: "上传失败", icon: "error" });
|
||||
wx.hideLoading();
|
||||
this.setData({
|
||||
submitText: "提交",
|
||||
isSubmitting: false
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
this.setData({
|
||||
submitText: "正在提交..",
|
||||
isSubmitting: true
|
||||
})
|
||||
});
|
||||
|
||||
// 获取 openId
|
||||
const getOpenId = new Promise<string>((resolve, reject) => {
|
||||
@ -224,51 +246,97 @@ Page({
|
||||
// 文件上传
|
||||
const uploadFiles = new Promise<string[]>((resolve, reject) => {
|
||||
const mediaList = this.data.mediaList || [];
|
||||
const total = mediaList.length;
|
||||
let completed = 0;
|
||||
|
||||
if (total === 0) {
|
||||
if (mediaList.length === 0) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
// 更新进度初始状态
|
||||
this.setData({
|
||||
submitProgress: 0,
|
||||
});
|
||||
|
||||
const uploadPromises = mediaList.map((item) => {
|
||||
wx.showLoading({ title: "正在上传..", mask: true });
|
||||
|
||||
// 计算总大小
|
||||
const sizePromises = mediaList.map(item => {
|
||||
return new Promise<number>((sizeResolve, sizeReject) => {
|
||||
wx.getFileSystemManager().getFileInfo({
|
||||
filePath: item.path,
|
||||
success: (res) => sizeResolve(res.size),
|
||||
fail: (err) => sizeReject(err)
|
||||
});
|
||||
});
|
||||
});
|
||||
Promise.all(sizePromises).then(fileSizes => {
|
||||
const totalSize = fileSizes.reduce((acc, size) => acc + size, 0);
|
||||
const uploadTasks: WechatMiniprogram.UploadTask[] = [];
|
||||
let uploadedSize = 0;
|
||||
let lastUploadedSize = 0;
|
||||
|
||||
this.setData({
|
||||
uploadTotal: IOSize.format(totalSize, 2, Unit.MB)
|
||||
});
|
||||
// 计算上传速度
|
||||
const speedUpdateInterval = setInterval(() => {
|
||||
const chunkSize = uploadedSize - lastUploadedSize;
|
||||
this.setData({
|
||||
uploadSpeed: `${IOSize.format(chunkSize)} / s`
|
||||
});
|
||||
lastUploadedSize = uploadedSize;
|
||||
}, 1000);
|
||||
// 上传文件
|
||||
const uploadPromises = mediaList.map(item => {
|
||||
return new Promise<string>((uploadResolve, uploadReject) => {
|
||||
wx.uploadFile({
|
||||
const task = wx.uploadFile({
|
||||
url: `${config.url}/temp/file/upload`,
|
||||
filePath: item.path,
|
||||
name: "file",
|
||||
success: (resp) => {
|
||||
const result = JSON.parse(resp.data);
|
||||
if (result && result.code === 20000) {
|
||||
completed++;
|
||||
// 更新进度
|
||||
this.setData({
|
||||
submitProgress: (completed / total),
|
||||
});
|
||||
uploadResolve(result.data[0].id);
|
||||
} else {
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || '未知错误'}`));
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || "未知错误"}`));
|
||||
}
|
||||
},
|
||||
fail: (err) => uploadReject(new Error(`文件上传失败: ${err.errMsg}`))
|
||||
});
|
||||
});
|
||||
});
|
||||
// 并行执行所有文件上传
|
||||
Promise.all(uploadPromises).then((tempFileIds) => {
|
||||
|
||||
// 监听上传进度
|
||||
let prevProgress = 0;
|
||||
task.onProgressUpdate((res) => {
|
||||
const fileUploaded = (res.totalBytesExpectedToSend * res.progress) / 100;
|
||||
const delta = fileUploaded - prevProgress;
|
||||
uploadedSize += delta;
|
||||
prevProgress = fileUploaded;
|
||||
|
||||
// 更新进度条
|
||||
this.setData({
|
||||
submitProgress: 1,
|
||||
uploaded: IOSize.formatWithoutUnit(uploadedSize, 2, Unit.MB),
|
||||
uploadProgress: Math.round((uploadedSize / totalSize) * 10000) / 100
|
||||
});
|
||||
});
|
||||
uploadTasks.push(task);
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all(uploadPromises).then((tempFileIds) => {
|
||||
// 清除定时器
|
||||
clearInterval(speedUpdateInterval);
|
||||
uploadTasks.forEach(task => task.offProgressUpdate());
|
||||
this.setData({
|
||||
uploadProgress: 100,
|
||||
uploadSpeed: "0 MB / s"
|
||||
});
|
||||
resolve(tempFileIds);
|
||||
}).catch((e: Error) => {
|
||||
// 取消所有上传任务
|
||||
uploadTasks.forEach(task => task.abort());
|
||||
clearInterval(speedUpdateInterval);
|
||||
reject(e);
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
|
||||
// 并行执行获取 openId 和文件上传
|
||||
Promise.all([getOpenId, uploadFiles]).then(([openId, tempFileIds]) => {
|
||||
wx.showLoading({ title: "正在保存..", mask: true });
|
||||
wx.request({
|
||||
url: `${config.url}/journal/create`,
|
||||
method: "POST",
|
||||
@ -276,28 +344,30 @@ Page({
|
||||
Key: wx.getStorageSync("key")
|
||||
},
|
||||
data: {
|
||||
type: "NORMAL",
|
||||
idea: this.data.idea,
|
||||
createdAt: Date.parse(`${this.data.date} ${this.data.time}`),
|
||||
type: this.data.type,
|
||||
lat: this.data.location?.lat,
|
||||
lng: this.data.location?.lng,
|
||||
location: this.data.location?.text,
|
||||
pusher: openId,
|
||||
createdAt: Date.parse(`${this.data.date} ${this.data.time}`),
|
||||
tempFileIds
|
||||
},
|
||||
success: async (resp: any) => {
|
||||
success: async () => {
|
||||
Events.emit("JOURNAL_REFRESH");
|
||||
wx.showToast({ title: "提交成功", icon: "success" });
|
||||
this.setData({
|
||||
idea: "",
|
||||
mediaList: [],
|
||||
submitText: "提交",
|
||||
isSubmitting: false,
|
||||
uploaded: "0",
|
||||
uploadTotal: "0 MB",
|
||||
uploadProgress: 0
|
||||
});
|
||||
await Toolkit.sleep(1000);
|
||||
wx.switchTab({
|
||||
url: "/pages/main/journal/index",
|
||||
})
|
||||
url: "/pages/main/journal/index"
|
||||
});
|
||||
},
|
||||
fail: handleFail
|
||||
});
|
||||
|
||||
@ -17,6 +17,13 @@
|
||||
model:value="{{idea}}"
|
||||
/>
|
||||
</view>
|
||||
<view class="section type">
|
||||
<text class="label">类型:</text>
|
||||
<t-radio-group bind:change="onChangeType" default-value="NORMAL" borderless t-class="box">
|
||||
<t-radio class="radio" block="{{false}}" label="日常" value="NORMAL" />
|
||||
<t-radio class="radio" block="{{false}}" label="专拍" value="PORTFOLIO" />
|
||||
</t-radio-group>
|
||||
</view>
|
||||
<view class="section time">
|
||||
<text class="label">时间:</text>
|
||||
<picker class="picker" mode="date" model:value="{{date}}">
|
||||
@ -80,13 +87,17 @@
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{isSubmitting}}" class="uploading">
|
||||
<progress
|
||||
wx:if="{{isSubmitting}}"
|
||||
class="progress"
|
||||
percent="{{submitProgress.toFixed(2) * 100}}"
|
||||
show-info
|
||||
stroke-width="4"
|
||||
percent="{{uploadProgress}}"
|
||||
stroke-width="6"
|
||||
/>
|
||||
<view class="text">
|
||||
<view>{{uploaded}} / {{uploadTotal}}</view>
|
||||
<view>{{uploadSpeed}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="ctrl">
|
||||
<t-button
|
||||
class="clear"
|
||||
@ -101,7 +112,7 @@
|
||||
theme="primary"
|
||||
bind:tap="submit"
|
||||
disabled="{{(!idea && mediaList.length === 0) || isSubmitting}}"
|
||||
>{{submitText}}</t-button>
|
||||
>提交</t-button>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
@ -1,8 +1,8 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"calendar": "/components/calendar/index",
|
||||
"journal-detail-panel": "/components/journal-detail-panel/index"
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"journal-detail-popup": "/components/journal-detail-popup/index"
|
||||
},
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
|
||||
@ -1,49 +1,28 @@
|
||||
// pages/main/journal-date/index.ts
|
||||
import config from "../../../config/index";
|
||||
import Time from "../../../utils/Time";
|
||||
import { Journal, JournalPageType } from "../../../types/Journal";
|
||||
import { MediaAttachType } from "../../../types/Attachment";
|
||||
|
||||
interface JournalInfo {
|
||||
id: number;
|
||||
date: string;
|
||||
time: string;
|
||||
lat?: number;
|
||||
lng?: number;
|
||||
location?: string;
|
||||
idea?: string;
|
||||
items: Array<{
|
||||
type: number;
|
||||
thumbURL: string;
|
||||
sourceURL: string;
|
||||
mongoId: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
interface SelectedDateInfo {
|
||||
displayDate: string;
|
||||
journals: JournalInfo[];
|
||||
}
|
||||
import Time from "../../../utils/Time";
|
||||
|
||||
interface JournalDateData {
|
||||
journalMap: Record<string, number[]>; // 存储每个日期的日记 id 列表
|
||||
selectedDate: SelectedDateInfo | null;
|
||||
// 存储每个日期的日记 id 列表
|
||||
isLoading: boolean;
|
||||
popupVisible: boolean; // popup 显示状态
|
||||
journalMap: Record<string, number[]>;
|
||||
|
||||
popupIds: number[];
|
||||
popupVisible: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: <JournalDateData>{
|
||||
journalMap: {},
|
||||
selectedDate: null,
|
||||
isLoading: true,
|
||||
popupVisible: false
|
||||
},
|
||||
journalMap: {},
|
||||
|
||||
popupIds: [],
|
||||
popupVisible: false,
|
||||
},
|
||||
async onLoad() {
|
||||
await this.loadJournals();
|
||||
},
|
||||
|
||||
/** 加载所有日记 */
|
||||
async loadJournals() {
|
||||
this.setData({ isLoading: true });
|
||||
@ -70,24 +49,19 @@ Page({
|
||||
fail: reject
|
||||
});
|
||||
}) || [];
|
||||
|
||||
// 按日期分组,只存储 id
|
||||
const journalMap: Record<string, number[]> = {};
|
||||
list.forEach((journal: any) => {
|
||||
const date = new Date(journal.createdAt);
|
||||
const dateKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
||||
|
||||
const dateKey = Time.toDate(journal.createdAt);
|
||||
if (!journalMap[dateKey]) {
|
||||
journalMap[dateKey] = [];
|
||||
}
|
||||
journalMap[dateKey].push(journal.id);
|
||||
});
|
||||
|
||||
// 按 id 倒序排序每天的日记
|
||||
Object.keys(journalMap).forEach(dateKey => {
|
||||
journalMap[dateKey].sort((a, b) => b - a);
|
||||
});
|
||||
|
||||
this.setData({
|
||||
journalMap,
|
||||
isLoading: false
|
||||
@ -100,12 +74,10 @@ Page({
|
||||
this.setData({ isLoading: false });
|
||||
}
|
||||
},
|
||||
|
||||
/** 日期选择事件(来自 calendar 组件) */
|
||||
onDateSelect(e: WechatMiniprogram.CustomEvent) {
|
||||
const { date, year, month, day } = e.detail;
|
||||
const { date } = e.detail;
|
||||
const journalIds = this.data.journalMap[date];
|
||||
|
||||
if (!journalIds || journalIds.length === 0) {
|
||||
wx.showToast({
|
||||
title: "该日期无日记",
|
||||
@ -113,81 +85,22 @@ Page({
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用接口获取详情
|
||||
this.loadJournalsByIds(journalIds, `${year} 年 ${month} 月 ${day} 日`);
|
||||
this.loadJournalsByIds(journalIds);
|
||||
},
|
||||
/** 根据 id 列表加载日记详情 */
|
||||
async loadJournalsByIds(ids: number[], displayDate: string) {
|
||||
wx.showLoading({ title: "加载中...", mask: true });
|
||||
try {
|
||||
const list: 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
|
||||
});
|
||||
}) || [];
|
||||
|
||||
// 转换为 JournalInfo 格式
|
||||
const journals: JournalInfo[] = list.sort((a, b) => a.createdAt! - b.createdAt!).map((journal: any) => {
|
||||
const date = new Date(journal.createdAt);
|
||||
return {
|
||||
id: journal.id,
|
||||
date: Time.toPassedDateTime(journal.createdAt),
|
||||
time: `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`,
|
||||
lat: journal.lat,
|
||||
lng: journal.lng,
|
||||
location: journal.location,
|
||||
idea: journal.idea,
|
||||
items: journal.items
|
||||
.filter((item: any) => item.attachType === MediaAttachType.THUMB)
|
||||
.map((item: any) => {
|
||||
const ext = JSON.parse(item.ext);
|
||||
return {
|
||||
type: ext.isVideo ? 1 : 0,
|
||||
thumbURL: `${config.url}/attachment/read/${item.mongoId}`,
|
||||
sourceURL: `${config.url}/attachment/read/${ext.sourceMongoId}`,
|
||||
mongoId: item.mongoId,
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
async loadJournalsByIds(ids: number[]) {
|
||||
this.setData({
|
||||
selectedDate: {
|
||||
displayDate,
|
||||
journals
|
||||
},
|
||||
popupVisible: true // 显示 popup
|
||||
popupIds: ids,
|
||||
popupVisible: true
|
||||
});
|
||||
|
||||
wx.hideLoading();
|
||||
} catch (err: any) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: err.message || "加载失败",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** 关闭详情 */
|
||||
closeDetail() {
|
||||
this.setData({
|
||||
popupVisible: false,
|
||||
selectedDate: null
|
||||
popupIds: []
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -9,11 +9,9 @@
|
||||
</view>
|
||||
</view>
|
||||
<!-- 详情面板 -->
|
||||
<journal-detail-panel
|
||||
<journal-detail-popup
|
||||
visible="{{popupVisible}}"
|
||||
title="{{selectedDate.displayDate}}"
|
||||
journals="{{selectedDate.journals}}"
|
||||
show-journal-date="{{false}}"
|
||||
show-journal-location="{{true}}"
|
||||
ids="{{popupIds}}"
|
||||
mode="DATE"
|
||||
bind:close="closeDetail"
|
||||
/>
|
||||
|
||||
@ -2,9 +2,11 @@
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-input": "tdesign-miniprogram/input/input",
|
||||
"t-radio": "tdesign-miniprogram/radio/radio",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-dialog": "tdesign-miniprogram/dialog/dialog",
|
||||
"t-input": "tdesign-miniprogram/input/input"
|
||||
"t-radio-group": "tdesign-miniprogram/radio-group/radio-group"
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,14 @@
|
||||
width: 100%;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
&.type {
|
||||
display: flex;
|
||||
|
||||
.radio {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
&.time {
|
||||
display: flex;
|
||||
|
||||
@ -111,9 +119,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
.progress {
|
||||
.uploading {
|
||||
width: 100%;
|
||||
margin-top: 1rem;
|
||||
|
||||
.progress {
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.text {
|
||||
color: var(--theme-text-secondary);
|
||||
display: flex;
|
||||
font-size: .8rem;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
|
||||
.ctrl {
|
||||
|
||||
@ -4,22 +4,26 @@ import Time from "../../../utils/Time";
|
||||
import Toolkit from "../../../utils/Toolkit";
|
||||
import config from "../../../config/index";
|
||||
import { Location, MediaItem, MediaItemType, WechatMediaItem } from "../../../types/UI";
|
||||
import { Journal } from "../../../types/Journal";
|
||||
import { Journal, JournalType } from "../../../types/Journal";
|
||||
import { MediaAttachExt, MediaAttachType } from "../../../types/Attachment";
|
||||
import IOSize, { Unit } from "../../../utils/IOSize";
|
||||
|
||||
interface JournalEditorData {
|
||||
id?: number;
|
||||
idea: string;
|
||||
date: string;
|
||||
time: string;
|
||||
type: JournalType;
|
||||
mediaList: MediaItem[];
|
||||
newMediaList: WechatMediaItem[];
|
||||
location?: Location;
|
||||
isAuthLocation: boolean;
|
||||
isLoading: boolean;
|
||||
saveText: string;
|
||||
isSaving: boolean;
|
||||
saveProgress: number;
|
||||
uploaded: string;
|
||||
uploadTotal: string;
|
||||
uploadSpeed: string;
|
||||
uploadProgress: number;
|
||||
mediaItemTypeEnum: any;
|
||||
deleteDialogVisible: boolean;
|
||||
deleteConfirmText: string;
|
||||
@ -31,13 +35,16 @@ Page({
|
||||
idea: "",
|
||||
date: "2025-06-28",
|
||||
time: "16:00",
|
||||
type: JournalType.NORMAL,
|
||||
mediaList: [],
|
||||
newMediaList: [],
|
||||
location: undefined,
|
||||
saveText: "保存",
|
||||
isSaving: false,
|
||||
saveProgress: 0,
|
||||
isLoading: true,
|
||||
uploaded: "0",
|
||||
uploadTotal: "0 MB",
|
||||
uploadSpeed: "0 MB / s",
|
||||
uploadProgress: 0,
|
||||
mediaItemTypeEnum: {
|
||||
...MediaItemType
|
||||
},
|
||||
@ -114,6 +121,7 @@ Page({
|
||||
idea: journal.idea || "",
|
||||
date: Time.toDate(journal.createdAt),
|
||||
time: Time.toTime(journal.createdAt),
|
||||
type: journal.type,
|
||||
location: journal.location ? {
|
||||
lat: journal.lat,
|
||||
lng: journal.lng,
|
||||
@ -134,6 +142,10 @@ Page({
|
||||
}, 1500);
|
||||
}
|
||||
},
|
||||
onChangeType(e: any) {
|
||||
const { value } = e.detail;
|
||||
this.setData({ type: value });
|
||||
},
|
||||
/** 选择位置 */
|
||||
async chooseLocation() {
|
||||
const location = await wx.chooseLocation({});
|
||||
@ -189,10 +201,16 @@ Page({
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
const allSources = [...sources, ...newSources];
|
||||
const currentIndex = isNewMedia ? this.data.mediaList.length + index : index;
|
||||
const itemIndex = isNewMedia ? this.data.mediaList.length + index : index;
|
||||
const total = allSources.length;
|
||||
|
||||
const startIndex = Math.max(0, itemIndex - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = itemIndex - startIndex;
|
||||
|
||||
wx.previewMedia({
|
||||
current: currentIndex,
|
||||
sources: allSources as WechatMiniprogram.MediaSource[]
|
||||
current: newCurrentIndex,
|
||||
sources: allSources.slice(startIndex, endIndex) as WechatMiniprogram.MediaSource[]
|
||||
});
|
||||
},
|
||||
/** 删除附件 */
|
||||
@ -287,63 +305,111 @@ Page({
|
||||
save() {
|
||||
const handleFail = () => {
|
||||
wx.showToast({ title: "保存失败", icon: "error" });
|
||||
wx.hideLoading();
|
||||
this.setData({
|
||||
saveText: "保存",
|
||||
isSaving: false
|
||||
});
|
||||
};
|
||||
|
||||
this.setData({
|
||||
saveText: "正在保存..",
|
||||
isSaving: true
|
||||
});
|
||||
// 收集保留的附件 ID(缩略图 ID)
|
||||
const attachmentIds = this.data.mediaList.map(item => item.attachmentId);
|
||||
|
||||
// 上传新媒体文件
|
||||
const uploadFiles = new Promise<string[]>((resolve, reject) => {
|
||||
const total = this.data.newMediaList.length;
|
||||
let completed = 0;
|
||||
if (total === 0) {
|
||||
if (this.data.newMediaList.length === 0) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
saveProgress: 0,
|
||||
|
||||
wx.showLoading({ title: "正在上传..", mask: true });
|
||||
|
||||
// 计算总大小
|
||||
const sizePromises = this.data.newMediaList.map(item => {
|
||||
return new Promise<number>((sizeResolve, sizeReject) => {
|
||||
wx.getFileSystemManager().getFileInfo({
|
||||
filePath: item.path,
|
||||
success: (res) => sizeResolve(res.size),
|
||||
fail: (err) => sizeReject(err)
|
||||
});
|
||||
// 上传临时文件
|
||||
const uploadPromises = this.data.newMediaList.map((item) => {
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all(sizePromises).then(fileSizes => {
|
||||
const totalSize = fileSizes.reduce((acc, size) => acc + size, 0);
|
||||
const uploadTasks: WechatMiniprogram.UploadTask[] = [];
|
||||
let uploadedSize = 0;
|
||||
let lastUploadedSize = 0;
|
||||
|
||||
this.setData({
|
||||
uploadTotal: IOSize.format(totalSize, 2, Unit.MB)
|
||||
});
|
||||
|
||||
// 计算上传速度
|
||||
const speedUpdateInterval = setInterval(() => {
|
||||
const chunkSize = uploadedSize - lastUploadedSize;
|
||||
this.setData({
|
||||
uploadSpeed: `${IOSize.format(chunkSize)} / s`
|
||||
});
|
||||
lastUploadedSize = uploadedSize;
|
||||
}, 1000);
|
||||
|
||||
// 上传文件
|
||||
const uploadPromises = this.data.newMediaList.map(item => {
|
||||
return new Promise<string>((uploadResolve, uploadReject) => {
|
||||
wx.uploadFile({
|
||||
const task = wx.uploadFile({
|
||||
url: `${config.url}/temp/file/upload`,
|
||||
filePath: item.path,
|
||||
name: "file",
|
||||
success: (resp) => {
|
||||
const result = JSON.parse(resp.data);
|
||||
if (result && result.code === 20000) {
|
||||
completed++;
|
||||
// 更新进度
|
||||
this.setData({
|
||||
saveProgress: (completed / total),
|
||||
});
|
||||
uploadResolve(result.data[0].id);
|
||||
} else {
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || '未知错误'}`));
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || "未知错误"}`));
|
||||
}
|
||||
},
|
||||
fail: (err) => uploadReject(new Error(`文件上传失败: ${err.errMsg}`))
|
||||
});
|
||||
});
|
||||
});
|
||||
// 并行执行所有文件上传
|
||||
Promise.all(uploadPromises).then((tempFileIds) => {
|
||||
|
||||
// 监听上传进度
|
||||
let prevProgress = 0;
|
||||
task.onProgressUpdate((res) => {
|
||||
const fileUploaded = (res.totalBytesExpectedToSend * res.progress) / 100;
|
||||
const delta = fileUploaded - prevProgress;
|
||||
uploadedSize += delta;
|
||||
prevProgress = fileUploaded;
|
||||
|
||||
// 更新进度条
|
||||
this.setData({
|
||||
saveProgress: 1,
|
||||
uploaded: IOSize.formatWithoutUnit(uploadedSize, 2, Unit.MB),
|
||||
uploadProgress: Math.round((uploadedSize / totalSize) * 10000) / 100
|
||||
});
|
||||
});
|
||||
uploadTasks.push(task);
|
||||
});
|
||||
});
|
||||
Promise.all(uploadPromises).then((tempFileIds) => {
|
||||
// 清除定时器
|
||||
clearInterval(speedUpdateInterval);
|
||||
uploadTasks.forEach(task => task.offProgressUpdate());
|
||||
this.setData({
|
||||
uploadProgress: 100,
|
||||
uploadSpeed: "0 MB / s"
|
||||
});
|
||||
resolve(tempFileIds);
|
||||
}).catch((e: Error) => {
|
||||
// 取消所有上传任务
|
||||
uploadTasks.forEach(task => task.abort());
|
||||
clearInterval(speedUpdateInterval);
|
||||
reject(e);
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
// 提交保存
|
||||
uploadFiles.then((tempFileIds) => {
|
||||
wx.showLoading({ title: "正在保存..", mask: true });
|
||||
wx.request({
|
||||
url: `${config.url}/journal/update`,
|
||||
method: "POST",
|
||||
@ -353,6 +419,7 @@ Page({
|
||||
data: {
|
||||
id: this.data.id,
|
||||
idea: this.data.idea,
|
||||
type: this.data.type,
|
||||
lat: this.data.location?.lat,
|
||||
lng: this.data.location?.lng,
|
||||
location: this.data.location?.text,
|
||||
@ -368,8 +435,10 @@ Page({
|
||||
Events.emit("JOURNAL_LIST_REFRESH");
|
||||
wx.showToast({ title: "保存成功", icon: "success" });
|
||||
this.setData({
|
||||
saveText: "保存",
|
||||
isSaving: false,
|
||||
uploaded: "0",
|
||||
uploadTotal: "0 MB",
|
||||
uploadProgress: 0
|
||||
});
|
||||
await Toolkit.sleep(1000);
|
||||
wx.navigateBack();
|
||||
|
||||
@ -21,6 +21,13 @@
|
||||
model:value="{{idea}}"
|
||||
/>
|
||||
</view>
|
||||
<view class="section type">
|
||||
<text class="label">类型:</text>
|
||||
<t-radio-group bind:change="onChangeType" default-value="{{type}}" borderless t-class="box">
|
||||
<t-radio class="radio" block="{{false}}" label="日常" value="NORMAL" />
|
||||
<t-radio class="radio" block="{{false}}" label="专拍" value="PORTFOLIO" />
|
||||
</t-radio-group>
|
||||
</view>
|
||||
<view class="section time">
|
||||
<text class="label">时间:</text>
|
||||
<picker class="picker" mode="date" model:value="{{date}}">
|
||||
@ -124,13 +131,17 @@
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{isSaving}}" class="uploading">
|
||||
<progress
|
||||
wx:if="{{isSaving}}"
|
||||
class="progress"
|
||||
percent="{{saveProgress.toFixed(2) * 100}}"
|
||||
show-info
|
||||
stroke-width="4"
|
||||
percent="{{uploadProgress}}"
|
||||
stroke-width="6"
|
||||
/>
|
||||
<view class="text">
|
||||
<view>{{uploaded}} / {{uploadTotal}}</view>
|
||||
<view>{{uploadSpeed}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="ctrl">
|
||||
<t-button class="delete" theme="danger" bind:tap="deleteJournal" disabled="{{isSaving}}">删除记录</t-button>
|
||||
<t-button
|
||||
@ -138,7 +149,7 @@
|
||||
theme="primary"
|
||||
bind:tap="save"
|
||||
disabled="{{(!idea && mediaList.length === 0 && newMediaList.length === 0) || isSaving}}"
|
||||
>{{saveText}}</t-button>
|
||||
>保存</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"journal-detail-panel": "/components/journal-detail-panel/index"
|
||||
"journal-detail-popup": "/components/journal-detail-popup/index"
|
||||
},
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
import config from "../../../config/index";
|
||||
import Time from "../../../utils/Time";
|
||||
import { Journal, JournalPageType } from "../../../types/Journal";
|
||||
import { MediaAttachExt, MediaAttachType } from "../../../types/Attachment";
|
||||
import Toolkit from "../../../utils/Toolkit";
|
||||
|
||||
interface MapMarker {
|
||||
@ -18,20 +17,6 @@ interface MapMarker {
|
||||
};
|
||||
}
|
||||
|
||||
interface JournalInfo {
|
||||
id: number;
|
||||
date: string;
|
||||
time: string;
|
||||
location?: string;
|
||||
idea?: string;
|
||||
items: Array<{
|
||||
type: number;
|
||||
thumbURL: string;
|
||||
sourceURL: string;
|
||||
mongoId: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
interface LocationMarker {
|
||||
locationKey: string; // 位置键 "lat,lng"
|
||||
lat: number;
|
||||
@ -43,11 +28,6 @@ interface LocationMarker {
|
||||
previewThumb?: string; // 预览缩略图
|
||||
}
|
||||
|
||||
interface SelectedLocationInfo {
|
||||
location?: string;
|
||||
journals: JournalInfo[];
|
||||
}
|
||||
|
||||
interface JournalMapData {
|
||||
centerLat: number;
|
||||
centerLng: number;
|
||||
@ -56,9 +36,8 @@ interface JournalMapData {
|
||||
locations: LocationMarker[]; // 位置标记列表
|
||||
customCalloutMarkerIds: string[]; // 改为 string[] 以支持 locationKey
|
||||
includePoints: Array<{ latitude: number; longitude: number }>; // 缩放视野以包含所有点
|
||||
selectedLocation: SelectedLocationInfo | null; // 选中的位置信息
|
||||
showDetail: boolean; // 是否显示详情(控制 DOM 存在)
|
||||
detailVisible: boolean; // 详情是否可见(控制动画)
|
||||
popupIds: number[];
|
||||
popupVisible: boolean;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
@ -72,8 +51,8 @@ Page({
|
||||
customCalloutMarkerIds: [],
|
||||
includePoints: [],
|
||||
selectedLocation: null,
|
||||
showDetail: false,
|
||||
detailVisible: false,
|
||||
popupIds: [],
|
||||
popupVisible: false,
|
||||
isLoading: true,
|
||||
},
|
||||
async onLoad() {
|
||||
@ -105,10 +84,8 @@ Page({
|
||||
fail: reject
|
||||
});
|
||||
}) || [];
|
||||
|
||||
// 过滤有位置信息的记录,并按位置分组
|
||||
const locationMap = new Map<string, LocationMarker>();
|
||||
|
||||
list.filter((journal: any) => journal.lat && journal.lng).forEach((journal: any) => {
|
||||
// 保留 6 位小数作为位置键,约等于 0.1 米精度
|
||||
const lat = Number(journal.lat.toFixed(6));
|
||||
@ -116,7 +93,6 @@ Page({
|
||||
const locationKey = `${lat},${lng}`;
|
||||
|
||||
if (!locationMap.has(locationKey)) {
|
||||
// 获取第一个有缩略图的日记
|
||||
const thumbItem = journal.items.find((item: any) => item.attachType === "THUMB");
|
||||
locationMap.set(locationKey, {
|
||||
locationKey,
|
||||
@ -129,7 +105,6 @@ Page({
|
||||
previewThumb: thumbItem ? `${config.url}/attachment/read/${thumbItem.mongoId}` : undefined
|
||||
});
|
||||
}
|
||||
|
||||
const marker = locationMap.get(locationKey)!;
|
||||
marker.journalIds.push(journal.id);
|
||||
marker.count++;
|
||||
@ -141,9 +116,7 @@ Page({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const locations = Array.from(locationMap.values());
|
||||
|
||||
if (locations.length === 0) {
|
||||
wx.showToast({
|
||||
title: "暂无位置记录",
|
||||
@ -152,7 +125,6 @@ Page({
|
||||
this.setData({ isLoading: false });
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成地图标记
|
||||
const markers: MapMarker[] = locations.map((location, index) => ({
|
||||
id: index,
|
||||
@ -162,11 +134,11 @@ Page({
|
||||
height: 30,
|
||||
customCallout: {
|
||||
anchorY: -2,
|
||||
anchorX: 0,
|
||||
// 随机错位避免近距离重叠
|
||||
anchorX: Toolkit.random(-10, 10),
|
||||
display: "ALWAYS"
|
||||
}
|
||||
}));
|
||||
|
||||
// 所有标记的 locationKey 列表
|
||||
const customCalloutMarkerIds = locations.map(l => l.locationKey);
|
||||
// 计算中心点(所有标记的平均位置)
|
||||
@ -177,7 +149,6 @@ Page({
|
||||
latitude: l.lat,
|
||||
longitude: l.lng
|
||||
}));
|
||||
|
||||
this.setData({
|
||||
locations,
|
||||
markers,
|
||||
@ -208,79 +179,18 @@ Page({
|
||||
/** 加载位置详情(该位置的所有日记) */
|
||||
async loadLocationDetail(markerId: number) {
|
||||
const location = this.data.locations[markerId];
|
||||
if (!location) return;
|
||||
|
||||
wx.showLoading({ title: "加载中...", mask: true });
|
||||
try {
|
||||
// 根据 journalIds 加载日记详情
|
||||
const list: Journal[] = await new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: `${config.url}/journal/list/ids`,
|
||||
method: "POST",
|
||||
header: {
|
||||
Key: wx.getStorageSync("key")
|
||||
},
|
||||
data: location.journalIds,
|
||||
success: (resp: any) => {
|
||||
if (resp.data.code === 20000) {
|
||||
resolve(resp.data.data);
|
||||
} else {
|
||||
reject(new Error(resp.data.message || "加载失败"));
|
||||
if (!location) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
fail: reject
|
||||
});
|
||||
}) || [];
|
||||
|
||||
// 转换为 JournalInfo 格式
|
||||
const journals: JournalInfo[] = list.map((journal: any) => {
|
||||
const date = new Date(journal.createdAt);
|
||||
return {
|
||||
id: journal.id,
|
||||
date: Time.toPassedDateTime(journal.createdAt),
|
||||
time: `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`,
|
||||
location: journal.location,
|
||||
idea: journal.idea,
|
||||
items: journal.items
|
||||
.filter((item: any) => item.attachType === MediaAttachType.THUMB)
|
||||
.map((item: any) => {
|
||||
const ext = JSON.parse(item.ext);
|
||||
return {
|
||||
type: ext.isVideo ? 1 : 0,
|
||||
thumbURL: `${config.url}/attachment/read/${item.mongoId}`,
|
||||
sourceURL: `${config.url}/attachment/read/${ext.sourceMongoId}`,
|
||||
mongoId: item.mongoId,
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
// 先显示元素,再触发动画
|
||||
this.setData({
|
||||
selectedLocation: {
|
||||
location: location.location,
|
||||
journals
|
||||
},
|
||||
showDetail: true
|
||||
popupIds: location.journalIds,
|
||||
popupVisible: true
|
||||
});
|
||||
wx.nextTick(() => {
|
||||
this.setData({ detailVisible: true });
|
||||
});
|
||||
wx.hideLoading();
|
||||
} catch (err: any) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: err.message || "加载失败",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 关闭详情 */
|
||||
async closeDetail() {
|
||||
this.setData({ detailVisible: false });
|
||||
await Toolkit.sleep(350);
|
||||
this.setData({
|
||||
showDetail: false,
|
||||
popupVisible: false,
|
||||
selectedLocation: null
|
||||
});
|
||||
},
|
||||
|
||||
@ -37,12 +37,9 @@
|
||||
</view>
|
||||
</view>
|
||||
<!-- 详情面板 -->
|
||||
<journal-detail-panel
|
||||
visible="{{showDetail && detailVisible}}"
|
||||
title="{{selectedLocation.location}}"
|
||||
journals="{{selectedLocation.journals}}"
|
||||
show-location-icon="{{true}}"
|
||||
show-journal-date="{{true}}"
|
||||
show-journal-location="{{false}}"
|
||||
<journal-detail-popup
|
||||
visible="{{popupVisible}}"
|
||||
ids="{{popupIds}}"
|
||||
mode="LOCATION"
|
||||
bind:close="closeDetail"
|
||||
/>
|
||||
|
||||
@ -1,21 +1,18 @@
|
||||
.custom-navbar {
|
||||
|
||||
.more-menu {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
background: var(--theme-bg-overlay);
|
||||
|
||||
.content {
|
||||
margin: 190rpx 0 0 12rpx;
|
||||
z-index: 1;
|
||||
z-index: 1000;
|
||||
position: fixed;
|
||||
background: var(--theme-bg-menu);
|
||||
box-shadow: 0 0 12px var(--theme-shadow-medium);
|
||||
border-radius: 2px;
|
||||
}
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,6 +63,7 @@
|
||||
.location {
|
||||
gap: 6rpx;
|
||||
display: flex;
|
||||
margin-top: 16rpx;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
|
||||
|
||||
@ -36,6 +36,8 @@ interface JournalData {
|
||||
isFinished: boolean;
|
||||
stickyOffset: number;
|
||||
isShowMoreMenu: boolean;
|
||||
menuTop: number;
|
||||
menuLeft: number;
|
||||
}
|
||||
|
||||
Page({
|
||||
@ -63,7 +65,9 @@ Page({
|
||||
isFetching: false,
|
||||
isFinished: false,
|
||||
stickyOffset: 0,
|
||||
isShowMoreMenu: false
|
||||
isShowMoreMenu: false,
|
||||
menuTop: 0,
|
||||
menuLeft: 0
|
||||
},
|
||||
onLoad() {
|
||||
Events.reset("JOURNAL_REFRESH", () => {
|
||||
@ -110,9 +114,30 @@ Page({
|
||||
});
|
||||
},
|
||||
toggleMoreMenu() {
|
||||
if (!this.data.isShowMoreMenu) {
|
||||
// 打开菜单时计算位置
|
||||
const query = wx.createSelectorQuery();
|
||||
query.select(".more").boundingClientRect();
|
||||
query.exec((res) => {
|
||||
if (res[0]) {
|
||||
const { top, left, height } = res[0];
|
||||
this.setData({
|
||||
isShowMoreMenu: !this.data.isShowMoreMenu
|
||||
})
|
||||
isShowMoreMenu: true,
|
||||
menuTop: top + height + 16, // 按钮下方 8px
|
||||
menuLeft: left
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 关闭菜单
|
||||
this.setData({
|
||||
isShowMoreMenu: false
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 阻止事件冒泡 */
|
||||
stopPropagation() {
|
||||
// 空函数,仅用于阻止事件冒泡
|
||||
},
|
||||
toCreater() {
|
||||
wx.navigateTo({
|
||||
@ -198,8 +223,7 @@ Page({
|
||||
});
|
||||
},
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const journalIndex = e.target.dataset.journalIndex;
|
||||
const itemIndex = e.target.dataset.itemIndex;
|
||||
const { journalIndex, itemIndex } = e.currentTarget.dataset;
|
||||
const items = this.data.list[journalIndex].items;
|
||||
const total = items.length;
|
||||
|
||||
@ -219,7 +243,7 @@ Page({
|
||||
})
|
||||
},
|
||||
openLocation(e: WechatMiniprogram.BaseEvent) {
|
||||
const journalIndex = e.target.dataset.journalIndex;
|
||||
const { journalIndex } = e.currentTarget.dataset;
|
||||
const journal = this.data.list[journalIndex] as Journal;
|
||||
if (journal.lat && journal.lng) {
|
||||
wx.openLocation({
|
||||
|
||||
@ -2,17 +2,22 @@
|
||||
<t-navbar title="我们的记录">
|
||||
<view slot="left" class="more" bind:tap="toggleMoreMenu">
|
||||
<t-icon name="view-list" size="24px" />
|
||||
<view wx:if="{{isShowMoreMenu}}" class="more-menu">
|
||||
<t-cell-group class="content" theme="card">
|
||||
</view>
|
||||
</t-navbar>
|
||||
</view>
|
||||
<view wx:if="{{isShowMoreMenu}}" class="more-menu" catchtap="toggleMoreMenu">
|
||||
<t-cell-group
|
||||
class="content"
|
||||
theme="card"
|
||||
style="top: {{menuTop}}px; left: {{menuLeft}}px;"
|
||||
catchtap="stopPropagation"
|
||||
>
|
||||
<t-cell title="新纪录" leftIcon="add" bind:tap="toCreater" />
|
||||
<t-cell title="按列表查找" leftIcon="view-list" bind:tap="toSearch" />
|
||||
<t-cell title="按日期查找" leftIcon="calendar-1" bind:tap="toDate" />
|
||||
<t-cell title="按地图查找" leftIcon="location" bind:tap="toMap" />
|
||||
</t-cell-group>
|
||||
</view>
|
||||
</view>
|
||||
</t-navbar>
|
||||
</view>
|
||||
<t-indexes
|
||||
class="journal-list"
|
||||
bind:scroll="onScroll"
|
||||
|
||||
@ -125,8 +125,7 @@ Page({
|
||||
});
|
||||
},
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const journalIndex = e.target.dataset.journalIndex;
|
||||
const itemIndex = e.target.dataset.itemIndex;
|
||||
const { journalIndex, itemIndex } = e.currentTarget.dataset;
|
||||
const items = this.data.list[journalIndex].items;
|
||||
const total = items.length;
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ Page({
|
||||
});
|
||||
},
|
||||
toLuggageList(e: WechatMiniprogram.BaseEvent) {
|
||||
const name = e.target.dataset.name;
|
||||
const { name } = e.currentTarget.dataset;
|
||||
wx.setStorageSync("luggage", {
|
||||
name,
|
||||
luggage: this.data.luggage
|
||||
@ -91,8 +91,7 @@ Page({
|
||||
})
|
||||
},
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const index = e.target.dataset.index;
|
||||
const imageIndex = e.target.dataset.imageIndex;
|
||||
const { index, imageIndex } = e.currentTarget.dataset;
|
||||
const images = this.data.guides[index].images;
|
||||
wx.previewMedia({
|
||||
current: imageIndex,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Attachment } from "./Attachment";
|
||||
import { Model, QueryPage } from "./Model";
|
||||
import { MediaItem } from "./UI";
|
||||
|
||||
/** 日记 */
|
||||
export type Journal = {
|
||||
@ -22,8 +23,22 @@ export type Journal = {
|
||||
/** 天气 */
|
||||
weatcher?: string;
|
||||
|
||||
// ---------- 以下为 VO 字段 ----------
|
||||
|
||||
/** 日期 */
|
||||
date?: string;
|
||||
|
||||
/** 时间 */
|
||||
time?: string;
|
||||
|
||||
/** 时间 */
|
||||
datetime?: string;
|
||||
|
||||
/** 附件(照片、视频等) */
|
||||
items?: Attachment[];
|
||||
|
||||
/** 媒体项(由附件转) */
|
||||
mediaItems?: MediaItem[];
|
||||
} & Model;
|
||||
|
||||
/** 日记类型 */
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
/** 系统媒体项目 */
|
||||
export type MediaItem = {
|
||||
|
||||
journalId?: number;
|
||||
|
||||
/** 类型 */
|
||||
type: MediaItemType;
|
||||
|
||||
@ -62,3 +64,10 @@ export type Location = {
|
||||
/** 描述 */
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export enum JournalDetailType {
|
||||
|
||||
DATE = "DATE",
|
||||
|
||||
LOCATION = "LOCATION"
|
||||
}
|
||||
Reference in New Issue
Block a user