import axios from 'axios';
axios.defaults.baseURL = 'http://localhost:3000';
axios.interceptors.response.use((res)=>{
return res.data;
})
export let typeOne=()=>{
return axios.get('/type?typesOne=1');
}
后台返回json格式:
[{"pid":0,"typeId":1,"typeName":"洗衣"},{"pid":0,"typeId":2,"typeName":"洗鞋"},{"pid":0,"typeId":3,"typeName":"洗家纺"},{"pid":0,"typeId":4,"typeName":"洗窗帘"},{"pid":0,"typeId":5,"typeName":"袋洗"}]
点击一级类,如果有二级类则获取二级类+二级类第一个类别的产品,如果没有二级类,则直接显示产品
export let typeTwoOrProducts=(typeId)=>{
return axios.get(`/type?oneId=${typeId}`);
}
后台返回格式一个对象:
有二级类情况:
{"twoTypes":[{"pid":1,"typeId":6,"typeName":"上衣"},{"pid":1,"typeId":7,"typeName":"大衣外套"},{"pid":1,"typeId":8,"typeName":"裙装裤装"},{"pid":1,"typeId":9,"typeName":"配件"}],"DefaultProducts":[{"typeId":6,"productID":1,"productName":"单衬衫","price":15,"img":"https://img.alicdn.com/bao/uploaded/i3/196993935/TB13CrqnjuhSKJjSspmXXcQDpXa_!!0-item_pic.jpg_430x430q90.jpg"},{"typeId":6,"productID":2,"productName":"保暖衬衫","price":25,"img":"https://img.alicdn.com/bao/uploaded/i2/2269753886/TB1aoLfcwjN8KJjSZFkXXaboXXa_!!0-item_pic.jpg_430x430q90.jpg"}}]}
没有二级类情况
{"DefaultProducts":[{"typeId":4,"productID":91,"productName":"e袋洗","price":299,"img":""},{"typeId":4,"productID":92,"productName":"窗帘拆装费","price":100,"img":""}]}
就是一个对象里有twoTypes属性,一个没有
export let products=(typeId)=>{
return axios.get(`/type?twoId=${typeId}`);
}
//列表页显示 pageIndex第几页,perPage每页显示几条
export let comments=(pageIndex,perPage)=>{
return axios.get(`/comments?pageIndex=${pageIndex}&perPage=${perPage}`);
}
格式如下http://localhost:3000/comments?pageIndex=2&perPage=5
{"coms":[{"ID":6,"userId":1,"typeId":5,"content":"服务很好呀!!","tel":"1314659333","time":"2017-12-1"},{"ID":7,"userId":1,"typeId":5,"content":"服务很好呀!!","tel":"1314659333","time":"2017-12-1"},{"ID":8,"userId":3,"typeId":5,"content":"服务很好呀!!","tel":"1314659333","time":"2017-12-1"},{"ID":9,"userId":2,"typeId":5,"content":"服务很好呀!!","tel":"1314659333","time":"2017-12-1"},{"ID":10,"userId":1,"typeId":5,"content":"服务很好呀!!","tel":"13146593373","time":"2017-12-11"}],"hasMore":true}
<!-- comment 是一个对象格式为{userId:,typeId:,content:,tel}-->
export let addComment = (comment) => {
return axios.post(`/comment`,comment);
};
user是一个对象{username:"fly1",password:"111111"}
export let Reg = (user) => {
return axios.post(`/user`,user);
};
成功返回:{"code":0,"success":"注册成功"}
失败返回:{code: 1, err: '用户名重复'}
user是一个对象{username:"fly1",password:"111111"}
export let login = (user) => {
return axios.post(`/login`,user);
};
成功返回:{"code":0,"success":"登陆成功","user":{"username":"fly1","password":"111111","userId":2,"time":"2017-12-15T11:48:24.429Z"}}
失败返回:{"code":1,"err":"用户名或密码错误"}
export let logout = () => {
return axios.get('/logout');
};
返回:{code:0,success:'退出成功'}
export let validate = () => {
return axios.get('/validate');
};
如果存在返回 {code:0,user}
不存在返回 {code:1}
export let uploadImge = (user) => {
return axios.post('/uploadImge',user);
};
返回:{code: 0}上传成功
export let orders = (userid) => {
return axios.get(`/orders?userid=${userid}`);
};
返回格式:
[
{
"userId": 1,
"orderId": 1,
"orderProduct": [{"proId": 1, "sum": 1}, {"proId": 2, "sum": 4}],
"orderPriceSum": 100,
"addressId": 1,
"time": "2017-12-07"
},
{
"userId": 1,
"orderId": 2,
"orderProduct": [{"proId": 1, "sum": 1}, {"proId": 2, "sum": 4}],
"orderPriceSum": 100,
"addressId": 1,
"time": "2017-12-07"
}
]
export let adresses = (userid) => {
return axios.get(`/adresses?userid=${userid}`);
};
返回格式为一个数组:
[{
"ID": 1,
"userId": 1,
"province": "北京市",
"city": "北京市",
"address1": "通州区",
"address2": "新潮嘉园3期",
"name": "李唐菲",
"tel": "13146593373",
"sex": "女"
}, {
"ID": 2,
"userId": 1,
"province": "河南省",
"city": "郑州市",
"address1": "海淀区",
"address2": "新潮嘉园3期",
"name": "左钊",
"tel": "13146593374",
"sex": "男"
}]
export let getAddress = (addressid) => {
return axios.get(`/address?addressid=${addressid}`);
};
返回内容是一个对象:
{"ID":1,"userId":1,"province":"北京市","city":"北京市","address1":"通州区","address2":"新潮嘉园3期","name":"李唐菲","tel":"13146593373","sex":"女"}
order={userId:3,orderProduct:[{proId:1,sum:1},{proId:2,sum:4}],orderPriceSum:100,addressId:1}
export let order = (order) => {
return axios.post('/order',order);
};
//根据产品id获取产品详细信息
export let getProduct = (id) => {
return axios.get(`/product?id=${id}`);
};