173 lines
5.4 KiB
JavaScript
173 lines
5.4 KiB
JavaScript
// let requestPath = 'http://192.168.0.47:8092/';
|
|
let requestPath = 'http://192.168.151.34:8092/'; // 后台请求地址https://skqhdg.porthebei.com:9004/qa-prevention-gwj/
|
|
// export var requestPath = 'https://skqhdg.porthebei.com:9005/qa-regulatory-gwj/'; // 后台请求地址
|
|
let videoApiPath = 'https://arqsp.qhdsafety.com:10010'; // 视频平台后台请求地址
|
|
function post(url, data) {
|
|
return new Promise((resolve, reject) => {
|
|
if (data && data.loading !== false) {
|
|
uni.showLoading({
|
|
title: '加载中'
|
|
});
|
|
}
|
|
uni.request({
|
|
url: requestPath + url,
|
|
data,
|
|
method: 'POST',
|
|
header: {
|
|
'Content-type': 'application/x-www-form-urlencoded'
|
|
},
|
|
success: (res) => {
|
|
if (data && data.loading !== false) {
|
|
uni.hideLoading();
|
|
}
|
|
if (res.data.result === 'success') {
|
|
resolve(res.data)
|
|
} else {
|
|
if(url =='/admin/check'){
|
|
uni.showToast({
|
|
title: res.data.msg || '系统开小差了',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
reject(res.data)
|
|
}else{
|
|
uni.showToast({
|
|
title: res.data.msg || '系统开小差了',
|
|
icon: 'error',
|
|
duration: 2000
|
|
});
|
|
reject(res.data)
|
|
}
|
|
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
if (data && data.loading !== false) {
|
|
uni.hideLoading();
|
|
}
|
|
uni.showToast({
|
|
title: '网络错误请重试',
|
|
icon: 'error',
|
|
duration: 2000
|
|
});
|
|
reject(err)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
function upload(url, data) {
|
|
return new Promise((resolve, reject) => {
|
|
if (data && data.loading !== false) {
|
|
uni.showLoading({
|
|
title: '加载中'
|
|
});
|
|
}
|
|
uni.uploadFile({
|
|
url: requestPath + url,
|
|
filePath: data.filePath,
|
|
name: data.name || 'file',
|
|
formData: data.formData || {},
|
|
success: (res) => {
|
|
uni.hideLoading();
|
|
if (JSON.parse(res.data).result === 'success') {
|
|
resolve(JSON.parse(res.data))
|
|
} else {
|
|
uni.showToast({
|
|
title: JSON.parse(res.data).msg || '系统开小差了',
|
|
icon: 'error',
|
|
duration: 2000
|
|
});
|
|
reject(JSON.parse(res.data))
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '网络错误请重试',
|
|
icon: 'error',
|
|
duration: 2000
|
|
});
|
|
reject(err)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
function uploads(url, data) {
|
|
return new Promise((resolve, reject) => {
|
|
if (data && data.loading !== false) {
|
|
uni.showLoading({
|
|
title: '加载中'
|
|
});
|
|
}
|
|
uni.uploadFile({
|
|
url: requestPath + url,
|
|
files: data.files,
|
|
formData: data.formData || {},
|
|
success: (res) => {
|
|
uni.hideLoading();
|
|
if (JSON.parse(res.data).result === 'success') {
|
|
resolve(JSON.parse(res.data))
|
|
} else {
|
|
uni.showToast({
|
|
title: JSON.parse(res.data).msg || '系统开小差了',
|
|
icon: 'error',
|
|
duration: 2000
|
|
});
|
|
reject(JSON.parse(res.data))
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '网络错误请重试',
|
|
icon: 'error',
|
|
duration: 2000
|
|
});
|
|
reject(err)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
function setBasePath(url, data) {
|
|
requestPath = url
|
|
}
|
|
|
|
function videoApiGet(url, data) {
|
|
return new Promise((resolve, reject) => {
|
|
if (data && data.loading !== false) {
|
|
uni.showLoading({
|
|
title: '加载中'
|
|
});
|
|
}
|
|
uni.request({
|
|
url: videoApiPath + url + (data.token?`?token=${data.token}`:''),
|
|
data: {
|
|
...data
|
|
},
|
|
method: 'GET',
|
|
header: {
|
|
'Content-type': 'application/json'
|
|
},
|
|
success: (res) => {
|
|
uni.hideLoading();
|
|
resolve(res.data)
|
|
},
|
|
fail: (err) => {
|
|
if (data && data.loading !== false) {
|
|
uni.hideLoading();
|
|
}
|
|
uni.showToast({
|
|
title: '网络错误请重试',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
reject(err)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
export {post, upload, uploads,setBasePath,videoApiGet}
|