import config from "@/config"; export function request(options) { return new Promise((resolve, reject) => { let header = options.header || { 'Content-Type': 'application/json' } if (uni.getStorageSync('token')) header['token'] = uni.getStorageSync('token'); if (options.url === '/im/message/save') header['token'] = uni.getStorageSync('systemChatToken'); uni.request({ url: config.baseUrl + options.url, // 服务器url method: options.method || 'GET', // 请求方法,默认为GET data: options.data || {}, // 请求参数 header: header, // 设置请求的 header success: (res) => { // 请求成功 if (res.statusCode === 200) { resolve(res.data); if (res.data.code != 200) uni.showToast({ title: res.data.message, icon: 'none' }) } else { // 可以根据项目要求修改错误处理 reject(res.data); uni.hideLoading(); } }, fail: (err) => { // 请求失败处理 uni.showToast({ title: '出错了,请联系管理员~', icon: 'none' }) reject(err); uni.hideLoading(); }, }); }); };