Browse Source

add:增加两个用于获取枚举的公共方法

temp
chenpingsen 2 months ago
parent
commit
97c3945848
  1. 43
      hx-ai-intelligent/src/api/index.ts

43
hx-ai-intelligent/src/api/index.ts

@ -38,3 +38,46 @@ export const dict = async ({
} }
return Promise.resolve({ data: { data: get(dictMap, key) } }); 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) } });
};
Loading…
Cancel
Save