公共服务平台-宣传物料
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 {getMaterialListAPI} from '@/api/publicService/proMaterials'
|
||||||
import { encryptCBCTime } from '@/utils/aes'
|
import { encryptCBCTime } from '@/utils/aes'
|
||||||
import useBase64 from '@/utils/base64Utils.js'
|
import useBase64 from '@/utils/base64Utils.js'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ProMaterials',
|
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://')) {
|
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
if (url.startsWith('www.')) {
|
|
||||||
url = 'https://' + url;
|
|
||||||
} else {
|
|
||||||
url = 'https://' + url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建临时 a 标签来触发下载
|
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = ''; // 可指定文件名,如 'filename.zip';空字符串表示使用服务器原文件名
|
link.setAttribute('download', service.fileName || 'file'); // 设置下载文件名
|
||||||
link.target = '_blank'; // 兼容某些浏览器
|
|
||||||
link.style.display = 'none';
|
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
document.body.removeChild(link); // 清理
|
link.remove();
|
||||||
alert('下载成功')
|
window.URL.revokeObjectURL(url); // 清理URL对象
|
||||||
|
|
||||||
/*// 确保 URL 是完整的绝对路径
|
this.$message.success('下载成功');
|
||||||
let url = service.filePath
|
} catch (error) {
|
||||||
// 如果 URL 不是以 http:// 或 https:// 开头,则添加 https://
|
this.$message.error('下载失败');
|
||||||
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) {
|
handleCardHover(serviceId) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue