mobile-workflow/api/request.js

97 lines
4.1 KiB
JavaScript
Raw Normal View History

2024-04-28 10:10:03 +08:00
//基础请求地址,需要根据自己的需求切换
2024-05-25 20:47:31 +08:00
// 开发环境
// export const BASE_URL = "http://42.180.188.17:9809" // 鞍钢正式环境
2024-06-25 10:23:25 +08:00
// export const BASE_URL = "http://42.180.188.17:19098" // 鞍钢线上测试环境
2024-05-18 00:52:06 +08:00
// export const BASE_URL = "http://47.93.215.234:9809" // 鞍钢正式环境(弃用)
// export const BASE_URL = "http://47.93.215.234:19098" // 鞍钢线上测试环境(弃用)
2024-04-30 00:30:46 +08:00
// export const BASE_URL = "http://47.93.215.234:19097"
2024-06-02 20:15:25 +08:00
// export const BASE_URL = "http://jxj.zhgdyun.com:61212" // 洁远程
2024-04-28 10:10:03 +08:00
// export const BASE_URL = "http://182.90.224.237:35557"
2024-06-02 20:15:25 +08:00
// export const BASE_URL = "http://192.168.34.155:19111"
// export const BASE_URL = "http://192.168.34.221:9111"
// axios.defaults.baseURL ='http://192.168.34.221:9111/' //郭圣雄本地
//export const BASE_URL = "http://192.168.8.100:10000"
//export const BASE_URL = "http://106.13.16.28:10000"
2024-04-28 10:10:03 +08:00
2024-05-25 20:47:31 +08:00
// 生产环境
2024-10-11 16:56:42 +08:00
// export const BASE_URL = "http://101.43.164.214:11111" // 百色 通用
2024-05-25 22:34:09 +08:00
// export const BASE_URL = "http://42.180.188.17:9809" // 鞍钢正式环境
2024-08-23 09:38:23 +08:00
// export const BASE_URL = "http://42.180.188.17:19098" // 鞍钢线上测试环境
// export const BASE_URL = "http://jxj.zhgdyun.com:18004" // 包头线上地址
// export const BASE_URL = "http://219.147.96.219:9809" // 包头线上地址(正式)
export const BASE_URL = process.env.NODE_ENV === 'development' ? "http://192.168.34.221:9111" : "http://219.147.96.219:9809" // 包头线上地址(正式)
//是否已显示未登录弹窗
2024-04-28 10:10:03 +08:00
let showNoLoginTip = false
/**
* 封装请求保持与pc端一致的风格
* @param {Object} config uni request的配置
*/
export function request(config = {}, sl = true) {
2024-12-21 16:57:51 +08:00
return new Promise((resolve, reject) => {
if (sl) {
uni.showLoading({
title: '加载中...'
})
}
uni.request({
url: BASE_URL + (config.url.startsWith("/") ? config.url : ("/" + config.url)),
method: (config.method || 'GET').toLocaleUpperCase(),
timeout: config.timeout || 20000,
withCredentials: true,
header: {
//大家在这里传自定义的token这里默认wflow的
Authorization: "Bearer " + uni.getStorageSync('wflow-token'),
TenantId: JSON.parse(uni.getStorageSync("loginUser")).sn,
...config.header,
},
dataType: 'json',
data: config.data,
success: (res) => {
if (res.statusCode === 200) {
showNoLoginTip = false
resolve(res)
} else if (res.statusCode === 401) {
if (!showNoLoginTip) {
showNoLoginTip = true
// uni.showModal({
// title: '提示',
// content: '登录已失效,是否重新跳转到登录',
// success: function(res) {
// showNoLoginTip = false
// uni.removeStorageSync('loginUser')
// if (res.confirm) {
// uni.navigateTo({ url: '/pages/login/login' })
// }
// }
// });
}
} else if (res.statusCode === 500) {
console.log(res)
uni.showToast({
icon: 'none',
title: '系统异常:' + res.data
})
} else {
showNoLoginTip = false
reject({
statusCode: res.statusCode,
msg: res.data
})
}
},
fail: (err) => {
console.log(err)
uni.showToast({
title: '网络异常,请检查网络',
duration: 2000,
icon: 'none'
})
},
complete: () => uni.hideLoading()
})
})
2024-04-28 10:10:03 +08:00
}
export default request