1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 15:01:23 +08:00

add the function of deleteNoticeType and modify the router of notice.ts

This commit is contained in:
cccccyb
2023-05-25 01:27:57 +08:00
parent c060a762af
commit 16325f21de
10 changed files with 243 additions and 165 deletions

View File

@@ -35,7 +35,7 @@ public class NoticeController {
//根据公告id查公告信息及发布人
@GetMapping("/{nid}")
public ResponseResult selectByNoticeId(@PathVariable Long nid) {
public ResponseResult<Notice> selectByNoticeId(@PathVariable Long nid) {
Notice noticeById = noticeService.selectByNoticeId(nid);
Integer code = noticeById != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = noticeById != null ? "" : "数据查询失败,请重试!";
@@ -44,7 +44,7 @@ public class NoticeController {
//查询所有公告或模糊查询
@GetMapping
public ResponseResult selectAllNotice(String title, String type, String startTime, String endTime) {
public ResponseResult<List<Notice>> selectAllNotice(String title, String type, String startTime, String endTime) {
List<Notice> noticeList;
if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) {
noticeList = noticeService.selectAllNotice();
@@ -59,7 +59,7 @@ public class NoticeController {
//根据登录用户id查询所接收的公告
@GetMapping("/self")
public ResponseResult selectByUserId(Integer readStatus) {
public ResponseResult<List<Notice>> selectByUserId(Integer readStatus) {
List<Notice> noticesByUserId = noticeReceiveService.selectByUserId(readStatus);
Integer code = noticesByUserId != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = noticesByUserId != null ? "" : "数据查询失败,请重试!";
@@ -68,52 +68,52 @@ public class NoticeController {
//修改登录用户所接收公告的阅读状态
@PutMapping("/modify_notice_read")
public ResponseResult modifyNoticeIsRead(@RequestBody Notice notice) {
public ResponseResult<?> modifyNoticeIsRead(@RequestBody Notice notice) {
boolean updateById = false;
if (null != notice) {
updateById = noticeReceiveService.modifyNoticeIsRead(notice);
}
String msg = updateById ? "" : "服务器出错,请重试!";
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, updateById);
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
}
//更新公告
@PutMapping
public ResponseResult updateNotice(@RequestBody Notice notice) {
public ResponseResult<?> updateNotice(@RequestBody Notice notice) {
boolean updateById = noticeService.updateNotice(notice);
String msg = updateById ? "" : "数据修改失败,请重试!";
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, updateById);
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
}
//修改公告置顶状态
@PutMapping("/update_notice_top")
public ResponseResult updateNoticeTop(@RequestBody Notice notice) {
public ResponseResult<?> updateNoticeTop(@RequestBody Notice notice) {
String operationMessage = notice.getTop() == 1 ? "取消置顶" : "置顶";
boolean updateResult = noticeService.updateNoticeTop(notice);
String msg = updateResult ? "已成功" + operationMessage : operationMessage + "失败,请重试!";
return ResponseResult.build(updateResult ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, updateResult);
return ResponseResult.build(updateResult ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
}
//添加公告
@PostMapping
public ResponseResult addNotice(@RequestBody Notice notice) {
public ResponseResult<?> addNotice(@RequestBody Notice notice) {
Boolean insertNotice = noticeService.addNotice(notice);
String msg = insertNotice ? "" : "数据添加失败,请重试!";
return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, insertNotice);
return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg,null);
}
//删除公告
@DeleteMapping("/{nid}")
public ResponseResult deleteByNoticeId(@PathVariable Long nid) {
public ResponseResult<?> deleteByNoticeId(@PathVariable Long nid) {
boolean removeById = noticeService.deleteById(nid);
String msg = removeById ? "" : "数据删除失败,请重试!";
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, removeById);
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, null);
}
//分页查询所有公告或分页模糊查询
@GetMapping("/page")
public ResponseResult selectPageAllNotice(Integer currentPage, Integer pageSize, String title, String type, String startTime, String endTime) {
public ResponseResult<List<Notice>> selectPageAllNotice(Integer currentPage, Integer pageSize, String title, String type, String startTime, String endTime) {
IPage<Notice> noticePageList;
Page<?> page = new Page();
if (null != currentPage && null != pageSize) {

View File

@@ -32,7 +32,7 @@ public class NoticeTypeController {
//查询已启用的公告类型
@GetMapping("/enable")
public ResponseResult selectEnableTypeList(){
public ResponseResult<List<NoticeType>> selectEnableTypeList(){
List<NoticeType> selectTypeName = noticeTypeService.selectEnableTypeList();
Integer code = selectTypeName != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = selectTypeName != null ? "" : "数据查询失败,请重试!";
@@ -41,7 +41,7 @@ public class NoticeTypeController {
//查询所有公告类型
@GetMapping
public ResponseResult selectTypeList(){
public ResponseResult<List<NoticeType>> selectTypeList(){
List<NoticeType> selectTypeList = noticeTypeService.selectTypeList();
Integer code = selectTypeList != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = selectTypeList != null ? "" : "数据查询失败,请重试!";
@@ -50,14 +50,14 @@ public class NoticeTypeController {
//修改公告类型启用或禁用
@GetMapping("/update")
public ResponseResult updateTypeEnableById(String typeId,Integer enable){
public ResponseResult<?> updateTypeEnableById(String typeId,Integer enable){
Long tid=null;
if (StringUtils.hasText(typeId)){
tid = Long.parseLong(typeId);
}
Boolean updateEnableById = noticeTypeService.updateTypeEnableById(tid, enable);
String msg = updateEnableById ? "" : "修改失败,请重试!";
return ResponseResult.build(updateEnableById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, updateEnableById);
return ResponseResult.build(updateEnableById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
}
//添加公告类型
@@ -67,4 +67,20 @@ public class NoticeTypeController {
String msg = insertNotice ? "" : "数据添加失败,请重试!";
return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, insertNotice);
}
//修改公告类型
@PutMapping
public ResponseResult<?> updateNoticeType(@RequestBody NoticeType noticeType){
boolean updateById =noticeTypeService.updateNoticeType(noticeType);
String msg = updateById ? "" : "数据修改失败,请重试!";
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
}
//删除公告类型
@DeleteMapping("/{typeId}")
public ResponseResult<?> deleteNoticeTypeById(@PathVariable Long typeId) {
boolean removeById = noticeTypeService.deleteNoticeTypeById(typeId);
String msg = removeById ? "" : "数据删除失败,请重试!";
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, null);
}
}

View File

@@ -21,4 +21,9 @@ public interface INoticeTypeService extends IService<NoticeType> {
Boolean addNoticeType(NoticeType noticeType);
Boolean updateNoticeType(NoticeType noticeType);
Boolean deleteNoticeTypeById(Long typeId);
}

View File

@@ -54,4 +54,14 @@ public class NoticeTypeServiceImpl extends ServiceImpl<NoticeTypeMapper, NoticeT
public Boolean addNoticeType(NoticeType noticeType) {
return noticeTypeMapper.insert(noticeType)>0;
}
@Override
public Boolean updateNoticeType(NoticeType noticeType) {
return noticeTypeMapper.updateById(noticeType)>0;
}
@Override
public Boolean deleteNoticeTypeById(Long typeId) {
return noticeTypeMapper.deleteById(typeId)>0;
}
}

View File

@@ -1,5 +1,6 @@
<template>
<el-form :model="addData" :rules="rules" ref="addData" label-width="150px">
<el-scrollbar max-height="60vh">
<el-form :model="addData" :rules="this.myRule" ref="addData" label-width="150px">
<el-form-item label="公告标题" prop="title">
<el-input v-model="addData.title"></el-input>
</el-form-item>
@@ -54,7 +55,13 @@
/>
</el-form-item>
<el-form-item label="公告优先级" prop="priority">
<el-slider v-model="addData.priority" show-input show-stops :max="15" size="large" />
<el-slider
v-model="addData.priority"
show-input
show-stops
:max="15"
size="large"
/>
</el-form-item>
<el-form-item label="是否仅自己可见:">
<el-switch v-model="visible" inline-prompt active-text="是" inactive-text="否" />
@@ -75,7 +82,8 @@
>
<template #default="scope">
<span v-if="scope.node.level === 1">{{
((scope.node.value = scope.data.id), (scope.node.label = scope.data.name))
((scope.node.value = scope.data.id),
(scope.node.label = scope.data.name))
}}</span>
<span v-if="scope.node.level === 2">{{
((scope.node.value = scope.data.id),
@@ -93,21 +101,23 @@
<el-button @click="resetForm()">重置</el-button>
</el-form-item>
</el-form>
</el-scrollbar>
</template>
<script lang="js">
<script lang="ts">
import { useNoticeStore, useNoticeTypeStore } from '@/store/notice'
import { mapState } from 'pinia'
const noticeStore = useNoticeStore()
export default {
computed:{
...mapState(useNoticeStore,['departmentList','noticeShowData']),
...mapState(useNoticeTypeStore,['enableNoticeTypeList'])
computed: {
...mapState(useNoticeStore, ['departmentList', 'noticeShowData']),
...mapState(useNoticeTypeStore, ['enableNoticeTypeList'])
},
data() {
return {
visible:false,
rightClickVisible:false,
visible: false,
rightClickVisible: false,
addData: {
title: '',
typeId: '',
@@ -116,70 +126,70 @@ export default {
top: 0,
priority: 1,
content: '',
receivers:[]
receivers: []
},
rules: {
myRule: {
title: [
{ required: true, message: '请输入公告标题', trigger: 'blur' },
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
],
typeId: [
{ required: true, message: '请选择公告类型', trigger: 'change' }
],
typeId: [{ required: true, message: '请选择公告类型', trigger: 'change' }],
sendTime: [
{ type: 'date', required: true, message: '请选择生效时间', trigger: 'change' }
],
endTime: [
{ type: 'date', required: true, message: '请选择失效时间', trigger: 'change' }
],
content: [
{ required: true, message: '请填写公告内容', trigger: 'blur' }
],
content: [{ required: true, message: '请填写公告内容', trigger: 'blur' }],
receivers: [
{ type:'array',required: true, message: '请选择公告接收者', trigger: 'change' }
{
type: 'array',
required: true,
message: '请选择公告接收者',
trigger: 'change'
}
]
}
}
},
methods: {
submitForm() {
const receiveId=[]
if (this.addData.receivers.length!=null){
const receiveId = []
if (this.addData.receivers.length != null) {
for (let i = 0; i < this.addData.receivers.length; i++) {
receiveId.push(this.addData.receivers[i][1])
}
}
this.addData.receivers=receiveId
this.addData.receivers = receiveId
this.$refs.addData.validate((valid) => {
if (valid) {
if (noticeStore.editFlag===true){
if (noticeStore.editFlag === true) {
// 编辑操作
noticeStore.handleUpdateNotice(this.addData)
}else {
} else {
// 添加操作
noticeStore.handleAddNotice(this.addData)
}
} else {
return false;
return false
}
});
})
},
closeForm(){
noticeStore.$patch(state=>{
state.dialogAddVisible=false
state.dialogEditVisible=false
state.hackReset=false
state.editFlag=false
closeForm() {
noticeStore.$patch((state) => {
state.dialogAddVisible = false
state.dialogEditVisible = false
state.hackReset = false
state.editFlag = false
})
},
resetForm() {
this.$refs.addData.resetFields();
this.$refs.addData.resetFields()
}
},
created() {
// 编辑操作
if (noticeStore.editFlag===true) {
if (noticeStore.editFlag === true) {
this.addData = noticeStore.noticeShowData
}
},
@@ -192,15 +202,19 @@ export default {
.el-button {
margin: 0 auto;
}
.el-button--text {
margin-right: 15px;
}
.el-select {
width: 300px;
}
.el-input {
width: 300px;
}
.el-slider {
margin-left: 20px;
}

View File

@@ -38,7 +38,7 @@
<el-button size="default" type="primary" @click="handleOpenEditDialog(scope.row)"
>编辑</el-button
>
<el-button size="default" type="danger" @click="handleDeleteById(scope.row)"
<el-button size="default" type="danger" @click="deleteTypeById(scope.row.id)"
>删除</el-button
>
</template>
@@ -89,6 +89,7 @@ const noticeStore = useNoticeStore()
const noticeTypeStore = useNoticeTypeStore()
export default {
emits: ['deleteTypeById'],
computed: {
...mapState(useNoticeTypeStore, [
'total',
@@ -124,14 +125,15 @@ export default {
handleOpenEditDialog(row) {
noticeTypeStore.$patch((state) => {
state.hackReset = true
state.showTypeData.id = row.id
state.showTypeData.name = row.name
state.showTypeData.enable = row.enable
state.editFlag = true
state.dialogEditTypeVisible = true
})
},
handleDeleteById(deleteId) {
this.$emit('handleDeleteById', deleteId)
deleteTypeById(deleteId) {
this.$emit('deleteTypeById', deleteId)
},
handleSizeChange(pageSize) {
// pageSize每页多少条数据
@@ -144,7 +146,7 @@ export default {
submitEditForm() {
this.$refs.editForm.$refs.addTypeData.validate((valid) => {
if (valid) {
// noticeTypeStore.handleUpdateNoticeType(this.addTypeData)
noticeTypeStore.handleUpdateNoticeType(this.addTypeData)
} else {
return false
}

View File

@@ -40,7 +40,7 @@
</el-dialog>
</el-header>
<el-main>
<notice-type-table />
<notice-type-table @deleteTypeById="deleteTypeById" />
</el-main>
</el-container>
</template>
@@ -48,6 +48,8 @@
import { SIZE_ICON_MD } from '@/constants/Common.constants'
import { useNoticeTypeStore } from '@/store/notice'
import { mapState } from 'pinia'
import { ElMessage, ElMessageBox } from 'element-plus'
import request from '@/services'
const noticeTypeStore = useNoticeTypeStore()
@@ -99,6 +101,30 @@ export default {
},
resetForm() {
this.$refs.addForm.$refs.addTypeData.resetFields()
},
deleteTypeById(typeId) {
ElMessageBox.confirm('确定是否要删除?该操作将无法回退', '警告', {
confirmButtonText: '确定',
cancelButtonText: '我再想想',
type: 'warning'
})
.then(() => {
request.delete('/notice_type/' + typeId).then((response) => {
if (response.data.code === 20024) {
ElMessage({
message: '删除成功.',
type: 'success'
})
noticeTypeStore.selectNoticeType()
} else if (response.data.code === 20034) {
ElMessage({
message: response.data.msg,
type: 'error'
})
}
})
})
.catch(() => {})
}
},
mounted() {}

View File

@@ -5,9 +5,9 @@
</el-header>
<el-main>
<el-menu :default-active="$route.path" class="el-menu-demo" mode="horizontal" router>
<el-menu-item index="/notice/noticeView/all">所有公告</el-menu-item>
<el-menu-item index="/notice/noticeView/toRead">未读</el-menu-item>
<el-menu-item index="/notice/noticeView/alRead">已读</el-menu-item>
<el-menu-item index="/notice/view/all">所有公告</el-menu-item>
<el-menu-item index="/notice/view/toRead">未读</el-menu-item>
<el-menu-item index="/notice/view/alRead">已读</el-menu-item>
</el-menu>
<router-view />
</el-main>

View File

@@ -4,30 +4,17 @@ const noticeRouter = {
meta: {
title: '公告',
icon: shallowRef(IconPinnacleNotice),
requiresMenu: true,
requiresScrollbar: false,
requiresPadding: true
},
children: [
{
path: 'noticeManage',
component: async () => await import('@/pages/notice/NoticeManage.vue'),
name: 'noticeManage',
meta: {
title: '公告管理',
requiresMenu: true,
requiresScrollbar: false,
requiresPadding: true
}
},
{
path: 'noticeView',
path: 'view',
component: async () => await import('@/pages/notice/NoticeView.vue'),
name: 'noticeView',
redirect: '/notice/noticeView/all',
redirect: '/notice/view/all',
meta: {
title: '公告查看',
requiresMenu: true,
requiresScrollbar: false,
requiresPadding: true
},
@@ -50,12 +37,21 @@ const noticeRouter = {
]
},
{
path: 'noticeTypeManage',
path: 'manage',
component: async () => await import('@/pages/notice/NoticeManage.vue'),
name: 'noticeManage',
meta: {
title: '公告管理',
requiresScrollbar: false,
requiresPadding: true
}
},
{
path: 'typeManage',
component: async () => await import('@/pages/notice/NoticeTypeManage.vue'),
name: 'noticeTypeManage',
meta: {
title: '公告类型管理',
requiresMenu: true,
requiresScrollbar: false,
requiresPadding: true
}

View File

@@ -13,6 +13,7 @@ export interface IAddNoticeData {
receivers: []
}
export interface IAddNoticeTypeData {
id: string
name: string
enable: number
}
@@ -238,10 +239,12 @@ export const useNoticeTypeStore = defineStore('notice_type', {
}
],
addTypeData: {
id: '',
name: '',
enable: 1
},
showTypeData: {
id: '',
name: '',
enable: 1
}
@@ -309,6 +312,12 @@ export const useNoticeTypeStore = defineStore('notice_type', {
if (response.data.code === 20023) {
this.dialogEditTypeVisible = false
this.editFlag = false
this.hackReset = false
this.addTypeData = {
id: '',
name: '',
enable: 1
}
ElMessage({
message: '修改成功.',
type: 'success'