fix: shipping template form encoding and sale category customize_page_id

- request: add qs serialization when Content-Type is application/x-www-form-urlencoded so backend receives form body instead of JSON
- request: append country_code to string data (e.g. qs string) instead of assigning property to avoid breaking form body
- shipping: create/update template APIs send data via qs.stringify(params) with form-urlencoded header for correct backend parsing
- saleCategory: use numeric 0 for customize_page_id default and in submit, avoid empty string for consistency

Made-with: Cursor
This commit is contained in:
zhangjing1
2026-03-17 19:40:53 +08:00
parent dc5bab6725
commit 281b471e43
4 changed files with 31 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
import qs from 'qs'
import Vue from 'vue'
import store from '@/store'
import router from '@/router'
@@ -93,6 +94,14 @@ function createRequestClient() {
config.data = formData
// FormData 会自动设置 Content-Type不需要手动设置
delete config.headers['Content-Type']
} else if (
config.headers &&
config.headers['Content-Type'] === 'application/x-www-form-urlencoded' &&
typeof config.data === 'object' &&
config.data !== null
) {
// 声明为表单时若 data 仍是对象,则序列化为 form-urlencoded避免后端解析失败
config.data = qs.stringify(config.data)
}
}

View File

@@ -60,11 +60,16 @@ class RequestClient {
ar: 'ar-SA'
}
if (lang && !skipCountryCode) {
const countryCode = langMap[lang]
if (config.data) {
config.data.country_code = langMap[lang]
if (typeof config.data === 'string') {
config.data = config.data + (config.data ? '&' : '') + 'country_code=' + encodeURIComponent(countryCode)
} else {
config.data.country_code = countryCode
}
} else {
config.data = {
country_code: langMap[lang]
country_code: countryCode
}
}
}

View File

@@ -2,6 +2,7 @@
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
import qs from 'qs'
import { fetch } from './request'
export function getShippingTemplatesList(query) {
@@ -19,6 +20,7 @@ export function getShippingTemplatesInfo(id) {
})
}
/** 以表单格式提交,避免 Content-Type 为 form-urlencoded 但 body 为 JSON 导致后端解析失败 */
export function createShippingTemplates(params) {
return fetch({
url: '/shipping/templates/create',
@@ -26,15 +28,21 @@ export function createShippingTemplates(params) {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
params: params
params,
data: qs.stringify(params)
})
}
/** 编辑同样以表单格式提交 */
export function updateShippingTemplates(id, params) {
return fetch({
url: '/shipping/templates/update/' + id,
method: 'put',
params: params
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
params,
data: qs.stringify(params)
})
}

View File

@@ -146,7 +146,7 @@ export default {
parent_id: 0,
parent_name: '',
image_url: '',
customize_page_id: ''
customize_page_id: 0
},
categoryFormList: [
{
@@ -226,7 +226,7 @@ export default {
parent_id: 0,
parent_name: '',
image_url: '',
customize_page_id: ''
customize_page_id: 0
}
this.categoryDialog = true
},
@@ -238,7 +238,7 @@ export default {
sort,
parent_id,
image_url,
customize_page_id: customize_page_id == 0 ? '' : customize_page_id
customize_page_id
}
this.categoryDialog = true
},
@@ -253,7 +253,7 @@ export default {
parent_id: category_id,
parent_name: category_name,
image_url: '',
customize_page_id: ''
customize_page_id: 0
}
this.categoryDialog = true
},
@@ -297,7 +297,7 @@ export default {
resolve(list)
},
async onCategoryFormSubmit() {
const { category_name, sort, image_url, customize_page_id, parent_id, category_id } =
const { category_name, sort, image_url, customize_page_id=0, parent_id, category_id } =
this.categoryForm
if (category_id) {
await this.$api.goods.editCategory({