Files
miniprogram-1/miniprogram/pages/history/history.ts
2025-12-12 20:23:28 +08:00

135 lines
3.4 KiB
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// history.ts
import apiManager from '../../utils/api';
import { ICacheableAuditHistoryItem } from '../../types/app';
import { FILE_BASE_URL } from '../../utils/config';
import logger from '../../utils/logger'
Page({
data: {
isLoading: true,
showImage: false,
visible: false,
loopList: new Array(10),
images: [] as string[],
historyItems: [] as ICacheableAuditHistoryItem[],
page: 1,
size: 15,
total: 0,
hasMore: true,
// 添加全局域名变量
fileBaseUrl: FILE_BASE_URL
},
onLoad() {
logger.info('历史记录页面加载');
this.loadHistoryData();
},
onShow() {
logger.info('历史记录页面显示');
},
async loadHistoryData(page: number = 1) {
try {
if (page === 1) {
this.setData({ isLoading: true });
}
const result = await apiManager.getAuditHistory(page, this.data.size);
// 处理图片 URL添加完整的域名路径并缓存处理结果
const processedItems = result.items.map(item => {
// 检查是否已经处理过这个项目
const existingItem = this.data.historyItems.find(existing =>
existing.image_id === item.image_id && existing.file_id === item.file_id);
if (existingItem && existingItem.thumbnail_url && existingItem.file_url) {
// 如果已经处理过,直接使用缓存的结果
return existingItem;
} else {
// 如果没有处理过,进行处理并缓存
return {
...item,
thumbnail_url: item.thumbnail_id ? `${this.data.fileBaseUrl}/${item.thumbnail_id}` : '',
file_url: item.file_id ? `${this.data.fileBaseUrl}/${item.file_id}` : ''
};
}
});
const newData = page === 1 ? processedItems : [...this.data.historyItems, ...processedItems];
this.setData({
historyItems: newData,
page: result.page,
total: result.total,
hasMore: newData.length < result.total,
isLoading: false,
});
} catch (error) {
logger.error('加载历史记录失败:', error);
this.setData({ isLoading: false });
wx.showToast({
title: '加载失败',
icon: 'none'
});
}
},
onRefresh() {
this.setData({
enable: true,
page: 1,
});
this.loadHistoryData(1).then(() => {
setTimeout(() => {
this.setData({ enable: false });
}, 500);
});
},
onScrollToBottom() {
if (this.data.hasMore && !this.data.isLoading) {
const nextPage = this.data.page + 1;
this.loadHistoryData(nextPage);
}
},
onScroll(e: any) {
const { scrollTop } = e.detail;
this.setData({ scrollTop });
},
onImageTap(e: any) {
const { image } = e.currentTarget.dataset;
if (image) {
wx.previewImage({
current: image,
urls: [image]
});
}
},
onClose() {
this.setData({
visible: false,
showImage: false
});
},
onReachBottom() {
// 触底加载更多数据
if (this.data.hasMore && !this.data.isLoading) {
const nextPage = this.data.page + 1;
this.loadHistoryData(nextPage);
}
},
onChange(e: any) {
logger.info('图片查看器变化:', e.detail);
},
onDelete(e: any) {
logger.info('删除图片:', e.detail);
}
})