提交 da8ed706 authored 作者: zgy's avatar zgy

首页海报管理

上级 78baba37
package com.platform.controller;
import com.platform.entity.TbCfPostersEntity;
import com.platform.service.TbCfPostersService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* Controller
*
* @author lipengjun
* @date 2020-03-01 16:45:10
*/
@Controller
@RequestMapping("tbcfposters")
public class TbCfPostersController {
@Autowired
private TbCfPostersService tbCfPostersService;
/**
* 查看列表
*/
@RequestMapping("/list")
@RequiresPermissions("tbcfposters:list")
@ResponseBody
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<TbCfPostersEntity> tbCfPostersList = tbCfPostersService.queryList(query);
int total = tbCfPostersService.queryTotal(query);
PageUtils pageUtil = new PageUtils(tbCfPostersList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 查看信息
*/
@RequestMapping("/info/{id}")
@RequiresPermissions("tbcfposters:info")
@ResponseBody
public R info(@PathVariable("id") String id) {
TbCfPostersEntity tbCfPosters = tbCfPostersService.queryObject(id);
return R.ok().put("tbCfPosters", tbCfPosters);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("tbcfposters:save")
@ResponseBody
public R save(@RequestBody TbCfPostersEntity tbCfPosters) {
tbCfPostersService.save(tbCfPosters);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("tbcfposters:update")
@ResponseBody
public R update(@RequestBody TbCfPostersEntity tbCfPosters) {
tbCfPostersService.update(tbCfPosters);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("tbcfposters:delete")
@ResponseBody
public R delete(@RequestBody String[] ids) {
tbCfPostersService.deleteBatch(ids);
return R.ok();
}
/**
* 查看所有列表
*/
@RequestMapping("/queryAll")
@ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) {
List<TbCfPostersEntity> list = tbCfPostersService.queryList(params);
return R.ok().put("list", list);
}
}
package com.platform.dao;
import com.platform.entity.TbCfPostersEntity;
/**
* Dao
*
* @author lipengjun
* @date 2020-03-01 16:45:10
*/
public interface TbCfPostersDao extends BaseDao<TbCfPostersEntity> {
}
package com.platform.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 首页海报实体
* 表名 tb_cf_posters
*
* @author lipengjun
* @date 2020-03-01 16:59:28
*/
public class TbCfPostersEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 海报ID
*/
private String id;
/**
* 标题
*/
private String postersTitle;
/**
* 类型 0:不跳转,1:商品 2:分类 3:
*/
private Integer postersType;
/**
* 图片
*/
private String postersPicture;
/**
* 是否展示
*/
private Integer isShow;
/**
* 跳转链接
*/
private String redirectUrl;
/**
* 备注
*/
private String remark;
/**
* 设置:海报ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:海报ID
*/
public String getId() {
return id;
}
/**
* 设置:标题
*/
public void setPostersTitle(String postersTitle) {
this.postersTitle = postersTitle;
}
/**
* 获取:标题
*/
public String getPostersTitle() {
return postersTitle;
}
/**
* 设置:类型 0:不跳转,1:商品 2:分类 3:
*/
public void setPostersType(Integer postersType) {
this.postersType = postersType;
}
/**
* 获取:类型 0:不跳转,1:商品 2:分类 3:
*/
public Integer getPostersType() {
return postersType;
}
/**
* 设置:图片
*/
public void setPostersPicture(String postersPicture) {
this.postersPicture = postersPicture;
}
/**
* 获取:图片
*/
public String getPostersPicture() {
return postersPicture;
}
/**
* 设置:是否展示
*/
public void setIsShow(Integer isShow) {
this.isShow = isShow;
}
/**
* 获取:是否展示
*/
public Integer getIsShow() {
return isShow;
}
/**
* 设置:跳转链接
*/
public void setRedirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
}
/**
* 获取:跳转链接
*/
public String getRedirectUrl() {
return redirectUrl;
}
/**
* 设置:备注
*/
public void setRemark(String remark) {
this.remark = remark;
}
/**
* 获取:备注
*/
public String getRemark() {
return remark;
}
}
package com.platform.service;
import com.platform.entity.TbCfPostersEntity;
import java.util.List;
import java.util.Map;
/**
* Service接口
*
* @author lipengjun
* @date 2020-03-01 16:45:10
*/
public interface TbCfPostersService {
/**
* 根据主键查询实体
*
* @param id 主键
* @return 实体
*/
TbCfPostersEntity queryObject(String id);
/**
* 分页查询
*
* @param map 参数
* @return list
*/
List<TbCfPostersEntity> queryList(Map<String, Object> map);
/**
* 分页统计总数
*
* @param map 参数
* @return 总数
*/
int queryTotal(Map<String, Object> map);
/**
* 保存实体
*
* @param tbCfPosters 实体
* @return 保存条数
*/
int save(TbCfPostersEntity tbCfPosters);
/**
* 根据主键更新实体
*
* @param tbCfPosters 实体
* @return 更新条数
*/
int update(TbCfPostersEntity tbCfPosters);
/**
* 根据主键删除
*
* @param id
* @return 删除条数
*/
int delete(String id);
/**
* 根据主键批量删除
*
* @param ids
* @return 删除条数
*/
int deleteBatch(String[] ids);
}
package com.platform.service.impl;
import com.platform.dao.TbCfPostersDao;
import com.platform.entity.TbCfPostersEntity;
import com.platform.service.TbCfPostersService;
import com.platform.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* Service实现类
*
* @author lipengjun
* @date 2020-03-01 16:45:10
*/
@Service("tbCfPostersService")
public class TbCfPostersServiceImpl implements TbCfPostersService {
@Autowired
private TbCfPostersDao tbCfPostersDao;
@Override
public TbCfPostersEntity queryObject(String id) {
return tbCfPostersDao.queryObject(id);
}
@Override
public List<TbCfPostersEntity> queryList(Map<String, Object> map) {
return tbCfPostersDao.queryList(map);
}
@Override
public int queryTotal(Map<String, Object> map) {
return tbCfPostersDao.queryTotal(map);
}
@Override
public int save(TbCfPostersEntity tbCfPosters) {
tbCfPosters.setId(IdUtil.createIdbyUUID());
return tbCfPostersDao.save(tbCfPosters);
}
@Override
public int update(TbCfPostersEntity tbCfPosters) {
return tbCfPostersDao.update(tbCfPosters);
}
@Override
public int delete(String id) {
return tbCfPostersDao.delete(id);
}
@Override
public int deleteBatch(String[] ids) {
return tbCfPostersDao.deleteBatch(ids);
}
}
<?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="com.platform.dao.TbCfPostersDao">
<resultMap type="com.platform.entity.TbCfPostersEntity" id="tbCfPostersMap">
<result property="id" column="id"/>
<result property="postersTitle" column="posters_title"/>
<result property="postersType" column="posters_type"/>
<result property="postersPicture" column="posters_picture"/>
<result property="isShow" column="is_show"/>
<result property="redirectUrl" column="redirect_url"/>
<result property="remark" column="remark"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.TbCfPostersEntity">
select
`id`,
`posters_title`,
`posters_type`,
`posters_picture`,
`is_show`,
`redirect_url`,
`remark`
from tb_cf_posters
where id = #{id}
</select>
<select id="queryList" resultType="com.platform.entity.TbCfPostersEntity">
select
`id`,
`posters_title`,
`posters_type`,
`posters_picture`,
`is_show`,
`redirect_url`,
`remark`
from tb_cf_posters
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from tb_cf_posters
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert id="save" parameterType="com.platform.entity.TbCfPostersEntity">
insert into tb_cf_posters(
`id`,
`posters_title`,
`posters_type`,
`posters_picture`,
`is_show`,
`redirect_url`,
`remark`)
values(
#{id},
#{postersTitle},
#{postersType},
#{postersPicture},
#{isShow},
#{redirectUrl},
#{remark})
</insert>
<update id="update" parameterType="com.platform.entity.TbCfPostersEntity">
update tb_cf_posters
<set>
<if test="postersTitle != null">`posters_title` = #{postersTitle}, </if>
<if test="postersType != null">`posters_type` = #{postersType}, </if>
<if test="postersPicture != null">`posters_picture` = #{postersPicture}, </if>
<if test="isShow != null">`is_show` = #{isShow}, </if>
<if test="redirectUrl != null">`redirect_url` = #{redirectUrl}, </if>
<if test="remark != null">`remark` = #{remark}</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete from tb_cf_posters where id = #{value}
</delete>
<delete id="deleteBatch">
delete from tb_cf_posters where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
<title>首页海报</title>
#parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak style="height: calc(100% - 15px);">
<div v-show="showList" style="height: 100%;">
<Row :gutter="16">
<div class="search-group">
<i-col span="4">
<i-input v-model="q.name" @on-enter="query" placeholder="名称"/>
</i-col>
<i-button @click="query">查询</i-button>
<i-button @click="reloadSearch">重置</i-button>
</div>
<div class="buttons-group">
#if($shiro.hasPermission("tbcfposters:save"))
<i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>
#end
#if($shiro.hasPermission("tbcfposters:update"))
<i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>
#end
#if($shiro.hasPermission("tbcfposters:delete"))
<i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
#end
</div>
</Row>
<table id="jqGrid"></table>
</div>
<Card v-show="!showList">
<p slot="title">{{title}}</p>
<i-form ref="formValidate" :model="tbCfPosters" :rules="ruleValidate" :label-width="80">
<Form-item label="标题" prop="postersTitle">
<i-input v-model="tbCfPosters.postersTitle" placeholder="标题"/>
</Form-item>
<Form-item label="类型" prop="postersType">
<i-input v-model="tbCfPosters.postersType" placeholder="类型"/>
</Form-item>
<!--<Form-item label="图片" prop="postersPicture">
<i-input v-model="tbCfPosters.postersPicture" placeholder="图片"/>
</Form-item>-->
<Form-item label="图片" prop="postersPicture">
<img v-bind:src="tbCfPosters.postersPicture" v-show="!!tbCfPosters.postersPicture"/>
<input type="file" placeholder="图片" @change="tirggerFile($event)"/>
</Form-item>
<Form-item label="是否展示" prop="isShow">
<i-input v-model="tbCfPosters.isShow" placeholder="是否展示"/>
</Form-item>
<Form-item label="跳转链接" prop="redirectUrl">
<i-input v-model="tbCfPosters.redirectUrl" placeholder="跳转链接"/>
</Form-item>
<Form-item label="备注" prop="remark">
<i-input v-model="tbCfPosters.remark" placeholder="备注"/>
</Form-item>
<Form-item>
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
<i-button type="warning" @click="reload" style="margin-left: 8px"/>
返回</i-button>
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
</Form-item>
</i-form>
</Card>
</div>
<script src="${rc.contextPath}/js/sys/tbcfposters.js?_${date.systemTime}"></script>
</body>
</html>
\ No newline at end of file
$(function () {
$("#jqGrid").Grid({
url: '../tbcfposters/list',
colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: '标题', name: 'postersTitle', index: 'posters_title', width: 80},
{label: '类型', name: 'postersType', index: 'posters_type', width: 80},
{label: '图片', name: 'postersPicture', index: 'posters_picture', width: 80, formatter: imageFormat},
{label: '是否展示', name: 'isShow', index: 'is_show', width: 80},
{label: '跳转链接', name: 'redirectUrl', index: 'redirect_url', width: 80},
{label: '备注', name: 'remark', index: 'remark', width: 80}]
});
});
let vm = new Vue({
el: '#rrapp',
data: {
showList: true,
title: null,
tbCfPosters: {},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
q: {
name: ''
}
},
methods: {
query: function () {
vm.reload();
},
add: function () {
vm.showList = false;
vm.title = "新增";
vm.tbCfPosters = {};
},
update: function (event) {
let id = getSelectedRow("#jqGrid");
if (id == null) {
return;
}
vm.showList = false;
vm.title = "修改";
vm.getInfo(id);
},
saveOrUpdate: function (event) {
let url = vm.tbCfPosters.id == null ? "../tbcfposters/save" : "../tbcfposters/update";
Ajax.request({
url: url,
params: JSON.stringify(vm.tbCfPosters),
type: "POST",
contentType: "application/json",
successCallback: function (r) {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
del: function (event) {
let ids = getSelectedRows("#jqGrid");
if (ids == null){
return;
}
confirm('确定要删除选中的记录?', function () {
Ajax.request({
url: "../tbcfposters/delete",
params: JSON.stringify(ids),
type: "POST",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
});
},
getInfo: function(id){
Ajax.request({
url: "../tbcfposters/info/"+id,
async: true,
successCallback: function (r) {
vm.tbCfPosters = r.tbCfPosters;
}
});
},
reload: function (event) {
vm.showList = true;
let page = $("#jqGrid").jqGrid('getGridParam', 'page');
$("#jqGrid").jqGrid('setGridParam', {
postData: {'name': vm.q.name},
page: page
}).trigger("reloadGrid");
vm.handleReset('formValidate');
},
reloadSearch: function() {
vm.q = {
name: ''
};
vm.reload();
},
handleSubmit: function (name) {
handleSubmitValidate(this, name, function () {
vm.saveOrUpdate()
});
},
handleReset: function (name) {
handleResetForm(this, name);
},
tirggerFile: function (event) {
var file = event.target.files[0];
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: "../api/upload/image/",
type: "POST",
data: formData,
cache: false, //不设置缓存
processData: false, // 不处理数据
contentType: false,// 不设置内容类型
success: function (result) {
result = JSON.parse(result);
//console.log(result)
if (result.errno == 0) {//成功
vm.tbCfPosters.postersPicture = result.data;
vm.$forceUpdate();
} else {
iview.Message.error(result.errmsg);
}
}
});
}
}
});
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论