diff --git a/src/components/Cascader/Dictionary/index.js b/src/components/Cascader/Dictionary/index.js index 5e982b0..ecd1eac 100644 --- a/src/components/Cascader/Dictionary/index.js +++ b/src/components/Cascader/Dictionary/index.js @@ -3,6 +3,9 @@ import { useEffect, useState } from "react"; import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary"; import BasicCascader from "../Basic"; +// 全局缓存 +const cacheMap = new Map(); + /** * 数据字典级联组件 */ @@ -30,7 +33,20 @@ function DictionaryCascader(props) { return; } + // 生成缓存键 + const cacheKey = JSON.stringify({ appKey, dictValue }); + + // 检查缓存,如果存在直接返回缓存结果 + if (cacheMap.has(cacheKey)) { + setTreeData(cacheMap.get(cacheKey)); + return; + } + const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); + + // 存入缓存 + cacheMap.set(cacheKey, data); + setTreeData(data); }; diff --git a/src/components/LeftTree/Department/Gwj/index.js b/src/components/LeftTree/Department/Gwj/index.js index 71c6c72..79068b3 100644 --- a/src/components/LeftTree/Department/Gwj/index.js +++ b/src/components/LeftTree/Department/Gwj/index.js @@ -2,6 +2,9 @@ import { request } from "@cqsjjb/jjb-common-lib/http.js"; import { useEffect, useState } from "react"; import BasicLeftTree from "../../Basic"; +// 全局缓存 +const cacheMap = new Map(); + /** * 部门左侧树组件(港务局版本) */ @@ -15,6 +18,18 @@ function DepartmentLeftTree(props) { const [treeData, setTreeData] = useState([]); const getData = async () => { + setTreeData([]); + + // 生成缓存键 + const paramsStr = JSON.stringify(params); + const cacheKey = `${searchType}_${paramsStr}`; + + // 检查缓存,如果存在直接返回缓存结果 + if (cacheMap.has(cacheKey)) { + setTreeData(cacheMap.get(cacheKey)); + return; + } + let requestUrl = ""; const actualParams = { ...params, time: new Date().getTime() }; if (searchType === "current") { @@ -39,6 +54,10 @@ function DepartmentLeftTree(props) { } const { data } = await request(requestUrl, "post", actualParams); + + // 存入缓存 + cacheMap.set(cacheKey, data); + setTreeData(data); }; diff --git a/src/components/LeftTree/Dictionary/index.js b/src/components/LeftTree/Dictionary/index.js index 2cc1088..baf2eb3 100644 --- a/src/components/LeftTree/Dictionary/index.js +++ b/src/components/LeftTree/Dictionary/index.js @@ -3,6 +3,9 @@ import { useEffect, useState } from "react"; import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary"; import BasicLeftTree from "../Basic"; +// 全局缓存 +const cacheMap = new Map(); + /** * 数据字典左侧树组件 */ @@ -30,7 +33,20 @@ function DictionaryLeftTree(props) { return; } + // 生成缓存键 + const cacheKey = JSON.stringify({ appKey, dictValue }); + + // 检查缓存,如果存在直接返回缓存结果 + if (cacheMap.has(cacheKey)) { + setTreeData(cacheMap.get(cacheKey)); + return; + } + const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); + + // 存入缓存 + cacheMap.set(cacheKey, data); + setTreeData(data); }; diff --git a/src/components/Select/Dictionary/index.js b/src/components/Select/Dictionary/index.js index 21b41b1..70fcb21 100644 --- a/src/components/Select/Dictionary/index.js +++ b/src/components/Select/Dictionary/index.js @@ -3,6 +3,9 @@ import { useEffect, useState } from "react"; import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary"; import BasicSelect from "../Basic"; +// 全局缓存 +const cacheMap = new Map(); + /** * 数据字典下拉组件 */ @@ -30,7 +33,20 @@ function DictionarySelect(props) { return; } + // 生成缓存键 + const cacheKey = JSON.stringify({ appKey, dictValue }); + + // 检查缓存,如果存在直接返回缓存结果 + if (cacheMap.has(cacheKey)) { + setData(cacheMap.get(cacheKey)); + return; + } + const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); + + // 存入缓存 + cacheMap.set(cacheKey, data); + setData(data); }; diff --git a/src/components/SelectTree/Dictionary/index.js b/src/components/SelectTree/Dictionary/index.js index 569d641..3f43edc 100644 --- a/src/components/SelectTree/Dictionary/index.js +++ b/src/components/SelectTree/Dictionary/index.js @@ -3,6 +3,9 @@ import { useEffect, useState } from "react"; import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary"; import BasicSelectTree from "../Basic"; +// 全局缓存 +const cacheMap = new Map(); + /** * 数据字典下拉树组件 */ @@ -30,7 +33,20 @@ function DictionarySelectTree(props) { return; } + // 生成缓存键 + const cacheKey = JSON.stringify({ appKey, dictValue }); + + // 检查缓存,如果存在直接返回缓存结果 + if (cacheMap.has(cacheKey)) { + setTreeData(cacheMap.get(cacheKey)); + return; + } + const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); + + // 存入缓存 + cacheMap.set(cacheKey, data); + setTreeData(data); };