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

modify the function of paging the noticeType

This commit is contained in:
cccccyb
2023-05-28 18:21:46 +08:00
parent e6e9ce9965
commit 10d3d0e4e8
12 changed files with 194 additions and 86 deletions

View File

@@ -7,12 +7,13 @@ import com.cfive.pinnacle.entity.common.ResponseCode;
import com.cfive.pinnacle.entity.common.ResponseResult; import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.service.INoticeReceiveService; import com.cfive.pinnacle.service.INoticeReceiveService;
import com.cfive.pinnacle.service.INoticeService; import com.cfive.pinnacle.service.INoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
@@ -26,6 +27,7 @@ import java.util.List;
@RestController @RestController
@RequestMapping("/notice") @RequestMapping("/notice")
@CrossOrigin @CrossOrigin
@Slf4j
public class NoticeController { public class NoticeController {
@Autowired @Autowired
private INoticeService noticeService; private INoticeService noticeService;
@@ -34,7 +36,6 @@ public class NoticeController {
//根据公告id查公告信息及发布人 //根据公告id查公告信息及发布人
@GetMapping("/{nid}") @GetMapping("/{nid}")
@PreAuthorize("hasAuthority('notice:manage:get')")
public ResponseResult<Notice> selectByNoticeId(@PathVariable Long nid) { public ResponseResult<Notice> selectByNoticeId(@PathVariable Long nid) {
Notice noticeById = noticeService.selectByNoticeId(nid); Notice noticeById = noticeService.selectByNoticeId(nid);
Integer code = noticeById != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR; Integer code = noticeById != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
@@ -44,7 +45,6 @@ public class NoticeController {
//查询所有公告或模糊查询 //查询所有公告或模糊查询
@GetMapping @GetMapping
@PreAuthorize("hasAuthority('notice:manage:get')")
public ResponseResult<List<Notice>> 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; List<Notice> noticeList;
if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) { if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) {
@@ -60,7 +60,6 @@ public class NoticeController {
//根据登录用户id查询所接收的公告 //根据登录用户id查询所接收的公告
@GetMapping("/self") @GetMapping("/self")
@PreAuthorize("hasAuthority('notice:self:get')")
public ResponseResult<List<Notice>> selectByUserId(Integer readStatus) { public ResponseResult<List<Notice>> selectByUserId(Integer readStatus) {
List<Notice> noticesByUserId = noticeReceiveService.selectByUserId(readStatus); List<Notice> noticesByUserId = noticeReceiveService.selectByUserId(readStatus);
Integer code = noticesByUserId != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR; Integer code = noticesByUserId != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
@@ -70,9 +69,8 @@ public class NoticeController {
//修改登录用户所接收公告的阅读状态 //修改登录用户所接收公告的阅读状态
@PutMapping("/modify_notice_read") @PutMapping("/modify_notice_read")
@PreAuthorize("hasAuthority('notice:self:get')")
public ResponseResult<?> modifyNoticeIsRead(@RequestBody Notice notice) { public ResponseResult<?> modifyNoticeIsRead(@RequestBody Notice notice) {
boolean updateById = false; Boolean updateById = false;
if (null != notice) { if (null != notice) {
updateById = noticeReceiveService.modifyNoticeIsRead(notice); updateById = noticeReceiveService.modifyNoticeIsRead(notice);
} }
@@ -84,24 +82,22 @@ public class NoticeController {
//更新公告 //更新公告
@PutMapping @PutMapping
public ResponseResult<?> updateNotice(@RequestBody Notice notice) { public ResponseResult<?> updateNotice(@RequestBody Notice notice) {
boolean updateById = noticeService.updateNotice(notice); Boolean updateById = noticeService.updateNotice(notice);
String msg = updateById ? "" : "数据修改失败,请重试!"; String msg = updateById ? "" : "数据修改失败,请重试!";
return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null); return ResponseResult.build(updateById ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
} }
//修改公告置顶状态 //修改公告置顶状态
@PutMapping("/update_notice_top") @PutMapping("/update_notice_top")
@PreAuthorize("hasAuthority('notice:self:get')")
public ResponseResult<?> updateNoticeTop(@RequestBody Notice notice) { public ResponseResult<?> updateNoticeTop(@RequestBody Notice notice) {
String operationMessage = notice.getTop() == 1 ? "取消置顶" : "置顶"; String operationMessage = notice.getTop() == 1 ? "取消置顶" : "置顶";
boolean updateResult = noticeService.updateNoticeTop(notice); Boolean updateResult = noticeService.updateNoticeTop(notice);
String msg = updateResult ? "已成功" + operationMessage : operationMessage + "失败,请重试!"; String msg = updateResult ? "已成功" + operationMessage : operationMessage + "失败,请重试!";
return ResponseResult.build(updateResult ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null); return ResponseResult.build(updateResult ? ResponseCode.DATABASE_UPDATE_OK : ResponseCode.DATABASE_UPDATE_ERROR, msg, null);
} }
//添加公告 //添加公告
@PostMapping @PostMapping
@PreAuthorize("hasAuthority('notice:manage:add')")
public ResponseResult<?> addNotice(@RequestBody Notice notice) { public ResponseResult<?> addNotice(@RequestBody Notice notice) {
Boolean insertNotice = noticeService.addNotice(notice); Boolean insertNotice = noticeService.addNotice(notice);
String msg = insertNotice ? "" : "数据添加失败,请重试!"; String msg = insertNotice ? "" : "数据添加失败,请重试!";
@@ -110,19 +106,27 @@ public class NoticeController {
//删除公告 //删除公告
@DeleteMapping("/{nid}") @DeleteMapping("/{nid}")
@PreAuthorize("hasAuthority('notice:manage:modify')")
public ResponseResult<?> deleteByNoticeId(@PathVariable Long nid) { public ResponseResult<?> deleteByNoticeId(@PathVariable Long nid) {
boolean removeById = noticeService.deleteById(nid); Boolean removeById = noticeService.deleteById(nid);
String msg = removeById ? "" : "数据删除失败,请重试!"; String msg = removeById ? "" : "数据删除失败,请重试!";
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, null); return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, null);
} }
//批量删除公告
@PostMapping("/batch")
public ResponseResult<?> deleteBatchByIds(@RequestBody List<String> noticeIds){
// List<String>转List<Long>
List<Long> nIds = noticeIds.stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
Boolean deleteBatchByIds = noticeService.deleteBatchByIds(nIds);
String msg = deleteBatchByIds ? "" : "数据删除失败,请重试!";
return ResponseResult.build(deleteBatchByIds ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, null);
}
//分页查询所有公告或分页模糊查询 //分页查询所有公告或分页模糊查询
@GetMapping("/page") @GetMapping("/page")
@PreAuthorize("hasAuthority('notice:manage:get')")
public ResponseResult<List<Notice>> 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; IPage<Notice> noticePageList;
Page<?> page = new Page(); Page<Notice> page = new Page();
if (null != currentPage && null != pageSize) { if (null != currentPage && null != pageSize) {
page.setCurrent(currentPage.intValue()); page.setCurrent(currentPage.intValue());
page.setSize(pageSize.intValue()); page.setSize(pageSize.intValue());

View File

@@ -1,5 +1,7 @@
package com.cfive.pinnacle.controller; package com.cfive.pinnacle.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfive.pinnacle.entity.NoticeType; import com.cfive.pinnacle.entity.NoticeType;
import com.cfive.pinnacle.entity.common.ResponseCode; import com.cfive.pinnacle.entity.common.ResponseCode;
import com.cfive.pinnacle.entity.common.ResponseResult; import com.cfive.pinnacle.entity.common.ResponseResult;
@@ -49,6 +51,24 @@ public class NoticeTypeController {
return ResponseResult.build(code, msg, selectTypeList); return ResponseResult.build(code, msg, selectTypeList);
} }
//分页查询所有公告类型
@GetMapping("/page")
public ResponseResult<List<NoticeType>> selectPageTypeList(Integer currentPage, Integer pageSize){
Page<NoticeType> noticeTypePage=new Page<>();
if (null != currentPage && null != pageSize) {
noticeTypePage.setCurrent(currentPage.intValue());
noticeTypePage.setSize(pageSize.intValue());
} else {
// 不进行分页
noticeTypePage.setCurrent(1);
noticeTypePage.setSize(-1);
}
IPage<NoticeType> selectPageTypeList = noticeTypeService.selectPageTypeList(noticeTypePage);
Integer code = selectPageTypeList.getRecords() != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = selectPageTypeList.getRecords() != null ? String.valueOf(selectPageTypeList.getTotal()) : "数据查询失败,请重试!";
return ResponseResult.build(code, msg, selectPageTypeList.getRecords());
}
//修改公告类型启用或禁用 //修改公告类型启用或禁用
@GetMapping("/update") @GetMapping("/update")
@PreAuthorize("hasAuthority('notice:type:modify')") @PreAuthorize("hasAuthority('notice:type:modify')")

View File

@@ -23,13 +23,15 @@ public interface INoticeService extends IService<Notice> {
Boolean deleteById(Long nid); Boolean deleteById(Long nid);
Boolean deleteBatchByIds(List<Long> noticeIds);
Boolean updateNotice(Notice notice); Boolean updateNotice(Notice notice);
Boolean updateNoticeTop(Notice notice); Boolean updateNoticeTop(Notice notice);
Boolean addNotice(Notice notice); Boolean addNotice(Notice notice);
IPage<Notice> selectPageAllNotice(IPage<?> page); IPage<Notice> selectPageAllNotice(IPage<Notice> page);
IPage<Notice> selectPageByCond(IPage<?> page, String title, String type, String startTime, String endTime); IPage<Notice> selectPageByCond(IPage<Notice> page, String title, String type, String startTime, String endTime);
} }

View File

@@ -1,5 +1,6 @@
package com.cfive.pinnacle.service; package com.cfive.pinnacle.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cfive.pinnacle.entity.NoticeType; import com.cfive.pinnacle.entity.NoticeType;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
@@ -15,6 +16,8 @@ import java.util.List;
*/ */
public interface INoticeTypeService extends IService<NoticeType> { public interface INoticeTypeService extends IService<NoticeType> {
List<NoticeType> selectTypeList(); List<NoticeType> selectTypeList();
IPage<NoticeType> selectPageTypeList(IPage<NoticeType> page);
List<NoticeType> selectEnableTypeList(); List<NoticeType> selectEnableTypeList();
Boolean updateTypeEnableById(Long typeId, Integer enable); Boolean updateTypeEnableById(Long typeId, Integer enable);

View File

@@ -50,7 +50,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
} }
@Override @Override
public List<Notice> selectByCond(String title, String type, String startTime,String endTime) { public List<Notice> selectByCond(String title, String type, String startTime, String endTime) {
LocalDateTime start; LocalDateTime start;
LocalDateTime end; LocalDateTime end;
try { try {
@@ -60,27 +60,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
start = null; start = null;
end = null; end = null;
} }
// LambdaQueryWrapper<Notice> lqw_notice = new LambdaQueryWrapper<>(); List<Notice> notices = noticeMapper.selectByCond(title, type, start, end);
// LambdaQueryWrapper<NoticeType> lqw_type = new LambdaQueryWrapper<>();
// lqw_type.like(null != type, NoticeType::getName, type);
// List<NoticeType> noticeTypes = noticeTypeMapper.selectList(lqw_type);
// for (NoticeType noticeType : noticeTypes
// ) {
// lqw_notice.clear();
// lqw_notice.eq(!noticeTypes.isEmpty(), Notice::getTypeId, noticeType.getId()).like(null != title, Notice::getTitle, title);
// lqw_notice.ge(StringUtils.hasText(startTime), Notice::getSendTime, start);
// lqw_notice.le(StringUtils.hasText(endTime), Notice::getEndTime, end);
// lqw_notice.eq(Notice::getOld, 0);
// List<Notice> temp_notice = noticeMapper.selectList(lqw_notice);
// notices.addAll(temp_notice);
// }
// for (Notice n : notices
// ) {
// n.setSender(userMapper.selectById(n.getSenderId()));
// n.setNoticeType(noticeTypeMapper.selectById(n.getTypeId()));
// }
List<Notice> notices=noticeMapper.selectByCond(title, type, start, end);
return notices; return notices;
} }
@@ -89,8 +69,23 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
public Boolean deleteById(Long nid) { public Boolean deleteById(Long nid) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
lqw.eq(NoticeReceive::getNoticeId, nid); lqw.eq(NoticeReceive::getNoticeId, nid);
Boolean flag=noticeReceiveMapper.delete(lqw)>0; Boolean flag = noticeReceiveMapper.delete(lqw) > 0;
return flag&&noticeMapper.deleteById(nid) > 0; return flag && noticeMapper.deleteById(nid) > 0;
}
@Override
public Boolean deleteBatchByIds(List<Long> noticeIds) {
Boolean flag = false;
for (Long nid :
noticeIds) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
lqw.eq(NoticeReceive::getNoticeId, nid);
flag = noticeReceiveMapper.delete(lqw) > 0;
if (!flag){
break;
}
}
return flag && noticeMapper.deleteBatchIds(noticeIds) > 0;
} }
@Override @Override
@@ -114,25 +109,25 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
@Override @Override
public Boolean addNotice(Notice notice) { public Boolean addNotice(Notice notice) {
Boolean noticeFlag,noticeRecFlag=false; Boolean noticeFlag, noticeRecFlag = false;
notice.setSenderId(WebUtil.getLoginUser().getUser().getId()); notice.setSenderId(WebUtil.getLoginUser().getUser().getId());
// notice.setSenderId(1652714496280469506L); // notice.setSenderId(1652714496280469506L);
noticeFlag = noticeMapper.insert(notice)>0; noticeFlag = noticeMapper.insert(notice) > 0;
Long noticeId = notice.getId(); Long noticeId = notice.getId();
if (notice.getReceivers().size()==0){ if (notice.getReceivers().size() == 0) {
//该公告仅发布者自己可见 //该公告仅发布者自己可见
NoticeReceive noticeReceive = new NoticeReceive(); NoticeReceive noticeReceive = new NoticeReceive();
noticeReceive.setNoticeId(noticeId); noticeReceive.setNoticeId(noticeId);
noticeReceive.setUserId(WebUtil.getLoginUser().getUser().getId()); noticeReceive.setUserId(WebUtil.getLoginUser().getUser().getId());
noticeRecFlag = noticeReceiveMapper.insert(noticeReceive)>0; noticeRecFlag = noticeReceiveMapper.insert(noticeReceive) > 0;
}else { } else {
for (Long receiveId : for (Long receiveId :
notice.getReceivers()) { notice.getReceivers()) {
NoticeReceive noticeReceive = new NoticeReceive(); NoticeReceive noticeReceive = new NoticeReceive();
noticeReceive.setNoticeId(noticeId); noticeReceive.setNoticeId(noticeId);
noticeReceive.setUserId(receiveId); noticeReceive.setUserId(receiveId);
noticeRecFlag = noticeReceiveMapper.insert(noticeReceive)>0; noticeRecFlag = noticeReceiveMapper.insert(noticeReceive) > 0;
if (!noticeRecFlag){ if (!noticeRecFlag) {
break; break;
} }
} }
@@ -141,12 +136,12 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
} }
@Override @Override
public IPage<Notice> selectPageAllNotice(IPage<?> page) { public IPage<Notice> selectPageAllNotice(IPage<Notice> page) {
return noticeMapper.selectPageAllNotice(page); return noticeMapper.selectPageAllNotice(page);
} }
@Override @Override
public IPage<Notice> selectPageByCond(IPage<?> page, String title, String type, String startTime, String endTime) { public IPage<Notice> selectPageByCond(IPage<Notice> page, String title, String type, String startTime, String endTime) {
LocalDateTime start; LocalDateTime start;
LocalDateTime end; LocalDateTime end;
try { try {
@@ -156,7 +151,7 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
start = null; start = null;
end = null; end = null;
} }
return noticeMapper.selectPageByCond(page,title, type, start, end); return noticeMapper.selectPageByCond(page, title, type, start, end);
} }
} }

View File

@@ -1,8 +1,8 @@
package com.cfive.pinnacle.service.impl; package com.cfive.pinnacle.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cfive.pinnacle.entity.NoticeType; import com.cfive.pinnacle.entity.NoticeType;
import com.cfive.pinnacle.mapper.NoticeTypeMapper; import com.cfive.pinnacle.mapper.NoticeTypeMapper;
import com.cfive.pinnacle.service.INoticeTypeService; import com.cfive.pinnacle.service.INoticeTypeService;
@@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@@ -32,6 +31,13 @@ public class NoticeTypeServiceImpl extends ServiceImpl<NoticeTypeMapper, NoticeT
return noticeTypeMapper.selectList(lqw); return noticeTypeMapper.selectList(lqw);
} }
@Override
public IPage<NoticeType> selectPageTypeList(IPage<NoticeType> page) {
LambdaQueryWrapper<NoticeType> lqw = new LambdaQueryWrapper<>();
lqw.orderByDesc(NoticeType::getId);
return noticeTypeMapper.selectPage(page, lqw);
}
@Override @Override
public List<NoticeType> selectEnableTypeList() { public List<NoticeType> selectEnableTypeList() {
LambdaQueryWrapper<NoticeType> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<NoticeType> lqw = new LambdaQueryWrapper<>();

View File

@@ -1,5 +1,4 @@
<template> <template>
<el-button size="large" @click="clearFilter" type="primary">清除筛选条件</el-button>
<el-table <el-table
v-loading="loading" v-loading="loading"
element-loading-text="加载中..." element-loading-text="加载中..."
@@ -29,10 +28,11 @@
prop="title" prop="title"
label="公告标题" label="公告标题"
width="200" width="200"
:formatter="formatter"
show-overflow-tooltip show-overflow-tooltip
align="center" align="center"
/> >
<template #default="scope"> {{ formatterTitle(scope.row.title) }} </template>
</el-table-column>
<el-table-column prop="noticeType.name" label="公告类别" width="160" align="center"> <el-table-column prop="noticeType.name" label="公告类别" width="160" align="center">
<template #default="scope"> <template #default="scope">
<el-tag <el-tag
@@ -166,16 +166,16 @@ export default {
'dialogShowVisible', 'dialogShowVisible',
'noticeShowData', 'noticeShowData',
'dialogEditVisible', 'dialogEditVisible',
'hackReset' 'hackReset',
'currentPage',
'pageSize',
'multiDeleteSelection'
]) ])
}, },
emits: ['clearFilter', 'handleDeleteById'], emits: ['clearFilter', 'handleDeleteById'],
data() { data() {
return { return {
filterSenderName: [], filterSenderName: []
multipleSelection: [],
currentPage: 1,
pageSize: 5
} }
}, },
props: [], props: [],
@@ -191,14 +191,20 @@ export default {
}, },
handleSelectionChange(val) { handleSelectionChange(val) {
// val的值为所勾选行的数组对象 // val的值为所勾选行的数组对象
this.multipleSelection = val noticeStore.$patch((state) => {
state.multiDeleteSelection = val
})
}, },
clearFilter() { clearFilter() {
this.$refs.tableRef.clearFilter(['senderName']) this.$refs.tableRef.clearFilter(['senderName'])
this.$emit('clearFilter') this.$emit('clearFilter')
}, },
formatter(row) { formatterTitle(title) {
return row.title if (title.length > 10) {
return title.substring(0, 10) + ' ...'
} else {
return title
}
}, },
filterTag(value, row) { filterTag(value, row) {
return row.sender.username === value return row.sender.username === value
@@ -237,10 +243,16 @@ export default {
}, },
handleSizeChange(pageSize) { handleSizeChange(pageSize) {
// pageSize每页多少条数据 // pageSize每页多少条数据
noticeStore.$patch((state) => {
state.pageSize = pageSize
})
noticeStore.selectAllNotice(this.currentPage, parseInt(pageSize)) noticeStore.selectAllNotice(this.currentPage, parseInt(pageSize))
}, },
handleCurrentChange(currentPage) { handleCurrentChange(currentPage) {
// currentPage当前第几页 // currentPage当前第几页
noticeStore.$patch((state) => {
state.currentPage = currentPage
})
noticeStore.selectAllNotice(parseInt(currentPage), this.pageSize) noticeStore.selectAllNotice(parseInt(currentPage), this.pageSize)
} }
}, },

View File

@@ -15,7 +15,7 @@
color: '#fff' color: '#fff'
}" }"
><el-table-column type="selection" width="65" align="center" /> ><el-table-column type="selection" width="65" align="center" />
<el-table-column type="index" label="序号" width="80" align="center" /> <el-table-column type="index" label="序号" width="80" align="center" :index="indexFormat" />
<el-table-column label="类型名称" prop="name" width="500" align="center" /> <el-table-column label="类型名称" prop="name" width="500" align="center" />
<el-table-column label="是否启用" prop="enable" width="350" align="center"> <el-table-column label="是否启用" prop="enable" width="350" align="center">
<template #default="scope"> <template #default="scope">
@@ -84,8 +84,7 @@
<script lang="ts"> <script lang="ts">
import { mapState } from 'pinia' import { mapState } from 'pinia'
import { useNoticeStore, useNoticeTypeStore } from '@/store/notice' import { useNoticeTypeStore } from '@/store/notice'
const noticeStore = useNoticeStore()
const noticeTypeStore = useNoticeTypeStore() const noticeTypeStore = useNoticeTypeStore()
export default { export default {
@@ -93,6 +92,8 @@ export default {
computed: { computed: {
...mapState(useNoticeTypeStore, [ ...mapState(useNoticeTypeStore, [
'total', 'total',
'currentPage',
'pageSize',
'dialogEditTypeVisible', 'dialogEditTypeVisible',
'noticeTypeList', 'noticeTypeList',
'dataLoading', 'dataLoading',
@@ -105,8 +106,6 @@ export default {
return { return {
filterSenderName: [], filterSenderName: [],
multipleSelection: [], multipleSelection: [],
currentPage: 1,
pageSize: 5,
search: '' search: ''
} }
}, },
@@ -116,10 +115,13 @@ export default {
// val的值为所勾选行的数组对象 // val的值为所勾选行的数组对象
this.multipleSelection = val this.multipleSelection = val
}, },
indexFormat(index) {
return (this.currentPage - 1) * this.pageSize + index + 1
},
switchChang(id, value) { switchChang(id, value) {
noticeTypeStore.updateNoticeTypeEnable(id, value) noticeTypeStore.updateNoticeTypeEnable(id, value)
setTimeout(() => { setTimeout(() => {
noticeTypeStore.selectNoticeType() noticeTypeStore.selectNoticeType(this.currentPage, this.pageSize)
}, 800) }, 800)
}, },
handleOpenEditDialog(row) { handleOpenEditDialog(row) {
@@ -137,11 +139,17 @@ export default {
}, },
handleSizeChange(pageSize) { handleSizeChange(pageSize) {
// pageSize每页多少条数据 // pageSize每页多少条数据
noticeStore.selectAllNotice(this.currentPage, parseInt(pageSize)) noticeTypeStore.$patch((state) => {
state.pageSize = pageSize
})
noticeTypeStore.selectNoticeType(this.currentPage, parseInt(pageSize))
}, },
handleCurrentChange(currentPage) { handleCurrentChange(currentPage) {
// currentPage当前第几页 // currentPage当前第几页
noticeStore.selectAllNotice(parseInt(currentPage), this.pageSize) noticeTypeStore.$patch((state) => {
state.currentPage = currentPage
})
noticeTypeStore.selectNoticeType(parseInt(currentPage), this.pageSize)
}, },
submitEditForm() { submitEditForm() {
this.$refs.editForm.$refs.addTypeData.validate((valid) => { this.$refs.editForm.$refs.addTypeData.validate((valid) => {
@@ -163,7 +171,7 @@ export default {
}, },
mounted() { mounted() {
noticeTypeStore.dataLoading = true noticeTypeStore.dataLoading = true
noticeTypeStore.selectNoticeType() noticeTypeStore.selectNoticeType(1, 5)
}, },
updated() {} updated() {}
} }

View File

@@ -13,6 +13,16 @@
<icon-pinnacle-add /> </el-icon <icon-pinnacle-add /> </el-icon
>发布公告</el-button >发布公告</el-button
> >
<el-button type="primary" :size="'large'" @click="deleteBatchByIds"
><el-icon :size="SIZE_ICON_MD()" style="color: white; margin-right: 3px">
<icon-pinnacle-delete /> </el-icon
>批量删除</el-button
>
<el-button type="primary" :size="'large'" @click="getLoading"
><el-icon :size="SIZE_ICON_MD()" style="color: white; margin-right: 3px">
<icon-pinnacle-reset /> </el-icon
>刷新数据</el-button
>
<!-- 添加公告对话框--> <!-- 添加公告对话框-->
<el-dialog <el-dialog
v-model="dialogAddVisible" v-model="dialogAddVisible"
@@ -27,7 +37,7 @@
</el-dialog> </el-dialog>
<notice-manage-table <notice-manage-table
@handleDeleteById="handleDeleteById" @handleDeleteById="handleDeleteById"
@clearFilter="clearFilter" ref="manageTable"
></notice-manage-table> ></notice-manage-table>
</el-main> </el-main>
</el-container> </el-container>
@@ -118,17 +128,51 @@ export default {
state.editFlag = false state.editFlag = false
}) })
}, },
clearFilter() { getLoading() {
// this.selectAllNotice() noticeStore.loading = true
// location.reload() noticeStore.selectAllNotice(this.currentPage, this.pageSize)
this.$router.go(0) },
deleteBatchByIds() {
const multiDeleteIds = []
if (this.multiDeleteSelection.length > 0) {
for (let i = 0; i < this.multiDeleteSelection.length; i++) {
multiDeleteIds.push(this.multiDeleteSelection[i].id)
}
ElMessageBox.confirm('确定是否要批量删除?该操作将无法回退', '警告', {
confirmButtonText: '确定',
cancelButtonText: '我再想想',
type: 'warning'
})
.then(() => {
request.post('/notice/batch', multiDeleteIds).then((response) => {
if (response.data.code === 20024) {
ElMessage({
message: '删除成功.',
type: 'success'
})
noticeStore.selectAllNotice(this.currentPage, this.pageSize)
} else if (response.data.code === 20034) {
ElMessage({
message: response.data.msg,
type: 'error'
})
}
})
})
.catch(() => {})
}
} }
}, },
mounted() { mounted() {
noticeTypeStore.selectEnableNoticeType() noticeTypeStore.selectEnableNoticeType()
}, },
computed: { computed: {
...mapState(useNoticeStore, ['dialogAddVisible']) ...mapState(useNoticeStore, [
'dialogAddVisible',
'currentPage',
'pageSize',
'multiDeleteSelection'
])
} }
} }
</script> </script>

View File

@@ -61,7 +61,9 @@ export default {
'dialogEditTypeVisible', 'dialogEditTypeVisible',
'editFlag', 'editFlag',
'hackReset', 'hackReset',
'addTypeData' 'addTypeData',
'currentPage',
'pageSize'
]) ])
}, },
data() { data() {
@@ -73,7 +75,7 @@ export default {
}, },
getLoadData() { getLoadData() {
noticeTypeStore.dataLoading = true noticeTypeStore.dataLoading = true
noticeTypeStore.selectNoticeType() noticeTypeStore.selectNoticeType(this.currentPage, this.pageSize)
}, },
handleOpenAddDialog() { handleOpenAddDialog() {
noticeTypeStore.$patch((state) => { noticeTypeStore.$patch((state) => {
@@ -115,7 +117,7 @@ export default {
message: '删除成功.', message: '删除成功.',
type: 'success' type: 'success'
}) })
noticeTypeStore.selectNoticeType() noticeTypeStore.selectNoticeType(this.currentPage, this.pageSize)
} else if (response.data.code === 20034) { } else if (response.data.code === 20034) {
ElMessage({ ElMessage({
message: response.data.msg, message: response.data.msg,

View File

@@ -4,6 +4,7 @@ const noticeRouter = {
meta: { meta: {
title: '公告', title: '公告',
icon: shallowRef(IconPinnacleNotice), icon: shallowRef(IconPinnacleNotice),
requiresMenu: true,
requiresScrollbar: false, requiresScrollbar: false,
requiresPadding: true requiresPadding: true
}, },
@@ -16,6 +17,7 @@ const noticeRouter = {
meta: { meta: {
title: '公告查看', title: '公告查看',
requiresScrollbar: false, requiresScrollbar: false,
requiresMenu: true,
requiresPadding: true requiresPadding: true
}, },
children: [ children: [
@@ -42,6 +44,7 @@ const noticeRouter = {
name: 'noticeManage', name: 'noticeManage',
meta: { meta: {
title: '公告管理', title: '公告管理',
requiresMenu: true,
requiresScrollbar: false, requiresScrollbar: false,
requiresPadding: true requiresPadding: true
} }
@@ -52,6 +55,7 @@ const noticeRouter = {
name: 'noticeTypeManage', name: 'noticeTypeManage',
meta: { meta: {
title: '公告类型管理', title: '公告类型管理',
requiresMenu: true,
requiresScrollbar: false, requiresScrollbar: false,
requiresPadding: true requiresPadding: true
} }

View File

@@ -46,6 +46,8 @@ export const useNoticeStore = defineStore('notice', {
state: () => { state: () => {
return { return {
total: 0, total: 0,
pageSize: 5,
currentPage: 1,
selectData: [ selectData: [
{ {
content: '', content: '',
@@ -81,6 +83,7 @@ export const useNoticeStore = defineStore('notice', {
currentViewPage: 'All', currentViewPage: 'All',
hackReset: true, hackReset: true,
departmentList: [], departmentList: [],
multiDeleteSelection: [],
noticeShowData: { noticeShowData: {
content: '', content: '',
createTime: '', createTime: '',
@@ -225,6 +228,8 @@ export const useNoticeTypeStore = defineStore('notice_type', {
state: () => { state: () => {
return { return {
total: 0, total: 0,
pageSize: 5,
currentPage: 1,
dataLoading: true, dataLoading: true,
dialogAddTypeVisible: false, dialogAddTypeVisible: false,
dialogEditTypeVisible: false, dialogEditTypeVisible: false,
@@ -256,11 +261,14 @@ export const useNoticeTypeStore = defineStore('notice_type', {
this.enableNoticeTypeList = response.data.data this.enableNoticeTypeList = response.data.data
}) })
}, },
async selectNoticeType() { async selectNoticeType(currentPage: number, pageSize: number) {
await request.get('/notice_type').then((response) => { await request.get('/notice_type/page', { currentPage, pageSize }).then((response) => {
if (response.data.code === 20021) { if (response.data.code === 20021) {
this.noticeTypeList = response.data.data this.noticeTypeList = response.data.data
this.dataLoading = false this.total = parseInt(response.data.msg)
if (this.noticeTypeList.length !== 0) {
this.dataLoading = false
}
} else { } else {
this.dataLoading = false this.dataLoading = false
ElMessage({ ElMessage({
@@ -305,7 +313,7 @@ export const useNoticeTypeStore = defineStore('notice_type', {
}) })
} }
}) })
await this.selectNoticeType() await this.selectNoticeType(1, 5)
}, },
async handleUpdateNoticeType(updateNotice: IAddNoticeTypeData) { async handleUpdateNoticeType(updateNotice: IAddNoticeTypeData) {
await request.put('/notice_type', updateNotice).then((response) => { await request.put('/notice_type', updateNotice).then((response) => {
@@ -329,7 +337,7 @@ export const useNoticeTypeStore = defineStore('notice_type', {
}) })
} }
}) })
await this.selectNoticeType() await this.selectNoticeType(this.currentPage, this.pageSize)
} }
} }
}) })