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

加密很慢的问题

上级 2764de90
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';
var BASE16 = "0123456789abcdef"; var BASE16 = '0123456789abcdef';
var bs16 = baseX(BASE16); var bs16 = baseX(BASE16);
function checkOpenBase16(){ function checkOpenBase16() {
const is_open_base14 = sessionStorage.getItem("is_open_base16") const is_open_base14 = sessionStorage.getItem('is_open_base16')
? JSON.parse(sessionStorage.getItem("is_open_base16")) ? JSON.parse(sessionStorage.getItem('is_open_base16'))
: false; : false;
return is_open_base14; return is_open_base14;
} }
export function Base16Encode(value) { export function Base16Encode(value) {
let is_open_base14 = checkOpenBase16(); const is_open_base14 = checkOpenBase16();
if (is_open_base14) return value ? bs16.encode(new Buffer(value)) : null; if (is_open_base14) {
if (!value) {
return null;
} else {
let newV = new Buffer(value); // 快
const r = bs16.encode(newV); // 慢
return r;
}
}
return value; return value;
} }
...@@ -28,123 +36,120 @@ const giveKey = (key, datas) => { ...@@ -28,123 +36,120 @@ const giveKey = (key, datas) => {
const encryptApiList = [ const encryptApiList = [
{ {
api: "DataColumnApi/getOptions", api: 'DataColumnApi/getOptions',
key: ["filterSql"] key: ['filterSql'],
}, },
{ {
api: "DataColumnApi/getLabels", api: 'DataColumnApi/getLabels',
key: ["allValues"], key: ['allValues'],
setNull: true, setNull: true,
}, },
{ {
api: "DataColumnApi/getSqlOptions", api: 'DataColumnApi/getSqlOptions',
key: ["allValues",], key: ['allValues'],
query: true query: true,
}, },
{ {
api: "DataColumnApi/getSqlLabels", api: 'DataColumnApi/getSqlLabels',
key: ["allValues"], key: ['allValues'],
query: true query: true,
}, },
{ {
api: "DataColumnApi/getSqlData", api: 'DataColumnApi/getSqlData',
key: ["allValues", "sqlKey"], key: ['allValues', 'sqlKey'],
query: true query: true,
}, },
{ {
api: "DataRightApi/add", api: 'DataRightApi/add',
key: ["filterSql"] key: ['filterSql'],
}, },
{ {
api: "DataRightApi/addBatch", api: 'DataRightApi/addBatch',
key: ["filterSql"] key: ['filterSql'],
}, },
{ {
api: "DataObjApi/add", api: 'DataObjApi/add',
key: ["sqlScript"] key: ['sqlScript'],
}, },
{ {
api: "DataObjApi/getFormDataList", api: 'DataObjApi/getFormDataList',
key: ["custom"] key: ['custom'],
}, },
{ {
api: "DataObjApi/getFormDataPage", api: 'DataObjApi/getFormDataPage',
key: ["sql", "custom"] key: ['sql', 'custom'],
}, },
{ {
api: "UserApi/getPage", api: 'UserApi/getPage',
key: ["addSignSql"] key: ['addSignSql'],
}, },
{ {
api: "UnifiedAppFormApi/examineProcess", api: 'UnifiedAppFormApi/examineProcess',
key: ["taskForm"] key: ['taskForm'],
}, },
{ {
api: "UnifiedAppFormApi/saveDraft", api: 'UnifiedAppFormApi/saveDraft',
key: ["content"] key: ['content'],
}, },
{ {
api: "UnifiedAppFormApi/startProcess", api: 'UnifiedAppFormApi/startProcess',
key: ["content"] key: ['content'],
}, },
{ {
api: "UnifiedAppFormApi/startProcessByService", api: 'UnifiedAppFormApi/startProcessByService',
key: ["content"] key: ['content'],
}, },
{ {
api: "UnifiedAppFormApi/getHandleUser", api: 'UnifiedAppFormApi/getHandleUser',
key: ["content"], key: ['content'],
}, },
{ {
api: 'SqlManageEntityApi/findParamsKey', api: 'SqlManageEntityApi/findParamsKey',
key: ['sqlKey'], key: ['sqlKey'],
} },
]; ];
const countAllValues = async (datas, item) => { const countAllValues = async (datas, item) => {
if (item.setNull) { if (item.setNull) {
datas.allValues = JSON.stringify({}); datas.allValues = JSON.stringify({});
} else { } else {
if (item.query) { if (item.query) {
if (datas?.sqlKey.length < 13) { if (datas?.sqlKey.length < 13) {
const response = await apiRequest("/SqlManageEntityApi/findParamsKey", { sqlKey: datas.sqlKey }); const response = await apiRequest('/SqlManageEntityApi/findParamsKey', { sqlKey: datas.sqlKey });
if (!response || (Array.isArray(response) && response.length === 0)) { if (!response || (Array.isArray(response) && response.length === 0)) {
datas.allValues = JSON.stringify({}); datas.allValues = JSON.stringify({});
} else { } else {
const x = isJSON(data.allValues) && JSON.parse(data.allValues) || {}; const x = isJSON(data.allValues) && JSON.parse(data.allValues) || {};
const y = {}; const y = {};
for (let i of response) { for (let i of response) {
if (x[i]) { if (x[i]) {
y[i] = x[i]; y[i] = x[i];
}
datas.allValues = JSON.stringify(y);
} }
datas.allValues = JSON.stringify(y);
} }
} else {
datas.allValues = JSON.stringify({});
} }
} else {
datas.allValues = JSON.stringify({});
} }
} }
return datas; }
} return datas;
};
export async function giveBase16EnCode(datas, url) { // 全局加解密函数. export async function giveBase16EnCode(datas, url) { // 全局加解密函数.
if(!checkOpenBase16){ if (!checkOpenBase16) {
return datas; return datas;
} }
// if(datas?.allValues){
// console.log(JSON.stringify(datas)); if (url && typeof url === 'string') {
// }
if (url && typeof url === "string") {
for (let item of encryptApiList) { for (let item of encryptApiList) {
if (url.indexOf(item.api) > -1) { if (url.indexOf(item.api) > -1) {
for (let g of item.key) { for (let g of item.key) {
if(g === 'allValues' && typeof datas[g] !== 'undefined'){ if (g === 'allValues' && typeof datas[g] !== 'undefined') {
datas = await countAllValues(datas, item); datas = await countAllValues(datas, item);
datas = giveKey('allValues', datas); datas = giveKey('allValues', datas);
}else{ } else {
datas = giveKey(g, datas); datas = giveKey(g, datas);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论