export function request(options) { return new Promise((resolve, reject) => { uni.request({ url: uni.conf.baseUrl + options.url, data: options.data || {}, method: options.method, // 设置请求头,添加版本号 header: { 'Content-Type': 'application/json;charset=UTF-8', version: uni.conf.version, type: uni.getSystemInfoSync().platform, // #ifdef APP-PLUS environment: 'app', // #endif // #ifdef H5 environment: 'h5', // #endif // #ifdef MP-WEIXIN environment: 'wx', // #endif // #ifdef MP-ALIPAY environment: 'alipay', // #endif token: uni.cache.get('token'), openId: uni.cache.get('miniAppOpenId'), id: uni.cache.get('userInfo').id, loginName: "", }, success(res) { const data = res.data || res; // 根据项目返回的code判断 if (data.code != 0){ switch (data.code) { case '200': resolve(data.data); break; case '500': uni.showToast({ title: data.message, icon: "none" }); reject(false); break; case '400': uni.showToast({ title: data.message, icon: "none" }); // 跳转到登录页面等操作 reject(false); break; default: reject(false); break; } }else{ resolve(data.data); } }, fail(res) { // 失败处理 reject(res); } }); }); }