ソースを参照

修复excel导出问题

kagg886 3 ヶ月 前
コミット
fb664fd68b
2 ファイル変更27 行追加50 行削除
  1. 26 49
      src/utils/zipdownload.ts
  2. 1 1
      src/views/flow/flowModel/list/index.vue

+ 26 - 49
src/utils/zipdownload.ts

@@ -1,12 +1,15 @@
 import axios from 'axios'
-import {baseURL, getToken} from "/@/utils/gfast"
+import {getToken} from "/@/utils/gfast"
 import { ElMessage,ElLoading } from 'element-plus';
+import getOrigin from '/@/utils/origin'
+import downloadFile from '/@/utils/download'
+import { file } from '/@/utils/request'
 const mimeMap = {
   xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
   zip: 'application/zip'
 }
 
-const baseUrl = import.meta.env.VITE_API_URL
+const baseUrl = getOrigin()
 export function downLoadZip(str:string, filename:string) {
   var url = baseUrl + str
   axios({
@@ -22,17 +25,8 @@ export function downLoadZip(str:string, filename:string) {
   })
 }
 
-const getHost = ():string=>{
-  return window.location.origin
-}
-
 // 下载插件
-export function downLoadXml (url:string,params:any,rType='get') {
-  if (baseUrl=='' ||baseURL=='/'){
-    url = getHost() + url
-  }else{
-    url = baseUrl + url
-  }
+export function downLoadXml (url:string,params:any,rType: 'get' | 'post'='get') {
   const loading = ElLoading.service({
     lock: true,
     text: '正在生成导出数据...',
@@ -57,43 +51,26 @@ export function downLoadXml (url:string,params:any,rType='get') {
       headers: { 'Authorization': 'Bearer ' + getToken() }
     }
   }
-  axios(option).then(res => {
-    loading.close()
-    if (res.status !== 200) {
-      ElMessage({
-        message: '发生错误,导出失败。',
-        type: 'error'
-      })
-      return
-    }
-    try {
-      const aLink = document.createElement('a')
-      var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
-      var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
-      var contentDisposition = decodeURI(res.headers['content-disposition'] || res.headers['Content-Disposition'])
-      var result = patt.exec(contentDisposition)
-      var fileName = result[1]
-      fileName = fileName.replace(/"/g, '')
-      aLink.href = URL.createObjectURL(blob)
-      aLink.setAttribute('download', fileName) // 设置下载文件名称
-      document.body.appendChild(aLink)
-      aLink.click()
-      document.body.appendChild(aLink)
-    } catch (e) {
-      console.log(e)
-      ElMessage({
-        message: '下载失败,可能您登录状态过期,请重新登录后下载。',
-        type: 'error'
-      })
-    }
-  }).catch(e=>{
-    console.log(e)
-    loading.close()
-    ElMessage({
-      message: '导出失败',
-      type: 'error'
-    })
-  })
+	file(url,params,rType).then((res:any)=> downloadFile(res,'data'))
+	loading.close()
+  // axios(option).then(res => {
+  //   loading.close()
+  //   if (res.status !== 200) {
+  //     ElMessage({
+  //       message: '发生错误,导出失败。',
+  //       type: 'error'
+  //     })
+  //     return
+  //   }
+  //   downloadFile(res,'export.xlsx')
+  // }).catch(e=>{
+  //   console.log(e)
+  //   loading.close()
+  //   ElMessage({
+  //     message: '导出失败',
+  //     type: 'error'
+  //   })
+  // })
 }
 
 /**

+ 1 - 1
src/views/flow/flowModel/list/index.vue

@@ -397,7 +397,7 @@ export default defineComponent({
         }
         //导出excel
         const handleExport = ()=>{
-            downLoadXml('/api/v1/flow/flowModel/export',state.tableData.param,'get')
+            downLoadXml('flow/flowModel/export',state.tableData.param,'get')
         }
         const handleImport=()=>{
             loadExcelFlowModelRef.value.open()