forked from NervJS/taro
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 33 additions & 5 deletions
38
packages/taro-platform-harmony-hybrid/src/api/apis/network/request/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
import { request as h5Request } from '@tarojs/taro-h5' | ||
|
||
import { request as nativeReuqest } from './nativeRequest' | ||
import { request as h5Request, addInterceptor as h5AddInterceptor, cleanInterceptors as h5CleanInterceptors } from '@tarojs/taro-h5' | ||
|
||
import { request as nativeReuqest, addInterceptor as nativeAddInterceptor, cleanInterceptors as nativeCleanInterceptors } from './nativeRequest' | ||
|
||
/** | ||
* 封装请求方法 | ||
* @param options 请求选项 | ||
* 发起 HTTPS 网络请求 | ||
* | ||
* @canUse request | ||
* @__object [url, data, header, timeout, method[OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT], dataType[json, text, base64, arraybuffer], responseType[text, arraybuffer], enableCache] | ||
* @__success [data, header, statusCode, cookies] | ||
* @param useNativeRequest 默认使用true | ||
*/ | ||
export function request (options: any, useNativeRequest: boolean = true) { | ||
return useNativeRequest ? nativeReuqest(options) : h5Request(options) | ||
} | ||
|
||
|
||
/** | ||
* 网络请求任务对象 | ||
* | ||
* @canUse RequestTask | ||
* @__class [abort, onHeadersReceived, offHeadersReceived] | ||
*/ | ||
|
||
/** | ||
* 使用拦截器 | ||
* | ||
* @canUse addInterceptor | ||
*/ | ||
export function addInterceptor (interceptor, useNativeRequest: boolean = true){ | ||
return useNativeRequest ? nativeAddInterceptor(interceptor) : h5AddInterceptor(interceptor) | ||
} | ||
|
||
/** | ||
* 清除所有拦截器 | ||
* | ||
* @canUse cleanInterceptors | ||
*/ | ||
export function cleanInterceptors (interceptor, useNativeRequest: boolean = true) { | ||
return useNativeRequest ? nativeCleanInterceptors(interceptor) : h5CleanInterceptors(interceptor) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters