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

hrefWithToken函数修改

上级 b689f826
...@@ -42,7 +42,6 @@ export default class Detail extends Component { ...@@ -42,7 +42,6 @@ export default class Detail extends Component {
render() { render() {
const { id, showAll } = this.state; const { id, showAll } = this.state;
const url = config.onestopPC.split('/#/'); const url = config.onestopPC.split('/#/');
// console.log(url);
const iframeUrl = `${url[0]}/#/IFrameSnapshot?token=${getToken()}`; const iframeUrl = `${url[0]}/#/IFrameSnapshot?token=${getToken()}`;
// iframeUrl = `http://localhost:8000/onestop/IframeForDetail?id=${id}&token=${getToken()}`; // iframeUrl = `http://localhost:8000/onestop/IframeForDetail?id=${id}&token=${getToken()}`;
return ( return (
......
...@@ -362,7 +362,6 @@ export function handleColumns(columns) { ...@@ -362,7 +362,6 @@ export function handleColumns(columns) {
if (item.extendType === 'qrCode') { if (item.extendType === 'qrCode') {
if (text && typeof text === 'string' && text) { if (text && typeof text === 'string' && text) {
let url = text.replace('{window.location.origin}', config.gateWayPort); let url = text.replace('{window.location.origin}', config.gateWayPort);
console.log(url);
const clickUrl = () => { const clickUrl = () => {
Modal.info({ Modal.info({
title: item.title, title: item.title,
......
...@@ -136,7 +136,6 @@ export async function requestFileInfo(url, datas) { ...@@ -136,7 +136,6 @@ export async function requestFileInfo(url, datas) {
formData.append(key, datas[key]); formData.append(key, datas[key]);
} }
if (!url || typeof url !== 'string') { if (!url || typeof url !== 'string') {
console.log(url);
return false; return false;
} }
return fetch(url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url, { return fetch(url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url, {
......
...@@ -118,7 +118,6 @@ export default class Index extends Component { ...@@ -118,7 +118,6 @@ export default class Index extends Component {
// if (!('value' in this.props)) { // if (!('value' in this.props)) {
// this.setState({ url: url }); // this.setState({ url: url });
// } // }
// console.log(url);
// this.triggerChange(url); // this.triggerChange(url);
// //
......
...@@ -130,7 +130,6 @@ export default function request( ...@@ -130,7 +130,6 @@ 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');
......
...@@ -6,6 +6,8 @@ import { getHeaders, getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils'; ...@@ -6,6 +6,8 @@ import { getHeaders, getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
/** /**
* 本地开发可能会存在跨域问题 * 本地开发可能会存在跨域问题
* 只能用于学工的接口的下载文件 * 只能用于学工的接口的下载文件
* 2022年7月8日
* 如果ext 传空字符串 则从response.headers 中获取文件名
* */ * */
export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx', method = 'POST') { export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx', method = 'POST') {
if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) { if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) {
...@@ -14,6 +16,8 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx ...@@ -14,6 +16,8 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
} }
url = urlTransform(url); url = urlTransform(url);
let responseHeadersFileName = '';
fetch(url, { fetch(url, {
method, method,
body: method === 'GET' ? undefined : FormdataWrapper(params), body: method === 'GET' ? undefined : FormdataWrapper(params),
...@@ -27,8 +31,8 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx ...@@ -27,8 +31,8 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
let fileNameEncode = contentDisposition && contentDisposition.split('filename='); let fileNameEncode = contentDisposition && contentDisposition.split('filename=');
if(fileNameEncode.length > 1){ if(fileNameEncode.length > 1){
fileNameEncode = fileNameEncode[1]; fileNameEncode = fileNameEncode[1];
fileName = decodeURIComponent(fileNameEncode); responseHeadersFileName = decodeURIComponent(fileNameEncode);
console.log('fileName', fileName); console.log(responseHeadersFileName);
} }
// 解码 // 解码
return res.blob(); return res.blob();
...@@ -37,10 +41,9 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx ...@@ -37,10 +41,9 @@ export function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx
.then((data) => { .then((data) => {
if (data instanceof Blob) { if (data instanceof Blob) {
let a = document.createElement('a'); let a = document.createElement('a');
let url = window.URL.createObjectURL(data); url = window.URL.createObjectURL(data);
let filename = fileName + '.' + ext;
a.href = url; a.href = url;
a.download = filename; a.download = !ext ? responseHeadersFileName : fileName + '.' + ext; // 如果传入的ext 为空字符串(不等于不传) 则使用响应头中的文件作为文件名
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
a = null; a = null;
......
...@@ -3,8 +3,10 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token'; ...@@ -3,8 +3,10 @@ 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, arg = {
}) {
if (!getIsBei_Dian()) { if (!getIsBei_Dian()) {
if (url.indexOf('?') > -1) { if (url.indexOf('?') > -1) {
url = `${url}&token=${getToken()}`; url = `${url}&token=${getToken()}`;
...@@ -15,18 +17,14 @@ export function hrefWithToken(url) { ...@@ -15,18 +17,14 @@ 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);
console.log(u); console.log('hrefWithToken', u);
if(u && u.indexOf('v1/api/zydsgWeb') > -1){ if (u && u.indexOf('v1/api/zydsgWeb') > -1 && getIsBei_Dian()) {
downloadFile(u, {}, '', '', 'GET'); downloadFile(u, {}, '', '', 'GET');
return; return;
} }
console.log('hrefWithToken', u);
getInfo({}, '/InstructorConfigApi/getCurrentDate') getInfo({}, '/InstructorConfigApi/getCurrentDate')
.then((response) => { .then((response) => {
// const hrefUrl = transformApi(url);
// let u = `${hrefUrl}${url}`;
// u = urlTransform(u);
if (response) { if (response) {
window.open(`${u}`); // 存在问题 浏览器会自动切换内核到IE 内核导致 文件名称乱码. window.open(`${u}`); // 存在问题 浏览器会自动切换内核到IE 内核导致 文件名称乱码.
return true; return true;
...@@ -35,26 +33,3 @@ export function hrefWithToken(url) { ...@@ -35,26 +33,3 @@ export function hrefWithToken(url) {
} }
}); });
} }
export function hrefWithTokenSg(url) {
if (!getIsBei_Dian()) {
if (url.indexOf('?') > -1) {
url = `${url}&token=${getToken()}`;
} else {
url = `${url}?token=${getToken()}`;
}
}
getInfo({}, '/InstructorConfigApi/getCurrentDate')
.then((response) => {
const hrefUrl = `${config.mockServer}/${config.gateWayUrl.zydsg}`;
if (response) {
let u = `${hrefUrl}${url}`;
u = urlTransform(u);
window.open(u); // 存在问题 浏览器会自动切换内核到IE 内核导致 文件名称乱码.
return true;
} else {
return false;
}
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论