import env from './env'; // import uniChat from "./uniChat"; export default function requst(url : string, type : string, params : any, header : object = {}) { // #ifndef APP-PLUS uni.showLoading({ mask: true }) // #endif // #ifdef APP-PLUS plus.nativeUI.showWaiting(); // #endif console.log('检查URL' + env.API_URL + url,) console.log(params); return new Promise((resolve, reject) => { uni.request({ url: env.API_URL + url, method: type, data: params, header: { Authorization: 'Bearer '+ uni.getStorageSync('TOKEN') || '' }, timeout: 5000, success(result : any) { console.log(result); let res = result.data; if (res.code === 200) { console.log('请求成功') resolve(res); } else if (res.code == 401) { console.log('请求失败') // #ifdef APP-PLUS plus.nativeUI.toast('登录状态失效,请重新登录'); // #endif uni.showToast({ icon: 'none', mask: true, title: '登录状态失效,请重新登录', duration: 2500, }) // uni.removeStorageSync('TOKEN') // uni.removeStorageSync('userInfo'); // uni.clearStorage(); // tools.jumpTo('/pages/client/account/login', {}, 0) resolve(res) } else { setTimeout(() => { uni.showToast({ icon: 'none', mask: true, title: res.msg }) }) resolve(res) } }, fail(error : any) { console.log(error); uni.showToast({ icon: 'none', mask: true, title: '与服务器断开' }) reject(error) }, complete() { // #ifndef APP-PLUS uni.hideLoading(); // #endif // #ifdef APP-PLUS plus.nativeUI.closeWaiting(); // #endif }, }) }) }