diff --git a/src/utils/download.js b/src/utils/download.js new file mode 100644 index 0000000..8760449 --- /dev/null +++ b/src/utils/download.js @@ -0,0 +1,70 @@ +function myBrowser() { + var userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串 + var isOpera = userAgent.indexOf('Opera') > -1; + if (isOpera) { + return 'Opera'; + } // 判断是否Opera浏览器 + if (userAgent.indexOf('Firefox') > -1) { + return 'FF'; + } // 判断是否Firefox浏览器 + if (userAgent.indexOf('Chrome') > -1) { + return 'Chrome'; + } + if (userAgent.indexOf('Safari') > -1) { + return 'Safari'; + } // 判断是否Safari浏览器 + if (userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 && !isOpera) { + return 'IE'; + } // 判断是否IE浏览器 + if (userAgent.indexOf('Trident') > -1) { + return 'Edge'; + } // 判断是否Edge浏览器 +} +function SaveAs5(imgURL) { + var oPop = window.open(imgURL, '', 'width=1, height=1, top=5000, left=5000'); + for (; oPop.document.readyState !== 'complete'; ) { + if (oPop.document.readyState === 'complete') break; + } + oPop.document.execCommand('SaveAs'); + oPop.close(); +} +function download(src, fileName) { + // 创建隐藏的可下载链接 + var eleLink = document.createElement('a'); + if (fileName) { + eleLink.setAttribute('download', fileName); + } else { + eleLink.download = src; + } + eleLink.style.display = 'none'; + // // 字符内容转变成blob地址 + eleLink.href = src; + // // 触发点击 + document.body.appendChild(eleLink); + eleLink.click(); + // // 然后移除 + document.body.removeChild(eleLink); +} +function downLoadFile(url, fileName = '') { + if (myBrowser() === 'IE' || myBrowser() === 'Edge') { + SaveAs5(url); + } else { + download(url, fileName); + } +} +function conversionFileDownload(res) { + const a = document.createElement('a'); + const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }); + const temp = res.headers['content-disposition'].split(';')[1].split('filename=')[1]; + // 对文件名乱码转义--【Node.js】使用iconv-lite解决中文乱码 + const iconv = require('iconv-lite'); + iconv.skipDecodeWarning = true; // 忽略警告 + const fileName = iconv.decode(temp, 'utf-8'); + console.log(fileName); + a.setAttribute('download', fileName); + const objectUrl = URL.createObjectURL(blob); + a.setAttribute('href', objectUrl); + a.click(); +} + +export { downLoadFile, conversionFileDownload }; diff --git a/src/views/cet/cet-ana-3.vue b/src/views/cet/cet-ana-3.vue index 3ffcaa3..db4c644 100644 --- a/src/views/cet/cet-ana-3.vue +++ b/src/views/cet/cet-ana-3.vue @@ -261,7 +261,6 @@ this.collegeMajor = '全校'; } //如果this.batch[1]不存在则设为null - let major = this.batch.length > 1 ? this.batch[1] : ''; this.topCollege = this.collegeMajor; this.topBath = this.batch; this.loading = true; diff --git a/src/views/cet/cet-student-query.vue b/src/views/cet/cet-student-query.vue index daa56fe..ef222fb 100644 --- a/src/views/cet/cet-student-query.vue +++ b/src/views/cet/cet-student-query.vue @@ -55,7 +55,7 @@ }); const isShow = ref(false); const loading = ref(false); - const tableData = ref([]); + const tableData: any = ref([]); const tableLabel = ref([ { title: '考试批次', diff --git a/src/views/cet/data-import/cet4-data-import.vue b/src/views/cet/data-import/cet4-data-import.vue index bd4d311..cd0efa0 100644 --- a/src/views/cet/data-import/cet4-data-import.vue +++ b/src/views/cet/data-import/cet4-data-import.vue @@ -2,24 +2,31 @@
- - - - - - - +
- - - - - 导入文件 - - + 考试批次: + + +
- 下载模板 + + + + + 导入文件 + +
+
{{ uploading ? 'Uploading' : '确认上传文件' }} @@ -27,7 +34,6 @@
-
@@ -38,15 +44,22 @@
- diff --git a/src/views/cet/data-import/dataImportApi.ts b/src/views/cet/data-import/dataImportApi.ts new file mode 100644 index 0000000..7f66485 --- /dev/null +++ b/src/views/cet/data-import/dataImportApi.ts @@ -0,0 +1,9 @@ +import { defHttp } from '/@/utils/http/axios'; + +export function downloadTemplateExcel() { + return defHttp.request({ + url: '/cetDataImport/downloadTemplate', + method: 'post', + responseType: 'blob', + }); +}