| | |
| | | }, |
| | | data() { |
| | | return { |
| | | queryParams: {}, |
| | | uploadRef: null, |
| | | targetColumn: [], |
| | | accept: `.zip`, |
| | |
| | | } |
| | | }, |
| | | handleDownloadFile() { |
| | | // fetch(`${process.env.VITE_APP_BASE_API}/project/info/export/template`, { |
| | | // method: 'GET', |
| | | // headers: self.upload.headers |
| | | // }) |
| | | // .then(response => response.blob()) |
| | | // .then(blob => { |
| | | // const url = window.URL.createObjectURL(blob); |
| | | // const a = document.createElement('a'); |
| | | // a.style.display = 'none'; |
| | | // a.href = url; |
| | | // a.download = `项目文件模板_${new Date().getTime()}.zip`; |
| | | // document.body.appendChild(a); |
| | | // a.click(); |
| | | // window.URL.revokeObjectURL(url); |
| | | // }) |
| | | // .catch(error => { |
| | | // console.error('文件下载失败:', error); |
| | | // }); |
| | | |
| | | const url = process.env.VUE_APP_BASE_API + '/project/info/export/template'; |
| | | axios.post(url, [], { // 发送一个空数组而不是空对象 |
| | | responseType: 'blob', // 告诉axios期望服务器返回的是blob类型 |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | Authorization: "Bearer " + getToken() |
| | | } |
| | | }) |
| | | .then(response => { |
| | | // 处理文件下载 |
| | | const blob = new Blob([response.data], { type: 'application/zip' }); // 指定MIME类型为zip |
| | | const url = window.URL.createObjectURL(blob); |
| | | const a = document.createElement('a'); |
| | | a.style.display = 'none'; |
| | | a.href = url; |
| | | a.download = `项目文件模板_${new Date().getTime()}.zip`; |
| | | document.body.appendChild(a); |
| | | a.click(); |
| | | document.body.removeChild(a); |
| | | window.URL.revokeObjectURL(url); |
| | | }) |
| | | .catch(error => { |
| | | console.error('There was an error!', error); |
| | | }); |
| | | this.download('/project/info/export/template', {}, `项目文件模板_${new Date().getTime()}.zip`) |
| | | }, |
| | | submitFileForm() { |
| | | if (this.uploadRef) { |
| | |
| | | this.$emit('fileDialogCancel'); |
| | | }, |
| | | handleDownloadTargetList() { |
| | | console.log('导出目标列表内容', this.currentColumns); |
| | | this.targetColumn = this.currentColumns.filter(item => item.visible); |
| | | this.queryParams.fieldList = this.currentColumns.filter(item => item.visible).map(item =>item.id); |
| | | this.queryParams.requireFile = false; |
| | | this.download('project/info/export', { |
| | | ...this.queryParams |
| | | }, `项目库${new Date().getTime()}.xlsx`) |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.uploadRef = this.$refs.uploadRef; |
| | | }, |
| | | created() { |
| | | |
| | | this.isFileDialogVisible = this.fileDialogVisible; |
| | | } |
| | | }; |