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

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

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