Commit 1f1fce16 authored by 陈天文's avatar 陈天文

添加mock server和调试长时拍的请求接口

parent 6dc81f0e
// 导入koa,在koa2.x版本中,导入的是一个class
const Koa = require('koa')
const bodyParser = require('koa-bodyparser');
const cors = require('koa2-cors');
const routes = require('./routes');
const { restify } = require('./rest');
const { port } = require('./config');
const app = new Koa();
app.use(cors());
app.use(bodyParser());
app.use(async (ctx, next) => {
console.log(`${ctx.request.method} ${ctx.request.url}...`);
await next();
});
app.use(restify());
app.use(routes());
app.listen(port || 3600);
console.log('server start at http://localhost:3600/');
module.exports = {
port: '3600'
}
const APIError = require('../rest').APIError;
const listData = require('../models');
module.exports = {
'GET /api/listData':async(ctx,next)=>{
ctx.rest({
listData:listData.getlistData()
})
},
'POST /api/editlistData':async(ctx,next)=>{
ctx.rest({
listData:listData.editlistData(ctx.request.body)
})
}
}
const listData = [
{
"id":4605,
"carNumber":"V001141",
"carName":"克莱斯勒 大捷龙(进口) 99款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"冀R03Z58",
"region":-1,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":65,
"grade":"C",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1414771200000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1420560000000,
"odographNum":1000,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/507635fc-5151-45cd-b018-1727edb7f4eb.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":-1,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4604,
"carNumber":"V001140",
"carName":"克莱斯勒 大捷龙(进口) 99款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"冀R03Z58",
"region":-1,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"D",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1414771200000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1420560000000,
"odographNum":20000,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/f252bb12-0b26-41f9-b5c2-dcd0ecf0b00c.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":-1,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4603,
"carNumber":"V925038",
"carName":"大众 宝来 08款 2.0L 手动舒适型",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"黑A7EQ16",
"region":-1,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":35,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1222790400000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1228406400000,
"odographNum":130000,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/c9f87bf5-3dd4-40ac-9f44-c2aa7d483e97.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":-1,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4602,
"carNumber":"V925038",
"carName":"大众 宝来 08款 2.0L 手动舒适型",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"黑A7EQ16",
"region":-1,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":80,
"grade":"D",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1222790400000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1228406400000,
"odographNum":130000,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/4f337fa5-2b7a-4f02-bab3-067d948d9d28.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":-1,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4601,
"carNumber":"V003166",
"carName":"克莱斯勒 大捷龙(进口) 04款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"京A00001",
"region":110100,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1522512000000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1483200000000,
"odographNum":123600,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/a485b409-9a49-46b6-a959-be9a84e68d59.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":4,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4600,
"carNumber":"V003165",
"carName":"克莱斯勒 大捷龙(进口) 04款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"京A00001",
"region":110100,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1522512000000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1483200000000,
"odographNum":123600,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/c8217afb-c4f1-40b9-8aed-090020dc8b27.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":4,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4599,
"carNumber":"V003164",
"carName":"克莱斯勒 大捷龙(进口) 04款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"京A00001",
"region":110100,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1522512000000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1483200000000,
"odographNum":123600,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/017776c4-ca08-4b83-98f8-4e8ad4cf0ad3.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":4,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4598,
"carNumber":"V003163",
"carName":"克莱斯勒 大捷龙(进口) 04款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"京A00001",
"region":110100,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1522512000000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1483200000000,
"odographNum":123600,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/f275dcbd-fb12-4734-a948-cc59b93b95db.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":4,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4597,
"carNumber":"V003162",
"carName":"克莱斯勒 大捷龙(进口) 04款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"京A00001",
"region":110100,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1522512000000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1483200000000,
"odographNum":123600,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/5400d413-64f2-48e3-916d-7ccf1b0bf8f6.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":4,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
},
{
"id":4596,
"carNumber":"V003161",
"carName":"克莱斯勒 大捷龙(进口) 04款 大捷龙 3.3L",
"vinCode":"",
"expectPrice":"",
"licencePlateNum":"京A00001",
"region":110100,
"carStatus":1,
"roundStatus":4,
"proprietaryId":"",
"score":95,
"grade":"A",
"carStatusDesc":"在售",
"roundStatusDesc":"",
"manufactureDate":1522512000000,
"shelveTime":"",
"bidTime":"",
"priceSpread":"",
"customerServicerId":"",
"customerServicerName":"",
"firstRegistrationDate":1483200000000,
"odographNum":123600,
"pic":"https://img1.yixinfinance.com/xinxiangmu/20180613/24de7ceb-b24c-4011-92e8-fa2aea1d4845.jpg",
"bidCount":"",
"bidMaxPrice":0,
"bidStartTime":"",
"bidEndTime":"",
"emissionStandard":4,
"isGeFloorPrice":0,
"isGeBidPrice":0,
"repeatBidStart":0
}
];
module.exports={
getlistData:()=>{
return listData;
},
editlistData:async(v)=>{
listData.forEach(function(el, index, arr){
if(parseInt(el.id)==parseInt(v.id)){
listData[index].score=v.score;
listData[index].isGeFloorPrice=v.isGeFloorPrice;
listData[index].repeatBidStart=v.repeatBidStart;
return;
}
})
}
}
module.exports = {
APIError: function (code, message) {
this.code = code || 'internal: unknown_error';
this.message = message || '';
},
restify: (pathPrefix) => {
pathPrefix = pathPrefix || '/api/';
return async (ctx,next)=>{
if(ctx.request.path.startsWith(pathPrefix)){
ctx.rest = (data) => {
ctx.response.type='application/json';
ctx.response.body=data;
}
try {
await next();
} catch(e) {
ctx.response.status=400;
ctx.response.type='application/json';
ctx.response.body={
code: e.code || 'internal:unknow_error',
message: e.message || ''
};
}
} else {
await next();
}
}
}
}
const fs = require('fs');
function addMapping(router, mapping) {
for (var url in mapping) {
if (url.startsWith('GET ')) {
var path = url.substring(4);
router.get(path, mapping[url]);
} else if (url.startsWith('POST ')) {
var path = url.substring(5);
router.post(path, mapping[url]);
} else if (url.startsWith('PUT ')) {
var path = url.substring(4);
router.put(path, mapping[url]);
} else if (url.startsWith('DELETE ')) {
var path = url.substring(7);
router.del(path, mapping[url]);
} else {
console.log(`invalid URL: ${url}`);
}
}
}
function addControllers(router, dir) {
fs.readdirSync(__dirname + '/' + dir).filter((f) => {
return f.startsWith('api');
}).forEach((f) => {
console.log(`process controller: ${f}...`);
let mapping = require(__dirname + '/' + dir + '/' + f);
addMapping(router, mapping);
});
}
module.exports = function (dir) {
let controllers_dir = dir || '../controllers', router = require('koa-router')();
addControllers(router, controllers_dir);
return router.routes();
};
This diff is collapsed.
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start", "start": "node node_modules/react-native/local-cli/cli.js start",
"mockserver": "node mockserver/app.js",
"ios": "node node_modules/react-native/local-cli/cli.js run-ios", "ios": "node node_modules/react-native/local-cli/cli.js run-ios",
"android": "node node_modules/react-native/local-cli/cli.js run-android", "android": "node node_modules/react-native/local-cli/cli.js run-android",
"copy-apk": "mkdir -p dist/android && cp -f android/app/build/outputs/apk/app-release.apk dist/android", "copy-apk": "mkdir -p dist/android && cp -f android/app/build/outputs/apk/app-release.apk dist/android",
...@@ -33,7 +34,11 @@ ...@@ -33,7 +34,11 @@
"redux": "^4.0.0", "redux": "^4.0.0",
"redux-logger": "^3.0.6", "redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0", "redux-thunk": "^2.3.0",
"underscore": "^1.9.1" "underscore": "^1.9.1",
"koa": "^2.5.1",
"koa-bodyparser": "^4.2.1",
"koa-router": "^7.4.0",
"koa2-cors": "^2.0.5"
}, },
"devDependencies": { "devDependencies": {
"babel-jest": "23.0.1", "babel-jest": "23.0.1",
......
const HOST = 'http://localhost:3600/api/';
function _apiFetch(uri, params, headers, method = 'GET') {
return fetch(`${HOST}${uri}`, {
headers: Object.assign({
'Content-Type': 'application/json',
'Cache-Control': 'no-cache'
}, headers),
method,
body: JSON.stringify(params)
});
}
function _authFetch(config) {
const uri = config.uri;
const accesstoken = config.accessToken;
const method = config.method;
const params = config.params;
return _apiFetch(uri, params, { accesstoken }, method);
}
export default {
getListData(params) {
return _apiFetch('listdata', params);
},
};
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { import {
...@@ -6,13 +7,15 @@ import { ...@@ -6,13 +7,15 @@ import {
WebView, WebView,
View, View,
FlatList, FlatList,
TouchableOpacity,
Text, Text,
} from 'react-native'; } from 'react-native';
import { Map } from 'immutable';
import FormatText from '../../components/format-text'; import FormatText from '../../components/format-text';
import MarketListItem from '../../components/market-list-item'; import MarketListItem from '../../components/market-list-item';
import * as auctionActions from '../../reducers/auction/auctionActions';
var DEFAULT_URL = "http://192.168.155.26/#/auction/longtimeAuctionList";
var Screen = Dimensions.get('window'); var Screen = Dimensions.get('window');
class Market extends Component { class Market extends Component {
...@@ -25,28 +28,47 @@ class Market extends Component { ...@@ -25,28 +28,47 @@ class Market extends Component {
this.refreshData = this.refreshData.bind(this); this.refreshData = this.refreshData.bind(this);
} }
componentWillMount() {
this.props.actions.getLongAuctionList();
}
refreshData() { refreshData() {
this.setState({refreshState: true}); this.setState({refreshState: true});
setTimeout(() => { setTimeout(() => {
this.setState({refreshState: false}); this.setState({refreshState: false});
}, 1000); }, 1000);
} }
// <FlatList
// data={demoData}
// onRefresh={this.refreshData}
// refreshing={this.state.refreshState}
// renderItem={({item}) => <MarketListItem item={item}></MarketListItem>}
// />
// <TouchableOpacity onPress={ this.onButtonPress.bind(this) }>
// <Text>获取测试列表数据</Text>
// </TouchableOpacity>
render() { render() {
const { navigate } = this.props.navigation; const { navigate } = this.props.navigation;
const listData = this.props.auction;
console.log('listData', this.props.auction);
return ( return (
<View style = {styles.container}> <View style = {styles.container}>
<Text>长时拍</Text> <FlatList
data={listData}
onRefresh={this.refreshData}
refreshing={this.state.refreshState}
renderItem={({item}) => <MarketListItem item={item}></MarketListItem>}
/>
</View> </View>
); );
} }
onButtonPress() {
this.props.actions.getLongAuctionList();
console.log('auction', this.props.auction);
}
} }
const actions = [
auctionActions
];
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
...state ...state
...@@ -54,7 +76,13 @@ function mapStateToProps(state) { ...@@ -54,7 +76,13 @@ function mapStateToProps(state) {
} }
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return { return {
actions: bindActionCreators(creators, dispatch),
dispatch dispatch
}; };
} }
...@@ -65,6 +93,8 @@ const styles = StyleSheet.create({ ...@@ -65,6 +93,8 @@ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: '#ffffff', backgroundColor: '#ffffff',
// alignItems: 'center',
// justifyContent: 'center'
}, },
webviewWrap: { webviewWrap: {
width: Screen.width, width: Screen.width,
......
import keyMirror from 'key-mirror';
export default keyMirror({
// mobile
SET_CODE_PUSH: null,
SET_PLATFORM: null,
SET_VERSION: null,
IS_DEV: null,
GET_LIST_SUCC: null
});
import api from '../../api';
const { GET_LIST_SUCC } = require('../actionTypes').default;
function getLoanListSucc(payload) {
return {
type: GET_LIST_SUCC,
payload
};
}
export function getLongAuctionList(params) {
return async (dispatch) => {
try {
const res = await api.getListData();
const resJson = await res.json();
if (res.status === 200) {
dispatch(getLoanListSucc(resJson.listData));
}
} catch (err) {
console.warn(err);
}
};
}
import { Record, fromJS } from 'immutable';
const InitialState = {
listData: []
};
// Record({
// listData: fromJS([])
// });
export default InitialState;
import { fromJS } from 'immutable';
// import alert from '../../components/alert';
import initialState from './auctionInitialState';
const { GET_LIST_SUCC } = require('../actionTypes').default;
// function handleError(error) {
// alert(error.errorMessage || '网络错误');
// }
export default function auctionReducer(state = initialState, action) {
switch (action.type) {
case GET_LIST_SUCC: {
const listData = action.payload;
return state.listData = listData;
}
}
return state;
}
/* @flow weak */ /* @flow weak */
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import device from './device/deviceReducer'; import device from './device/deviceReducer';
import auction from './auction/auctionReducer';
const rootReducer = combineReducers({ const rootReducer = combineReducers({
auction,
device device
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment