Commit e4ca2e25f9f518e366b4266cff9553bb49bea1c4

Authored by JeromeSoar
1 parent d3edaec2

树化

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/CategoryController.java
... ... @@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletResponse;
20 20 import javax.validation.Valid;
21 21 import java.io.IOException;
22 22 import java.util.Collection;
  23 +import java.util.Comparator;
23 24 import java.util.List;
24 25  
25 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
... ... @@ -78,8 +79,9 @@ public class CategoryController {
78 79 @GetMapping("/listByQuery")
79 80 @ApiOperation("获得商品分类列表")
80 81 @PreAuthorize("@ss.hasPermission('product:category:query')")
81   - public CommonResult<List<CategoryRespVO>> listByQuery() {
82   - List<CategoryDO> list = categoryService.listByQuery();
  82 + public CommonResult<List<CategoryRespVO>> listByQuery(@Valid CategoryTreeListReqVO treeListReqVO) {
  83 + List<CategoryDO> list = categoryService.getCategoryTreeList(treeListReqVO);
  84 + list.sort(Comparator.comparing(CategoryDO::getSort));
83 85 return success(CategoryConvert.INSTANCE.convertList(list));
84 86 }
85 87  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/vo/CategoryTreeListReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.controller.admin.category.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import org.springframework.format.annotation.DateTimeFormat;
  7 +
  8 +import java.util.Date;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Data
  13 +@ApiModel(value = "管理后台 - 商品分类列表查询 Request VO", description = "参数和 CategoryPageReqVO 是一致的")
  14 +public class CategoryTreeListReqVO extends CategoryExportReqVO {
  15 +
  16 + @ApiModelProperty(value = "分类名称", example = "办公文具")
  17 + private String name;
  18 +
  19 + @ApiModelProperty(value = "开启状态", example = "0")
  20 + private Integer status;
  21 +
  22 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  23 + @ApiModelProperty(value = "开始创建时间")
  24 + private Date beginCreateTime;
  25 +
  26 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  27 + @ApiModelProperty(value = "结束创建时间")
  28 + private Date endCreateTime;
  29 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java
1 1 package cn.iocoder.yudao.module.product.service.category;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO;
5   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO;
6   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO;
7   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO;
  4 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*;
8 5 import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
9 6  
10 7 import javax.validation.Valid;
... ... @@ -75,7 +72,8 @@ public interface CategoryService {
75 72 /**
76 73 * 获得商品分类列表
77 74 *
  75 + * @param treeListReqVO 查询条件
78 76 * @return 商品分类列表
79 77 */
80   - List<CategoryDO> listByQuery();
  78 + List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO);
81 79 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java
1 1 package cn.iocoder.yudao.module.product.service.category;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryCreateReqVO;
5   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryExportReqVO;
6   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryPageReqVO;
7   -import cn.iocoder.yudao.module.product.controller.admin.category.vo.CategoryUpdateReqVO;
  4 +import cn.iocoder.yudao.module.product.controller.admin.category.vo.*;
8 5 import cn.iocoder.yudao.module.product.convert.category.CategoryConvert;
9 6 import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO;
10 7 import cn.iocoder.yudao.module.product.dal.mysql.category.CategoryMapper;
... ... @@ -83,8 +80,8 @@ public class CategoryServiceImpl implements CategoryService {
83 80 }
84 81  
85 82 @Override
86   - public List<CategoryDO> listByQuery() {
87   - return categoryMapper.selectList();
  83 + public List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO) {
  84 + return categoryMapper.selectList(treeListReqVO);
88 85 }
89 86  
90 87 }
... ...
yudao-ui-admin/src/views/mall/product/category/index.vue
... ... @@ -12,10 +12,6 @@
12 12 :key="dict.value" :label="dict.label" :value="dict.value"/>
13 13 </el-select>
14 14 </el-form-item>
15   - <el-form-item label="创建时间">
16   - <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
17   - type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
18   - </el-form-item>
19 15 <el-form-item>
20 16 <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
21 17 <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
... ... @@ -30,6 +26,9 @@
30 26 </el-button>
31 27 </el-col>
32 28 <el-col :span="1.5">
  29 + <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
  30 + </el-col>
  31 + <el-col :span="1.5">
33 32 <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
34 33 :loading="exportLoading"
35 34 v-hasPermi="['product:category:export']">导出
... ... @@ -39,7 +38,8 @@
39 38 </el-row>
40 39  
41 40 <!-- 列表 -->
42   - <el-table v-loading="loading" :data="list">
  41 + <el-table v-if="refreshTable" v-loading="loading" :data="list" row-key="id" :default-expand-all="isExpandAll"
  42 + :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
43 43 <el-table-column label="分类名称" align="center" prop="name"/>
44 44 <el-table-column label="分类图标" align="center" prop="icon">
45 45 <template slot-scope="scope">
... ... @@ -73,9 +73,6 @@
73 73 </template>
74 74 </el-table-column>
75 75 </el-table>
76   - <!-- 分页组件 -->
77   - <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
78   - @pagination="getList"/>
79 76  
80 77 <!-- 对话框(添加 / 修改) -->
81 78 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
... ... @@ -161,7 +158,10 @@ export default {
161 158 title: "",
162 159 // 是否显示弹出层
163 160 open: false,
164   - dateRangeCreateTime: [],
  161 + // 是否展开,默认全部折叠
  162 + isExpandAll: false,
  163 + // 重新渲染表格状态
  164 + refreshTable: true,
165 165 // 查询参数
166 166 queryParams: {
167 167 pageNo: 1,
... ... @@ -190,11 +190,9 @@ export default {
190 190 this.loading = true;
191 191 // 处理查询参数
192 192 let params = {...this.queryParams};
193   - this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
194 193 // 执行查询
195   - getCategoryPage(params).then(response => {
196   - this.list = response.data.list;
197   - this.total = response.data.total;
  194 + listCategory(params).then(response => {
  195 + this.list = this.handleTree(response.data, "id", "pid");
198 196 this.loading = false;
199 197 });
200 198 },
... ... @@ -248,10 +246,17 @@ export default {
248 246 },
249 247 /** 重置按钮操作 */
250 248 resetQuery() {
251   - this.dateRangeCreateTime = [];
252 249 this.resetForm("queryForm");
253 250 this.handleQuery();
254 251 },
  252 + /** 展开/折叠操作 */
  253 + toggleExpandAll() {
  254 + this.refreshTable = false;
  255 + this.isExpandAll = !this.isExpandAll;
  256 + this.$nextTick(() => {
  257 + this.refreshTable = true;
  258 + });
  259 + },
255 260 /** 新增按钮操作 */
256 261 handleAdd() {
257 262 this.reset();
... ... @@ -310,7 +315,6 @@ export default {
310 315 let params = {...this.queryParams};
311 316 params.pageNo = undefined;
312 317 params.pageSize = undefined;
313   - this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
314 318 // 执行导出
315 319 this.$modal.confirm('是否确认导出所有商品分类数据项?').then(() => {
316 320 this.exportLoading = true;
... ...