fix: 修复API请求,POST使用form-urlencoded格式匹配后端@RequestParam

This commit is contained in:
Agent
2026-03-27 07:46:47 +00:00
parent c2929ae00a
commit df9e2b722b
2 changed files with 7 additions and 4 deletions

View File

@@ -2,18 +2,21 @@
const BASE_URL = 'https://sales.violin-work.online/api/v1'
// 请求拦截器
const request = (url, method, data = {}) => {
const request = (url, method, query = {}, data = {}) => {
const token = uni.getStorageSync('token')
const userId = uni.getStorageSync('userId') || ''
const username = uni.getStorageSync('username') || ''
// POST 请求且有 data 时,用 form-urlencoded 格式
const useFormData = method === 'POST' && Object.keys(data).length > 0
return new Promise((resolve, reject) => {
uni.request({
url: BASE_URL + url,
method: method,
data: data,
data: useFormData ? data : (method === 'GET' ? query : {}),
header: {
'Content-Type': 'application/json',
'Content-Type': useFormData ? 'application/x-www-form-urlencoded' : 'application/json',
'Authorization': token ? `Bearer ${token}` : '',
'X-User-Id': userId,
'X-Username': username

View File

@@ -22,7 +22,7 @@ export default {
* 入库
*/
stockIn(data) {
return api.request('/stock/in', 'POST', data)
return api.request('/stock/in', 'POST', null, data)
},
/**