|
@@ -5,12 +5,11 @@ import { $startWuxRefresher, $stopWuxRefresher,$stopWuxLoader} from '../miniprog
|
|
|
|
|
|
// 配置项
|
|
|
const config = {
|
|
|
- // baseURL: 'http://192.168.1.2:8901', // 基础URL
|
|
|
- baseURL: 'https://www.xsip.cn', // 基础URL
|
|
|
+ baseURL: 'http://192.168.1.2:8901', // 基础URL
|
|
|
+ // baseURL: 'https://www.xsip.cn', // 基础URL
|
|
|
timeout: 30000, // 超时时间(单位ms)
|
|
|
header: {
|
|
|
'content-type': 'application/json', // 默认请求头
|
|
|
-
|
|
|
// 其他全局请求头...
|
|
|
},
|
|
|
// 其他全局配置...
|
|
@@ -25,7 +24,8 @@ function request(url, method = 'GET', data = {}, header = {},isLogin=true) {
|
|
|
}
|
|
|
var pages = getCurrentPages()
|
|
|
var route = pages[pages.length - 1]?.route
|
|
|
- if(config.tabbar.indexOf(route)==-1){
|
|
|
+ console.log(config.tabbar,route)
|
|
|
+ if(route && config.tabbar.indexOf(route)==-1){
|
|
|
obj.top = "90"
|
|
|
}
|
|
|
wx.request({
|
|
@@ -64,7 +64,11 @@ function request(url, method = 'GET', data = {}, header = {},isLogin=true) {
|
|
|
// icon: 'error',
|
|
|
// duration: 2000
|
|
|
// })
|
|
|
- Notify(obj)
|
|
|
+ console.log(obj)
|
|
|
+ if(obj.message){
|
|
|
+ Notify(obj)
|
|
|
+ }
|
|
|
+
|
|
|
reject(res.data.message || '未知错误');
|
|
|
}
|
|
|
if($stopWuxRefresher()){
|
|
@@ -84,15 +88,101 @@ function request(url, method = 'GET', data = {}, header = {},isLogin=true) {
|
|
|
// Notify({ type: 'danger', message: '请求失败',top:'90' });
|
|
|
Notify(obj)
|
|
|
reject(error);
|
|
|
+ if($stopWuxRefresher()){
|
|
|
+ $stopWuxRefresher()
|
|
|
+ }
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function upload(url="/fileManager/uploadNormalFile", path = '', header = {},formData={}) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ var obj = {
|
|
|
+ type: 'danger'
|
|
|
+ }
|
|
|
+ var pages = getCurrentPages()
|
|
|
+ var route = pages[pages.length - 1]?.route
|
|
|
+ console.log(config.tabbar,route)
|
|
|
+ if(route && config.tabbar.indexOf(route)==-1){
|
|
|
+ obj.top = "90"
|
|
|
+ }
|
|
|
+ wx.uploadFile({
|
|
|
+ url: config.baseURL + url, //仅为示例,非真实的接口地址
|
|
|
+ filePath: path,
|
|
|
+ name: 'multipartFile',
|
|
|
+ formData: formData,
|
|
|
+ header: {
|
|
|
+ ...config.header,
|
|
|
+ ...header,
|
|
|
+ "Cookie": "token="+wx.getStorageSync('token')
|
|
|
+ },
|
|
|
+ timeout: config.timeout,
|
|
|
+ success: function(res){
|
|
|
+ if(res.data){
|
|
|
+ res.data = JSON.parse(res.data)
|
|
|
+ }
|
|
|
+ // 根据业务逻辑处理成功响应
|
|
|
+ if (res.data && res.data.code === 200) { // 假设服务器返回code为200表示成功
|
|
|
+ resolve(res.data);
|
|
|
+ } else {
|
|
|
+ switch(res.data.code){
|
|
|
+ case 401:
|
|
|
+ if(isLogin){
|
|
|
+ // Notify({ type: 'danger', message: '未登录',top:'90' });
|
|
|
+ obj.message = '未登录'
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/login/login',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ wx.setStorageSync('token', '')
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ obj.message = '请求失败'
|
|
|
+ // Notify({ type: 'danger', message: '请求失败',top:'90' });
|
|
|
+
|
|
|
+ }
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '请求失败',
|
|
|
+ // icon: 'error',
|
|
|
+ // duration: 2000
|
|
|
+ // })
|
|
|
+ console.log(obj)
|
|
|
+ if(obj.message){
|
|
|
+ Notify(obj)
|
|
|
+ }
|
|
|
+
|
|
|
+ reject(res.data.message || '未知错误');
|
|
|
+ }
|
|
|
+ if($stopWuxRefresher()){
|
|
|
+ $stopWuxRefresher()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function(error) {
|
|
|
+ console.log(error)
|
|
|
+
|
|
|
+ // 处理请求失败
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '请求失败',
|
|
|
+ // icon: 'error',
|
|
|
+ // duration: 2000
|
|
|
+ // })
|
|
|
+ obj.message = '请求失败'
|
|
|
+ // Notify({ type: 'danger', message: '请求失败',top:'90' });
|
|
|
+ Notify(obj)
|
|
|
+ reject(error);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// 导出请求方法
|
|
|
module.exports = {
|
|
|
get: (url, data,isLogin, header) => request(url, 'GET', data, header,isLogin),
|
|
|
post: (url, data,isLogin, header) => request(url, 'POST', data, header,isLogin),
|
|
|
// 可以继续添加其他方法,如put, delete等
|
|
|
// ...
|
|
|
+ upload: ( path,formData,url, header) => upload(url, path, header,formData),
|
|
|
};
|