bugfix
This commit is contained in:
parent
d9647cf17e
commit
97d54661f0
@ -183,3 +183,21 @@ export function reqHomepageProductCategory(data){
|
||||
data
|
||||
})
|
||||
}
|
||||
//产品树更新 /product/homepage_category_tree_update.dspy
|
||||
export function reqHomepageCategoryTreeUpdate(data){
|
||||
return request({
|
||||
url: '/product/homepage_category_tree_update.dspy',
|
||||
method: 'post',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
data
|
||||
})
|
||||
}
|
||||
//产品树删除 /product/homepage_category_tree_delete.dspy
|
||||
export function reqHomepageCategoryTreeDelete(data){
|
||||
return request({
|
||||
url: '/product/homepage_category_tree_delete.dspy',
|
||||
method: 'post',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
data
|
||||
})
|
||||
}
|
||||
@ -91,7 +91,7 @@
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm">保存</el-button>
|
||||
<el-button type="primary" @click="submitForm">{{ isEdit ? '保存' : '新增' }}</el-button>
|
||||
<el-button @click="resetForm">重置</el-button>
|
||||
<el-button @click="drawer = false">取消</el-button>
|
||||
</el-form-item>
|
||||
@ -104,7 +104,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { reqNcMatchMenu,reqAddProductMenu } from '@/api/ncmatch';
|
||||
import { reqNcMatchMenu,reqAddProductMenu,reqHomepageCategoryTreeUpdate,reqHomepageCategoryTreeDelete } from '@/api/ncmatch';
|
||||
export default {
|
||||
name: 'menuMangement',
|
||||
data() {
|
||||
@ -116,6 +116,7 @@ export default {
|
||||
direction: 'rtl',
|
||||
labelPosition: 'right',
|
||||
|
||||
isEdit: false,
|
||||
formLabelAlign: {
|
||||
name: '',
|
||||
icon: '',
|
||||
@ -206,8 +207,16 @@ export default {
|
||||
}).catch(() => {});
|
||||
},
|
||||
|
||||
// 提交表单
|
||||
// 提交表单(区分新增与保存)
|
||||
submitForm() {
|
||||
// reqHomepageCategoryTreeUpdate({id:row.id,name:row.name,poriority:row.poriority,source:row.source,url_link:window.location.href}).then(res=>{
|
||||
// if(res.status){
|
||||
// this.$message.success('编辑成功!');
|
||||
// this.getCategories();
|
||||
// }else{
|
||||
// this.$message.error(res.msg);
|
||||
// }
|
||||
// })
|
||||
this.$refs.menuForm.validate((valid) => {
|
||||
if (valid) {
|
||||
// 创建FormData对象
|
||||
@ -243,8 +252,21 @@ export default {
|
||||
console.log(`${key}:`, value);
|
||||
}
|
||||
|
||||
// 这里调用API保存数据
|
||||
this.saveMenuData(formData);
|
||||
// 这里调用API保存数据(根据 isEdit 区分)
|
||||
if (this.isEdit) {
|
||||
this.updateMenuData({
|
||||
id: this.formLabelAlign.id,
|
||||
name: this.formLabelAlign.name,
|
||||
poriority: this.formLabelAlign.poriority,
|
||||
source: this.formLabelAlign.source,
|
||||
parentid: this.formLabelAlign.parentid,
|
||||
url_link: window.location.href,
|
||||
// 如果是顶级并且未改图标,不传 icon 字段
|
||||
// 图标更新仅在新增或更换图片时通过另一路径处理
|
||||
})
|
||||
} else {
|
||||
this.saveMenuData(formData);
|
||||
}
|
||||
} else {
|
||||
this.$message.error('请检查表单信息!');
|
||||
return false;
|
||||
@ -252,7 +274,7 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
// 保存菜单数据
|
||||
// 新增菜单数据
|
||||
saveMenuData(formData) {
|
||||
// 这里添加实际的API调用
|
||||
// 例如:
|
||||
@ -274,6 +296,21 @@ export default {
|
||||
// console.log('FormData数据已准备就绪,可以发送到服务器');
|
||||
},
|
||||
|
||||
// 保存(编辑)菜单数据(非文件字段)
|
||||
updateMenuData(payload) {
|
||||
reqHomepageCategoryTreeUpdate(payload).then(res => {
|
||||
if (res.status) {
|
||||
this.$message.success('保存成功!');
|
||||
this.drawer = false;
|
||||
this.getCategories();
|
||||
} else {
|
||||
this.$message.error(res.msg);
|
||||
}
|
||||
}).catch(error => {
|
||||
this.$message.error('保存失败:' + error.message);
|
||||
})
|
||||
},
|
||||
|
||||
// 重置表单
|
||||
resetForm() {
|
||||
this.$refs.menuForm.resetFields();
|
||||
@ -283,6 +320,7 @@ export default {
|
||||
addNode(row, type) {
|
||||
this.drawer = true;
|
||||
this.resetForm();
|
||||
this.isEdit = false;
|
||||
if (type === 'child') {
|
||||
this.formLabelAlign.parentid = row.id;
|
||||
} else if (type === 'sibling') {
|
||||
@ -309,17 +347,22 @@ export default {
|
||||
this.formLabelAlign = { ...row };
|
||||
// 编辑时清除iconFile,避免重复上传
|
||||
this.formLabelAlign.iconFile = null;
|
||||
console.log('编辑节点:', row);
|
||||
this.isEdit = true;
|
||||
|
||||
|
||||
},
|
||||
deleteNode(row) {
|
||||
this.$confirm('确定要删除这个菜单吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
console.log('删除节点:', row);
|
||||
this.$message.success('删除成功!');
|
||||
}).catch(() => {});
|
||||
|
||||
reqHomepageCategoryTreeDelete({id:row.id}).then(res=>{
|
||||
if(res.status){
|
||||
this.$message.success('删除成功!');
|
||||
this.getCategories();
|
||||
|
||||
}else{
|
||||
this.$message.error(res.msg);
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
buildTree(data, parentId = null) {
|
||||
if (!Array.isArray(data)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user