跟进详细页面补充文件下载功能

This commit is contained in:
WindowBird 2025-11-10 14:55:19 +08:00
parent 8a184a90d2
commit dee37e4e2b
4 changed files with 235 additions and 4 deletions

View File

@ -95,8 +95,8 @@
<text class="action-text">电话</text>
</view>
<view class="action-item" @click.stop="handleMore(customer)">
<text class="action-icon">+</text>
<text class="action-text">更多</text>
<text class="action-arrow"></text>
</view>
</view>
</view>

View File

@ -30,7 +30,7 @@
<view class="delete-btn" @click.stop="handleDelete(item)">
<text class="delete-icon">🗑</text>
</view>
<text class="followup-arrow"></text>
</view>
</view>
<text class="followup-text">{{ item.content }}</text>

View File

@ -62,6 +62,26 @@
</view>
</view>
<!-- 附件列表 -->
<view class="info-card" v-if="followupAttachments.length > 0">
<view class="card-title">附件</view>
<view class="attachments-list">
<view
class="attachment-item"
v-for="(file, index) in followupAttachments"
:key="index"
@click="previewAttachment(file)"
>
<text class="file-icon">{{ getFileIcon(file.name || file.path) }}</text>
<view class="file-info">
<text class="file-name">{{ file.name || getFileNameFromUrl(file.path) }}</text>
<text class="file-size" v-if="file.size">{{ formatFileSize(file.size) }}</text>
</view>
<text class="preview-arrow"></text>
</view>
</view>
</view>
<!-- 下次跟进 -->
<view class="info-card" v-if="followupDetail.nextFollowTime">
<view class="card-title">时间信息</view>
@ -206,6 +226,60 @@ const followupImages = computed(() => {
return [];
});
//
const followupAttachments = computed(() => {
const detail = followupDetail.value;
const attachments = [];
const normalizeAttachment = (item) => {
if (!item) return null;
if (typeof item === 'string') {
const trimmed = item.trim();
if (!trimmed) return null;
return {
path: trimmed,
name: getFileNameFromUrl(trimmed),
size: 0
};
}
if (typeof item === 'object' && item.path) {
return {
path: item.path,
name: item.name || getFileNameFromUrl(item.path),
size: item.size || 0
};
}
return null;
};
const attachSources = [
detail.attaches,
detail.attachments,
detail.files
];
attachSources.forEach((source) => {
if (!source) return;
if (typeof source === 'string') {
source.split(',').forEach((url) => {
const normalized = normalizeAttachment(url);
if (normalized) attachments.push(normalized);
});
} else if (Array.isArray(source)) {
source.forEach((item) => {
const normalized = normalizeAttachment(item);
if (normalized) attachments.push(normalized);
});
}
});
return attachments;
});
//
onLoad((options) => {
if (options && options.followId) {
@ -360,6 +434,118 @@ const previewFollowupImages = (images, currentIndex) => {
});
};
//
function getFileNameFromUrl(url = '') {
try {
const decodedUrl = decodeURIComponent(url);
const parts = decodedUrl.split('/');
return parts.pop() || decodedUrl;
} catch (err) {
return url;
}
}
//
function getFileIcon(filename = '') {
const ext = filename.split('.').pop()?.toLowerCase() || '';
const iconMap = {
pdf: '📄',
doc: '📝',
docx: '📝',
xls: '📊',
xlsx: '📊',
ppt: '📈',
pptx: '📈',
txt: '📄',
zip: '📦',
rar: '📦',
jpg: '🖼️',
jpeg: '🖼️',
png: '🖼️',
gif: '🖼️',
mp4: '🎞️',
mp3: '🎵'
};
return iconMap[ext] || '📁';
}
//
function formatFileSize(bytes) {
if (!bytes || bytes <= 0) return '';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
}
//
const previewAttachment = (file) => {
if (!file || !file.path) {
uni.showToast({
title: '文件不存在',
icon: 'none'
});
return;
}
const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
const filename = file.name || getFileNameFromUrl(file.path);
const ext = filename.split('.').pop()?.toLowerCase() || '';
if (imageExts.includes(ext)) {
uni.previewImage({
urls: [file.path],
current: file.path
});
return;
}
// #ifdef H5
window.open(file.path, '_blank');
// #endif
// #ifdef APP-PLUS
if (typeof plus !== 'undefined' && plus.runtime) {
plus.runtime.openURL(file.path);
return;
}
// #endif
//
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'
});
}
});
} else {
uni.showToast({
title: '下载文件失败',
icon: 'none'
});
}
},
fail: (err) => {
console.error('下载附件失败:', err);
uni.showToast({
title: '下载文件失败',
icon: 'none'
});
}
});
};
//
const handleBack = () => {
uni.navigateBack();
@ -534,6 +720,53 @@ onMounted(() => {
object-fit: cover;
}
.attachments-list {
display: flex;
flex-direction: column;
gap: 12px;
}
.attachment-item {
display: flex;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid #f5f5f5;
&:last-child {
border-bottom: none;
padding-bottom: 0;
}
}
.file-icon {
font-size: 24px;
margin-right: 12px;
}
.file-info {
flex: 1;
display: flex;
flex-direction: column;
gap: 4px;
}
.file-name {
font-size: 14px;
color: #333;
word-break: break-word;
}
.file-size {
font-size: 12px;
color: #999;
}
.preview-arrow {
font-size: 20px;
color: #bbb;
margin-left: 12px;
}
.status-badge {
display: inline-block;
padding: 4px 12px;

View File

@ -1207,7 +1207,5 @@ const handleCancel = () => {
background-color: #fff;
border-top: 1px solid #e0e0e0;
}
</style>