feat: 新增很多页面
This commit is contained in:
@@ -86,7 +86,30 @@ const state = reactive({
|
||||
*/
|
||||
const downExcelTemp = async () => {
|
||||
try {
|
||||
await other.downBlobFile(other.adaptationUrl(prop.tempUrl), {}, 'temp.xlsx');
|
||||
// 如果是 assets 文件夹下的文件,使用 import.meta.url 获取文件
|
||||
if (prop.tempUrl && prop.tempUrl.includes('assets/file')) {
|
||||
// 从路径中提取文件名
|
||||
const fileName = prop.tempUrl.split('/').pop() || 'template.xlsx';
|
||||
// 使用动态导入获取文件URL,从 components/Upload 到 assets/file 的相对路径
|
||||
const fileUrl = new URL(`../../assets/file/${fileName}`, import.meta.url).href;
|
||||
const response = await fetch(fileUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error('文件下载失败');
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(link);
|
||||
} else {
|
||||
// 使用后端接口下载
|
||||
const fileName = prop.tempUrl?.split('/').pop() || 'template.xlsx';
|
||||
await other.downBlobFile(other.adaptationUrl(prop.tempUrl), {}, fileName);
|
||||
}
|
||||
} catch (error) {
|
||||
useMessage().error('模板下载失败,请先维护模板文件');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user