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

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

上级 ca1a4b12
import baseX from 'base-x'; import baseX from 'base-x';
import { apiRequest } from '../utils/request'; import { apiRequest } from '../utils/request';
import { isJSON } from '@/webPublic/zyd_public/utils/utils'; 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 BASE16 = '0123456789abcdef';
var bs16 = baseX(BASE16); var bs16 = baseX(BASE16);
...@@ -39,6 +42,9 @@ const encryptApiList = [ ...@@ -39,6 +42,9 @@ const encryptApiList = [
api: 'DataColumnApi/getOptions', api: 'DataColumnApi/getOptions',
key: ['filterSql'], key: ['filterSql'],
}, },
{
api: 'UnifiedServicePatternApi/updateForm',
},
{ {
api: 'DataColumnApi/getLabels', api: 'DataColumnApi/getLabels',
key: ['allValues'], key: ['allValues'],
...@@ -162,7 +168,86 @@ const countAllValues = async (datas, item) => { ...@@ -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) { // 全局加解密函数. export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
if(queryIsSafe()){
return giveFilePostData(datas, url);
}
if (!checkOpenBase16()) { if (!checkOpenBase16()) {
return datas; return datas;
} }
...@@ -191,13 +276,13 @@ export async function giveBase16EnCode(datas, url) { // 全局加解密函数. ...@@ -191,13 +276,13 @@ export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
} }
} }
if(item.yinShe){ // 映射参数字段. if (item.yinShe) { // 映射参数字段.
datas.isBase = true; datas.isBase = true;
for(let oldKey in item.yinShe){ for (let oldKey in item.yinShe) {
let newKey = item.yinShe[oldKey]; let newKey = item.yinShe[oldKey];
// if(typeof datas[oldKey] !== 'undefined'){ // if(typeof datas[oldKey] !== 'undefined'){
datas[newKey] = datas[oldKey]; datas[newKey] = datas[oldKey];
delete datas[oldKey]; delete datas[oldKey];
// } // }
} }
} }
...@@ -207,3 +292,5 @@ export async function giveBase16EnCode(datas, url) { // 全局加解密函数. ...@@ -207,3 +292,5 @@ export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
} }
return datas; return datas;
} }
...@@ -135,7 +135,6 @@ export const queryCheckPath = () => queryConfig('CHECK_PATH'); ...@@ -135,7 +135,6 @@ export const queryCheckPath = () => queryConfig('CHECK_PATH');
export const queryLoginRedirect = () => queryConfig('LOGIN_REDIRECT'); export const queryLoginRedirect = () => queryConfig('LOGIN_REDIRECT');
export const queryApiVersion = () => queryConfig('apiVersion'); export const queryApiVersion = () => queryConfig('apiVersion');
export const queryUiaApi = () => queryConfig('oauthServer'); export const queryUiaApi = () => queryConfig('oauthServer');
export const queryIsSafe = () => queryConfig('IS_SAFE'); // 是否开启文件上传加密 2022年5月24日 钟是志 解决北电科安全防火墙bug
export default queryConfig; export default queryConfig;
/** /**
* 设置token * 设置token
* */ * */
import { isJSON } from '@/webPublic/one_stop_public/copy';
export const setToken = (value, time) => { export const setToken = (value, time) => {
localStorage.setItem('antd-pro-token-onestop', value); localStorage.setItem('antd-pro-token-onestop', value);
localStorage.setItem('antd-pro-token', value); localStorage.setItem('antd-pro-token', value);
...@@ -31,3 +33,15 @@ export const delToken = () => { ...@@ -31,3 +33,15 @@ export const delToken = () => {
localStorage.removeItem('antd-pro-token'); localStorage.removeItem('antd-pro-token');
localStorage.removeItem('wisdom-school-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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论