Skip to content

Instantly share code, notes, and snippets.

@eightHundreds
Created February 26, 2021 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eightHundreds/46d55febf688c87e00efc67579f9a375 to your computer and use it in GitHub Desktop.
Save eightHundreds/46d55febf688c87e00efc67579f9a375 to your computer and use it in GitHub Desktop.
api.ts 接口请求代码
{
"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