diff --git a/examples/client-mock/frontend/src/models/client.ts b/examples/client-mock/frontend/src/models/client.ts index 2b35f2e..559f8de 100644 --- a/examples/client-mock/frontend/src/models/client.ts +++ b/examples/client-mock/frontend/src/models/client.ts @@ -9,12 +9,12 @@ export const client = new HttpClient(serviceProto, { }); // Client Mock -client.flows.preCallApiFlow.push(v => { +client.flows.preCallApiFlow.push(async v => { // 有对应的 MockAPI 则 Mock,否则请求真实后端 let mockApi = mockApis[v.apiName]; if (mockApi) { client.logger?.log('[MockReq]', v.apiName, v.req); - v.return = mockApi!(v.req as any); + v.return = await mockApi!(v.req as any); client.logger?.log('[MockRes]', v.apiName, v.return); } diff --git a/examples/client-mock/frontend/src/models/mockApis.ts b/examples/client-mock/frontend/src/models/mockApis.ts index c5c8cea..e4a829b 100644 --- a/examples/client-mock/frontend/src/models/mockApis.ts +++ b/examples/client-mock/frontend/src/models/mockApis.ts @@ -10,7 +10,9 @@ const data: { }[] = []; // { 接口名: (req: 请求) => 响应 } -export const mockApis: { [K in keyof ServiceType['api']]?: (req: ServiceType['api'][K]['req']) => ApiReturn } = { +export const mockApis: { + [K in keyof ServiceType['api']]?: (req: ServiceType['api'][K]['req']) => ApiReturn | Promise> +} = { AddData: req => { let time = new Date(); data.unshift({ content: req.content, time: time }) @@ -20,7 +22,12 @@ export const mockApis: { [K in keyof ServiceType['api']]?: (req: ServiceType['ap } }, - GetData: req => { + GetData: async req => { + // 模拟 1 秒延时 + await new Promise(rs => { + setTimeout(rs, 1000); + }) + return { isSucc: true, res: {