UNPKG

@fecp/mobile

Version:

96 lines (95 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const index = require("../../../../_virtual/index.js"); const index$1 = require("../axios/index.js"); const dataSourceUtil = require("./dataSourceUtil.js"); const env = require("./env.js"); const baseUrl = env.default.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 && !index.default.isEmpty(dicList)) { resolve(dicListToOption(dicList)); } else { getParmDicMapByKeys(dicKey).then((data) => { const option = dicListToOption(data[dicKey]); resolve(option); }); } break; case "library": const dataSourceRef = dataSourceUtil.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: index.default.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 = dataSourceUtil.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 = index$1.default(); const res = await http.postForm( `${baseUrl}/parm/sysParmDic/getDicListByKey`, { keyName: dicKeys } ); return res.data; }; exports.getOptions = getOptions; exports.getParmDicMapByKeys = getParmDicMapByKeys; exports.getTreeOptions = getTreeOptions;