This commit is contained in:
@@ -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' })
|
||||
|
||||
Reference in New Issue
Block a user