Created
February 26, 2021 09:28
-
-
Save eightHundreds/46d55febf688c87e00efc67579f9a375 to your computer and use it in GitHub Desktop.
api.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
{ | |
"pp-api": { | |
"prefix": "ppa", | |
"body": [ | |
"import { message } from 'antd';", | |
"import { AxiosResponse } from 'axios';", | |
"import http from 'helper/http';", | |
"import microservice from 'helper/microservice';", | |
"import { get as _get } from 'lodash';", | |
"const { javaAdmin } = microservice;", | |
"/**", | |
" * 处理网络请求返回数据(返回array类型数据)", | |
" */", | |
"const processResult = <T extends ArrayLike<T[number]>>(result: AxiosResponse<T> | null, defaultValue = []): T => {", | |
" if (_get(result, 'data.errcode') === 0) {", | |
" return _get(result, 'data.data', defaultValue);", | |
" } else {", | |
" return (defaultValue as unknown) as T;", | |
" }", | |
"};", | |
"/**", | |
" * 处理网络请求返回数据(返回obj类型数据)", | |
" */", | |
"const objectResult = <T>(result?: AxiosResponse<T> | null, defaultValue = {}): T => {", | |
" if (_get(result, 'data.errcode') === 0) {", | |
" return _get(result, 'data.data', defaultValue);", | |
" } else {", | |
" return (defaultValue as unknown) as T;", | |
" }", | |
"};", | |
"/**", | |
" * 处理网络请求返回数据(返回数据需判断成功与否)", | |
" */", | |
"const booleanResult = (result: any): boolean => {", | |
" if (_get(result, 'data.errcode') === 0) {", | |
" message.success('操作成功');", | |
" return true;", | |
" } else {", | |
" return false;", | |
" }", | |
"};", | |
"", | |
"// /**", | |
"// * 广告点位详情: 3932704", | |
"// * @param id", | |
"// */", | |
"// export const getAdPoint = async (id: string) => {", | |
"// const result = await http.get<AdPoint>(javaAdmin + `/admin/store/adpoint/detail/${id}`);", | |
"// return objectResult(result);", | |
"// };", | |
"" | |
], | |
"description": "pp api代码段" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment