Commit 3ad67e50 authored by 熊成伟's avatar 熊成伟

debug

parent 7b8975fe
Pipeline #16379 passed with stages
in 1 minute and 1 second
...@@ -2,7 +2,7 @@ import React, {useState, useEffect} from 'react'; ...@@ -2,7 +2,7 @@ import React, {useState, useEffect} from 'react';
import Document from 'react-document-title' import Document from 'react-document-title'
import {WingBlank, WhiteSpace, ActionSheet, Toast} from 'antd-mobile' import {WingBlank, WhiteSpace, ActionSheet, Toast} from 'antd-mobile'
import axiosRequest from '../../utils/request'; import axiosRequest from '../../utils/request';
import {exportExcel} from '../../utils/api' import downloadFile from '../../utils/downloadFile'
import TopTabs from '../../components/Tabs/BlankTabs' import TopTabs from '../../components/Tabs/BlankTabs'
import Skeleton from '../../components/Skeleton' import Skeleton from '../../components/Skeleton'
import Basic from './commponents/Basic' import Basic from './commponents/Basic'
...@@ -148,11 +148,16 @@ const Process = (props) => { ...@@ -148,11 +148,16 @@ const Process = (props) => {
}; };
const download = (uuid, callback) => { const download = (uuid, callback) => {
const developer = localStorage.getItem('developer'); const developer = localStorage.getItem('developer');
exportExcel({ downloadFile({
method: 'post', method: 'post',
url: `/idtAppServiceV6/oApp/downloadLargeFile`, url: `/idtAppServiceV6/oApp/downloadLargeFile`,
body: {uuid, tableId, developer}, body: {uuid, tableId, developer},
callback: callback }).then(res => {
var downloadElement = document.createElement('a');
downloadElement.href = res.request.responseURL;
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
}) })
} }
......
import { exportRequest } from './exportFile';
const token = localStorage.getItem('token')
// 导出
export function exportExcel(params) {
var body = {
name: params.name,
body: params.body,
callback: params.callback,
method: params.method || 'post'
};
var config = {
headers: {
token
}
};
return exportRequest(params.url, body, config);
}
import axios from 'axios';
const instance = axios.create();
export const apiUrl = '/';
const token = localStorage.getItem("token");
let defaultHeaders = {
token,
};
const createAPI = (baseURL) => {
return (conf = {}) => {
let opts = conf.opts || {};
let headers = { ...defaultHeaders, ...opts.headers };
return instance(Object.assign({}, {
url: conf.url,
baseURL: baseURL,
params: conf.opts,
method: conf.method,
data: conf.payload || null,
headers,
responseType: 'blob',
}))
.then(function (response) {
return response
})
.catch(error => {
return false;
});
};
}
const instance2 = createAPI(apiUrl);
async function downloadFile(option = {}) {
return await instance2({
method: option.method || 'get',
url: option.url,
opts: option.body || null,
});
}
export default downloadFile;
import axios from 'axios';
const instance = axios.create();
export function exportRequest(url, conf = {}, headers = {}) {
//导出添加header
const handleFunction = (res) => {
//这里res.data是返回的blob对象
try {
var enc = new TextDecoder('utf-8');
var result = JSON.parse(enc.decode(new Uint8Array(res.data))); //转化成json对象
console.log(result)
} catch (error) {
var blob = new Blob([res.data]);
var downloadElement = document.createElement('a');
var href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
// downloadElement.download = `${conf.name || 'table'}.xls`; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
conf.callback && typeof conf.callback === 'function' && conf.callback();
}
};
return instance({
url: 'http://124.93.101.8:9988' + url,
method: conf.method,
params: conf.body,
headers,
}).then(response => {
handleFunction(response);
console.log(response)
})
}
...@@ -39,7 +39,6 @@ export const createAPI = (baseURL) => { ...@@ -39,7 +39,6 @@ export const createAPI = (baseURL) => {
urlParams += qs.stringify(conf.opts) urlParams += qs.stringify(conf.opts)
} }
// console.log(headers)
return instance(Object.assign({}, { return instance(Object.assign({}, {
url: conf.url + urlParams, url: conf.url + urlParams,
...@@ -54,8 +53,8 @@ export const createAPI = (baseURL) => { ...@@ -54,8 +53,8 @@ export const createAPI = (baseURL) => {
if (!response || !(response.data || response.tree)) { if (!response || !(response.data || response.tree)) {
// response.status === 'failure' && (window.location.href = '/login') // response.status === 'failure' && (window.location.href = '/login')
response.code === 'idt-jwt-500' && (window.location.href = '/login') response.code === 'idt-jwt-500' && (window.location.href = '/login')
console.log('response出错, 无返回数据!'); console.log('response出错, 无返回数据!', response);
response.status === 'failure' && Toast.fail(response.message) Toast.fail(response.message)
// return false; // return false;
}; };
if (response.data && response.data.errorMessage) { if (response.data && response.data.errorMessage) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment