parent
b3db580bc8
commit
6fcebea344
@ -0,0 +1,37 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
//添加待办分类
|
||||||
|
export function addTodoCategory(data) {
|
||||||
|
return request({
|
||||||
|
url: '/warning/todo/category/add',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询所有待办分类
|
||||||
|
export function list() {
|
||||||
|
return request({
|
||||||
|
url: '/warning/todo/category/list',
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//删除待办分类
|
||||||
|
export function removeTodoCategory(id) {
|
||||||
|
return request({
|
||||||
|
url: `/warning/todo/category/remove/${id}`,
|
||||||
|
method: 'delete',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//修改待办分类
|
||||||
|
export function editTodoCategory(data) {
|
||||||
|
return request({
|
||||||
|
url: `/warning/todo/category/edit`,
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,182 @@
|
|||||||
|
<template>
|
||||||
|
|
||||||
|
<div class="app-container">
|
||||||
|
<at-card style="width: 100%;">
|
||||||
|
<h2 slot="title">待办分类</h2>
|
||||||
|
<div slot="extra">
|
||||||
|
<at-button icon="icon-user-plus" @click="openDialog">添加分类</at-button>
|
||||||
|
</div>
|
||||||
|
<div v-for="(data,index) in dataList"
|
||||||
|
style="width: 100%;height: 50px;border:1px solid #ffba00;margin-bottom: 10px;padding: 10px;border-radius: 6px">
|
||||||
|
<div style="float: left;font-size: 16px;font-weight: 800;margin-left: 20px;" :style="data.color">
|
||||||
|
{{ data.name }}
|
||||||
|
</div>
|
||||||
|
<div style="float: right">
|
||||||
|
<at-button-group>
|
||||||
|
<at-button @click="queryDialog(data)">修改</at-button>
|
||||||
|
<at-button type="error" hollow @click="removeTodoCategory(data.id)">删除</at-button>
|
||||||
|
</at-button-group>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</at-card>
|
||||||
|
|
||||||
|
<el-dialog
|
||||||
|
title="添加分类"
|
||||||
|
:visible.sync="dialogVisible"
|
||||||
|
@close="closeDialog"
|
||||||
|
width="20%"
|
||||||
|
>
|
||||||
|
<el-form :model="form" :rules="rules" ref="ruleForm" label-width="80px">
|
||||||
|
<el-form-item label="分类名称" prop="name">
|
||||||
|
<el-input v-model="form.name"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="分类排序" prop="sort">
|
||||||
|
<el-slider
|
||||||
|
v-model.number="form.sort"
|
||||||
|
show-input>
|
||||||
|
</el-slider>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="分类颜色" prop="color">
|
||||||
|
<el-color-picker v-model="form.color"></el-color-picker>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
</el-form>
|
||||||
|
<span slot="footer" class="dialog-footer">
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
<el-button type="primary" :loading=buttonLoading @click="submitForm('ruleForm')">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {addTodoCategory, editTodoCategory, list, removeTodoCategory} from "@/api/business/todo/todoCategory";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "TodoCategory",
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
dialogVisible: false,
|
||||||
|
dataList: [],
|
||||||
|
|
||||||
|
form: {
|
||||||
|
name: '',
|
||||||
|
sort: 0,
|
||||||
|
color: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
buttonLoading: false,
|
||||||
|
|
||||||
|
rules: {
|
||||||
|
name: [
|
||||||
|
{required: true, message: '请输入分类名称', trigger: 'blur'},
|
||||||
|
{min: 1, max: 5, message: '长度在 1 到 5 个字符', trigger: 'blur'}
|
||||||
|
],
|
||||||
|
sort: [
|
||||||
|
{required: true, message: '请输入分类排序', trigger: 'blur'},
|
||||||
|
],
|
||||||
|
color: [
|
||||||
|
{required: true, message: '请输入分类颜色', trigger: 'blur'},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
this.list()
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
//打开对话框
|
||||||
|
openDialog() {
|
||||||
|
this.dialogVisible = true
|
||||||
|
this.form = {color: '#789456', sort: 0}
|
||||||
|
},
|
||||||
|
|
||||||
|
//修改打开对话框
|
||||||
|
queryDialog(data) {
|
||||||
|
this.dialogVisible = true
|
||||||
|
this.form = data
|
||||||
|
//转换颜色
|
||||||
|
if (this.form.color) {
|
||||||
|
let split = this.form.color.split(':');
|
||||||
|
let colorSplit = split[1].split("\"");
|
||||||
|
this.form.color = colorSplit[0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
list() {
|
||||||
|
list().then(res => {
|
||||||
|
this.dataList = res.data
|
||||||
|
//颜色赋值
|
||||||
|
this.dataList.forEach(data => {
|
||||||
|
data.color = "color:" + data.color + ""
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
submitForm(formName) {
|
||||||
|
this.$refs[formName].validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
|
this.buttonLoading = true
|
||||||
|
|
||||||
|
if (this.form) {
|
||||||
|
//修改
|
||||||
|
editTodoCategory(this.form).then(res => {
|
||||||
|
this.$Message.success('修改成功')
|
||||||
|
this.list()
|
||||||
|
this.buttonLoading = false
|
||||||
|
this.dialogVisible = false
|
||||||
|
}).catch(err => {
|
||||||
|
this.buttonLoading = false
|
||||||
|
this.$Message.error('修改失败')
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//添加
|
||||||
|
addTodoCategory(this.form).then(res => {
|
||||||
|
this.$Message.success('添加成功')
|
||||||
|
this.list()
|
||||||
|
this.buttonLoading = false
|
||||||
|
this.dialogVisible = false
|
||||||
|
}).catch(err => {
|
||||||
|
this.buttonLoading = false
|
||||||
|
this.$Message.error('添加失败')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
//删除
|
||||||
|
removeTodoCategory(id) {
|
||||||
|
removeTodoCategory(id).then(res => {
|
||||||
|
this.$Message.success('删除成功')
|
||||||
|
this.list()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
//关闭对话框
|
||||||
|
closeDialog() {
|
||||||
|
this.list()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "TodoList"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.xjs.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.xjs.domain.todo.TodoCategory;
|
||||||
|
import com.xjs.service.TodoCateGoryService;
|
||||||
|
import com.xjs.validation.group.AddGroup;
|
||||||
|
import com.xjs.validation.group.UpdateGroup;
|
||||||
|
import com.xjs.web.MyBaseController;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待办控制器
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-28
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("todo")
|
||||||
|
@Api(tags = "业务模块-待办事项")
|
||||||
|
public class TodoController extends MyBaseController<TodoCategory> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TodoCateGoryService todoCateGoryService;
|
||||||
|
|
||||||
|
@PostMapping("category/add")
|
||||||
|
@ApiOperation("添加待办分类")
|
||||||
|
@RequiresPermissions("todo:category:add")
|
||||||
|
@Log(title = "添加待办分类", businessType = BusinessType.INSERT)
|
||||||
|
public AjaxResult addTodoCategory(@RequestBody @Validated(AddGroup.class) TodoCategory todoCategory) {
|
||||||
|
return toAjax(todoCateGoryService.save(todoCategory));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("category/list")
|
||||||
|
@ApiOperation("查询所有待办分类")
|
||||||
|
@RequiresPermissions("todo:category:list")
|
||||||
|
public AjaxResult listTodoCategory() {
|
||||||
|
LambdaQueryWrapper<TodoCategory> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.orderByDesc(TodoCategory::getSort);
|
||||||
|
return AjaxResult.success(todoCateGoryService.list(wrapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("category/remove/{id}")
|
||||||
|
@ApiOperation("删除待办分类")
|
||||||
|
@RequiresPermissions("todo:category:remove")
|
||||||
|
@Log(title = "删除待办分类", businessType = BusinessType.DELETE)
|
||||||
|
public AjaxResult removeTodoCategory(@PathVariable String id) {
|
||||||
|
return toAjax(todoCateGoryService.removeById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("category/edit")
|
||||||
|
@ApiOperation("修改待办分类")
|
||||||
|
@RequiresPermissions("todo:category:edit")
|
||||||
|
@Log(title = "修改待办分类", businessType = BusinessType.UPDATE)
|
||||||
|
public AjaxResult editTodoCategory(@RequestBody @Validated(UpdateGroup.class) TodoCategory todoCategory) {
|
||||||
|
return toAjax(todoCateGoryService.updateById(todoCategory));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.xjs.domain.todo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.xjs.entity.BaseEntity;
|
||||||
|
import com.xjs.validation.group.AddGroup;
|
||||||
|
import com.xjs.validation.group.UpdateGroup;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待办分类实体类
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-28
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class TodoCategory extends BaseEntity implements Serializable {
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "分类名称不能为空", groups = {UpdateGroup.class, AddGroup.class})
|
||||||
|
@Size(max = 5, message = "请控制分类名称长度在 5 字符", groups = {UpdateGroup.class, AddGroup.class})
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 颜色
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "颜色不能为空", groups = {UpdateGroup.class, AddGroup.class})
|
||||||
|
@Size(max = 10, message = "请控制分类名称长度在 10 字符", groups = {UpdateGroup.class, AddGroup.class})
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
@NotNull(message = "排序不能为空", groups = {UpdateGroup.class, AddGroup.class})
|
||||||
|
@Max(value = 100, message = "排序范围在 0 - 100 ", groups = {UpdateGroup.class, AddGroup.class})
|
||||||
|
private Long sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.xjs.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.xjs.domain.todo.TodoCategory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待办事项mapper
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-28
|
||||||
|
*/
|
||||||
|
public interface TodoCategoryMapper extends BaseMapper<TodoCategory> {
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.xjs.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.xjs.domain.todo.TodoCategory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待办事项service接口
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-28
|
||||||
|
*/
|
||||||
|
public interface TodoCateGoryService extends IService<TodoCategory> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.xjs.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.xjs.domain.todo.TodoCategory;
|
||||||
|
import com.xjs.exception.BusinessException;
|
||||||
|
import com.xjs.mapper.TodoCategoryMapper;
|
||||||
|
import com.xjs.service.TodoCateGoryService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待办事项service接口实现
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-28
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TodoCateGoryServiceImpl extends ServiceImpl<TodoCategoryMapper, TodoCategory> implements TodoCateGoryService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public boolean save(TodoCategory entity) {
|
||||||
|
this.hasExist(entity);
|
||||||
|
return super.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public boolean updateById(TodoCategory entity) {
|
||||||
|
//顺序不能乱
|
||||||
|
boolean b = super.updateById(entity);
|
||||||
|
this.hasExist(entity);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查数据库是否存在该数据
|
||||||
|
*
|
||||||
|
* @param entity 实体类
|
||||||
|
*/
|
||||||
|
private void hasExist(TodoCategory entity) {
|
||||||
|
LambdaQueryWrapper<TodoCategory> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TodoCategory::getName, entity.getName());
|
||||||
|
List<TodoCategory> categoryList = super.list(wrapper);
|
||||||
|
//根据id判断是添加还是修改
|
||||||
|
if (entity.getId() != null) {
|
||||||
|
if (CollUtil.isNotEmpty(categoryList) && categoryList.size() > 1) {
|
||||||
|
throw new BusinessException("已存在" + entity.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (CollUtil.isNotEmpty(categoryList)) {
|
||||||
|
throw new BusinessException("已存在" + entity.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue