/*
|
* 小程序 Promise 封装 wx.request
|
* @Author: T.y.z
|
* @Last Modified by: T.y.z
|
*/
|
const app = getApp()
|
class Ajax {
|
//定义baseURL
|
constructor(parms) {
|
this.baseURL = parms.baseURL
|
}
|
|
// get 请求
|
get(url, data) {
|
return this.ajax('GET', url, data)
|
}
|
|
// post 请求
|
post(url, data) {
|
return this.ajax('POST', url, data)
|
}
|
// 公共请求方法
|
ajax(method, url, data) {
|
|
wx.showLoading({
|
title: '加载中',
|
mask: false
|
})
|
return new Promise((resolve, reject) => {
|
wx.request({
|
url: this.baseURL + url,
|
data,
|
header: {
|
"content-type": "application/x-www-form-urlencoded",
|
Authorization: "Bearer" + " " + wx.getStorageSync('token'),
|
},
|
method,
|
dataType: 'json',
|
responseType: 'text',
|
success: res => {
|
if (res.data.code == 400) {
|
wx.showToast({
|
title: res.data.msg,
|
icon: "none"
|
})
|
return false
|
}
|
if ((res.data.message == 'token验证失败' || res.data.message == 'TOKEN_INVALID') && wx.getStorageSync('token') && wx.getStorageSync('token') !== 'quit') {
|
wx.showModal({
|
title: '提示',
|
content: '登录过期是否重新登录',
|
showCancel: true,
|
confirmText: "确定", //默认是“确定”
|
confirmColor: '#F07207', //确定文字的颜色
|
success: (res) => {
|
if (res.cancel) {
|
//点击取消,默认隐藏弹框
|
} else {
|
wx.redirectTo({
|
url: '/pages/index/index',
|
})
|
clearInterval(app.globalData.comparisonToken)
|
}
|
},
|
fail: function (res) {}, //接口调用失败的回调函数
|
complete: function (res) {}, //接口调用结束的回调函数(调用成功、失败都会执行)
|
})
|
}
|
if (res.data.code == 600 && (wx.getStorageSync('token') == '' || wx.getStorageSync('token') == 'quit')) {
|
wx.redirectTo({
|
url: '/pages/index/index',
|
})
|
}
|
resolve(res)
|
},
|
fail: res => {
|
wx.showToast({
|
title: '网络错误',
|
icon: "none"
|
})
|
reject(res)
|
},
|
complete: res => {
|
|
wx.hideLoading()
|
}
|
})
|
})
|
}
|
}
|
|
const ajax = new Ajax({
|
// baseURL: 'http://192.168.0.49:81/api',
|
// baseURL:"http://192.168.110.34:7777/user"
|
// baseURL:"http://221.182.45.100:7777/user"
|
|
// baseURL:"http://39.108.148.228:80/user"
|
// baseURL: 'http://120.220.4.138:9591/user',
|
baseURL: 'https://xn95128.cn/user',
|
|
})
|
|
/**
|
* 全部导出 ajax.get() 调用
|
*/
|
export default ajax
|
|
/**
|
* 单个导出 解构赋值 { getBanner } 调用
|
*/
|
|
// 专车查询专车类型
|
export const queryServerCarMo = (
|
endLonLat,
|
startLonLat,
|
type
|
) => {
|
return ajax.post('/base/serverCarModel/queryServerCarModel', {
|
endLonLat,
|
startLonLat,
|
type
|
})
|
}
|
|
|
// 专车查询专车类型
|
export const saveOrderPrivateCar = (
|
driverId,
|
endAddress,
|
endLat,
|
endLon,
|
orderSource,
|
orderType,
|
passengers,
|
passengersPhone,
|
placementLat,
|
placementLon,
|
serverCarModelId,
|
startAddress,
|
startLat,
|
startLon,
|
substitute,
|
travelTime,
|
type
|
) => {
|
return ajax.post('/api/orderPrivateCar/saveOrderPrivateCar', {
|
driverId,
|
endAddress,
|
endLat,
|
endLon,
|
orderSource,
|
orderType,
|
passengers,
|
passengersPhone,
|
placementLat,
|
placementLon,
|
serverCarModelId,
|
startAddress,
|
startLat,
|
startLon,
|
substitute,
|
travelTime,
|
type
|
})
|
}
|
|
|
// 跨城出行 获取 起点终点 站点
|
export const querySite = (
|
startSiteId
|
) => {
|
return ajax.post('/base/site/querySite', {
|
startSiteId
|
})
|
}
|
|
|
//根据选择的起点和终点获取线路
|
export const queryLines = (
|
endId,
|
startId
|
) => {
|
return ajax.post('/base/line/queryLines', {
|
endId,
|
startId
|
})
|
}
|
|
//根据线路id获取线路排班数据
|
export const queryDriver = (
|
day,
|
driverId,
|
lineId
|
) => {
|
return ajax.post('/base/lineSite/queryDriver', {
|
day,
|
driverId,
|
lineId
|
})
|
}
|
|
//根据站点id获取站点的区域范围数据(设置上车点和下车点)
|
|
export const queryLocation = (
|
siteId
|
) => {
|
return ajax.post('/base/site/queryLocation', {
|
siteId
|
})
|
}
|
|
|
|
//判断一个点是是否在区域范围内
|
export const areaMonitoringexport = (
|
code,
|
lonLat,
|
siteId
|
) => {
|
return ajax.post('/base/site/areaMonitoring', {
|
code,
|
lonLat,
|
siteId
|
})
|
}
|
|
|
//根据司机的排班id获取剩余座位数据
|
export const querySeat = (
|
id
|
) => {
|
return ajax.post('/base/lineSite/querySeat', {
|
id
|
})
|
}
|
|
//获取跨城的支付金额
|
export const queryOrderMoney = (
|
endLonLat,
|
startLonLat,
|
lineId,
|
peopleNumber,
|
seatNumber,
|
serverCarModelId,
|
totalSeat,
|
travelMode
|
) => {
|
return ajax.post('/base/orderCrossCity/queryOrderMoney', {
|
endLonLat,
|
startLonLat,
|
lineId,
|
peopleNumber,
|
seatNumber,
|
serverCarModelId,
|
totalSeat,
|
travelMode
|
})
|
}
|
|
|
//跨城出行下单操作
|
export const orderCrossCity = (
|
data
|
) => {
|
return ajax.post('/api/orderCrossCity/orderCrossCity', data)
|
}
|
|
//查询优惠券 跟 充值余额
|
export const queryBalance = (data) => {
|
return ajax.post('/api/taxi/queryBalance', data)
|
}
|
|
|
//获取服务中的详情数据
|
export const queryOrderInfo = (
|
data
|
) => {
|
return ajax.post('/api/order/queryOrderInfo', data)
|
}
|
|
|
//摆渡车下单
|
export const saveOrderFerry = (
|
data
|
) => {
|
return ajax.post('/api/orderCrossCity/saveOrderFerry', data)
|
}
|
|
|
//跨城出行须知
|
export const queryByType = (
|
data
|
) => {
|
return ajax.post('/base/agreement/queryByType', data)
|
}
|
|
|
//司机信息
|
export const queryDriverInfo = (
|
data
|
) => {
|
return ajax.post('/api/driver/queryDriverInfo', data)
|
}
|
|
//司机信息
|
export const addCancle = (
|
data
|
) => {
|
return ajax.post('/api/taxi/addCancle', data)
|
}
|
|
|
//
|
export const queryPhones = (
|
data
|
) => {
|
return ajax.post('/base/phone/queryPhones', data)
|
}
|
|
|
//获取业务对应的所有车型
|
export const queryServerCarModels = (data) => {
|
return ajax.post('/base/serverCarModel/queryServerCarModels', data)
|
}
|
|
|
//提交包车订单
|
export const orderCharteredCar = (data) => {
|
return ajax.post('/api/orderCharteredCar/orderCharteredCar', data)
|
}
|
|
//获取首页小件物流订单数量
|
export const queryLogisticsNumber = (data) => {
|
return ajax.post('/api/orderLogistics/queryLogisticsNumber', data)
|
}
|
|
|
//获取所在地区
|
|
|
export const queryRegion = (data) => {
|
return ajax.post('/api/orderLogistics/queryRegion', data)
|
}
|
|
//获取小件物流的单价数据
|
export const queryLogisticsUnitPrice = (data) => {
|
return ajax.post('/api/orderLogistics/queryLogisticsUnitPrice', data)
|
}
|
|
//获取支付金额
|
export const queryPayMoney = (data) => {
|
return ajax.post('/base/orderLogistics/queryPayMoney', data)
|
}
|
|
|
|
//根据起点和终点坐标判断是不是同一个市内
|
export const judgingTheCity = (data) => {
|
return ajax.post('/base/orderLogistics/judgingTheCity', data)
|
}
|
|
|
///小件物流下单操作(同城/跨城)
|
export const smallLogistics = (data) => {
|
return ajax.post('/api/orderLogistics/smallLogistics', data)
|
}
|
|
|
//获取积分兑换的商品
|
export const queryGoods = (data) => {
|
return ajax.post('/api/integralGoods/queryGoods', data)
|
}
|
|
|
|
|
//兑换商品
|
export const addIntegralOrder = (data) => {
|
return ajax.post('/api/integralGoods/addIntegralOrder', data)
|
}
|
|
|
|
|
|
export const queryConvertHistory = (data) => {
|
return ajax.post('/api/integralGoods/queryConvertHistory', data)
|
}
|