// API基础配置 const BASE_URL = 'http://localhost:8080/api/v1' // 请求拦截器 const request = (url, method, data = {}) => { const token = uni.getStorageSync('token') return new Promise((resolve, reject) => { uni.request({ url: BASE_URL + url, method: method, data: data, header: { 'Content-Type': 'application/json', 'Authorization': token ? `Bearer ${token}` : '' }, success: (res) => { if (res.data.code === 0) { resolve(res.data.data) } else { uni.showToast({ title: res.data.message || '请求失败', icon: 'none' }) reject(res.data) } }, fail: (err) => { uni.showToast({ title: '网络请求失败', icon: 'none' }) reject(err) } }) }) } export default { request }