in packages/renderer-core/src/utils/data-helper.ts [178:230]
getDataSource(id: string, params: any, otherOptions: any, callback: any) {
const req = this.parser(this.ajaxMap[id]);
const options = req.options || {};
let callbackFn = callback;
let otherOptionsObj = otherOptions;
if (typeof otherOptions === 'function') {
callbackFn = otherOptions;
otherOptionsObj = {};
}
const { headers, ...otherProps } = otherOptionsObj || {};
if (!req) {
logger.warn(`getDataSource API named ${id} not exist`);
return;
}
return this.asyncDataHandler([
{
...req,
options: {
...options,
// 支持参数为array的情况,当参数为array时,不做参数合并
params:
Array.isArray(options.params) || Array.isArray(params)
? params || options.params
: {
...options.params,
...params,
},
headers: {
...options.headers,
...headers,
},
...otherProps,
},
},
])
.then((res: any) => {
try {
callbackFn && callbackFn(res && res[id]);
} catch (e) {
logger.error('load请求回调函数报错', e);
}
return res && res[id];
})
.catch((err) => {
try {
callbackFn && callbackFn(null, err);
} catch (e) {
logger.error('load请求回调函数报错', e);
}
return err;
});
}