|
|
@@ -283,8 +283,8 @@
|
|
|
:before-upload="beforeAvatarUploadFile">
|
|
|
<i class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
</el-upload>
|
|
|
- <el-link v-if="item.fileUrl" type="primary" :href="downloadUrl(item.fileUrl)" download>
|
|
|
- {{ item.fileUrl }}
|
|
|
+ <el-link v-if="item.fileUrl" type="primary" @click="handleDownloadFile(item.fileUrl, item.fileName)">
|
|
|
+ {{ item.fileName || item.fileUrl }}
|
|
|
</el-link>
|
|
|
</el-form-item>
|
|
|
|
|
|
@@ -465,8 +465,8 @@
|
|
|
:before-upload="beforeAvatarUploadFile">
|
|
|
<i class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
</el-upload>
|
|
|
- <el-link v-if="item.fileUrl" type="primary" :href="downloadUrl(item.fileUrl)" download>
|
|
|
- {{ item.fileUrl }}
|
|
|
+ <el-link v-if="item.fileUrl" type="primary" @click="handleDownloadFile(item.fileUrl, item.fileName)">
|
|
|
+ {{ item.fileName || item.fileUrl }}
|
|
|
</el-link>
|
|
|
</el-form-item>
|
|
|
|
|
|
@@ -852,6 +852,8 @@ export default {
|
|
|
if (res.code === 200) {
|
|
|
// 使用 $set 确保响应式更新
|
|
|
this.$set(item, 'fileUrl', res.url);
|
|
|
+ // 优先使用后端返回的fileName,兜底使用前端文件名
|
|
|
+ this.$set(item, 'fileName', res.fileName || file.name);
|
|
|
} else {
|
|
|
this.msgError(res.msg);
|
|
|
}
|
|
|
@@ -869,6 +871,31 @@ export default {
|
|
|
// 直接返回文件 URL
|
|
|
return materialUrl;
|
|
|
},
|
|
|
+ // 处理文件下载(支持中文文件名)
|
|
|
+ handleDownloadFile(fileUrl, fileName) {
|
|
|
+ if (!fileUrl) return;
|
|
|
+
|
|
|
+ // 使用 fetch 下载文件并设置正确的文件名
|
|
|
+ fetch(fileUrl)
|
|
|
+ .then(response => response.blob())
|
|
|
+ .then(blob => {
|
|
|
+ // 创建下载链接
|
|
|
+ const url = window.URL.createObjectURL(blob);
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = url;
|
|
|
+ link.download = fileName || fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+
|
|
|
+ // 清理
|
|
|
+ document.body.removeChild(link);
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error('下载失败:', error);
|
|
|
+ this.$message.error('文件下载失败');
|
|
|
+ });
|
|
|
+ },
|
|
|
handleInputVideoText(value, content) {
|
|
|
// 允许的字符:中文、英文(大小写)、数字和指定标点符号(,。!?)
|
|
|
const regex = /^[\u4e00-\u9fa5,。!?,!?]+$/;
|