Skip to content

Commit

Permalink
RN 0.61.5
Browse files Browse the repository at this point in the history
  • Loading branch information
1280103995 committed Mar 23, 2021
1 parent 0f39b4b commit 23999ad
Show file tree
Hide file tree
Showing 31 changed files with 636 additions and 311 deletions.
28 changes: 0 additions & 28 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
import React, {Component} from 'react';
import {Provider} from 'mobx-react'
import RootStore from "./src/store/RootStore";
import {XFetchConfig} from "react-native-xfetch";
import Toast from "./src/view/Toast";
import {AppNavigator} from "./src/navigation/AppNavigator";
import {createAppContainer} from "react-navigation";

const AppContainer = createAppContainer(AppNavigator);

export default class App extends Component {

constructor(props) {
super(props);
XFetchConfig.getInstance()
.setBaseUrl('http://elm.cangdu.org')
.setCommonHeaders({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
.setResponseConfig(this.handleResponse)
}

handleResponse = async(response, resolve, reject, data, xfetch) => {
if (response.ok) {
if (data.status === 0) {
throw new Error(JSON.stringify(data))
} else {
resolve(data);
console.log('XFetch_success-->', response.url, data);
}
} else {
reject(data);
Toast.show(data.message);
console.log('XFetch_error-->', response.url, data);
}
};

render() {
return (
<Provider {...RootStore}>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"@react-native-community/async-storage": "^1.6.2",
"@react-native-community/blur": "^3.3.1",
"@react-native-community/viewpager": "^2.0.1",
"apisauce": "^2.0.1",
"lodash": "^4.17.15",
"mobx": "^5.13.0",
"mobx-react": "^6.1.3",
"prop-types": "^15.7.2",
"react": "16.9.0",
"react-native": "0.61.1",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.4.1",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-modals": "^0.19.8",
"react-native-reanimated": "^1.3.0",
"react-native-root-toast": "^3.1.2",
"react-native-scrollable-tab-view": "^1.0.0",
"react-native-webview": "^7.4.1",
"react-native-xfetch": "^0.3.3",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.9.1",
"react-navigation-tabs": "^2.5.5"
Expand All @@ -38,7 +38,7 @@
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.4.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.9.0"
Expand Down
32 changes: 32 additions & 0 deletions src/api/CreateApi.js
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
}

26 changes: 14 additions & 12 deletions src/api/FoodsApi.js
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)
}
}
}
28 changes: 15 additions & 13 deletions src/api/LocationApi.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import {XFetch} from "react-native-xfetch";
import {CreateApi} from './CreateApi';

const API = CreateApi();

