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

二进制修改

上级 e9511cfd
......@@ -122,4 +122,18 @@ const encryptApiList = [
},
];
const resBinaryApiList = [
{
api: 'UnifiedAppApi/getDetail',
},
{
api: 'UnifiedServiceApi/getDetail',
},
{
api: 'UnifiedAppFormApi/getFormDetail',
},
]
export { resBinaryApiList };
export default encryptApiList;
......@@ -7,7 +7,7 @@ import {
queryIsSafe,
} from '@/webPublic/one_stop_public/utils/queryConfig';
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import encryptApiList from './encryptApiList';
import encryptApiList, { resBinaryApiList } from './encryptApiList';
import { uploadFile } from '@/webPublic/one_stop_public/libs/PictureSignature/ShowItem';
import { deepCopy } from '@/webPublic/one_stop_public/utils/myutils';
......@@ -119,8 +119,8 @@ export function requestFileInfo(url, datas) {
});
return false;
}
if (datas && datas.bin) {
res = binaryToStr(res.result);
if (res && typeof res === 'object' && res.rbin) {
res = binaryToStr(res.rbin);
if (isJSON(res)) {
res = JSON.parse(res);
}
......@@ -129,7 +129,7 @@ export function requestFileInfo(url, datas) {
});
}
function formatDatas(datas) {
function formatDatas(datas, url = '') {
let datasCode = JSON.stringify(datas);
const openIsBinary = window.CONFIG?.IS_BINARY;
if (openIsBinary) {
......@@ -144,11 +144,16 @@ function formatDatas(datas) {
};
if (openIsBinary) {
datasTrue.bin = true;
let findIndexA = resBinaryApiList.findIndex(g => {
return url.includes(g.api);
});
if (findIndexA >= 0) {
datasTrue.rbin = true;
}
}
return datasTrue;
}
export function giveFilePostDataInfoForTrue(datas, url) {
if (!window.CONFIG?.IS_SAFE) {
return {
......@@ -158,7 +163,11 @@ export function giveFilePostDataInfoForTrue(datas, url) {
}
datas = deepCopy(datas);
for (let i in datas) {
if (datas[i] === null || (Array.isArray(datas[i]) && datas[i].length === 0) || datas[i] === undefined) {
if (
datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined
) {
delete datas[i];
}
}
......@@ -171,13 +180,16 @@ export function giveFilePostDataInfoForTrue(datas, url) {
url = url.replaceAll('//', '/');
}
return {
datas: formatDatas(datas),
datas: formatDatas(datas, url),
url,
};
}
}
function strToBinary(str) { // 字符串转二进制
/**
* 字符串转二进制
* */
function strToBinary(str) {
let result = [];
let list = str.split('');
for (let i = 0; i < list.length; i++) {
......@@ -189,16 +201,20 @@ function strToBinary(str) { // 字符串转二进制
.toString(2);
result.push(binaryStr);
}
return result.join('');
let resultStr = result.join('_');
resultStr = resultStr.replaceAll('0', '-').replaceAll('1', '.');
return resultStr;
}
/**
* 二进制字符串转JSON 字符串
* 二进制字符串转JSON字符串
* */
function binaryToStr(binaryStr = '') {
let res = '';
if (binaryStr) {
let strListArr = binaryStr.split(' ');
binaryStr.replaceAll('.', '1');
binaryStr.replaceAll('-', '0');
let strListArr = binaryStr.split('_');
for (let i = 0; i < strListArr.length; i++) {
let item = strListArr[i];
res += String.fromCharCode(parseInt(item, 2));
......@@ -207,10 +223,13 @@ function binaryToStr(binaryStr = '') {
return res;
}
function giveFilePostData(datas, url) {
for (let i in datas) {
if (datas[i] === null || (Array.isArray(datas[i]) && datas[i].length === 0) || datas[i] === undefined) {
if (
datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined
) {
delete datas[i];
}
}
......@@ -226,7 +245,7 @@ function giveFilePostData(datas, url) {
}
return new Promise((resolve, reject) => {
resolve({
datas: formatDatas(datas),
datas: formatDatas(datas, url),
url,
});
});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论