Commit efd49421298619d5828de9d29350f6015827c09c
1 parent
969c3877
mall:完善商品分类的 APP 后端接口
Showing
8 changed files
with
43 additions
and
27 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java
| ... | ... | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCateg |
| 5 | 5 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; | |
| 8 | +import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; | |
| 9 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; |
| 10 | 10 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 11 | 11 | import io.swagger.annotations.Api; |
| ... | ... | @@ -61,7 +61,7 @@ public class ProductCategoryController { |
| 61 | 61 | @PreAuthorize("@ss.hasPermission('product:category:query')") |
| 62 | 62 | public CommonResult<ProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { |
| 63 | 63 | ProductCategoryDO category = categoryService.getProductCategory(id); |
| 64 | - return success(CategoryConvert.INSTANCE.convert(category)); | |
| 64 | + return success(ProductCategoryConvert.INSTANCE.convert(category)); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | @GetMapping("/list") |
| ... | ... | @@ -70,7 +70,7 @@ public class ProductCategoryController { |
| 70 | 70 | public CommonResult<List<ProductCategoryRespVO>> getProductCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) { |
| 71 | 71 | List<ProductCategoryDO> list = categoryService.getEnableProductCategoryList(treeListReqVO); |
| 72 | 72 | list.sort(Comparator.comparing(ProductCategoryDO::getSort)); |
| 73 | - return success(CategoryConvert.INSTANCE.convertList(list)); | |
| 73 | + return success(ProductCategoryConvert.INSTANCE.convertList(list)); | |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.app.category; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | -import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryListRespVO; | |
| 5 | -import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; | |
| 4 | +import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO; | |
| 5 | +import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; | |
| 6 | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; |
| 7 | 7 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 8 | 8 | import io.swagger.annotations.Api; |
| ... | ... | @@ -29,10 +29,10 @@ public class AppCategoryController { |
| 29 | 29 | |
| 30 | 30 | @GetMapping("/list") |
| 31 | 31 | @ApiOperation("获得商品分类列表") |
| 32 | - public CommonResult<List<AppCategoryListRespVO>> listByQuery() { | |
| 32 | + public CommonResult<List<AppCategoryRespVO>> getProductCategoryList() { | |
| 33 | 33 | List<ProductCategoryDO> list = categoryService.getEnableProductCategoryList(); |
| 34 | 34 | list.sort(Comparator.comparing(ProductCategoryDO::getSort)); |
| 35 | - return success(CategoryConvert.INSTANCE.convertList03(list)); | |
| 35 | + return success(ProductCategoryConvert.INSTANCE.convertList03(list)); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/vo/AppCategoryListRespVO.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/vo/AppCategoryRespVO.java
| ... | ... | @@ -8,8 +8,8 @@ import javax.validation.constraints.NotBlank; |
| 8 | 8 | import javax.validation.constraints.NotNull; |
| 9 | 9 | |
| 10 | 10 | @Data |
| 11 | -@ApiModel(value = "App - 商品分类 Response VO") | |
| 12 | -public class AppCategoryListRespVO { | |
| 11 | +@ApiModel(value = "用户 APP - 商品分类 Response VO") | |
| 12 | +public class AppCategoryRespVO { | |
| 13 | 13 | |
| 14 | 14 | @ApiModelProperty(value = "分类编号", required = true, example = "2") |
| 15 | 15 | private Long id; | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/CategoryConvert.java renamed to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/ProductCategoryConvert.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.convert.category; |
| 3 | 3 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; |
| 4 | 4 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; |
| 5 | 5 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; |
| 6 | -import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryListRespVO; | |
| 6 | +import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO; | |
| 7 | 7 | import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; |
| 8 | 8 | import org.mapstruct.Mapper; |
| 9 | 9 | import org.mapstruct.factory.Mappers; |
| ... | ... | @@ -16,9 +16,9 @@ import java.util.List; |
| 16 | 16 | * @author 芋道源码 |
| 17 | 17 | */ |
| 18 | 18 | @Mapper |
| 19 | -public interface CategoryConvert { | |
| 19 | +public interface ProductCategoryConvert { | |
| 20 | 20 | |
| 21 | - CategoryConvert INSTANCE = Mappers.getMapper(CategoryConvert.class); | |
| 21 | + ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class); | |
| 22 | 22 | |
| 23 | 23 | ProductCategoryDO convert(ProductCategoryCreateReqVO bean); |
| 24 | 24 | |
| ... | ... | @@ -28,5 +28,5 @@ public interface CategoryConvert { |
| 28 | 28 | |
| 29 | 29 | List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list); |
| 30 | 30 | |
| 31 | - List<AppCategoryListRespVO> convertList03(List<ProductCategoryDO> list); | |
| 31 | + List<AppCategoryRespVO> convertList03(List<ProductCategoryDO> list); | |
| 32 | 32 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/category/ProductCategoryDO.java
| ... | ... | @@ -9,9 +9,9 @@ import lombok.*; |
| 9 | 9 | /** |
| 10 | 10 | * 商品分类 DO |
| 11 | 11 | * |
| 12 | - * 商品分类一共两级: | |
| 12 | + * 商品分类一共两类: | |
| 13 | 13 | * 1)一级分类:{@link #parentId} 等于 0 |
| 14 | - * 2)二级分类:{@link #parentId} 等于父分类 | |
| 14 | + * 2)二级 + 三级分类:{@link #parentId} 不等于 0 | |
| 15 | 15 | * |
| 16 | 16 | * @author 芋道源码 |
| 17 | 17 | */ |
| ... | ... | @@ -46,7 +46,7 @@ public class ProductCategoryDO extends BaseDO { |
| 46 | 46 | * 分类图片 |
| 47 | 47 | * |
| 48 | 48 | * 一级分类:推荐 200 x 100 分辨率 |
| 49 | - * 二级分类:推荐 100 x 100 分辨率 | |
| 49 | + * 二级 + 三级分类:推荐 100 x 100 分辨率 | |
| 50 | 50 | */ |
| 51 | 51 | private String picUrl; |
| 52 | 52 | /** | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java
| ... | ... | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; | |
| 8 | +import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; | |
| 9 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; |
| 10 | 10 | import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper; |
| 11 | 11 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -37,7 +37,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { |
| 37 | 37 | validateParentProductCategory(createReqVO.getParentId()); |
| 38 | 38 | |
| 39 | 39 | // 插入 |
| 40 | - ProductCategoryDO category = CategoryConvert.INSTANCE.convert(createReqVO); | |
| 40 | + ProductCategoryDO category = ProductCategoryConvert.INSTANCE.convert(createReqVO); | |
| 41 | 41 | productCategoryMapper.insert(category); |
| 42 | 42 | // 返回 |
| 43 | 43 | return category.getId(); |
| ... | ... | @@ -51,7 +51,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { |
| 51 | 51 | validateParentProductCategory(updateReqVO.getParentId()); |
| 52 | 52 | |
| 53 | 53 | // 更新 |
| 54 | - ProductCategoryDO updateObj = CategoryConvert.INSTANCE.convert(updateReqVO); | |
| 54 | + ProductCategoryDO updateObj = ProductCategoryConvert.INSTANCE.convert(updateReqVO); | |
| 55 | 55 | productCategoryMapper.updateById(updateObj); |
| 56 | 56 | } |
| 57 | 57 | ... | ... |
yudao-ui-admin/src/views/mall/product/category/index.vue
| ... | ... | @@ -61,15 +61,15 @@ |
| 61 | 61 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| 62 | 62 | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| 63 | 63 | <el-form-item label="上级分类" prop="parentId"> |
| 64 | - <el-select v-model="form.parentId" placeholder="请选择上级分类" clearable size="small"> | |
| 65 | - <el-option :key="0" label="顶级分类" :value="0"/> | |
| 66 | - <el-option v-for="item in list.filter(v => v.parentId === 0)" :key="item.id" :label="item.name" :value="item.id"/> | |
| 67 | - </el-select> | |
| 64 | + <Treeselect v-model="form.parentId" :options="parentCategoryOptions" :normalizer="normalizer" | |
| 65 | + :show-count="true" | |
| 66 | + :defaultExpandLevel="1" | |
| 67 | + placeholder="上级分类"/> | |
| 68 | 68 | </el-form-item> |
| 69 | 69 | <el-form-item label="分类名称" prop="name"> |
| 70 | 70 | <el-input v-model="form.name" placeholder="请输入分类名称"/> |
| 71 | 71 | </el-form-item> |
| 72 | - <el-form-item label="分类图片" prop="bannerUrl"> | |
| 72 | + <el-form-item label="分类图片" prop="picUrl"> | |
| 73 | 73 | <ImageUpload v-model="form.picUrl" :limit="1" :is-show-tip="false" /> |
| 74 | 74 | <div v-if="form.parentId === 0" style="font-size: 10px">推荐 200x100 图片分辨率</div> |
| 75 | 75 | <div v-else style="font-size: 10px">推荐 100x100 图片分辨率</div> |
| ... | ... | @@ -164,6 +164,11 @@ export default { |
| 164 | 164 | getProductCategoryList(params).then(response => { |
| 165 | 165 | this.list = this.handleTree(response.data, "id", "parentId"); |
| 166 | 166 | this.loading = false; |
| 167 | + // 属性下拉框 | |
| 168 | + this.parentCategoryOptions = []; | |
| 169 | + const menu = {id: 0, name: '顶级分类', children: []}; | |
| 170 | + menu.children = this.handleTree(response.data, "id", "parentId"); | |
| 171 | + this.parentCategoryOptions.push(menu); | |
| 167 | 172 | }); |
| 168 | 173 | }, |
| 169 | 174 | /** 取消按钮 */ |
| ... | ... | @@ -202,6 +207,17 @@ export default { |
| 202 | 207 | this.refreshTable = true; |
| 203 | 208 | }); |
| 204 | 209 | }, |
| 210 | + /** 转换菜单数据结构 */ | |
| 211 | + normalizer(node) { | |
| 212 | + if (node.children && !node.children.length) { | |
| 213 | + delete node.children; | |
| 214 | + } | |
| 215 | + return { | |
| 216 | + id: node.id, | |
| 217 | + label: node.name, | |
| 218 | + children: node.children | |
| 219 | + }; | |
| 220 | + }, | |
| 205 | 221 | /** 新增按钮操作 */ |
| 206 | 222 | handleAdd() { |
| 207 | 223 | this.reset(); | ... | ... |
yudao-ui-app/pages/category/category.vue
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | <!-- 右侧分类内容 --> |
| 21 | 21 | <scroll-view scroll-y="true" class="box-right"> |
| 22 | 22 | <view class="category-image"> |
| 23 | - <image :showLoading="true" :src="categoryList[currentIndex].bannerUrl" mode='widthFix' @click="click"></image> | |
| 23 | + <image :showLoading="true" :src="categoryList[currentIndex].picUrl" mode='widthFix' @click="click"></image> | |
| 24 | 24 | </view> |
| 25 | 25 | |
| 26 | 26 | <view class="sub-category-box" v-for="(item, index) in categoryList[currentIndex].children" :key="item.id"> |
| ... | ... | @@ -33,8 +33,8 @@ |
| 33 | 33 | <u-grid col="3"> |
| 34 | 34 | <u-grid-item v-for="(subItem, subIndex) in item.children" :key="subItem.id"> |
| 35 | 35 | <view class="sub-category-item" @click="handleCategory(item, subIndex)"> |
| 36 | - <u-icon name="photo" :size="80" v-if="subItem.bannerUrl === null"></u-icon> | |
| 37 | - <image :src="item.bannerUrl" v-if="subItem.bannerUrl != null" mode='widthFix' /> | |
| 36 | + <u-icon name="photo" :size="80" v-if="subItem.picUrl === null"></u-icon> | |
| 37 | + <image :src="item.picUrl" v-if="subItem.picUrl != null" mode='widthFix' /> | |
| 38 | 38 | <text class="sub-category-title">{{ subItem.name }}</text> |
| 39 | 39 | </view> |
| 40 | 40 | </u-grid-item> | ... | ... |