export default class LocationApi{

/**
* 获取首页默认地址
*/
static fetchCityGuess(){
return new XFetch().get('/v1/cities/').setParams({'type': 'guess'}).do()
return API.get('/v1/cities/', {'type': 'guess'})
}

/**
* 获取首页热门城市
*/
static fetchHotCity(){
return new XFetch().get('/v1/cities/').setParams({'type': 'hot'}).do()
return API.get('/v1/cities/', {'type': 'hot'})
}

/**
* 获取首页所有城市
*/
static fetchAllCtiy(){
return new XFetch().get('/v1/cities/').setParams({'type': 'group'}).do()
return API.get('/v1/cities/', {'type': 'group'})
}

/**
* 获取当前所在城市
*/
static fetchCurCtity(number){
return new XFetch().get(`/v1/cities/${number}`).do()
return API.get(`/v1/cities/${number}`)
}

/**
Expand All @@ -37,12 +39,12 @@ export default class LocationApi{
* @returns {返回Promise}
*/
static fetchSearchPlace(city_id, key_str){
let params = {
const params = {
'type': 'search',
'city_id': city_id,
'keyword': key_str
};
return new XFetch().get('/v1/pois').setParams(params).do()
return API.get('/v1/pois', params)
}

/**
Expand All @@ -51,19 +53,19 @@ export default class LocationApi{
* @returns {返回Promise}
*/
static fetchMSiteAddress(geohash){
return new XFetch().get(`/v2/pois/${geohash}`).do()
return API.get(`/v2/pois/${geohash}`)
}

/**
* 获取msite页面食品分类列表
*/
static fetchFoodTypes(geohash){
let params = {
const params = {
'geohash': geohash,
'group_type': '1',
'flags[]': 'F'
};
return new XFetch().get('/v2/index_entry').setParams(params).do()
return API.get('/v2/index_entry', params)
}

/**
Expand Down Expand Up @@ -93,7 +95,7 @@ export default class LocationApi{
}
});

let params = {
const params = {
latitude,
longitude,
offset,
Expand All @@ -105,6 +107,6 @@ export default class LocationApi{
order_by,
'delivery_mode[]': delivery_mode + supportStr
};
return new XFetch().get('/shopping/restaurants').setParams(params).do()
return API.get('/shopping/restaurants', params)
}
}
}
38 changes: 19 additions & 19 deletions src/api/OrderApi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {XFetch} from "react-native-xfetch";
import {CreateApi} from './CreateApi';

const API = CreateApi();

export default class OrderApi{

Expand All @@ -10,21 +12,20 @@ export default class OrderApi{
* @returns {返回Promise}
*/
static fetchCheckout(geohash, entities, shopid){
let params = {
const params = {
come_from: "web",
geohash,
entities,
restaurant_id: shopid,
};
return new XFetch().post('/v1/carts/checkout').setParams(params).do()
}
return API.post('/v1/carts/checkout', params)}

/**
* 获取快速备注列表
* @returns {返回Promise}
*/
static fetchGetRemark(){
return new XFetch().get(`/v1/carts/${id}/remarks`).do()
static fetchGetRemark(id){
return API.get(`/v1/carts/${id}/remarks`)
}

/**
Expand All @@ -39,7 +40,7 @@ export default class OrderApi{
* @returns {返回Promise}
*/
static fetchPlaceOrders(user_id, cart_id, address_id, description, entities, geohash, sig){
let params = {
const params = {
address_id,
'come_from': "mobile_web",
'deliver_time': "",
Expand All @@ -49,8 +50,7 @@ export default class OrderApi{
'paymethod_id': 1,
sig,
};
return new XFetch().get(`/v1/users/${user_id}/carts/${cart_id}/orders`).setParams(params).do()
}
return API.get(`/v1/users/${user_id}/carts/${cart_id}/orders`, params)}

/**
* 重新发送订单验证码
Expand All @@ -60,11 +60,11 @@ export default class OrderApi{
* @returns {返回Promise}
*/
static fetchrePostVerify(cart_id, sig, type){
let params = {
const params = {
sig,
type,
};
return new XFetch().get(`/v1/carts/${cart_id}/verify_code`).setParams(params).do()
return API.get(`/v1/carts/${cart_id}/verify_code`, params)
}

/**
Expand All @@ -88,7 +88,7 @@ export default class OrderApi{
sig,
validation_code,
validation_token){
let params = {
const params = {
address_id,
'come_from': "mobile_web",
'deliver_time': "",
Expand All @@ -100,7 +100,7 @@ export default class OrderApi{
validation_code,
validation_token,
};
return new XFetch().get(`/v1/users/${user_id}/carts/${cart_id}/orders`).setParams(params).do()
return API.get(`/v1/users/${user_id}/carts/${cart_id}/orders`, params)
}

/**
Expand All @@ -110,14 +110,14 @@ export default class OrderApi{
* @returns {返回Promise}
*/
static fetchPayRequest(merchantOrderNo, userId){
let params = {
const params = {
'merchantId': 5,
merchantOrderNo,
'source': 'MOBILE_WAP',
userId,
'version': '1.0.0',
};
return new XFetch().get('/payapi/payment/queryOrder').setParams(params).do()
return API.get('/payapi/payment/queryOrder', params)
}

/**
Expand All @@ -127,11 +127,11 @@ export default class OrderApi{
* @returns {返回Promise}
*/
static fetchOrderList(user_id, offset){
let params = {
const params = {
limit: 10,
offset,
};
return new XFetch().get(`/bos/v2/users/${user_id}/orders`).setParams(params).do()
return API.get(`/bos/v2/users/${user_id}/orders`, params)
}

/**
Expand All @@ -141,7 +141,7 @@ export default class OrderApi{
* @returns {返回Promise}
*/
static fetchOrderInfo(user_id, orderid){
return new XFetch().get(`/bos/v1/users/${user_id}/orders/${orderid}/snapshot`).do()
return API.get(`/bos/v1/users/${user_id}/orders/${orderid}/snapshot`)
}

}
}
Loading

0 comments on commit 23999ad

Please sign in to comment.