Browse Source

处理系统所有下载附件功能的文件名问题

ljb 9 months ago
parent
commit
ffa2b638b6

+ 2 - 5
src/components/upload-excel-dialog/index.vue

@@ -22,6 +22,7 @@
 <script>
 import { getDictValueByKey } from '@/api/system/dict';
 import {downExcelTemp} from "@/api/common";
+import { downloadFileByUrl } from "@/util/util";
 
 export default {
   name: "UploadExcelDialog",
@@ -88,11 +89,7 @@ export default {
             this.$message.error('暂未配置模板');
             return;
           }
-          let urlObj = new URL(data.data);
-          const link = document.createElement('a');
-          link.href = window.location.origin + urlObj.pathname;
-          link.download = this.templateName + '.xls'; // 设置下载文件名
-          link.click();
+          downloadFileByUrl(data.data, this.templateName + '.xls');
         }
       })
     },

+ 4 - 2
src/option/RDSystemManage/list.js

@@ -1,3 +1,5 @@
+import { downloadFileByUrl } from "@/util/util";
+
 const dict = [{
   name: '有效',
   code: true
@@ -58,7 +60,7 @@ export default {
         res: "data",
       },
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       tip: '注:可一次上传多个相关文件(文档、表格、图片等)。支持格式:DOC, PDF, Excel, PNG, JPG, PPT 等。请确保文件内容清晰有效。'
@@ -77,7 +79,7 @@ export default {
         res: "data",
       },
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       tip: '注:可一次上传多个相关文件(文档、表格、图片等)。支持格式:DOC, PDF, Excel, PNG, JPG, PPT 等。请确保文件内容清晰有效。'

+ 3 - 1
src/option/achievement/otherAchivement.js

@@ -1,4 +1,6 @@
 
+import { downloadFileByUrl } from "@/util/util";
+
 export default {
   height: "auto",
   calcHeight: 30,
@@ -194,7 +196,7 @@ export default {
       dataType: "object",
       action: '/api/kd-resource/oss/endpoint/put-file',
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       propsHttp: {

+ 3 - 2
src/option/achievement/patentAchievement.js

@@ -1,4 +1,6 @@
 
+import { downloadFileByUrl } from "@/util/util";
+
 export default {
   height: "auto",
   calcHeight: 30,
@@ -276,8 +278,7 @@ export default {
       dataType: "object",
       action: '/api/kd-resource/oss/endpoint/put-file',
       uploadPreview: (file, column, done) => {
-        console.log(file)
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       propsHttp: {

+ 3 - 1
src/option/achievement/researchPaper.js

@@ -1,4 +1,6 @@
 
+import { downloadFileByUrl } from "@/util/util";
+
 export default {
   height: "auto",
   calcHeight: 30,
@@ -176,7 +178,7 @@ export default {
       dataType: "object",
       action: '/api/kd-resource/oss/endpoint/put-file',
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       propsHttp: {

+ 2 - 1
src/option/achievement/softWorks.js

@@ -1,4 +1,5 @@
 
+import { downloadFileByUrl } from "@/util/util";
 export default {
   height: "auto",
   calcHeight: 30,
@@ -175,7 +176,7 @@ export default {
       dataType: "object",
       action: '/api/kd-resource/oss/endpoint/put-file',
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       propsHttp: {

+ 3 - 1
src/option/achievement/technicalStandard.js

@@ -1,4 +1,6 @@
 
+import { downloadFileByUrl } from "@/util/util";
+
 export default {
   height: "auto",
   calcHeight: 30,
@@ -183,7 +185,7 @@ export default {
       dataType: "object",
       action: '/api/kd-resource/oss/endpoint/put-file',
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
       propsHttp: {

+ 3 - 1
src/option/achiveManage/fileSupplement.js

@@ -1,3 +1,5 @@
+import { downloadFileByUrl } from "@/util/util";
+
 export default {
   calcHeight: 30,
   tip: false,
@@ -37,7 +39,7 @@ export default {
         res: "data",
       },
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
     },

+ 3 - 1
src/option/externalReports/torchDevelopAnnualReport.js

@@ -1,3 +1,5 @@
+import { downloadFileByUrl } from "@/util/util";
+
 export default {
   calcHeight: 30,
   tip: false,
@@ -42,7 +44,7 @@ export default {
         res: "data",
       },
       uploadPreview: (file, column, done) => {
-        window.open(file.url, "_blank");
+        downloadFileByUrl(file.url, file.name);
         return;
       },
     },

+ 13 - 0
src/util/util.js

@@ -440,3 +440,16 @@ export const getMonthDatesWithMarkers = (year, month) => {
   
   return dates;
 }
+
+/**
+ * 通过文件地址下载文件
+ * @param {*} url 文件地址
+ * @param {*} name 文件名
+ */
+export const downloadFileByUrl = (url, name) => {
+  let urlObj = new URL(url);
+  const link = document.createElement('a');
+  link.href = window.location.origin + urlObj.pathname;
+  link.download = name; // 设置下载文件名
+  link.click();
+}

+ 2 - 2
src/views/RD-system-manage/list.vue

@@ -97,7 +97,7 @@ import {exportBloByPost} from "@/api/common";
 import YearMonthSelect from "@/components/year-month-select";
 import moment, { isDate } from "moment";
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 
 
 export default window.$crudCommon({
@@ -179,7 +179,7 @@ export default window.$crudCommon({
       })
     },
     handleDownFile(file) {
-      window.open(file.value);
+      downloadFileByUrl(file.value, file.label);
     }
   },
 

+ 3 - 3
src/views/achievement/other-achievements.vue

@@ -75,7 +75,7 @@
 
       <template slot="attachment" slot-scope="{ row }">
         <div v-for="(file, index) of row.attachment" :key="index">
-          <el-link @click="handleDownFile(file)">{{ file.label }}</el-link>
+          <el-link type="primary" @click="handleDownFile(file)">{{ file.label }}</el-link>
         </div>
       </template>
 
@@ -105,7 +105,7 @@ import {exportBlob} from "@/api/common";
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 import { isAlphanumericCombination } from "@/util/regex";
 
 
@@ -197,7 +197,7 @@ export default window.$crudCommon({
       })
     },
     handleDownFile(file) {
-      window.open(file.value, "_blank");
+      downloadFileByUrl(file.value, file.label);
     }
   },
 }, {

+ 3 - 3
src/views/achievement/patent-achievement.vue

@@ -53,7 +53,7 @@
 
       <template slot="attachment" slot-scope="{ row }">
         <div v-for="(file, index) of row.attachment" :key="index">
-          <el-link @click="handleDownFile(file)">{{ file.label }}</el-link>
+          <el-link type="primary" @click="handleDownFile(file)">{{ file.label }}</el-link>
         </div>
       </template>
 
@@ -77,7 +77,7 @@ import projectSelect from "@/components/project-select";
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 
 
 export default window.$crudCommon({
@@ -131,7 +131,7 @@ export default window.$crudCommon({
       })
     },
     handleDownFile(file) {
-      window.open(file.value, "_blank");
+      downloadFileByUrl(file.value, file.label);
     }
   },
 }, {

+ 3 - 3
src/views/achievement/research-paper.vue

@@ -47,7 +47,7 @@
 
       <template slot="attachment" slot-scope="{ row }">
         <div v-for="(file, index) of row.attachment" :key="index">
-          <el-link @click="handleDownFile(file)">{{ file.label }}</el-link>
+          <el-link type="primary" @click="handleDownFile(file)">{{ file.label }}</el-link>
         </div>
       </template>
 
@@ -76,7 +76,7 @@ import {exportBlob} from "@/api/common";
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 
 
 export default window.$crudCommon({
@@ -131,7 +131,7 @@ export default window.$crudCommon({
       })
     },
     handleDownFile(file) {
-      window.open(file.value, "_blank");
+      downloadFileByUrl(file.value, file.label);
     }
   },
 }, {

+ 3 - 3
src/views/achievement/soft-works.vue

@@ -94,7 +94,7 @@
 
       <template slot="attachment" slot-scope="{ row }">
         <div v-for="(file, index) of row.attachment" :key="index">
-          <el-link @click="handleDownFile(file)">{{ file.label }}</el-link>
+          <el-link type="primary" @click="handleDownFile(file)">{{ file.label }}</el-link>
         </div>
       </template>
     </avue-crud>
@@ -118,7 +118,7 @@ import UploadExcelDialog from "@/components/upload-excel-dialog";
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 import projectSelect from "@/components/project-select";
 
 
@@ -188,7 +188,7 @@ export default window.$crudCommon({
       })
     },
     handleDownFile(file) {
-      window.open(file.value, "_blank");
+      downloadFileByUrl(file.value, file.label);
     }
   },
 }, {

+ 3 - 3
src/views/achievement/technical-standard.vue

@@ -47,7 +47,7 @@
 
       <template slot="attachment" slot-scope="{ row }">
         <div v-for="(file, index) of row.attachment" :key="index">
-          <el-link @click="handleDownFile(file)">{{ file.label }}</el-link>
+          <el-link type="primary" @click="handleDownFile(file)">{{ file.label }}</el-link>
         </div>
       </template>
 
@@ -77,7 +77,7 @@ import UploadExcelDialog from "@/components/upload-excel-dialog";
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 import { isAlphanumericCombination } from "@/util/regex";
 
 export default window.$crudCommon({
@@ -153,7 +153,7 @@ export default window.$crudCommon({
       })
     },
     handleDownFile(file) {
-      window.open(file.value, "_blank");
+      downloadFileByUrl(file.value, file.label);
     }
   },
 }, {

+ 4 - 11
src/views/archive-manage/file-supplement.vue

@@ -62,7 +62,7 @@
 import YearMonthSelect from "@/components/year-month-select";
 import {exportBlob} from "@/api/common";
 import {getToken} from "@/util/auth";
-import {downloadXls} from "@/util/util";
+import {downloadXls, downloadFileByUrl} from "@/util/util";
 import moment from "moment";
 import { getDictValueByKey } from '@/api/system/dict';
 
@@ -161,11 +161,7 @@ export default window.$crudCommon({
       });
     },
     handleDownFile(file) {
-      let urlObj = new URL(file.value);
-      const link = document.createElement('a');
-      link.href = window.location.origin + urlObj.pathname;
-      link.download = file.label; // 设置下载文件名
-      link.click();
+      downloadFileByUrl(file.value, file.label);
     },
     handleDownAll() {
       this.$message.warning("功能建设中...");
@@ -189,11 +185,8 @@ export default window.$crudCommon({
             'template3': '年度主要产品(服务)发挥核心支持作用的技术属于《国家重点支持的高新技术领域》规定范围的说明.doc',
             'template4': '研发费用结构明细表.xls'
           };
-          let urlObj = new URL(data.data);
-          const link = document.createElement('a');
-          link.href = window.location.origin + urlObj.pathname;
-          link.download = tempObj[templateKey]; // 设置下载文件名
-          link.click();
+
+          downloadFileByUrl(data.data, tempObj[templateKey]);
         }
       })
     },

+ 2 - 3
src/views/external-reports/external-manage/torch-develop-annual-report.vue

@@ -27,7 +27,7 @@
 </template>
 
 <script>
-
+import { downloadFileByUrl } from "@/util/util";
 
 export default window.$crudCommon({
   data() {
@@ -60,10 +60,9 @@ export default window.$crudCommon({
       done();
     },
     handleDownFile(file) {
-      window.open(file.value);
+      downloadFileByUrl(file.value, file.label);
     },
     handleDownTemp(row) {
-      console.log(row)
       this.$message.warning('功能建设中...');
     },
     getFormData() {

+ 6 - 5
src/views/project-manage/components/accept-form.vue

@@ -106,6 +106,7 @@ import { save, getDetail } from "@/api/projectManage/accept";
 import moment from "moment";
 import { mapGetters } from "vuex";
 import { getDetail as getTenantDetail } from '@/api/system/tenant';
+import { downloadFileByUrl } from "@/util/util";
 
 export default {
   components: {
@@ -157,7 +158,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             disabled: !this.currProjectId
@@ -176,7 +177,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             disabled: !this.currProjectId
@@ -195,7 +196,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             disabled: !this.currProjectId
@@ -214,7 +215,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             disabled: !this.currProjectId
@@ -228,7 +229,7 @@ export default {
             dataType: "object",
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             propsHttp: {

+ 4 - 3
src/views/project-manage/components/apply-form.vue

@@ -207,6 +207,7 @@ import { deepClone } from "@/util/util";
 import Decimal from "decimal.js";
 import { mapGetters } from "vuex";
 import { getDetail as getTenantDetail } from '@/api/system/tenant';
+import { downloadFileByUrl } from "@/util/util";
 
 export default {
   components: {
@@ -297,7 +298,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             // rules: [{
@@ -320,7 +321,7 @@ export default {
             action: '/api/kd-resource/oss/endpoint/put-file',
             disabled: this.isEdit,
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             // rules: [{
@@ -337,7 +338,7 @@ export default {
             action: '/api/kd-resource/oss/endpoint/put-file',
             disabled: this.isEdit,
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             dataType: "object",

+ 4 - 3
src/views/project-manage/components/change-form.vue

@@ -179,7 +179,7 @@
               ></avue-upload>
               <div v-else>
                 <div v-for="(item, index) of formData.attachment" :key="index" style="line-height: 26px; padding: 6px;">
-                  <el-link @click="handleDownFile(item)">{{ item.label }}</el-link>
+                  <el-link type="primary" @click="handleDownFile(item)">{{ item.label }}</el-link>
                 </div>
               </div>
             </td>
@@ -203,6 +203,7 @@ import projectSelect from "@/components/project-select";
 import secondUnitCascader from "@/components/second-unit-cascader";
 import personSelect from "@/components/person-select";
 import Decimal from "decimal.js";
+import { downloadFileByUrl } from "@/util/util";
 
 export default {
   props: {
@@ -428,10 +429,10 @@ export default {
       return save(params)
     },
     handleDownFile(file) {
-      window.open(file.value);
+      downloadFileByUrl(file.value, file.label);
     },
     handleUploadPreview (file, column, done) {
-      window.open(file.url, "_blank");
+      downloadFileByUrl(file.url, file.name);
       return;
     },
   },

+ 2 - 1
src/views/project-manage/components/implement-form.vue

@@ -149,6 +149,7 @@ import { save, getDetail } from "@/api/projectManage/implement";
 import moment from "moment";
 import { mapGetters } from "vuex";
 import { getDetail as getTenantDetail } from '@/api/system/tenant';
+import { downloadFileByUrl } from "@/util/util";
 
 export default {
   props: {
@@ -210,7 +211,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
             disabled: !this.currProjectId || this.disabled,

+ 8 - 6
src/views/project-manage/components/outsourcing-doc.vue

@@ -46,6 +46,7 @@
                                 <el-link
                                   v-for="(file, fileIdx) of typeItem.fileList"
                                   :key="fileIdx" style="margin: 0 4px;"
+                                  type="primary"
                                   @click="handleDownloadFile(file)"
                                 >
                                   {{ file.label }}
@@ -94,6 +95,7 @@ import yearMonthSelect from "@/components/year-month-select";
 import projectSelect from "@/components/project-select";
 import moment from "moment";
 import { getList, submit, remove } from "@/api/projectManage/outsourcingDoc";
+import { downloadFileByUrl } from "@/util/util";
 
 export default {
   props: {
@@ -210,7 +212,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
           },
@@ -229,7 +231,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
           },
@@ -247,7 +249,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
           },
@@ -265,7 +267,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
           },
@@ -283,7 +285,7 @@ export default {
             },
             action: '/api/kd-resource/oss/endpoint/put-file',
             uploadPreview: (file, column, done) => {
-              window.open(file.url, "_blank");
+              downloadFileByUrl(file.url, file.name);
               return;
             },
           },
@@ -385,7 +387,7 @@ export default {
       });
     },
     handleDownloadFile(file) {
-      window.open(file.value);
+      downloadFileByUrl(file.value, file.label);
     },
     handleResetForm() {
       this.drawerVisible = false;