Browse Source

fix: 获取字典数据方法

deploy-dev
xuziqiang 4 months ago
parent
commit
ab17c4a1f9
  1. 33
      hx-ai-intelligent/src/api/index.ts
  2. 6
      hx-ai-intelligent/src/view/equipmentManage/group/config.ts

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

@ -1,3 +1,6 @@
import { get } from 'lodash-es';
import { http } from '/nerv-lib/util/http';
/*** /***
* module:Array<resource> * module:Array<resource>
*/ */
@ -6,4 +9,32 @@ export const apiModule = {
}; };
export const BASE_URL = '/carbon-smart'; export const BASE_URL = '/carbon-smart';
export const dict = `${BASE_URL}/client/dict/listByKey`;
interface dictHttpConfig {
api?: string;
keyField?: string;
params: object;
transform?: Function;
}
/**
* (,)
*/
export const dict = async ({
api = `${BASE_URL}/client/dict/listByKey`,
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) } });
};

6
hx-ai-intelligent/src/view/equipmentManage/group/config.ts

@ -137,10 +137,10 @@ export const treeConfig = (orgId) => {
component: 'NsSelectApi', component: 'NsSelectApi',
autoSubmit: true, autoSubmit: true,
componentProps: { componentProps: {
api: dict, api: () => dict({ params: { dicKey: 'ENERGY_TYPE' } }),
params: { dicKey: 'ENERGY_TYPE' }, // params: { dicKey: 'ENERGY_TYPE' },
immediate: true, immediate: true,
resultField: 'data.ENERGY_TYPE', // resultField: 'data.ENERGY_TYPE',
labelField: 'cnValue', labelField: 'cnValue',
valueField: 'cnValue', valueField: 'cnValue',
placeholder: '请选择能耗种类', placeholder: '请选择能耗种类',

Loading…
Cancel
Save