forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client-sdk): support taro request (labring#1325)
* docs: update trigger.md * feat(client-sdk): add taro request support
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Request } from './request' | ||
import { CloudOptions, EnvironmentType } from '../types' | ||
|
||
interface GlobalObjectType { | ||
request: any | ||
uploadFile: any | ||
} | ||
declare const taro: GlobalObjectType | ||
|
||
/** | ||
* Taro 环境请求类 | ||
*/ | ||
export class TaroRequest extends Request { | ||
constructor(config: CloudOptions) { | ||
super(config) | ||
} | ||
|
||
/** | ||
* Taro 环境请求方法 | ||
* @override | ||
* @param data | ||
* @returns | ||
*/ | ||
async request(url: string, data: any, _options?: any) { | ||
if (this.options.environment !== EnvironmentType.TARO) { | ||
throw new Error('environment type must be taro') | ||
} | ||
|
||
const token = this.options.getAccessToken() | ||
const header = this.getHeaders(token) | ||
const options = { | ||
url, | ||
header, | ||
method: _options?.method ?? 'POST', | ||
data, | ||
dataType: 'json' | ||
} | ||
|
||
const res = await taro.request(options) | ||
return res | ||
} | ||
} |
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