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

/DataColumnApi/getSqlOptions接口缓存参数优化 增加 allValues 参数 参数变化则不调用缓存

上级 66371377
...@@ -12,7 +12,6 @@ import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/local ...@@ -12,7 +12,6 @@ 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 { saveCacheData } from '@/webPublic/one_stop_public/utils/apiServiceCache'; // 二进制字符串转JSON字符串 混淆代码
const test = !!getUrlInfo().test; const test = !!getUrlInfo().test;
......
...@@ -409,13 +409,17 @@ export default class TableCom extends Component { ...@@ -409,13 +409,17 @@ export default class TableCom extends Component {
dataColumn.base52 = this.props.uuid; dataColumn.base52 = this.props.uuid;
} }
} }
// if(this.props.uuid === 'id_44cd90f124abc2427428ee2285222628953f'){
// console.log('我去调接口查枚举了');
//
// }
if (this.dataFilter.includes(json.comName) || json.comName === 'TableSelect') { if (this.dataFilter.includes(json.comName) || json.comName === 'TableSelect') {
const obj2 = { const obj2 = {
...obj, ...obj,
...props.form.getFieldsValue(),
...props.defaultValues[this.props.formKey], ...props.defaultValues[this.props.formKey],
...props.form.getFieldsValue(),
}; };
console.log(obj2['KFRwZkWcNJQ'], '422222222');
this.getData(json, dataColumn, obj2); this.getData(json, dataColumn, obj2);
} }
if (!!json.formula && !json.isFormulaOnce) { if (!!json.formula && !json.isFormulaOnce) {
...@@ -1307,6 +1311,7 @@ export default class TableCom extends Component { ...@@ -1307,6 +1311,7 @@ export default class TableCom extends Component {
fetchData3 = (obj, dataColumn, init, json, allValues) => { fetchData3 = (obj, dataColumn, init, json, allValues) => {
const { sqlKey, labelName, valueName, isMeta, filterSql } = json; const { sqlKey, labelName, valueName, isMeta, filterSql } = json;
// console.log(sqlKey, allValues); // console.log(sqlKey, allValues);
// debugger; // debugger;
if (isMeta) { if (isMeta) {
...@@ -1329,6 +1334,8 @@ export default class TableCom extends Component { ...@@ -1329,6 +1334,8 @@ export default class TableCom extends Component {
} }
dispatch({ dispatch({
type: 'DataColumn/getSqlOptions', type: 'DataColumn/getSqlOptions',
payload: params, payload: params,
...@@ -1406,6 +1413,10 @@ export default class TableCom extends Component { ...@@ -1406,6 +1413,10 @@ export default class TableCom extends Component {
// 当上次的请求参数和这次的相同时 不再发起请求 // 当上次的请求参数和这次的相同时 不再发起请求
return false; return false;
} }
// if(params.sqlKey === 'KFRvOyGdyvU'){
// console.log(params);
// }
dispatch({ dispatch({
type: 'DataColumn/getSqlOptions', type: 'DataColumn/getSqlOptions',
payload: params, payload: params,
......
...@@ -23,11 +23,12 @@ const cacheApiconfig = [ ...@@ -23,11 +23,12 @@ const cacheApiconfig = [
key: 'getSqlOptions', // 接口唯一的键 key: 'getSqlOptions', // 接口唯一的键
url: '/DataColumnApi/getSqlOptions', // 接口地址 url: '/DataColumnApi/getSqlOptions', // 接口地址
searchParams: 'sqlKey', // 缓存的参数 searchParams: 'sqlKey', // 缓存的参数
time: 3, // 缓存数据有效期. 单位秒 otherParams: 'allValues',
time: 1, // 缓存数据有效期. 单位秒
}, },
]; ];
function getConfig(apiUrl){ function getConfig(apiUrl) {
let findConfig = cacheApiconfig.find((g) => { let findConfig = cacheApiconfig.find((g) => {
return apiUrl === g.url; return apiUrl === g.url;
}); });
...@@ -35,52 +36,53 @@ function getConfig(apiUrl){ ...@@ -35,52 +36,53 @@ function getConfig(apiUrl){
} }
// 获取缓存数据 // 获取缓存数据
export function getCacheData(apiUrl, params){ export function getCacheData(apiUrl, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let findConfig = getConfig(apiUrl); let findConfig = getConfig(apiUrl);
if(!findConfig){ if (!findConfig) {
resolve(false); resolve(false);
return; return;
} }
// console.log(apiUrl, params);
let res = window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]]; let res = window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]];
// console.log(res); if (!res ||
if(!res || new Date().getTime() > res?.expiresTime){ new Date().getTime() > res?.expiresTime ||
window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]] = 'pending'; (params[findConfig.otherParams] && params[findConfig.otherParams] !== res.otherParams)
) {
window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]] =
'pending';
resolve(false); resolve(false);
return; return;
} }
if(res === 'pending'){ if (res === 'pending') {
let interval = setInterval(() => { let interval = setInterval(() => {
let newD = window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]]; let newD =
if(newD !== 'pending'){ window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]];
if (newD !== 'pending') {
clearInterval(interval); clearInterval(interval);
resolve(newD.response); resolve(newD.response);
return newD.response; return newD.response;
} }
}, 200); }, 200);
}else{ } else {
resolve(res.response); resolve(res.response);
return res.response; return res.response;
} }
}); });
} }
// 保存缓存数据 // 保存缓存数据
export function saveCacheData(apiUrl = '', params,response = {}){ export function saveCacheData(apiUrl = '', params, response = {}) {
let findConfig = getConfig(apiUrl); let findConfig = getConfig(apiUrl);
if(findConfig){ if (findConfig) {
// console.log(params); // console.log(params);
window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]] = { window.onestopApiServiceCacheData[findConfig.key + params[findConfig.searchParams]] = {
response, response,
expiresTime: new Date().getTime() + findConfig.time * 1000, expiresTime: new Date().getTime() + findConfig.time * 1000,
otherParams: params[findConfig.otherParams] || undefined, // 接口参数做缓存
}; };
// console.log(window.onestopApiServiceCacheData); // console.log(window.onestopApiServiceCacheData);
return true; return true;
}else{ } else {
return false; return false;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论