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

解决北电科防火墙问题 把接口数据转成文件

上级 ca1a4b12
import baseX from 'base-x';
import { apiRequest } from '../utils/request';
import { isJSON } from '@/webPublic/zyd_public/utils/utils';
import { uploadFile } from '@/webPublic/one_stop_public/libs/PictureSignature/ShowItem';
import { queryApiActionPath, queryIsSafe } from '@/webPublic/one_stop_public/utils/queryConfig';
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
var BASE16 = '0123456789abcdef';
var bs16 = baseX(BASE16);
......@@ -39,6 +42,9 @@ const encryptApiList = [
api: 'DataColumnApi/getOptions',
key: ['filterSql'],
},
{
api: 'UnifiedServicePatternApi/updateForm',
},
{
api: 'DataColumnApi/getLabels',
key: ['allValues'],
......@@ -162,7 +168,86 @@ const countAllValues = async (datas, item) => {
};
export function requestFileInfo(url, datas){
const formData = new FormData();
if(getToken()){
datas.token = getToken();
}
for(let key in datas){
formData.append(key, datas[key]);
}
return fetch(queryApiActionPath() + url, {
headers: {
Accept: 'application/json',
// Authorization: `bearer ${getToken()}`,
},
method: 'POST',
credentials: 'omit',
mode: 'cors',
body: formData,
}).then((res) => {
return res.json();
}).then((res) => {
// console.log(res);
return res;
});
}
function giveFilePostData(datas, url){
url = url.replaceAll('\/\/', '\/');
if (url && typeof url === 'string') {
// const roleGroup = getUserInfo().groupsId;
// url = url.replace(url, `/safe/${roleGroup}/` + url);
// url = url.replaceAll('//', '/');
// console.table({datas, url});
// let file = new File([JSON.stringify(datas)], "fileParams.txt", {
// type: "text/plain",
// });
// datas = {
// fileParams: file,
// }
// return new Promise((resolve, reject) => {
// resolve({
// datas,
// url,
// });
// });
for (let item of encryptApiList) {
if (url.indexOf(item.api) > -1) {
const roleGroup = getUserInfo().groupsId;
url = url.replace(url, `/safe/${roleGroup}/` + url);
url = url.replaceAll('//', '/');
console.table(datas);
let file = new File([JSON.stringify(datas)], "fileParams.jpg", {
type: "text/plain",
});
// uploadFile(file);
datas = {
fileParams: file,
}
return new Promise((resolve, reject) => {
resolve({
datas,
url,
});
});
}
}
}
return new Promise((resolve, reject) => {
resolve(datas);
return datas;
});
}
export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
if(queryIsSafe()){
return giveFilePostData(datas, url);
}
if (!checkOpenBase16()) {
return datas;
}
......@@ -191,9 +276,9 @@ export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
}
}
if(item.yinShe){ // 映射参数字段.
if (item.yinShe) { // 映射参数字段.
datas.isBase = true;
for(let oldKey in item.yinShe){
for (let oldKey in item.yinShe) {
let newKey = item.yinShe[oldKey];
// if(typeof datas[oldKey] !== 'undefined'){
datas[newKey] = datas[oldKey];
......@@ -207,3 +292,5 @@ export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
}
return datas;
}
......@@ -135,7 +135,6 @@ export const queryCheckPath = () => queryConfig('CHECK_PATH');
export const queryLoginRedirect = () => queryConfig('LOGIN_REDIRECT');
export const queryApiVersion = () => queryConfig('apiVersion');
export const queryUiaApi = () => queryConfig('oauthServer');
export const queryIsSafe = () => queryConfig('IS_SAFE'); // 是否开启文件上传加密 2022年5月24日 钟是志 解决北电科安全防火墙bug
export default queryConfig;
......@@ -14,7 +14,7 @@ import {
import { openToast } from '../location/Notification';
import { showToast } from '../location/Toast';
import { offline } from '../location/Toast';
import { giveBase16EnCode } from "@/webPublic/one_stop_public/Base16";
import { giveBase16EnCode, requestFileInfo } from '@/webPublic/one_stop_public/Base16';
import objectToFormData from '@/webPublic/zyd_public/utils/object-to-formdata-custom';
const codeMessage = {
......@@ -42,7 +42,11 @@ const codeMessage = {
* return URL参数字符串
*/
const qqCw = ({ title = '请求错误', msg = '', customErrMsg = '' }) => {
const qqCw = ({
title = '请求错误',
msg = '',
customErrMsg = '',
}) => {
// 请求错误 增加自定义错误提示信息 customErrMsg 从发起 接口那里自定义
// 禅道bug 11794
notification.error({
......@@ -118,11 +122,14 @@ const loginUmiRequest = extend({
const getUrl = url => (url.startsWith('/') ? url : '/' + url);
export const request = (url, data, options = {}) => {
return giveBase16EnCode(data, url).then((newData) => {
// console.log(newData);
return giveBase16EnCode(data, url)
.then((newData) => {
if(typeof newData === 'object' && newData.url){
return requestFileInfo(newData.url, newData.datas, options);
}
return requestOrigin(url, newData, options);
});
}
};
export const requestOrigin = (url, data, options = {}) => {
......@@ -158,8 +165,8 @@ export const requestOrigin = (url, data, options = {}) => {
})
.then(response => {
// console.log(response);
if(response && response.errMsg){
response.errMsg = response.errMsg.slice(0,50);
if (response && response.errMsg) {
response.errMsg = response.errMsg.slice(0, 50);
}
if (response.errCode && response.errCode == '10000') {
const ul = window.location.href;
......@@ -241,9 +248,10 @@ export const requestOrigin = (url, data, options = {}) => {
requestType: 'form',
...options,
}).then(response => {
if(response && response.errMsg){
response.errMsg = response.errMsg.slice(0,30) + '...';
})
.then(response => {
if (response && response.errMsg) {
response.errMsg = response.errMsg.slice(0, 30) + '...';
}
if (response && response.errCode && response.errCode == '10000') {
const ul = window.location.href;
......@@ -350,26 +358,28 @@ export const getUiaRequest = (data) => { // 2.0的登录接口
return fetch(queryUiaApi() + '/oauth/token', {
credentials: 'omit',
mode: 'cors',
headers:{
headers: {
Accept: 'application/json',
// 'Content-Type': 'multipart/form-data',
},
method: 'POST',
body: objectToFormData(data),
}).then(response => {
})
.then(response => {
return response.json();
}).then((g) => {
if(g && g.access_token){
})
.then((g) => {
if (g && g.access_token) {
g.token = g.access_token;
return g;
}else{
if(g && g.message){
} else {
if (g && g.message) {
message.warn(g.message);
}
return false;
}
})
}
});
};
// export const testGetUiaRequest = (data) => { // 2.0的登录接口
......
/**
* 设置token
* */
import { isJSON } from '@/webPublic/one_stop_public/copy';
export const setToken = (value, time) => {
localStorage.setItem('antd-pro-token-onestop', value);
localStorage.setItem('antd-pro-token', value);
......@@ -31,3 +33,15 @@ export const delToken = () => {
localStorage.removeItem('antd-pro-token');
localStorage.removeItem('wisdom-school-token');
}
export const getUserInfo = () => {
let x = localStorage.getItem('user');
if(isJSON(x)){
x = JSON.parse(x);
return x;
}else{
return {
groupsId: 'pub',
};
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论