Files
todo-frontend/src/api/index.js
Agent 46e83862f4
All checks were successful
continuous-integration/drone/push Build is passing
fix: API域名改为sales.violin-work.online
2026-03-24 15:19:10 +00:00

42 lines
913 B
JavaScript

// API基础配置
const BASE_URL = 'https://sales.violin-work.online/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
}