let baseURL = 'https://shop.hxxfb.com/' // 请求超出时间 const timeout = 5000 // 需要修改token,和根据实际修改请求头 export function myRequestPhp(options) { let url = options.url; let method = options.method || "get"; let data = options.data || {}; let header = { 'Content-Type': 'application/json;charset=UTF-8', 'X-token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuaHh4ZmIuY29tIiwiYXVkIjoiYXBpLmh4eGZiLmNvbSIsImlhdCI6MTc0MDM3MTM1NSwibmJmIjoxNzQwMzcxMzU1LCJleHAiOjE3NTExNzEzNTUsImp0aSI6WzI5OCwibWVyIl19.j2f8VwdwWY4zBpcijHntzUZ9YUms2SxChaVsYf7KnPs', 'Accept': '*/*', ...options.header } return new Promise((resolve, reject) => { uni.request({ url: baseURL + url, method: method, header: header, data: data, timeout, success(response) { const res = response if (res.data.status == 200) { //接口返回200走一下操作 resolve(res) } else if (res.data.status == 500) { //接口返回500走一下操作 return uni.showToast({ title: res.data.error, icon: 'none' }) } else { //除了500都会走以下操作 return uni.showToast({ title: res.data.message, icon: 'none' }) } }, fail(err) { console.log(err) if (err.errMsg.indexOf('request:fail') !== -1) { uni.showToast({ title: '网络异常', icon: "error", duration: 2000 }) } else { uni.showToast({ title: '未知异常', duration: 2000 }) } reject(err); }, complete() { uni.hideToast(); } }); }).catch(() => {}); };