From 97c39458480cca555ccea216d2f9d40fd711c53e Mon Sep 17 00:00:00 2001 From: chenpingsen Date: Thu, 11 Jul 2024 17:35:02 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=A2=9E=E5=8A=A0=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=8E=B7=E5=8F=96=E6=9E=9A=E4=B8=BE=E7=9A=84?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hx-ai-intelligent/src/api/index.ts | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/hx-ai-intelligent/src/api/index.ts b/hx-ai-intelligent/src/api/index.ts index 22478b4..9f32029 100644 --- a/hx-ai-intelligent/src/api/index.ts +++ b/hx-ai-intelligent/src/api/index.ts @@ -38,3 +38,46 @@ export const dict = async ({ } return Promise.resolve({ data: { data: get(dictMap, key) } }); }; + +/** + * 获取所有枚举(无需传参) + */ +export const getAllEnum = async ({ + api = `${BASE_URL}/operation/enum/getAllEnum`, + params = {}, + keyField = 'dicKey', + transform = (res: any) => res, +}: dictHttpConfig) => { + const dictMap = JSON.parse(sessionStorage.getItem('dictMap') || '{}') as Object; + const key = get(params, keyField) as keyof typeof dictMap; + + if (!dictMap.hasOwnProperty(key)) { + const res = await http.post(api, params); + const options = get(transform(res), `data.${key}`); + dictMap[key] = options; + sessionStorage.setItem('dictMap', JSON.stringify(dictMap)); + } + return Promise.resolve({ data: { data: get(dictMap, key) } }); +}; + + +/** + * 获取单个枚举(需传参,参数 enumType) + */ +export const getEnum = async ({ + api = `${BASE_URL}/operation/enum/getEnum`, + params = {}, + keyField = 'dicKey', + transform = (res: any) => res, +}: dictHttpConfig) => { + const dictMap = JSON.parse(sessionStorage.getItem('dictMap') || '{}') as Object; + const key = get(params, keyField) as keyof typeof dictMap; + + if (!dictMap.hasOwnProperty(key)) { + const res = await http.post(api, params); + const options = get(transform(res), `data.${key}`); + dictMap[key] = options; + sessionStorage.setItem('dictMap', JSON.stringify(dictMap)); + } + return Promise.resolve({ data: { data: get(dictMap, key) } }); +}; \ No newline at end of file