ry_app/api/back.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

import request8081 from '@/api/product'
import apiUrl from '@/utils/api'
import { getToken } from '@/utils/auth'
// 专门用于8081端口的请求复用 product.js 中的 request8081 逻辑)
const request = config => {
config.header = config.header || {}
const token = getToken()
if (token) {
config.header['Authorization'] = 'Bearer ' + token
}
const requestUrl = apiUrl + config.url
return new Promise((resolve, reject) => {
uni.request({
method: config.method || 'GET',
timeout: 10000,
url: requestUrl,
data: config.data,
header: {
'Content-Type': 'application/json;charset=UTF-8',
...config.header
},
dataType: 'json'
}).then(response => {
let [error, res] = response
if (error) {
reject(new Error('后端接口连接异常'))
return
}
if (res.statusCode !== 200) {
reject(new Error(`HTTP异常: ${res.statusCode}`))
return
}
resolve(res.data)
}).catch(err => {
reject(err)
})
})
}
// 获取订单列表
export function getOrderList(data) {
return request({
url: '/mall/order/list',
method: 'POST',
data: data
})
}