| src/main/java/cc/mrbird/febs/dapp/dto/AddMallGoodsDto.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/cc/mrbird/febs/dapp/dto/MallGoodsUpdateDto.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/cc/mrbird/febs/dapp/entity/MallGoods.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/cc/mrbird/febs/dapp/entity/MallGoodsImages.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/cc/mrbird/febs/dapp/mapper/MallGoodsImagesMapper.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/cc/mrbird/febs/dapp/service/impl/AdminMallGoodsService.java | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/mapper/dapp/MallGoodsImagesMapper.xml | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/templates/febs/views/goods/goodsAddNew.html | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/templates/febs/views/goods/goodsUpdateNew.html | ●●●●● patch | view | raw | blame | history |
src/main/java/cc/mrbird/febs/dapp/dto/AddMallGoodsDto.java
@@ -24,6 +24,8 @@ @NotBlank(message = "参数不能为空") private String thumb; private String thumbs; //商品参数 @NotBlank(message = "参数不能为空") private String goodsParameter; src/main/java/cc/mrbird/febs/dapp/dto/MallGoodsUpdateDto.java
@@ -23,6 +23,8 @@ @NotBlank(message = "参数不能为空") private String thumb; private String thumbs; //商品参数 @NotBlank(message = "参数不能为空") private String goodsParameter; src/main/java/cc/mrbird/febs/dapp/entity/MallGoods.java
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import java.util.List; @Data @TableName("mall_goods") public class MallGoods extends BaseEntity { @@ -51,4 +53,7 @@ @TableField(exist = false) private String categoryName; @TableField(exist = false) private List<String> images; } src/main/java/cc/mrbird/febs/dapp/entity/MallGoodsImages.java
New file @@ -0,0 +1,20 @@ package cc.mrbird.febs.dapp.entity; import cc.mrbird.febs.common.entity.BaseEntity; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; /** * @author wzy * @date 2021-09-17 **/ @Data @TableName("mall_goods_images") public class MallGoodsImages extends BaseEntity { private String imageUrl; private Integer seq; private Long goodsId; } src/main/java/cc/mrbird/febs/dapp/mapper/MallGoodsImagesMapper.java
New file @@ -0,0 +1,20 @@ package cc.mrbird.febs.dapp.mapper; import cc.mrbird.febs.dapp.entity.MallGoodsImages; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** * @author wzy * @date 2021-09-17 **/ public interface MallGoodsImagesMapper extends BaseMapper<MallGoodsImages> { List<String> selectGoodsImagesByGoodsId(@Param("goodsId") Long goodsId); List<String> selectByGoodId(@Param("goodsId") long id); void deleteByGoodsId(@Param("goodsId")Long id); } src/main/java/cc/mrbird/febs/dapp/service/impl/AdminMallGoodsService.java
@@ -44,6 +44,7 @@ private final MallGoodsCategoryMapper mallGoodsCategoryMapper; private final PlatformBannerMapper platformBannerMapper; private final MallGoodsImagesMapper mallGoodsImagesMapper; @Override public IPage<MallGoods> getCategoryListInPage(MallGoods mallGoods, QueryRequest request) { @@ -70,6 +71,22 @@ BeanUtil.copyProperties(addMallGoodsDto, mallGoods); mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED); mallGoodsMapper.insert(mallGoods); String thumbs = addMallGoodsDto.getThumbs(); if (StrUtil.isNotEmpty(thumbs)) { List<String> imgs = StrUtil.splitTrim(thumbs, ","); if (CollUtil.isNotEmpty(imgs)) { int i = 1; for (String img : imgs) { MallGoodsImages mallGoodsImages = new MallGoodsImages(); mallGoodsImages.setGoodsId(mallGoods.getId()); mallGoodsImages.setImageUrl(img); mallGoodsImages.setSeq(i); mallGoodsImagesMapper.insert(mallGoodsImages); i++; } } } return new FebsResponse().success().message("操作成功"); } @@ -114,6 +131,8 @@ @Override public MallGoods selectGoodsById(long id) { MallGoods mallGoods = mallGoodsMapper.selectById(id); List<String> thumbs = mallGoodsImagesMapper.selectByGoodId(mallGoods.getId()); mallGoods.setImages(thumbs); return mallGoods; } @@ -137,6 +156,23 @@ BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods); mallGoodsMapper.updateById(mallGoods); mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId()); String thumbs = mallGoodsUpdateDto.getThumbs(); if (StrUtil.isNotEmpty(thumbs)) { List<String> imgs = StrUtil.splitTrim(thumbs, ","); if (CollUtil.isNotEmpty(imgs)) { int i = 1; for (String img : imgs) { MallGoodsImages mallGoodsImages = new MallGoodsImages(); mallGoodsImages.setGoodsId(mallGoods.getId()); mallGoodsImages.setImageUrl(img); mallGoodsImages.setSeq(i); mallGoodsImagesMapper.insert(mallGoodsImages); i++; } } } return new FebsResponse().success().message("操作成功"); } src/main/resources/mapper/dapp/MallGoodsImagesMapper.xml
New file @@ -0,0 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="cc.mrbird.febs.dapp.mapper.MallGoodsImagesMapper"> <select id="selectGoodsImagesByGoodsId" resultType="java.lang.String"> select image_url from mall_goods_images where goods_id=#{goodsId} </select> <select id="selectByGoodId" resultType="java.lang.String"> select image_url from mall_goods_images where goods_id = #{goodsId} </select> <delete id="deleteByGoodsId"> delete from mall_goods_images where goods_id = #{goodsId} </delete> </mapper> src/main/resources/templates/febs/views/goods/goodsAddNew.html
@@ -77,6 +77,26 @@ </div> </div> <div class="layui-form-item"> <label class="layui-form-label febs-form-item-require">轮播图:</label> <div class="layui-input-block"> <div class="layui-upload"> <button type="button" class="layui-btn layui-btn-normal layui-btn" id="thumbsBanner">上传</button> <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;"> <div class="layui-upload-list" id="thumbsBanners"></div> </blockquote> <div class="layui-word-aux">双击图片删除</div> </div> </div> </div> <div class="layui-form-item febs-hide"> <label class="layui-form-label">缩略图链接:</label> <div class="layui-input-block"> <input type="text" id="thumbs" lay-verify="required" name="thumbs" autocomplete="off" class="layui-input" readonly> </div> </div> <div class="layui-form-item febs-hide"> <label class="layui-form-label">商品图链接:</label> <div class="layui-input-block"> @@ -212,6 +232,57 @@ }) } //多图片上传 upload.render({ elem: '#thumbsBanner' ,url: ctx + 'admin/goods/uploadFileBase64' //改成您自己的上传接口 ,multiple: true ,before: function(obj){ //预读本地文件示例,不支持ie8 obj.preview(function(index, file, result){ $('#thumbsBanners').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img multi-images" style="width: 130px">') }); } ,done: function(res){ var thumbs = $("#thumbs").val(); if(thumbs == ''){ $("#thumbs").val(res.data.src); }else{ $("#thumbs").val(thumbs + ',' + res.data.src); } imgUnBind(".multi-images"); imgMultiBind(); } }); function imgUnBind(className) { $(className).each(function() { $(this).unbind('dblclick'); }) } function imgMultiBind() { $(".multi-images").each(function(index, element) { $(this).on("dblclick", function() { var imgThumb = $(".multi-images")[index]; $(imgThumb).remove(); var images = $("#thumbs").val(); var imagesArr; if (images) { imagesArr = images.split(","); imagesArr.splice(index, 1); images = imagesArr.join(","); } $("#thumbs").val(images); imgUnBind(".multi-images"); imgMultiBind(); }); }) } //图片上传 upload.render({ elem: '#test2' src/main/resources/templates/febs/views/goods/goodsUpdateNew.html
@@ -94,6 +94,32 @@ </div> </div> <div class="layui-form-item"> <label class="layui-form-label febs-form-item-require">轮播图:</label> <div class="layui-input-block"> <div class="layui-upload"> <button type="button" class="layui-btn layui-btn-normal layui-btn" id="thumbsBanner">上传 </button> <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;"> <div class="layui-upload-list" id="thumbsBanners"></div> </blockquote> <div class="layui-word-aux">双击图片删除</div> </div> </div> </div> <div class="layui-form-item febs-hide"> <label class="layui-form-label">缩略图链接:</label> <div class="layui-input-block"> <input type="text" id="thumbs" lay-verify="required" name="thumbs" autoComplete="off" class="layui-input" readOnly> </div> </div> <div class="layui-form-item"> <label class="layui-form-label">商品参数:</label> <div class="layui-input-block"> @@ -204,6 +230,56 @@ insertFn(res.data.src, res.data.title, '') }, } //多图片上传 upload.render({ elem: '#thumbsBanner' ,url: ctx + 'admin/goods/uploadFileBase64' //改成您自己的上传接口 ,multiple: true ,before: function(obj){ //预读本地文件示例,不支持ie8 obj.preview(function(index, file, result){ $('#thumbsBanners').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img multi-images" style="width: 130px">') }); } ,done: function(res){ var thumbs = $("#thumbs").val(); if(thumbs == ''){ $("#thumbs").val(res.data.src); }else{ $("#thumbs").val(thumbs + ',' + res.data.src); } imgUnBind(".multi-images"); imgMultiBind(); } }); function imgUnBind(className) { $(className).each(function() { $(this).unbind('dblclick'); }) } function imgMultiBind() { $(".multi-images").each(function(index, element) { $(this).on("dblclick", function() { var imgThumb = $(".multi-images")[index]; $(imgThumb).remove(); var images = $("#thumbs").val(); var imagesArr; if (images) { imagesArr = images.split(","); imagesArr.splice(index, 1); images = imagesArr.join(","); } $("#thumbs").val(images); imgUnBind(".multi-images"); imgMultiBind(); }); }) } //图片上传 upload.render({ @@ -264,6 +340,8 @@ initGoodsValue(); function initGoodsValue() { var images = goodsInfo.images; var thumbs = images.join(","); form.val("goods-update-form", { "id": goodsInfo.id, "goodsName": goodsInfo.goodsName, @@ -276,11 +354,18 @@ "presentPrice": goodsInfo.presentPrice, "thumb": goodsInfo.thumb, "sortCnt": goodsInfo.sortCnt, "thumbs": thumbs }); $('#demo2').append('<img src="' + goodsInfo.thumb + '" alt="" class="layui-upload-img single-image" style="width: 130px">') for (let i = 0; i < images.length; i++) { $('#thumbsBanners').append('<img src="' + images[i] + '" alt="" class="layui-upload-img multi-images" style="width: 130px">') } imgSingleBind(); imgMultiBind(); window.editor = E.createEditor({ html: goodsInfo.goodsDetails, selector: '#editor-container',