commit
52ce51e00b
@ -183,3 +183,21 @@ export function reqHomepageProductCategory(data){
|
|||||||
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-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="resetForm">重置</el-button>
|
||||||
<el-button @click="drawer = false">取消</el-button>
|
<el-button @click="drawer = false">取消</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -104,7 +104,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { reqNcMatchMenu,reqAddProductMenu } from '@/api/ncmatch';
|
import { reqNcMatchMenu,reqAddProductMenu,reqHomepageCategoryTreeUpdate,reqHomepageCategoryTreeDelete } from '@/api/ncmatch';
|
||||||
export default {
|
export default {
|
||||||
name: 'menuMangement',
|
name: 'menuMangement',
|
||||||
data() {
|
data() {
|
||||||
@ -116,6 +116,7 @@ export default {
|
|||||||
direction: 'rtl',
|
direction: 'rtl',
|
||||||
labelPosition: 'right',
|
labelPosition: 'right',
|
||||||
|
|
||||||
|
isEdit: false,
|
||||||
formLabelAlign: {
|
formLabelAlign: {
|
||||||
name: '',
|
name: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
@ -206,8 +207,16 @@ export default {
|
|||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单(区分新增与保存)
|
||||||
submitForm() {
|
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) => {
|
this.$refs.menuForm.validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
// 创建FormData对象
|
// 创建FormData对象
|
||||||
@ -243,8 +252,21 @@ export default {
|
|||||||
console.log(`${key}:`, value);
|
console.log(`${key}:`, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 这里调用API保存数据
|
// 这里调用API保存数据(根据 isEdit 区分)
|
||||||
this.saveMenuData(formData);
|
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 {
|
} else {
|
||||||
this.$message.error('请检查表单信息!');
|
this.$message.error('请检查表单信息!');
|
||||||
return false;
|
return false;
|
||||||
@ -252,7 +274,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 保存菜单数据
|
// 新增菜单数据
|
||||||
saveMenuData(formData) {
|
saveMenuData(formData) {
|
||||||
// 这里添加实际的API调用
|
// 这里添加实际的API调用
|
||||||
// 例如:
|
// 例如:
|
||||||
@ -274,6 +296,21 @@ export default {
|
|||||||
// console.log('FormData数据已准备就绪,可以发送到服务器');
|
// 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() {
|
resetForm() {
|
||||||
this.$refs.menuForm.resetFields();
|
this.$refs.menuForm.resetFields();
|
||||||
@ -283,6 +320,7 @@ export default {
|
|||||||
addNode(row, type) {
|
addNode(row, type) {
|
||||||
this.drawer = true;
|
this.drawer = true;
|
||||||
this.resetForm();
|
this.resetForm();
|
||||||
|
this.isEdit = false;
|
||||||
if (type === 'child') {
|
if (type === 'child') {
|
||||||
this.formLabelAlign.parentid = row.id;
|
this.formLabelAlign.parentid = row.id;
|
||||||
} else if (type === 'sibling') {
|
} else if (type === 'sibling') {
|
||||||
@ -309,17 +347,22 @@ export default {
|
|||||||
this.formLabelAlign = { ...row };
|
this.formLabelAlign = { ...row };
|
||||||
// 编辑时清除iconFile,避免重复上传
|
// 编辑时清除iconFile,避免重复上传
|
||||||
this.formLabelAlign.iconFile = null;
|
this.formLabelAlign.iconFile = null;
|
||||||
console.log('编辑节点:', row);
|
this.isEdit = true;
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
deleteNode(row) {
|
deleteNode(row) {
|
||||||
this.$confirm('确定要删除这个菜单吗?', '提示', {
|
|
||||||
confirmButtonText: '确定',
|
reqHomepageCategoryTreeDelete({id:row.id}).then(res=>{
|
||||||
cancelButtonText: '取消',
|
if(res.status){
|
||||||
type: 'warning'
|
this.$message.success('删除成功!');
|
||||||
}).then(() => {
|
this.getCategories();
|
||||||
console.log('删除节点:', row);
|
|
||||||
this.$message.success('删除成功!');
|
}else{
|
||||||
}).catch(() => {});
|
this.$message.error(res.msg);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
buildTree(data, parentId = null) {
|
buildTree(data, parentId = null) {
|
||||||
if (!Array.isArray(data)) {
|
if (!Array.isArray(data)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user