-
Notifications
You must be signed in to change notification settings - Fork 12
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
1280103995
committed
Mar 23, 2021
1 parent
0f39b4b
commit 23999ad
Showing
31 changed files
with
636 additions
and
311 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
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,32 @@ | ||
import apisauce from 'apisauce'; | ||
import Toast from "../view/Toast"; | ||
|
||
const baseHeader = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
export const CreateApi = () => { | ||
const api = apisauce.create({baseURL: 'http://elm.cangdu.org', headers: baseHeader, timeout: 15000}); | ||
|
||
api.addAsyncResponseTransform(async response => { | ||
if (response.status === 401) { | ||
// refresh token | ||
} | ||
console.log(response.config.url, { | ||
duration: response.duration, | ||
problem: response.problem, | ||
status: response.status, | ||
method: response.config.method, | ||
headers: response.config.headers, | ||
params: response.config.method === 'get' ? response.config.params : response.config.data, | ||
baseURL: response.config.baseURL, | ||
data: response.data, | ||
}); | ||
response.status > 300 && Toast.show(response.problem); | ||
return response | ||
}); | ||
|
||
return api | ||
} | ||
|
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,39 +1,41 @@ | ||
import {XFetch} from "react-native-xfetch"; | ||
import {CreateApi} from './CreateApi'; | ||
|
||
export default class FoodsApi{ | ||
const API = CreateApi(); | ||
|
||
export default class FoodsApi { | ||
|
||
/** | ||
* 获取food页面的 category 种类列表 | ||
*/ | ||
static fetchFoodCategory(latitude, longitude){ | ||
let params = { | ||
static fetchFoodCategory(latitude, longitude) { | ||
const params = { | ||
latitude, | ||
longitude | ||
}; | ||
return new XFetch().get('/shopping/v2/restaurant/category').setParams(params).do() | ||
return API.get('/shopping/v2/restaurant/category', params) | ||
} | ||
|
||
/** | ||
* 获取food页面的配送方式 | ||
*/ | ||
static fetchFoodDelivery(latitude, longitude){ | ||
let params = { | ||
static fetchFoodDelivery(latitude, longitude) { | ||
const params = { | ||
latitude, | ||
longitude, | ||
kw: '' | ||
}; | ||
return new XFetch().get('/shopping/v1/restaurants/delivery_modes').setParams(params).do() | ||
return API.get('/shopping/v1/restaurants/delivery_modes', params) | ||
} | ||
|
||
/** | ||
* 获取food页面的商家属性活动列表 | ||
*/ | ||
static fetchFoodActivity(latitude, longitude){ | ||
let params = { | ||
static fetchFoodActivity(latitude, longitude) { | ||
const params = { | ||
latitude, | ||
longitude, | ||
kw: '' | ||
}; | ||
return new XFetch().get('/shopping/v1/restaurants/activity_attributes').setParams(params).do() | ||
return API.get('/shopping/v1/restaurants/activity_attributes', params) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.