support archive moment to exist journal

This commit is contained in:
Timi
2025-12-08 15:52:59 +08:00
parent 75b553ac93
commit a25c38d50d
13 changed files with 392 additions and 133 deletions

View File

@ -25,6 +25,8 @@ type MD5Result = {
md5: string;
}
type ArchiveStep = "select-type" | "select-journal" | "form";
interface MomentData {
list: Item[];
type: string;
@ -42,6 +44,8 @@ interface MomentData {
uploadProgress: number;
isAuthLocation: boolean;
isVisibleArchivePopup: boolean;
archiveStep: ArchiveStep;
selectedJournalId: number | null;
}
Page({
@ -60,7 +64,9 @@ Page({
uploadTotal: "0 MB",
uploadProgress: 0,
isAuthLocation: false,
isVisibleArchivePopup: false
isVisibleArchivePopup: false,
archiveStep: "select-type",
selectedJournalId: null
},
async onLoad() {
this.fetch();
@ -163,7 +169,7 @@ Page({
preview(e: WechatMiniprogram.BaseEvent) {
const index = e.currentTarget.dataset.index;
const total = this.data.list.length;
const startIndex = Math.max(0, index - 25);
const endIndex = Math.min(total, startIndex + 50);
const newCurrentIndex = index - startIndex;
@ -240,7 +246,7 @@ Page({
});
// 过滤文件
const filterPath = md5Results.filter(item => filterMD5Result.indexOf(item.md5) !== -1)
.map(item => item.path);
.map(item => item.path);
files = files.filter(file => filterPath.indexOf(file.tempFilePath) !== -1);
if (files.length === 0) {
wx.hideLoading();
@ -295,7 +301,7 @@ Page({
});
uploadResolve(result.data[0].id);
} else {
uploadReject(new Error(`文件上传失败: ${result?.message || '未知错误'}`));
uploadReject(new Error(`文件上传失败: ${result?.message || "未知错误"}`));
}
},
fail: (err) => uploadReject(new Error(`文件上传失败: ${err.errMsg}`))
@ -375,6 +381,47 @@ Page({
}
})
},
showArchivePopup() {
this.setData({
isVisibleArchivePopup: true,
archiveStep: "select-type",
selectedJournalId: null
});
},
onArchiveToNew() {
this.setData({
archiveStep: "form",
selectedJournalId: null
});
},
onArchiveToExisting() {
this.setData({
archiveStep: "select-journal",
selectedJournalId: null
});
},
onJournalListSelect(e: any) {
const { id } = e.detail;
this.setData({
selectedJournalId: id
});
},
onJournalListConfirm() {
if (this.data.selectedJournalId) {
this.archiveChecked();
}
},
onJournalListCancel() {
this.setData({
archiveStep: "select-type",
selectedJournalId: null
});
},
onNewJournalBack() {
this.setData({
archiveStep: "select-type"
});
},
toggleArchivePopup() {
this.setData({
isVisibleArchivePopup: !this.data.isVisibleArchivePopup
@ -434,22 +481,26 @@ Page({
fail: handleFail
});
});
const archiveData: any = {
type: this.data.type,
idea: this.data.idea,
lat: this.data.location?.lat,
lng: this.data.location?.lng,
location: this.data.location?.text,
pusher: openId,
thumbIds: this.data.list.filter(item => item.checked).map(item => item.id)
};
// 如果选择了已存在的记录,添加 id 参数
if (this.data.selectedJournalId) {
archiveData.id = this.data.selectedJournalId;
}
wx.request({
url: `${config.url}/journal/moment/archive`,
method: "POST",
header: {
Key: wx.getStorageSync("key")
},
data: {
type: this.data.type,
idea: this.data.idea,
createdAt: Date.parse(`${this.data.date} ${this.data.time}`),
lat: this.data.location?.lat,
lng: this.data.location?.lng,
location: this.data.location?.text,
pusher: openId,
thumbIds: this.data.list.filter(item => item.checked).map(item => item.id)
},
data: archiveData,
success: async (resp: any) => {
if (resp.data && resp.data.code === 20000) {
Events.emit("JOURNAL_REFRESH");
@ -458,11 +509,12 @@ Page({
idea: "",
list: [],
hasChecked: false,
isArchiving: false
isArchiving: false,
selectedJournalId: undefined,
isVisibleArchivePopup: false
});
await Toolkit.sleep(1000);
this.fetch();
this.toggleArchivePopup();
} else {
wx.showToast({ title: "归档失败", icon: "error" });
this.setData({