提交 b689f826 authored 作者: 钟是志's avatar 钟是志

导出修改

上级 028b3280
...@@ -130,6 +130,7 @@ export default function request( ...@@ -130,6 +130,7 @@ export default function request(
url = url.replace(config.httpServer, ''); url = url.replace(config.httpServer, '');
return uaaRequest(url, options.body); return uaaRequest(url, options.body);
} }
console.log(url);
if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) { if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) {
url = url.replace('https://yx.bpi.edu.cn/produce', 'http://localhost:8010/produce'); url = url.replace('https://yx.bpi.edu.cn/produce', 'http://localhost:8010/produce');
url = url.replace('http://scjoyedu.eicp.net:51352/produce', 'http://localhost:8010/produce'); url = url.replace('http://scjoyedu.eicp.net:51352/produce', 'http://localhost:8010/produce');
...@@ -198,8 +199,6 @@ export default function request( ...@@ -198,8 +199,6 @@ export default function request(
delete newOptions.headers.Authorization; delete newOptions.headers.Authorization;
} }
console.log(newOptions);
return fetch(url, newOptions) return fetch(url, newOptions)
.then(checkStatus) .then(checkStatus)
//.then(response => cachedSave(response, hashcode)) //.then(response => cachedSave(response, hashcode))
......
...@@ -4,6 +4,11 @@ import config from '@/config/config'; ...@@ -4,6 +4,11 @@ import config from '@/config/config';
import { getCurrentUser } from '@/webPublic/one_stop_public/utils/token'; import { getCurrentUser } from '@/webPublic/one_stop_public/utils/token';
export default function urlTransform(url) { export default function urlTransform(url) {
if (url && url.indexOf(config.gateWayPort) > -1) {
let uArr = url.split(config.gateWayPort);
uArr[1] = uArr[1].replaceAll('\//', '\/');
url = config.gateWayPort + uArr[1];
}
return url; return url;
/** /**
......
import urlTransform from '@/webPublic/zyd_public/request/urlTransform';
import FormdataWrapper from '@/webPublic/zyd_public/utils/object-to-formdata-custom';
import { notification } from 'antd';
import { getHeaders, getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
/**
* 本地开发可能会存在跨域问题
* 只能用于学工的接口的下载文件
* */
export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx', method = 'POST') {
if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) {
url = url.replace('https://yx.bpi.edu.cn/produce', 'http://localhost:8010/produce');
url = url.replace('http://scjoyedu.eicp.net:51352/produce', 'http://localhost:8010/produce');
}
url = urlTransform(url);
fetch(url, {
method,
body: method === 'GET' ? undefined : FormdataWrapper(params),
...getHeaders(),
})
.then((res) => {
if (res.status + '' !== '200') {
return res.json();
} else {
const contentDisposition = res.headers.get('content-disposition');
let fileNameEncode = contentDisposition && contentDisposition.split('filename=');
if(fileNameEncode.length > 1){
fileNameEncode = fileNameEncode[1];
fileName = decodeURIComponent(fileNameEncode);
console.log('fileName', fileName);
}
// 解码
return res.blob();
}
})
.then((data) => {
if (data instanceof Blob) {
let a = document.createElement('a');
let url = window.URL.createObjectURL(data);
let filename = fileName + '.' + ext;
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
a = null;
} else {
notification.error({
message: `文件导出错误`,
description: data.errMsg,
});
}
})
.catch((err) => {
console.log(err);
notification.error({
message: `网络请求超时`,
});
})
.finally(() => {
return true;
});
}
import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils'; import { downloadFile, getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
import { getToken } from '@/webPublic/one_stop_public/utils/token'; import { getToken } from '@/webPublic/one_stop_public/utils/token';
import config from '@/config/config'; import config from '@/config/config';
import { getInfo, transformApi } from '@/highOrderComponent/Service'; import { getInfo, transformApi } from '@/highOrderComponent/Service';
import urlTransform from '@/webPublic/zyd_public/request/urlTransform'; import urlTransform from '@/webPublic/zyd_public/request/urlTransform';
import request from '@/utils/request';
export function hrefWithToken(url) { export function hrefWithToken(url) {
if (!getIsBei_Dian()) { if (!getIsBei_Dian()) {
if (url.indexOf('?') > -1) { if (url.indexOf('?') > -1) {
...@@ -14,10 +15,9 @@ export function hrefWithToken(url) { ...@@ -14,10 +15,9 @@ export function hrefWithToken(url) {
const hrefUrl = transformApi(url); const hrefUrl = transformApi(url);
let u = `${hrefUrl}${url}`; let u = `${hrefUrl}${url}`;
u = urlTransform(u); u = urlTransform(u);
if(u && u.indexOf('v1/api/zydsgWeb')){ console.log(u);
getInfo({}, u, { if(u && u.indexOf('v1/api/zydsgWeb') > -1){
method: 'GET', downloadFile(u, {}, '', '', 'GET');
});
return; return;
} }
console.log('hrefWithToken', u); console.log('hrefWithToken', u);
......
...@@ -281,55 +281,7 @@ export function diGuiTree(treeData = [], i = 0) { ...@@ -281,55 +281,7 @@ export function diGuiTree(treeData = [], i = 0) {
} }
/** export { downloadFile } from './downloadFile';
* 本地开发可能会存在跨域问题
* */
export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx', method = 'POST') {
if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) {
url = url.replace('https://yx.bpi.edu.cn/produce', 'http://localhost:8010/produce');
}
url = urlTransform(url);
fetch(url, {
method,
body: method === 'GET' ? undefined : FormdataWrapper(params),
...getHeaders(url),
})
.then((res) => {
if (res.status + '' !== '200') {
return res.json();
} else {
return res.blob();
}
})
.then((data) => {
if (data instanceof Blob) {
let a = document.createElement('a');
let url = window.URL.createObjectURL(data);
let filename = fileName + '.' + ext;
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
a = null;
} else {
notification.error({
message: `文件导出错误`,
description: data.errMsg,
});
}
})
.catch((err) => {
console.log(err);
notification.error({
message: `网络请求超时`,
});
})
.finally(() => {
return true;
});
}
// 校验密码是否符合 包含数字 字母 和特殊字符 解决 中医大的安全漏洞 // 校验密码是否符合 包含数字 字母 和特殊字符 解决 中医大的安全漏洞
export default function CheckPassWord(password = '', length = 12) { export default function CheckPassWord(password = '', length = 12) {
...@@ -391,7 +343,7 @@ export function getHeaders(url = '') { ...@@ -391,7 +343,7 @@ export function getHeaders(url = '') {
const token = getToken(); const token = getToken();
const currentInfo = getCurrentUser(); const currentInfo = getCurrentUser();
const timestamp = window.serviceCurrentDate || new Date().getTime(); const timestamp = window.serviceCurrentDate || new Date().getTime();
const secretString = token + currentInfo.xgUserId + currentInfo.typeString + timestamp; const secretString = token + currentInfo.userid + currentInfo.typeString + timestamp;
// console.log(secretString, awc_timestamp); // console.log(secretString, awc_timestamp);
// console.log(Md5(secretString)); // console.log(Md5(secretString));
if (isTest) { if (isTest) {
...@@ -400,7 +352,7 @@ export function getHeaders(url = '') { ...@@ -400,7 +352,7 @@ export function getHeaders(url = '') {
secretString, secretString,
md5S: Md5(secretString), md5S: Md5(secretString),
timestamp, timestamp,
userId: currentInfo.xgUserId, userId: currentInfo.userid,
typeString: currentInfo.typeString, typeString: currentInfo.typeString,
}, },
); );
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论