fix: 修复API请求,POST使用form-urlencoded格式匹配后端@RequestParam
This commit is contained in:
@@ -2,18 +2,21 @@
|
|||||||
const BASE_URL = 'https://sales.violin-work.online/api/v1'
|
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 token = uni.getStorageSync('token')
|
||||||
const userId = uni.getStorageSync('userId') || ''
|
const userId = uni.getStorageSync('userId') || ''
|
||||||
const username = uni.getStorageSync('username') || ''
|
const username = uni.getStorageSync('username') || ''
|
||||||
|
|
||||||
|
// POST 请求且有 data 时,用 form-urlencoded 格式
|
||||||
|
const useFormData = method === 'POST' && Object.keys(data).length > 0
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: BASE_URL + url,
|
url: BASE_URL + url,
|
||||||
method: method,
|
method: method,
|
||||||
data: data,
|
data: useFormData ? data : (method === 'GET' ? query : {}),
|
||||||
header: {
|
header: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': useFormData ? 'application/x-www-form-urlencoded' : 'application/json',
|
||||||
'Authorization': token ? `Bearer ${token}` : '',
|
'Authorization': token ? `Bearer ${token}` : '',
|
||||||
'X-User-Id': userId,
|
'X-User-Id': userId,
|
||||||
'X-Username': username
|
'X-Username': username
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default {
|
|||||||
* 入库
|
* 入库
|
||||||
*/
|
*/
|
||||||
stockIn(data) {
|
stockIn(data) {
|
||||||
return api.request('/stock/in', 'POST', data)
|
return api.request('/stock/in', 'POST', null, data)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user