1、精简文件表格字段
2、修改pdf在线查看逻辑
This commit is contained in:
@@ -320,12 +320,11 @@
|
||||
"
|
||||
>
|
||||
<div
|
||||
@click="openDoc(fileItem)"
|
||||
v-for="(fileItem, fileIndex) in record.workPaperIndex"
|
||||
:key="fileIndex"
|
||||
>
|
||||
<img
|
||||
src="@/assets/word.png"
|
||||
:src="getFileIcon(fileItem)"
|
||||
style="
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
@@ -337,17 +336,21 @@
|
||||
|
||||
<!-- 新格式支持 -->
|
||||
<span
|
||||
v-if="fileItem.fileUrl"
|
||||
v-if="getFileInfo(fileItem).url"
|
||||
@click.stop="handleFilePreview(fileItem)"
|
||||
class="file-link cursor-pointer text-wrap"
|
||||
style="color: #1890ff; text-decoration: none"
|
||||
>
|
||||
{{ fileItem.fileName || '未命名文件' }}
|
||||
{{ getFileInfo(fileItem).name || '未命名文件' }}
|
||||
</span>
|
||||
|
||||
<!-- 旧格式兼容 -->
|
||||
<span v-else class="cursor-pointer text-wrap">
|
||||
{{ fileItem.fileName || fileItem || '未命名文件' }}
|
||||
<span
|
||||
v-else
|
||||
class="cursor-pointer text-wrap"
|
||||
@click.stop="openDoc(fileItem)"
|
||||
>
|
||||
{{ getFileInfo(fileItem).name || '未命名文件' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2011,12 +2014,89 @@
|
||||
});
|
||||
};
|
||||
|
||||
const openDoc = (fileItem) => {
|
||||
console.log(fileItem);
|
||||
// window.open(
|
||||
// `http://view.officeapps.live.com/op/view.aspx?src=文件地址`,
|
||||
// '_blank'
|
||||
// );
|
||||
const getFileInfo = (fileItem: any) => {
|
||||
if (typeof fileItem === 'string') {
|
||||
const [fileId = '', fileName = '', fileUrl = ''] = fileItem.split('||');
|
||||
return {
|
||||
id: fileId,
|
||||
name: fileName || fileItem,
|
||||
url: fileUrl,
|
||||
ext: getFileExt(fileName || fileUrl || fileItem)
|
||||
};
|
||||
}
|
||||
|
||||
if (fileItem && typeof fileItem === 'object') {
|
||||
const name =
|
||||
fileItem.fileName || fileItem.file_name || fileItem.name || '';
|
||||
const url = fileItem.fileUrl || fileItem.url || '';
|
||||
const ext =
|
||||
fileItem.fileExt ||
|
||||
fileItem.fileType ||
|
||||
getFileExt(name || url || '');
|
||||
|
||||
return {
|
||||
id: fileItem.fileId || fileItem.file_id || '',
|
||||
name: name || '未命名文件',
|
||||
url,
|
||||
ext: String(ext || '').toLowerCase().replace(/^\./, '')
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
id: '',
|
||||
name: '未命名文件',
|
||||
url: '',
|
||||
ext: ''
|
||||
};
|
||||
};
|
||||
|
||||
const getFileExt = (value: string) => {
|
||||
const cleanValue = String(value || '').split('?')[0].trim();
|
||||
if (!cleanValue) return '';
|
||||
const ext = cleanValue.includes('.') ? cleanValue.split('.').pop() : '';
|
||||
return String(ext || '').toLowerCase().replace(/^\./, '');
|
||||
};
|
||||
|
||||
const buildFileIconDataUri = (label: string, color: string) => {
|
||||
const svg = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<rect width="20" height="20" rx="4" fill="${color}"/>
|
||||
<text x="10" y="13" text-anchor="middle" font-size="7" font-family="Arial, sans-serif" fill="#ffffff">${label}</text>
|
||||
</svg>
|
||||
`;
|
||||
return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(svg)}`;
|
||||
};
|
||||
|
||||
const getFileIcon = (fileItem: any) => {
|
||||
const ext = getFileInfo(fileItem).ext;
|
||||
|
||||
if (ext === 'pdf') {
|
||||
return buildFileIconDataUri('PDF', '#e53935');
|
||||
}
|
||||
if (['doc', 'docx'].includes(ext)) {
|
||||
return buildFileIconDataUri('DOC', '#2f6fed');
|
||||
}
|
||||
if (['xls', 'xlsx', 'csv'].includes(ext)) {
|
||||
return buildFileIconDataUri('XLS', '#2e7d32');
|
||||
}
|
||||
if (['ppt', 'pptx'].includes(ext)) {
|
||||
return buildFileIconDataUri('PPT', '#ef6c00');
|
||||
}
|
||||
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'].includes(ext)) {
|
||||
return buildFileIconDataUri('IMG', '#8e24aa');
|
||||
}
|
||||
if (['txt', 'md'].includes(ext)) {
|
||||
return buildFileIconDataUri('TXT', '#546e7a');
|
||||
}
|
||||
return buildFileIconDataUri('FILE', '#607d8b');
|
||||
};
|
||||
|
||||
const openDoc = (fileItem: any) => {
|
||||
const file = getFileInfo(fileItem);
|
||||
if (!file.url) {
|
||||
return;
|
||||
}
|
||||
window.open(file.url, '_blank', 'noopener,noreferrer');
|
||||
};
|
||||
|
||||
/* 键盘快捷键处理 */
|
||||
@@ -2168,18 +2248,31 @@
|
||||
}
|
||||
);
|
||||
|
||||
const handleFilePreview = (file) => {
|
||||
console.log(
|
||||
file.fileUrl,
|
||||
`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(
|
||||
file.fileUrl
|
||||
)}`
|
||||
);
|
||||
window.open(
|
||||
`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(
|
||||
file.fileUrl
|
||||
)}`
|
||||
);
|
||||
const handleFilePreview = (fileItem: any) => {
|
||||
const file = getFileInfo(fileItem);
|
||||
if (!file.url) {
|
||||
message.warning('该文件暂无可访问地址');
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.ext === 'pdf') {
|
||||
window.open(file.url, '_blank', 'noopener,noreferrer');
|
||||
return;
|
||||
}
|
||||
|
||||
const officePreviewExts = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'];
|
||||
if (officePreviewExts.includes(file.ext)) {
|
||||
window.open(
|
||||
`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(
|
||||
file.url
|
||||
)}`,
|
||||
'_blank',
|
||||
'noopener,noreferrer'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
window.open(file.url, '_blank', 'noopener,noreferrer');
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user