mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-04-20 04:18:05 +00:00
fix: will fetch 按照协议修改
This commit is contained in:
parent
af4bc83cc3
commit
b9bf8002dc
@ -106,12 +106,18 @@ class RuntimeDataSourceItem<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fetchOptions = this._options;
|
||||||
|
|
||||||
// willFetch
|
// willFetch
|
||||||
this._dataSourceConfig.willFetch!();
|
try {
|
||||||
|
fetchOptions = await this._dataSourceConfig.willFetch!(this._options);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
// 约定如果 params 有内容,直接做替换,如果没有就用默认的 options 的
|
// 约定如果 params 有内容,直接做替换,如果没有就用默认的 options 的
|
||||||
if (params && this._options) {
|
if (params && fetchOptions) {
|
||||||
this._options.params = params;
|
fetchOptions.params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataHandler = this._dataSourceConfig.dataHandler!;
|
const dataHandler = this._dataSourceConfig.dataHandler!;
|
||||||
@ -124,7 +130,7 @@ class RuntimeDataSourceItem<
|
|||||||
// _context 会给传,但是用不用由 handler 说了算
|
// _context 会给传,但是用不用由 handler 说了算
|
||||||
const result = await (this._request as RequestHandler<{
|
const result = await (this._request as RequestHandler<{
|
||||||
data: TResultData;
|
data: TResultData;
|
||||||
}>)(this._options, this._context).then(dataHandler, errorHandler);
|
}>)(fetchOptions, this._context).then(dataHandler, errorHandler);
|
||||||
|
|
||||||
// setState
|
// setState
|
||||||
this._context.setState({
|
this._context.setState({
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { DataHandler } from '@ali/lowcode-types';
|
import {
|
||||||
|
DataHandler,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
RuntimeOptionsConfig,
|
||||||
function noop() {}
|
WillFetch,
|
||||||
|
} from '@ali/lowcode-types';
|
||||||
|
|
||||||
// 默认的 dataSourceItem 的 dataHandler
|
// 默认的 dataSourceItem 的 dataHandler
|
||||||
export const defaultDataHandler: DataHandler = async <T = unknown>(response: {
|
export const defaultDataHandler: DataHandler = async <T = unknown>(response: {
|
||||||
@ -9,7 +10,8 @@ export const defaultDataHandler: DataHandler = async <T = unknown>(response: {
|
|||||||
}) => response.data;
|
}) => response.data;
|
||||||
|
|
||||||
// 默认的 dataSourceItem 的 willFetch
|
// 默认的 dataSourceItem 的 willFetch
|
||||||
export const defaultWillFetch = noop;
|
export const defaultWillFetch: WillFetch = (options: RuntimeOptionsConfig) =>
|
||||||
|
options;
|
||||||
|
|
||||||
// 默认的 dataSourceItem 的 shouldFetch
|
// 默认的 dataSourceItem 的 shouldFetch
|
||||||
export const defaultShouldFetch = () => true;
|
export const defaultShouldFetch = () => true;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export interface RuntimeDataSourceConfig {
|
|||||||
isInit?: boolean;
|
isInit?: boolean;
|
||||||
isSync?: boolean;
|
isSync?: boolean;
|
||||||
type?: string;
|
type?: string;
|
||||||
willFetch?: () => void;
|
willFetch?: WillFetch;
|
||||||
shouldFetch?: () => boolean;
|
shouldFetch?: () => boolean;
|
||||||
requestHandler?: () => void; // TODO: 待定
|
requestHandler?: () => void; // TODO: 待定
|
||||||
dataHandler?: DataHandler;
|
dataHandler?: DataHandler;
|
||||||
@ -23,6 +23,10 @@ export interface RuntimeDataSourceConfig {
|
|||||||
[otherKey: string]: unknown;
|
[otherKey: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type WillFetch = (
|
||||||
|
options: RuntimeOptionsConfig,
|
||||||
|
) => Promise<RuntimeOptionsConfig> | RuntimeOptionsConfig;
|
||||||
|
|
||||||
export type DataHandler = <T>(response: {
|
export type DataHandler = <T>(response: {
|
||||||
data: T;
|
data: T;
|
||||||
[index: string]: unknown;
|
[index: string]: unknown;
|
||||||
@ -45,7 +49,7 @@ export interface RuntimeOptionsConfig {
|
|||||||
// 可以采用 react 的 state,但是需要注意必须提供同步的 setState 功能
|
// 可以采用 react 的 state,但是需要注意必须提供同步的 setState 功能
|
||||||
export interface IDataSourceRuntimeContext<
|
export interface IDataSourceRuntimeContext<
|
||||||
TState extends Record<string, unknown> = Record<string, unknown>
|
TState extends Record<string, unknown> = Record<string, unknown>
|
||||||
> {
|
> {
|
||||||
/** 当前数据源的内容 */
|
/** 当前数据源的内容 */
|
||||||
state: TState;
|
state: TState;
|
||||||
/** 设置状态(浅合并) */
|
/** 设置状态(浅合并) */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user