import {requestOption} from './init.js'
|
import store from '../store/index.js'
|
export function request(option) {
|
return new Promise((resolve, reject) => {
|
//请求头
|
const header = option.header || {
|
'Content-Type': option.contentType || 'application/json',
|
// 'token': uni.getStorageSync('token'),
|
};
|
uni.showLoading({
|
title: '加载中...'
|
});
|
uni.request({
|
url: `http://${store.state.user.ip}:${store.state.user.port}/pda/${option.url}`,
|
// url: requestOption.HOST + option.url,
|
data: option.data || {},
|
method: option.method || 'GET',
|
header: header,
|
timeout: requestOption.timeout,
|
success: ((res) => {
|
|
if (res.statusCode===200) {
|
if (res.data) {
|
if (res.data.status===200) {
|
let ress = {data:res.data.date};
|
for (let key in res.data) {
|
if (key!=='msg'&&key!=='date'&&key!=='status') {
|
ress[key] = res.data[key]
|
}
|
}
|
resolve(ress)
|
} else {
|
let emsg = res.data.msg;
|
if (!emsg) emsg="请求错误"
|
uni.showToast({
|
title:emsg,
|
//icon: 'error',
|
icon: 'none' //用于文字的全部显示 【EditBy shaocx,2022-03-23】
|
})
|
reject(res)
|
}
|
} else {
|
resolve(res)
|
}
|
} else {
|
uni.showToast({
|
title:'请求错误-'+res.statusCode,
|
icon: 'error'
|
})
|
reject(res)
|
}
|
}),
|
fail: ((err) => {
|
uni.showToast({
|
title:'请求失败',
|
icon: 'error'
|
})
|
reject(err)
|
}),
|
complete() {
|
setTimeout(()=>{
|
uni.hideLoading()
|
},300)
|
}
|
})
|
})
|
}
|