@@ -19,9 +19,9 @@ import {
19
19
getFetchJsonpPromise ,
20
20
} from './adapters/'
21
21
import {
22
- setFullUrlMiddleware ,
23
22
formatResDataMiddleware ,
24
23
recordReqTimeMiddleware ,
24
+ setReqFnParamsMiddleware ,
25
25
recordStartTimeMiddleware ,
26
26
formatReqParamsMiddleware ,
27
27
} from './middlewareFns'
@@ -92,31 +92,37 @@ class TuaApi {
92
92
/**
93
93
* 根据 reqType 和 type 决定调用哪个库
94
94
* @param {Object } options
95
+ * @param {Object|Function } options.mock 模拟的响应数据或是生成数据的函数
95
96
* @param {String } options.url 接口地址
96
97
* @param {String } options.type 接口请求类型 get/post...
97
98
* @param {String } options.fullUrl 完整接口地址
98
- * @param {String } options.path 接口路径名称
99
+ * @param {String } options.reqType 使用什么工具发(axios/jsonp/wx)
100
+ * @param {Object } options.reqParams 请求参数
101
+ * @param {String } options.callbackName 使用 jsonp 时的回调函数名
102
+ * @param {Object } options.axiosOptions 透传 axios 配置参数
103
+ * @param {Object } options.jsonpOptions 透传 fetch-jsonp 配置参数
99
104
* @return {Promise }
100
105
*/
101
106
_reqFn ( {
102
107
url,
108
+ mock,
103
109
type,
104
110
fullUrl,
105
111
reqType,
106
112
reqParams : data ,
107
113
callbackName,
108
- jsonpOptions,
109
114
axiosOptions,
115
+ jsonpOptions,
110
116
...rest
111
117
} ) {
112
118
// check type
113
119
this . _checkReqType ( reqType )
114
120
115
121
// mock data
116
- if ( rest . mock ) {
117
- const resData = typeof rest . mock === 'function'
118
- ? rest . mock ( data )
119
- : { ...rest . mock }
122
+ if ( mock ) {
123
+ const resData = typeof mock === 'function'
124
+ ? mock ( data )
125
+ : { ...mock }
120
126
121
127
return Promise . resolve ( { data : resData } )
122
128
}
@@ -175,7 +181,7 @@ class TuaApi {
175
181
// 业务侧中间件函数数组
176
182
...middlewareFns ,
177
183
// 生成 fullUrl 参数
178
- setFullUrlMiddleware ,
184
+ setReqFnParamsMiddleware ,
179
185
// 统一转换响应数据为对象
180
186
formatResDataMiddleware ,
181
187
// 记录结束时间
@@ -199,7 +205,7 @@ class TuaApi {
199
205
* @param {String } options.type 接口请求类型 get/post...
200
206
* @param {Object|Function } options.mock 模拟的响应数据或是生成数据的函数
201
207
* @param {String } options.name 自定义的接口名称
202
- * @param {String } options.path 接口路径名称
208
+ * @param {String } options.path 接口结尾路径
203
209
* @param {String[] } options.params 接口参数数组
204
210
* @param {String } options.prefix 接口前缀
205
211
* @param {Function } options.afterFn 在请求完成后执行的钩子函数(将被废弃)
@@ -227,7 +233,6 @@ class TuaApi {
227
233
} ) {
228
234
// 优先使用 name
229
235
const apiName = name || path
230
- const fullPath = `${ prefix } /${ path } `
231
236
232
237
// 合并全局默认值
233
238
rest . host = rest . host || this . host
@@ -253,7 +258,7 @@ class TuaApi {
253
258
args = args === null ? { } : args
254
259
255
260
// 最终的运行时配置,runtimeOptions 有最高优先级
256
- const runtimeParams = { type, path, params, prefix, apiName, fullPath , ...rest , ...runtimeOptions }
261
+ const runtimeParams = { type, path, params, prefix, apiName, ...rest , ...runtimeOptions }
257
262
258
263
// 自定义回调函数名称(用于 jsonp)
259
264
runtimeParams . callbackName = runtimeParams . callbackName || `${ runtimeParams . path } Callback`
@@ -292,7 +297,7 @@ class TuaApi {
292
297
)
293
298
}
294
299
295
- apiFn . key = fullPath
300
+ apiFn . key = ` ${ prefix } / ${ path } `
296
301
apiFn . mock = mock
297
302
apiFn . params = params
298
303
0 commit comments