UNPKG

@fecp/mobile

Version:

96 lines (95 loc) 2.72 kB
import XEUtils from "../../../../_virtual/index.mjs"; import useHttp from "../axios/index.mjs"; import { useDataSource } from "./dataSourceUtil.mjs"; import envConfig from "./env.mjs"; const baseUrl = envConfig.api_base_url; const getOptions = ({ optionType, dicKey, dicList, dataSource, dataSourceParams, staticOptions, optionsFieldNames }) => { return new Promise((resolve, reject) => { switch (optionType) { case "static": resolve(staticOptions); break; case "dic": let dicListToOption = function(dicList2) { return dicList2.map((item) => { return { text: item.optName, value: item.optCode }; }); }; if (dicList && !XEUtils.isEmpty(dicList)) { resolve(dicListToOption(dicList)); } else { getParmDicMapByKeys(dicKey).then((data) => { const option = dicListToOption(data[dicKey]); resolve(option); }); } break; case "library": const dataSourceRef = useDataSource(dataSource); dataSourceRef == null ? void 0 : dataSourceRef.load(dataSourceParams || {}).then((res) => { var _a; const data = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.records) || (res == null ? void 0 : res.data) || res || []; const option = data.map((item) => { return { text: item[optionsFieldNames.text], value: XEUtils.toValueString(item[optionsFieldNames.value]) }; }); resolve(option); }).catch((err) => { console.error(err); }); break; } }); }; const getTreeOptions = ({ optionType, dataSource, dataSourceParams, staticOptions, optionsFieldNames }) => { return new Promise((resolve, reject) => { switch (optionType) { case "static": resolve(staticOptions); case "library": const dataSourceRef = useDataSource(dataSource); dataSourceRef == null ? void 0 : dataSourceRef.load(dataSourceParams || {}).then((res) => { var _a; const data = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.records) || (res == null ? void 0 : res.data) || res || []; resolve(data); }).catch((err) => { console.error(err); }); break; } }); }; const getParmDicMapByKeys = async (dicKeys) => { const http = useHttp(); const res = await http.postForm( `${baseUrl}/parm/sysParmDic/getDicListByKey`, { keyName: dicKeys } ); return res.data; }; export { getOptions, getParmDicMapByKeys, getTreeOptions };