发布于2021-05-30 00:02 阅读(1055) 评论(0) 点赞(11) 收藏(5)
src\views\modules\common\category.vue
添加了树形菜单过滤,但是清空过滤条件时,节点无法收起
在原有的基础上修改
<!-- 树形列表 -->
<template>
<div>
<el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
<el-tree
ref="categoryTree"
:filter-node-method="filterNode"
:highlight-current="true"
style="margin-top: 5px"
></el-tree>
</div>
<!-- 添加点击事件 -->
</template>
data() {
return {
filterText: '',
}
},
watch: {
filterText(val) {
this.$refs.categoryTree.filter(val)
},
},
methods: {
//树节点过滤
filterNode(value, data) {
if (!value) return true
return data.name.indexOf(value) !== -1
},
},
src\views\modules\product\attrgroup.vue
改动的较多,建议直接拷贝
新增分组中,选择属性分类,使用级联选择器
src\views\modules\product\attrgroup-add-or-update.vue
<el-form-item label="所属分类id" prop="categoryId">
<!-- filterable 打开搜索功能 -->
<el-cascader
v-model="dataForm.categoryPath"
:options="categoryList"
:props="props"
filterable
></el-cascader>
</el-form-item>
data() {
return {
props: {
value: 'catId',
label: 'name',
children: 'childrenList',
},
categoryList: [],
}
},
methods:
// 关闭对话框时,清空所选分类
dialogClose() {
this.dataForm.categoryPath = []
},
修改属性分组时,根据分类id,回显所属分类
CategoryEntity.java
@JsonInclude(Include.NON_EMPTY) // 为空则不返回这个字段
private List<CategoryEntity> childrenList;
AttrGroupEntity.java
/**
* 分类的全路径
*/
@TableField(exist = false)
private Long[] categoryPath;
AdminAttrGroupController.java
@Autowired
private CategoryService categoryService;
/**
* 信息
*/
@GetMapping("/info/{attrGroupId}")
public R info(@PathVariable("attrGroupId") Long attrGroupId){
AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);
Long categoryId = attrGroup.getCategoryId();
Long[] path = categoryService.findCategoryPath(categoryId);
attrGroup.setCategoryPath(path);
return R.ok().put("attrGroup", attrGroup);
}
CategoryService.java
/**
* 根据分类id,查找分类id的全路径
* @param categoryId
* @return
*/
Long[] findCategoryPath(Long categoryId);
CategoryServiceImpl.java
@Override
public Long[] findCategoryPath(Long categoryId) {
List<Long> pathList = new ArrayList<>();
List<Long> parentPathList = findParentPath(categoryId,pathList);
// 将数据反转过来
Collections.reverse(parentPathList);
return pathList.toArray(new Long[parentPathList.size()]);
}
/**
* 225,25,2
* 只要父节点不为0,就说明有父级,
* 则继续往上找
*/
private List<Long> findParentPath(Long categoryId, List<Long> pathList) {
// 1、收集当前节点id
pathList.add(categoryId);
// 先根据id,查出当前分类的信息
CategoryEntity category = this.getById(categoryId);
if (category.getParentCid() != 0){
// 如果父id不为0,则说明有父级,继续往上查
findParentPath(category.getParentCid(),pathList);
}
// 最后查到1级分类,父id为0了,则会返回整个列表
return pathList;
}
原文链接:https://blog.csdn.net/Alvin199765/article/details/117350317
作者:快起来搬砖啦
链接:http://www.javaheidong.com/blog/article/207943/e4d83fd3c8b0859be74e/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!