任务详细页面文件显示与下载

This commit is contained in:
WindowBird 2025-11-17 11:04:57 +08:00
parent a983e545fc
commit d530bd5fd8

View File

@ -88,6 +88,21 @@
/>
</view>
</view>
<!-- 任务文件展示 -->
<view class="task-files-wrapper" v-if="task.files && task.files.length > 0">
<view
class="file-attachment-item"
v-for="(file, fileIndex) in task.files"
:key="fileIndex"
@click="previewTaskFile(file)"
>
<text class="file-icon">{{ getFileIcon(file.name) }}</text>
<view class="file-info">
<text class="file-name">{{ file.name }}</text>
<text class="file-size" v-if="file.size > 0">{{ formatFileSize(file.size) }}</text>
</view>
</view>
</view>
<view class="delay-btn-wrapper">
<uv-button type="error" size="small" @click="applyDelay">申请延期</uv-button>
</view>
@ -325,6 +340,32 @@ const isImageUrl = (url) => {
return /\.(jpg|jpeg|png|gif|bmp|webp)(\?|$)/i.test(url);
};
//
const parseTaskAttachments = (attachStr) => {
if (!attachStr) return { pictures: [], files: [] };
if (typeof attachStr !== 'string') return { pictures: [], files: [] };
const urls = parseAttachUrls(attachStr);
const pictures = [];
const files = [];
urls.forEach(url => {
if (isImageUrl(url)) {
pictures.push(url);
} else {
// URL
const fileName = url.split('/').pop().split('?')[0] || '文件';
files.push({
name: fileName,
path: url,
size: 0 // API0
});
}
});
return { pictures, files };
};
//
const transformSubmitRecords = (submitList) => {
if (!Array.isArray(submitList) || submitList.length === 0) {
@ -488,6 +529,73 @@ const previewTaskImages = (imageUrls, index) => {
}
};
// /
const previewTaskFile = (file) => {
if (!file.path) {
uni.showToast({
title: '文件路径不存在',
icon: 'none'
});
return;
}
// 使
const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
const ext = file.name ? file.name.split('.').pop().toLowerCase() : '';
if (imageExts.includes(ext)) {
uni.previewImage({
urls: [file.path],
current: file.path
});
} else {
//
// #ifdef H5
window.open(file.path, '_blank');
// #endif
// #ifdef APP-PLUS
plus.runtime.openURL(file.path);
// #endif
// #ifndef H5 || APP-PLUS
uni.showToast({
title: '正在下载文件...',
icon: 'loading',
duration: 2000
});
//
uni.downloadFile({
url: file.path,
success: (res) => {
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.tempFilePath,
success: () => {
console.log('打开文档成功');
},
fail: (err) => {
console.error('打开文档失败:', err);
uni.showToast({
title: '无法打开此文件',
icon: 'none'
});
}
});
}
},
fail: (err) => {
console.error('下载文件失败:', err);
uni.showToast({
title: '下载文件失败',
icon: 'none'
});
}
});
// #endif
}
};
//
const previewRecordImages = (imageUrls, index) => {
if (imageUrls && imageUrls.length > 0) {
@ -679,8 +787,16 @@ const loadTaskData = async (taskId) => {
//
const submitRecords = transformSubmitRecords(res.submitList || []);
// URL
const taskPictures = res.picture ? parseAttachUrls(res.picture) : [];
//
// 使 file 使 picture
let taskAttachments = { pictures: [], files: [] };
if (res.file) {
// API file
taskAttachments = parseTaskAttachments(res.file);
} else if (res.picture) {
// picture
taskAttachments = parseTaskAttachments(res.picture);
}
//
task.value = {
@ -694,7 +810,8 @@ const loadTaskData = async (taskId) => {
responsible: getOwnerNames(res.memberList || []),
publishTime: res.createTime ? formatTimeToChinese(res.createTime) : '',
content: res.description || '',
pictures: taskPictures, //
pictures: taskAttachments.pictures, //
files: taskAttachments.files, //
submitRecords: submitRecords,
// 使
rawData: res
@ -1185,6 +1302,14 @@ onShow(() => {
object-fit: cover;
}
/* 任务文件展示 */
.task-files-wrapper {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 16px;
}
/* 提交记录图片展示(一行三个) */
.record-images-wrapper {
display: flex;