fix(data-source): http数据源中mock数据应该是数据源定义好的数据,不再是请求的数据源

This commit is contained in:
roymondchen 2024-09-20 12:42:06 +08:00 committed by roymondchen
parent 8b7dca8e23
commit 25646317ae

View File

@ -15,8 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { cloneDeep } from 'lodash-es';
import type { HttpOptions, RequestFunction } from '@tmagic/core';
import { getValueByKeyPath } from '@tmagic/core';
@ -141,7 +139,10 @@ export default class HttpDataSource extends DataSource<HttpDataSourceSchema> {
}
// 注意在编辑器中mockData不会为空至少是默认值不会发起请求
let res = this.mockData ? cloneDeep(this.mockData) : await this.#fetch?.(reqOptions);
if (this.mockData) {
this.setData(this.mockData);
} else {
let res = await this.#fetch?.(reqOptions);
for (const method of this.#afterRequest) {
await method({ res, options: reqOptions, params: {}, dataSource: this, app: this.app });
@ -157,6 +158,7 @@ export default class HttpDataSource extends DataSource<HttpDataSourceSchema> {
} else {
this.setData(res);
}
}
this.error = undefined;
} catch (error: any) {