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

2023年3月3日

* UC浏览器不支持 es6的 replaceAll方法 需要自己写一个
上级 54dd7273
import encryptApiList, { import encryptApiList, {
resBinaryApiList, resBinaryApiList,
} from '@/webPublic/one_stop_public/Base16/encryptApiList'; } from '@/webPublic/one_stop_public/Base16/encryptApiList';
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token'; import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfig'; import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfig';
...@@ -12,196 +12,215 @@ import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/local ...@@ -12,196 +12,215 @@ import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/local
import { strToBinary } from './strToBinary'; // 字符串转二进制 混淆代码 import { strToBinary } from './strToBinary'; // 字符串转二进制 混淆代码
import { binaryToStr } from './binaryToStr'; import { binaryToStr } from './binaryToStr';
import { getVisitorToken } from '@/webPublic/zyd_public/utils/getHeaders'; import { getVisitorToken } from '@/webPublic/zyd_public/utils/getHeaders';
import { replaceAll } from '@/webPublic/one_stop_public/Base16/utils';
const test = !!getUrlInfo().test;
function formatDatas(datas, url = '') { function formatDatas(datas, url = '') {
if (url && url.indexOf('getSqlData') > -1 && window.smartFormGlobalProps?.data) {
// 按欢哥的要求 getSqlData 接口要加上appId 参数 if (url && url.indexOf('getSqlData') > -1 && window.smartFormGlobalProps?.data) {
// 按欢哥的要求 getSqlData 接口要加上appId 参数
// 解决北电科接口越权的问题. // 解决北电科接口越权的问题.
datas.appId = window.smartFormGlobalProps?.data.appId || window.smartFormGlobalProps?.data.id; datas.appId = window.smartFormGlobalProps?.data.appId || window.smartFormGlobalProps?.data.id;
// console.log('getSqlData,AppId', datas.appId); // console.log('getSqlData,AppId', datas.appId);
} }
let datasCode = JSON.stringify(datas); let datasCode = JSON.stringify(datas);
const openIsBinary = window.CONFIG?.IS_BINARY; const openIsBinary = window.CONFIG?.IS_BINARY;
// if (test) { // if (test) {
// console.log(url, datas); // console.log(url, datas);
// } // }
if (openIsBinary) { if (openIsBinary) {
datasCode = strToBinary(datasCode); datasCode = strToBinary(datasCode);
} }
let file = new File([datasCode], 'fileParams.jpeg', { let file = new File([datasCode], 'fileParams.jpeg', {
type: 'image/jpeg', type: 'image/jpeg',
}); });
let datasTrue = { let datasTrue = {
fileParams: file, fileParams: window.CONFIG.SAFE_TYPE === 2 ? datasCode : file,
}; };
if (openIsBinary) { if (openIsBinary) {
datasTrue.bin = true; datasTrue.bin = true;
if (window.CONFIG?.ALL_R_BIN) { if (window.CONFIG?.ALL_R_BIN) {
datasTrue.rbin = true; datasTrue.rbin = true;
} else { } else {
let findIndexA = resBinaryApiList.findIndex((g) => { let findIndexA = resBinaryApiList.findIndex(g => {
return url.includes(g.api); return url.includes(g.api);
}); });
if (findIndexA >= 0) { if (findIndexA >= 0) {
datasTrue.rbin = true; datasTrue.rbin = true;
} }
} }
} }
return datasTrue; return datasTrue;
} }
export async function giveFilePostData(datas, url) { export async function giveFilePostData(datas, url) {
const staticS = window.CONFIG.SAFE_TYPE === 2 ? 'interface' : 'safe';
// console.log(datas, url); // console.log(datas, url);
for (let i in datas) { for (let i in datas) {
if ( if (
datas[i] === null || datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) || (Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined datas[i] === undefined
) { ) {
delete datas[i]; delete datas[i];
} }
} }
if (url && typeof url === 'string') { if (url && typeof url === 'string') {
for (let item of encryptApiList) { for (let item of encryptApiList) {
if ((window.CONFIG?.ALLBIN && url.indexOf('/onestop/') > -1) || url.indexOf(item.api) > -1) { if ((window.CONFIG?.ALLBIN && url.indexOf('/onestop/') > -1) || url.indexOf(item.api) > -1) {
const roleGroup = getUserInfo().groupsId; const roleGroup = getUserInfo().groupsId;
if (url.indexOf('http') > -1) {
console.log(url); if (url.indexOf('http') > -1) {
url = url.replace('/onestop/', `/onestop/safe/${roleGroup}/`); url = url.replace('/onestop/', `/onestop/${staticS}/${roleGroup}/`);
url = url.replace('/onestopapi/', `/onestopapi/safe/${roleGroup}/`); url = url.replace('/onestopapi/', `/onestopapi/${staticS}/${roleGroup}/`);
} else { } else {
url = url.replace(url, `/safe/${roleGroup}/` + url); url = url.replace(url, `/${staticS}/${roleGroup}/` + url);
url = url.replaceAll('//', '/'); url = replaceAll(url, '//', '/');
} }
datas = await countAllValues(datas, item);
return new Promise((resolve, reject) => { datas = await countAllValues(datas, item);
resolve({ return new Promise((resolve, reject) => {
datas: formatDatas(datas, url), resolve({
url, datas: formatDatas(datas, url),
}); url,
}); });
} });
} }
} }
return new Promise((resolve, reject) => { }
resolve(datas); return new Promise((resolve, reject) => {
return datas; resolve(datas);
}); return datas;
});
} }
function testPromise(d) { function testPromise(d) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(d); resolve(d);
}); });
} }
export async function requestFileInfo(url, datas) { export async function requestFileInfo(url, datas) {
// for (let i = 0; i < 100; i++) { const staticS = window.CONFIG.SAFE_TYPE === 2 ? 'interface' : 'safe';
// datas = await testPromise(datas); // for (let i = 0; i < 100; i++) {
// } // datas = await testPromise(datas);
const formData = new FormData(); // }
if (getVisitorToken()) { const formData = new FormData();
datas.token = getVisitorToken(); if (getVisitorToken()) {
} datas.token = getVisitorToken();
for (let key in datas) { } else {
formData.append(key, datas[key]); datas.token = getToken();
} }
if (!url || typeof url !== 'string') {
return false; if (!url || typeof url !== 'string') {
} return false;
}
let trueUrl = url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url;
const { transformApi, headersApi } = await getTransformApi(trueUrl); let trueUrl = url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url;
return fetch(transformApi, { const { transformApi, headersApi } = await getTransformApi(trueUrl);
headers: { let urlSafe2 = transformApi;
Accept: 'application/json', if (window.CONFIG.SAFE_TYPE === 2) {
...getHeaders(transformApi).headers, urlSafe2 = transformApi.split('/');
// apis: headersApi, let findSafeIndex = urlSafe2.findIndex(g => g === staticS);
// axxx: `select * from user123 where id = 1`, if (findSafeIndex >= 1) {
}, let path = urlSafe2.slice(findSafeIndex + 2).join('/');
method: 'POST', urlSafe2 = urlSafe2.slice(0, findSafeIndex + 2).join('/');
credentials: 'omit', datas.path = '/' + path;
mode: 'cors', }
body: formData, }
})
.then((res) => { for (let key in datas) {
// console.log(res); formData.append(key, datas[key]);
if (res.status === 401) { }
qqCw({ return fetch(urlSafe2, {
title: '登录过期401', headers: {
customErrMsg: '登录已过期,请重新登录', Accept: 'application/json',
}); ...getHeaders(transformApi).headers,
return false; ContentType: 'multipart/form-data',
} // apis: headersApi,
if (res.status === 404) { // axxx: `select * from user123 where id = 1`,
qqCw({ },
title: 'http404报错', method: 'POST',
customErrMsg: '请联系系统管理员', credentials: 'omit',
}); mode: 'cors',
return false; body: formData,
} })
return res.json(); .then(res => {
}) if (res.status === 401) {
.then((res) => { qqCw({
if (res && typeof res === 'object' && res.rbin) { title: '登录过期401',
res = binaryToStr(res.rbin); customErrMsg: '登录已过期,请重新登录',
if (isJSON(res)) { });
res = JSON.parse(res); return false;
}
if (res.status === 404) {
qqCw({
title: 'http404报错',
customErrMsg: '请联系系统管理员',
});
return false;
}
return res.json();
})
.then(res => {
if (res && typeof res === 'object' && res.rbin) {
res = binaryToStr(res.rbin);
if (isJSON(res)) {
res = JSON.parse(res);
} }
} }
if (res && res.errCode) { if (res && res.errCode) {
qqCw({ qqCw({
msg: res.errMsg || res.message, msg: res.errMsg || res.message,
customErrMsg: res.customErrMsg, customErrMsg: res.customErrMsg,
}); });
return false; return false;
} }
// if (test) { // if (test) {
// console.log({ // console.log({
// url, // url,
// res, // res,
// }); // });
// } // }
return res; return res;
}); });
} }
export function giveFilePostDataInfoForTrue(datas, url) { export function giveFilePostDataInfoForTrue(datas, url) {
if (!window.CONFIG?.IS_SAFE) { const staticS = window.CONFIG.SAFE_TYPE === 2 ? 'interface' : 'safe';
return { if (!window.CONFIG?.IS_SAFE) {
datas, return {
url, datas,
}; url,
} };
datas = deepCopy(datas); }
for (let i in datas) { datas = deepCopy(datas);
if ( for (let i in datas) {
datas[i] === null || if (
(Array.isArray(datas[i]) && datas[i].length === 0) || datas[i] === null ||
datas[i] === undefined (Array.isArray(datas[i]) && datas[i].length === 0) ||
) { datas[i] === undefined
delete datas[i]; ) {
} delete datas[i];
} }
if (url) { }
const roleGroup = getUserInfo().groupsId; if (url) {
if (url.indexOf('http') > -1) { const roleGroup = getUserInfo().groupsId;
url = url.replace('/onestop/', `/onestop/safe/${roleGroup}/`); if (url.indexOf('http') > -1) {
url = url.replace('/onestopapi/', `/onestopapi/safe/${roleGroup}/`); url = url.replace('/onestop/', `/onestop/${staticS}/${roleGroup}/`);
} else { url = url.replace('/onestopapi/', `/onestopapi/${staticS}/${roleGroup}/`);
url = url.replace(url, `/safe/${roleGroup}/` + url); } else {
url = url.replaceAll('//', '/'); url = url.replace(url, `/${staticS}/${roleGroup}/` + url);
} url = replaceAll(url, '//', '/');
return { }
datas: formatDatas(datas, url), return {
url, datas: formatDatas(datas, url),
}; url,
} };
}
} }
import { replaceAll } from '@/webPublic/one_stop_public/Base16/utils';
/** /**
* 二进制字符串转JSON字符串 * 二进制字符串转JSON字符串
* */ * */
export function binaryToStr(binaryStr = '') { export function binaryToStr(binaryStr = '') {
let res = ''; let res = '';
if (binaryStr) { if (binaryStr) {
binaryStr = binaryStr.replaceAll('.', '1'); binaryStr = replaceAll(binaryStr, '\\.', '1');
binaryStr = binaryStr.replaceAll('-', '0'); binaryStr = replaceAll(binaryStr, '-', '0');
let strListArr = binaryStr.split('_'); let strListArr = binaryStr.split('_');
for (let i = 0; i < strListArr.length; i++) { for (let i = 0; i < strListArr.length; i++) {
let item = strListArr[i]; let item = strListArr[i];
res += String.fromCharCode(parseInt(item, 2)); res += String.fromCharCode(parseInt(item, 2));
......
/** /**
* 字符串转二进制 * 字符串转二进制
* */ * */
import { replaceAll } from '@/webPublic/one_stop_public/Base16/utils';
export function strToBinary(str) { export function strToBinary(str) {
let result = []; let result = [];
let list = str.split(''); let list = str.split('');
...@@ -14,7 +16,7 @@ export function strToBinary(str) { ...@@ -14,7 +16,7 @@ export function strToBinary(str) {
result.push(binaryStr); result.push(binaryStr);
} }
let resultStr = result.join(''); let resultStr = result.join('');
resultStr = resultStr.replaceAll('0', '-').replaceAll('1', '.'); resultStr = replaceAll(resultStr, '0', '-');
// console.log(resultStr); resultStr = replaceAll(resultStr, '1', '.');
return resultStr; return resultStr;
} }
/**
* 2023年3月3日
* UC浏览器不支持 es6的 replaceAll方法 需要自己写一个
* */
export function replaceAll(str, before, after) {
return str.replace(new RegExp(before,'gm'), after);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论