This commit is contained in:
@@ -211,33 +211,19 @@ export default {
|
|||||||
this.showAttrDialog = false
|
this.showAttrDialog = false
|
||||||
},
|
},
|
||||||
async saveAttributes() {
|
async saveAttributes() {
|
||||||
|
console.log('this.attributes:', JSON.stringify(this.attributes))
|
||||||
const validAttrs = this.attributes.filter(a => a.name.trim())
|
const validAttrs = this.attributes.filter(a => a.name.trim())
|
||||||
|
console.log('validAttrs:', JSON.stringify(validAttrs))
|
||||||
if (validAttrs.length === 0) {
|
if (validAttrs.length === 0) {
|
||||||
uni.showToast({ title: '请至少添加一个属性', icon: 'none' })
|
uni.showToast({ title: '请至少添加一个属性', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('准备保存属性:', JSON.stringify(validAttrs))
|
|
||||||
try {
|
try {
|
||||||
const token = uni.getStorageSync('token')
|
const payload = { attributes: JSON.parse(JSON.stringify(validAttrs)) }
|
||||||
const role = uni.getStorageSync('role') || ''
|
console.log('payload:', JSON.stringify(payload))
|
||||||
const res = await uni.request({
|
await api.request(`/products/categories/${this.currentCategory.categoryId}/attributes`, 'POST', {}, payload)
|
||||||
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' })
|
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||||
this.closeAttrDialog()
|
this.closeAttrDialog()
|
||||||
} else {
|
|
||||||
uni.showToast({ title: res.data.message || '保存失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('保存失败:', e)
|
console.error('保存失败:', e)
|
||||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||||
|
|||||||
Reference in New Issue
Block a user