|
|
@@ -182,8 +182,7 @@ const parseFileName = (disposition) => {
|
|
|
return 'unknown'
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-const downloadBlob1 = (data, disposition = '', type = 'application/vnd.ms-excel') =>{
|
|
|
+const downloadBlob1 = (data, disposition = '', type = 'application/vnd.ms-excel')=> {
|
|
|
const blob = new Blob([data], { type: type })
|
|
|
const blobURL = window.URL.createObjectURL(blob)
|
|
|
const tempLink = document.createElement('a')
|
|
|
@@ -193,27 +192,16 @@ const downloadBlob1 = (data, disposition = '', type = 'application/vnd.ms-excel'
|
|
|
// 1. 解析文件名
|
|
|
let filename = parseFileName(disposition)
|
|
|
|
|
|
- // 2. 关键修复:处理文件名(解码 + 过滤特殊字符 + 确保后缀)
|
|
|
- try {
|
|
|
- // 先解码URL编码的字符(如%E6转为中文)
|
|
|
- filename = decodeURIComponent(filename)
|
|
|
- } catch (e) {
|
|
|
- // 若解码失败(如特殊字符不完整),直接使用原始值
|
|
|
- console.warn('文件名解码失败,使用原始值', e)
|
|
|
- }
|
|
|
-
|
|
|
- // 过滤不安全字符:保留中文、英文、数字、-、+、_、.,其他替换为_
|
|
|
+ // 2. 关键修复:过滤特殊字符并确保.xlsx后缀
|
|
|
+ // 过滤不安全字符:#、/、%等,替换为_
|
|
|
filename = filename.replace(/[#%/\\:*?"<>|]/g, '_')
|
|
|
-
|
|
|
- // 确保文件名以.xlsx结尾(若被截断或误加字符,强制修正)
|
|
|
+ // 强制确保以.xlsx结尾(移除可能的多余字符)
|
|
|
if (!filename.endsWith('.xlsx')) {
|
|
|
- // 移除现有后缀(如果有),再补全.xlsx
|
|
|
+ // 先移除现有后缀(如果有),再补全.xlsx
|
|
|
filename = filename.replace(/\.[^.]*$/, '') + '.xlsx'
|
|
|
}
|
|
|
|
|
|
- // 3. 设置处理后的文件名
|
|
|
tempLink.setAttribute('download', filename)
|
|
|
-
|
|
|
if (typeof tempLink.download === 'undefined') {
|
|
|
tempLink.setAttribute('target', '_blank')
|
|
|
}
|