|
@@ -1,5 +1,6 @@
|
|
|
import axios from 'axios'
|
|
|
import { ElMessage } from "element-plus";
|
|
|
+import { downloadFile } from '@/utils/util'
|
|
|
|
|
|
const instance = axios.create({
|
|
|
timeout: 40000
|
|
@@ -21,7 +22,7 @@ instance.interceptors.response.use((response: any) => {
|
|
|
localStorage.removeItem('sc_token')
|
|
|
location.reload()
|
|
|
} else {
|
|
|
- return response.data
|
|
|
+ return response
|
|
|
}
|
|
|
}
|
|
|
}, (error: any) => {
|
|
@@ -55,7 +56,7 @@ export const get = ({url, params, config = {}}: { [index: string]: any }) => {
|
|
|
},
|
|
|
...config
|
|
|
}).then((res: any) => {
|
|
|
- resolve(res)
|
|
|
+ resolve(res.data)
|
|
|
}).catch((err) => {
|
|
|
reject(err);
|
|
|
})
|
|
@@ -71,9 +72,43 @@ export const post = ({url, params, config = {}}: { [index: string]: any }) => {
|
|
|
},
|
|
|
...config
|
|
|
}).then((res: any) => {
|
|
|
+ resolve(res.data)
|
|
|
+ }).catch((err) => {
|
|
|
+ reject(err);
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export const download = ({url, params, fileName, config = {}}: { [index: string]: any }) => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let paramUrl = url
|
|
|
+ if (params) {
|
|
|
+ if (typeof params === 'object') {
|
|
|
+ let str = ''
|
|
|
+ Object.entries(params).map(([k, v]: any, i) => {
|
|
|
+ if (i > 0) {
|
|
|
+ str += '&'
|
|
|
+ }
|
|
|
+ str += `${k}=${encodeURIComponent(v)}`
|
|
|
+ })
|
|
|
+ paramUrl += `?${str}`
|
|
|
+ } else {
|
|
|
+ paramUrl += `?${params}`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ instance.get(paramUrl, {
|
|
|
+ headers: {
|
|
|
+ sessionToken: localStorage.getItem('sc_token'),
|
|
|
+ Authorization: localStorage.getItem('sc_token'),
|
|
|
+ },
|
|
|
+ responseType: 'arraybuffer',
|
|
|
+ ...config
|
|
|
+ }).then((res: any) => {
|
|
|
+ downloadFile(res, fileName)
|
|
|
resolve(res)
|
|
|
}).catch((err) => {
|
|
|
reject(err);
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
+
|