- 前端 + 后端:完善首页广告

pull/1/head
YunaiV 2019-05-06 23:30:30 +08:00
parent 2890af6311
commit 9a3b708738
11 changed files with 86 additions and 69 deletions

View File

@ -101,7 +101,7 @@ class PicturesWall extends React.Component {
// })
// .catch(onError);
let key = uuid.v4(); // TODO 芋艿可能后面要优化。MD5
let observable = qiniu.upload(e, key, this.state.token); // TODO 芋艿,最后后面去掉 qiniu 的库依赖,直接 http 请求,这样更轻量
let observable = qiniu.upload(file, key, this.state.token); // TODO 芋艿,最后后面去掉 qiniu 的库依赖,直接 http 请求,这样更轻量
observable.subscribe(function () {
// next
}, function () {
@ -109,6 +109,7 @@ class PicturesWall extends React.Component {
// TODO 芋艿,后续补充
debugger;
}, function (response) {
debugger;
// complete
// debugger;
response.url = 'http://static.shop.iocoder.cn/' + response.key; // 需要设置,用于后续 onSuccess ,合并到 file 中,从而设置到 fileList

View File

@ -55,7 +55,7 @@ export default {
'menu.order.order-list': '订单管理',
'menu.order.order-refunds': '退货维权',
// 营销相关
'menu.promotion.promotion-banner-list': 'Banner 管理',
'menu.promotion.promotion-banner-list': '首页广告',
'menu.promotion.product-recommend-list': '商品推荐',
'menu.promotion.coupon-card-template-list': '优惠劵管理',
};

View File

@ -25,9 +25,9 @@ import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from './BannerList.less';
import moment from "moment";
import PaginationHelper from "../../../helpers/PaginationHelper";
import PicturesWall from "../../components/Image/PicturesWall";
const FormItem = Form.Item;
const { TreeNode } = Tree;
const status = ['未知', '正常', '禁用'];
// 列表
@ -70,11 +70,13 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
const columns = [
{
title: '标题',
dataIndex: 'title'
dataIndex: 'title',
width: 120,
},
{
title: '跳转链接',
dataIndex: 'url',
width: 120,
},
{
title: '图片',
@ -97,15 +99,17 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
{
title: '备注',
dataIndex: 'memo',
width: 150,
},
{
title: '创建时间',
dataIndex: 'createTime',
render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>,
width: 120,
render: val => <span>{moment(val).format('YYYY-MM-DD')}</span>,
},
{
title: '操作',
width: 360,
width: 150,
render: (text, record) => {
const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改
return (
@ -214,6 +218,7 @@ const SearchForm = Form.create()(props => {
// 添加 or 修改 Form 表单
const AddOrUpdateForm = Form.create()(props => {
const { dispatch, modalVisible, form, handleModalVisible, modalType, formVals } = props;
let picturesWall = null;
const okHandle = () => {
form.validateFields((err, fields) => {
@ -225,6 +230,7 @@ const AddOrUpdateForm = Form.create()(props => {
payload: {
body: {
...fields,
picUrl: picturesWall ? picturesWall.getUrl() : undefined,
},
callback: () => {
// 清空表单
@ -244,12 +250,13 @@ const AddOrUpdateForm = Form.create()(props => {
body: {
id: formVals.id,
...fields,
picUrl: picturesWall ? picturesWall.getUrl() : undefined,
},
callback: () => {
// 清空表单
form.resetFields();
// 提示
message.success('更新成功');
message.success('编辑成功');
// 关闭弹窗
handleModalVisible();
},
@ -259,7 +266,7 @@ const AddOrUpdateForm = Form.create()(props => {
});
};
const title = modalType === 'add' ? '新建 Banner' : '更新 Banner';
const title = modalType === 'add' ? '新建广告' : '编辑广告';
return (
<Modal
destroyOnClose
@ -286,11 +293,9 @@ const AddOrUpdateForm = Form.create()(props => {
initialValue: formVals.picUrl,
})(<Input placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="图片">
{form.getFieldDecorator('picUrl', {
rules: [{ required: true, message: '请输入跳转链接!'},],
initialValue: formVals.picUrl,
})(<Input placeholder="请输入" />)}
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="分类图片"
extra="建议尺寸640*340px大小不超过 2M" required={true}>
<PicturesWall urls={formVals.picUrl ? [formVals.picUrl] : undefined} ref={(node) => picturesWall = node} maxLength={1} />
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="排序值">
{form.getFieldDecorator('sort', {
@ -365,7 +370,7 @@ class BannerList extends PureComponent {
dispatch,
};
// 添加 or 更新表单属性
// 添加 or 编辑表单属性
const addOrUpdateFormProps = {
modalVisible,
modalType,
@ -387,7 +392,7 @@ class BannerList extends PureComponent {
type="primary"
onClick={() => this.handleModalVisible(true, 'add', {})}
>
新建 Banner
新建广告
</Button>
</div>
</div>
@ -401,4 +406,4 @@ class BannerList extends PureComponent {
}
}
export default BannerList;
export default BannerList;

View File

@ -39,11 +39,11 @@ public class MVCConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 用户
registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**");
registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口
// registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**");
// registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口
// 管理员
registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**");
registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**");
// registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**");
// registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**");
}
@Override

View File

@ -15,14 +15,18 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/banner")
@Api("Banner 模块")
public class AdminsBannerController {
@Reference(validation = "true")
@Autowired
private BannerService bannerService;
@GetMapping("/page")
@ -35,8 +39,8 @@ public class AdminsBannerController {
public CommonResult<AdminsBannerPageVO> page(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
CommonResult<BannerPageBO> result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize));
return BannerConvert.INSTANCE.convert(result);
BannerPageBO result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize));
return success(BannerConvert.ADMINS.convert3(result));
}
@PostMapping("/add")
@ -55,7 +59,7 @@ public class AdminsBannerController {
@RequestParam(value = "memo", required = false) String memo) {
BannerAddDTO bannerAddDTO = new BannerAddDTO().setTitle(title).setUrl(url).setPicUrl(picUrl)
.setSort(sort).setMemo(memo);
return BannerConvert.INSTANCE.convert2(bannerService.addBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO));
return success(BannerConvert.ADMINS.convert(bannerService.addBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO)));
}
@PostMapping("/update")
@ -75,7 +79,7 @@ public class AdminsBannerController {
@RequestParam(value = "memo", required = false) String memo) {
BannerUpdateDTO bannerUpdateDTO = new BannerUpdateDTO().setId(id).setTitle(title).setUrl(url).setPicUrl(picUrl)
.setSort(sort).setMemo(memo);
return bannerService.updateBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO);
return success(bannerService.updateBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO));
}
@PostMapping("/update_status")
@ -86,14 +90,14 @@ public class AdminsBannerController {
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return bannerService.updateBannerStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status);
return success(bannerService.updateBannerStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
@PostMapping("/delete")
@ApiOperation(value = "删除 Banner")
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1")
public CommonResult<Boolean> delete(@RequestParam("id") Integer id) {
return bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id);
return success(bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id));
}
}

View File

@ -17,6 +17,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
@ -28,6 +29,7 @@ import java.util.Date;
public class AdminsCouponController {
@Reference(validation = "true")
@Autowired
private CouponService couponService;
// ========== 优惠劵(码)模板 ==========

View File

@ -15,6 +15,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
public class AdminsProductRecommendController {
@Reference(validation = "true")
@Autowired
private ProductRecommendService productRecommendService;
@GetMapping("/page")

View File

@ -30,11 +30,11 @@ public class UsersBannerController {
@PermitAll
public CommonResult<List<UsersBannerVO>> list() {
// 查询 Banner 列表
List<BannerBO> result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue()).getData();
List<BannerBO> result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue());
// 排序,按照 sort 升序
result.sort(Comparator.comparing(BannerBO::getSort));
// 返回
return CommonResult.success(BannerConvert.INSTANCE.convertList(result));
return CommonResult.success(BannerConvert.USERS.convertList(result));
}
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO;
@ -12,21 +11,29 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
Users USERS = Mappers.getMapper(Users.class);
@Mappings({})
AdminsBannerVO convert(BannerBO bannerBO);
Admins ADMINS = Mappers.getMapper(Admins.class);
@Mappings({})
CommonResult<AdminsBannerVO> convert2(CommonResult<BannerBO> result);
@Mapper
interface Admins {
@Mappings({})
CommonResult<AdminsBannerPageVO> convert(CommonResult<BannerPageBO> result);
@Mappings({})
AdminsBannerVO convert(BannerBO bannerBO);
@Mappings({})
List<UsersBannerVO> convertList(List<BannerBO> banners);
@Mappings({})
AdminsBannerPageVO convert3(BannerPageBO bannerPageBO);
}
}
@Mapper
interface Users {
@Mappings({})
List<UsersBannerVO> convertList(List<BannerBO> banners);
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.promotion.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.api.dto.BannerAddDTO;
@ -11,16 +12,17 @@ import java.util.List;
public interface BannerService {
CommonResult<List<BannerBO>> getBannerListByStatus(Integer status);
List<BannerBO> getBannerListByStatus(Integer status);
CommonResult<BannerPageBO> getBannerPage(BannerPageDTO bannerPageDTO);
BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO);
CommonResult<BannerBO> addBanner(Integer adminId, BannerAddDTO bannerAddDTO);
BannerBO addBanner(Integer adminId, BannerAddDTO bannerAddDTO);
CommonResult<Boolean> updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO);
Boolean updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO);
CommonResult<Boolean> updateBannerStatus(Integer adminId, Integer bannerId, Integer status);
Boolean updateBannerStatus(Integer adminId, Integer bannerId,
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
CommonResult<Boolean> deleteBanner(Integer adminId, Integer bannerId);
Boolean deleteBanner(Integer adminId, Integer bannerId);
}
}

View File

@ -2,9 +2,7 @@ package cn.iocoder.mall.promotion.biz.service;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.BannerService;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
@ -29,13 +27,13 @@ public class BannerServiceImpl implements BannerService {
private BannerMapper bannerMapper;
@Override
public CommonResult<List<BannerBO>> getBannerListByStatus(Integer status) {
public List<BannerBO> getBannerListByStatus(Integer status) {
List<BannerDO> banners = bannerMapper.selectListByStatus(status);
return CommonResult.success(BannerConvert.INSTANCE.convertToBO(banners));
return BannerConvert.INSTANCE.convertToBO(banners);
}
@Override
public CommonResult<BannerPageBO> getBannerPage(BannerPageDTO bannerPageDTO) {
public BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO) {
BannerPageBO bannerPageBO = new BannerPageBO();
// 查询分页数据
int offset = (bannerPageDTO.getPageNo() - 1) * bannerPageDTO.getPageSize();
@ -43,61 +41,57 @@ public class BannerServiceImpl implements BannerService {
offset, bannerPageDTO.getPageSize())));
// 查询分页总数
bannerPageBO.setTotal(bannerMapper.selectCountByTitleLike(bannerPageDTO.getTitle()));
return CommonResult.success(bannerPageBO);
return bannerPageBO;
}
@Override
public CommonResult<BannerBO> addBanner(Integer adminId, BannerAddDTO bannerAddDTO) {
public BannerBO addBanner(Integer adminId, BannerAddDTO bannerAddDTO) {
// 保存到数据库
BannerDO banner = BannerConvert.INSTANCE.convert(bannerAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue());
banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date());
bannerMapper.insert(banner);
// 返回成功
return CommonResult.success(BannerConvert.INSTANCE.convertToBO(banner));
return BannerConvert.INSTANCE.convertToBO(banner);
}
@Override
public CommonResult<Boolean> updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO) {
public Boolean updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerUpdateDTO.getId()) == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = BannerConvert.INSTANCE.convert(bannerUpdateDTO);
bannerMapper.update(updateBanner);
// 返回成功
return CommonResult.success(true);
return true;
}
@Override
public CommonResult<Boolean> updateBannerStatus(Integer adminId, Integer bannerId, Integer status) {
// 校验参数
if (!CommonStatusEnum.isValid(status)) {
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启1或关闭2"); // TODO 有点搓
}
public Boolean updateBannerStatus(Integer adminId, Integer bannerId, Integer status) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status);
bannerMapper.update(updateBanner);
// 返回成功
return CommonResult.success(true);
return true;
}
@Override
public CommonResult<Boolean> deleteBanner(Integer adminId, Integer bannerId) {
public Boolean deleteBanner(Integer adminId, Integer bannerId) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO().setId(bannerId);
updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
bannerMapper.update(updateBanner);
// 返回成功
return CommonResult.success(true);
return true;
}
}