公共服务平台-宣传物料
This commit is contained in:
parent
cf09f1d57d
commit
e02d9e8000
|
|
@ -95,6 +95,7 @@ import DialogModel from '@/components/DialogModel/index'
|
|||
import {getMaterialListAPI} from '@/api/publicService/proMaterials'
|
||||
import { encryptCBCTime } from '@/utils/aes'
|
||||
import useBase64 from '@/utils/base64Utils.js'
|
||||
import axios from 'axios'
|
||||
|
||||
export default {
|
||||
name: 'ProMaterials',
|
||||
|
|
@ -182,42 +183,32 @@ export default {
|
|||
}
|
||||
},
|
||||
// 下载
|
||||
handleDownload(service) {
|
||||
let url = service.filePath;
|
||||
// 下载
|
||||
async handleDownload(service) {
|
||||
try {
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: process.env.VUE_APP_BASE_API + '/system/files/download',
|
||||
params: {
|
||||
filePath: service.fileDownloadPath
|
||||
},
|
||||
responseType: 'blob' // 重要:指定响应类型为blob
|
||||
});
|
||||
|
||||
// 确保 URL 是完整的绝对路径
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||
if (url.startsWith('www.')) {
|
||||
url = 'https://' + url;
|
||||
} else {
|
||||
url = 'https://' + url;
|
||||
}
|
||||
// 创建下载链接
|
||||
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', service.fileName || 'file'); // 设置下载文件名
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(url); // 清理URL对象
|
||||
|
||||
this.$message.success('下载成功');
|
||||
} catch (error) {
|
||||
this.$message.error('下载失败');
|
||||
}
|
||||
|
||||
// 创建临时 a 标签来触发下载
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = ''; // 可指定文件名,如 'filename.zip';空字符串表示使用服务器原文件名
|
||||
link.target = '_blank'; // 兼容某些浏览器
|
||||
link.style.display = 'none';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link); // 清理
|
||||
alert('下载成功')
|
||||
|
||||
/*// 确保 URL 是完整的绝对路径
|
||||
let url = service.filePath
|
||||
// 如果 URL 不是以 http:// 或 https:// 开头,则添加 https://
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||
// 如果 URL 以 www. 开头,直接添加 https://
|
||||
if (url.startsWith('www.')) {
|
||||
url = 'https://' + url
|
||||
} else {
|
||||
// 其他情况,添加 https://
|
||||
url = 'https://' + url
|
||||
}
|
||||
}
|
||||
window.open(url, '_blank')*/
|
||||
},
|
||||
// 鼠标悬浮
|
||||
handleCardHover(serviceId) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue