From 33281cb44e4009871df29d31158340e80ac03b2f Mon Sep 17 00:00:00 2001 From: Agent Date: Sun, 29 Mar 2026 15:34:39 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8api.request=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=B9=B6=E5=8A=A0=E8=AF=A6=E7=BB=86=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/category/index.vue | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/pages/category/index.vue b/src/pages/category/index.vue index 491bfd5..ea8f4e6 100644 --- a/src/pages/category/index.vue +++ b/src/pages/category/index.vue @@ -211,33 +211,19 @@ export default { this.showAttrDialog = false }, async saveAttributes() { + console.log('this.attributes:', JSON.stringify(this.attributes)) const validAttrs = this.attributes.filter(a => a.name.trim()) + console.log('validAttrs:', JSON.stringify(validAttrs)) if (validAttrs.length === 0) { uni.showToast({ title: '请至少添加一个属性', icon: 'none' }) return } - console.log('准备保存属性:', JSON.stringify(validAttrs)) try { - const token = uni.getStorageSync('token') - const role = uni.getStorageSync('role') || '' - const res = await uni.request({ - url: `${import.meta.env.VITE_API_BASE_URL}/products/categories/${this.currentCategory.categoryId}/attributes`, - method: 'POST', - data: { - attributes: validAttrs - }, - header: { - 'Authorization': token ? `Bearer ${token}` : '', - 'X-User-Role': role - } - }) - console.log('保存结果:', res.data) - if (res.data.code === 0) { - uni.showToast({ title: '保存成功', icon: 'success' }) - this.closeAttrDialog() - } else { - uni.showToast({ title: res.data.message || '保存失败', icon: 'none' }) - } + const payload = { attributes: JSON.parse(JSON.stringify(validAttrs)) } + console.log('payload:', JSON.stringify(payload)) + await api.request(`/products/categories/${this.currentCategory.categoryId}/attributes`, 'POST', {}, payload) + uni.showToast({ title: '保存成功', icon: 'success' }) + this.closeAttrDialog() } catch (e) { console.error('保存失败:', e) uni.showToast({ title: '保存失败', icon: 'none' })