1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-04 22:41:24 +08:00

nitice module modified query with mybatis plus linked table to xml

This commit is contained in:
cccccyb
2023-05-11 15:26:55 +08:00
parent 3c7fc85b9e
commit 1defd7ef4e
21 changed files with 498 additions and 151 deletions

View File

@@ -42,12 +42,12 @@ public class NoticeController {
//查询所有公告
@GetMapping
public ResponseResult selectAllNotice(String title, String type, String startTime,String endTime) {
public ResponseResult 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)) {
if (!StringUtils.hasText(title) && !StringUtils.hasText(type) && !StringUtils.hasText(startTime) && !StringUtils.hasText(endTime)) {
noticeList = noticeService.selectAllNotice();
} else {
noticeList = noticeService.selectByCond(title, type, startTime,endTime);
noticeList = noticeService.selectByCond(title, type, startTime, endTime);
}
int code = noticeList != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
@@ -55,6 +55,14 @@ public class NoticeController {
return ResponseResult.build(code, msg, noticeList);
}
//根据登录用户id查询所接收的公告
@GetMapping("/ByUserId")
public ResponseResult selectAllByUserId() {
List<Notice> noticesByUserId = noticeReceiveService.selectAllByUserId();
Integer code = noticesByUserId != null ? ResponseCode.DATABASE_SELECT_OK : ResponseCode.DATABASE_SELECT_ERROR;
String msg = noticesByUserId != null ? "" : "数据查询失败,请尝试!";
return ResponseResult.build(code, msg, noticesByUserId);
}
//更新公告
@PutMapping
@@ -67,19 +75,9 @@ public class NoticeController {
//添加公告
@PostMapping
public ResponseResult addNotice(@RequestBody Notice notice) {
notice.setSenderId(WebUtil.getLoginUser().getUser().getId());
boolean insertNotice = noticeService.save(notice);
Long noticeId = notice.getId();
boolean flag = false;
for (Long receiveId :
notice.getReceivers()) {
NoticeReceive noticeReceive = new NoticeReceive();
noticeReceive.setNoticeId(noticeId);
noticeReceive.setUserId(receiveId);
flag = noticeReceiveService.save(noticeReceive);
}
String msg = (insertNotice && flag) ? "" : "数据添加失败,请尝试!";
return ResponseResult.build((insertNotice && flag) ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, noticeId);
Boolean insertNotice = noticeService.addNotice(notice);
String msg = insertNotice ? "" : "数据添加失败,请尝试!";
return ResponseResult.build(insertNotice ? ResponseCode.DATABASE_SAVE_OK : ResponseCode.DATABASE_SAVE_ERROR, msg, insertNotice);
}
//删除公告
@@ -88,6 +86,6 @@ public class NoticeController {
boolean removeById = noticeService.deleteById(nid);
String msg = removeById ? "" : "数据删除失败,请尝试!";
return ResponseResult.build(removeById ? ResponseCode.DATABASE_DELETE_OK : ResponseCode.DATABASE_DELETE_ERROR, msg, removeById);
}
}

View File

@@ -128,6 +128,9 @@ public class Notice implements Serializable {
@TableField("old")
private Integer old;
@TableField(exist = false)
private Integer isRead;
@TableField("deleted")
@TableLogic
private Integer deleted;

View File

@@ -4,6 +4,8 @@ import com.cfive.pinnacle.entity.Department;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* <p>
* 部门 Mapper 接口
@@ -14,5 +16,5 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {
List<Department> getDepartAndUser();
}

View File

@@ -4,6 +4,7 @@ import com.cfive.pinnacle.entity.Notice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -19,4 +20,6 @@ public interface NoticeMapper extends BaseMapper<Notice> {
Notice selectByNoticeId(Long nid);
List<Notice> selectAllNotice();
List<Notice> selectByCond(String title, String type, LocalDateTime startTime, LocalDateTime endTime);
}

View File

@@ -1,9 +1,12 @@
package com.cfive.pinnacle.mapper;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* <p>
* 公告接收 Mapper 接口
@@ -14,5 +17,6 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface NoticeReceiveMapper extends BaseMapper<NoticeReceive> {
List<Notice> selectAllByUserId(Long userId);
}

View File

@@ -1,8 +1,11 @@
package com.cfive.pinnacle.service;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* <p>
* 公告接收 服务类
@@ -12,5 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2023-04-30
*/
public interface INoticeReceiveService extends IService<NoticeReceive> {
List<Notice> selectAllByUserId();
}

View File

@@ -23,4 +23,6 @@ public interface INoticeService extends IService<Notice> {
Boolean deleteById(Long nid);
Boolean updateNotice(Notice notice);
Boolean addNotice(Notice notice);
}

View File

@@ -29,13 +29,6 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
private UserMapper userMapper;
@Override
public List<Department> getDepartAndUser() {
List<Department> departments = departmentMapper.selectList(null);
for (Department department:
departments) {
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.eq(User::getDepartmentId, department.getId());
department.setUserList(userMapper.selectList(lqw));
}
return departments;
return departmentMapper.getDepartAndUser();
}
}

View File

@@ -1,11 +1,16 @@
package com.cfive.pinnacle.service.impl;
import com.cfive.pinnacle.entity.Notice;
import com.cfive.pinnacle.entity.NoticeReceive;
import com.cfive.pinnacle.mapper.NoticeReceiveMapper;
import com.cfive.pinnacle.service.INoticeReceiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfive.pinnacle.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 公告接收 服务实现类
@@ -16,5 +21,11 @@ import org.springframework.stereotype.Service;
*/
@Service
public class NoticeReceiveServiceImpl extends ServiceImpl<NoticeReceiveMapper, NoticeReceive> implements INoticeReceiveService {
@Autowired
private NoticeReceiveMapper noticeReceiveMapper;
@Override
public List<Notice> selectAllByUserId() {
Long userId = WebUtil.getLoginUser().getUser().getId();
return noticeReceiveMapper.selectAllByUserId(userId);
}
}

View File

@@ -11,6 +11,7 @@ import com.cfive.pinnacle.mapper.NoticeTypeMapper;
import com.cfive.pinnacle.mapper.UserMapper;
import com.cfive.pinnacle.service.INoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfive.pinnacle.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -47,56 +48,59 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
@Override
public List<Notice> selectAllNotice() {
List<Notice> notices = noticeMapper.selectAllNotice();
if (null != notices) {
for (Notice notice :
notices) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
lqw.eq(NoticeReceive::getNoticeId, notice.getId());
List<NoticeReceive> noticeReceives = noticeReceiveMapper.selectList(lqw);
List<Long> receiverIdList = new ArrayList<>();
for (NoticeReceive noticeReceive :
noticeReceives) {
receiverIdList.add(noticeReceive.getUserId());
}
notice.setReceivers(receiverIdList);
}
}
// if (null != notices) {
// for (Notice notice :
// notices) {
// LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
// lqw.eq(NoticeReceive::getNoticeId, notice.getId());
// List<NoticeReceive> noticeReceives = noticeReceiveMapper.selectList(lqw);
// List<Long> receiverIdList = new ArrayList<>();
// for (NoticeReceive noticeReceive :
// noticeReceives) {
// receiverIdList.add(noticeReceive.getUserId());
// }
// notice.setReceivers(receiverIdList);
// }
// }
return notices;
}
@Override
public List<Notice> selectByCond(String title, String type, String startTime,String endTime) {
List<Notice> notices = new ArrayList<>();
LocalDateTime start = null;
LocalDateTime end = null;
LocalDateTime start;
LocalDateTime end;
try {
start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} catch (Exception e) {
startTime = null;
endTime = null;
}
LambdaQueryWrapper<Notice> lqw_notice = new LambdaQueryWrapper<>();
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);
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()));
start = null;
end = null;
}
// LambdaQueryWrapper<Notice> lqw_notice = new LambdaQueryWrapper<>();
// 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;
}
@Override
public Boolean deleteById(Long nid) {
LambdaQueryWrapper<NoticeReceive> lqw = new LambdaQueryWrapper<>();
@@ -120,4 +124,24 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
return noticeMapper.insert(notice) > 0;
}
@Override
public Boolean addNotice(Notice notice) {
Boolean noticeFlag,noticeRecFlag=false;
// notice.setSenderId(WebUtil.getLoginUser().getUser().getId());
notice.setSenderId(1652714496280469506L);
noticeFlag = noticeMapper.insert(notice)>0;
Long noticeId = notice.getId();
for (Long receiveId :
notice.getReceivers()) {
NoticeReceive noticeReceive = new NoticeReceive();
noticeReceive.setNoticeId(noticeId);
noticeReceive.setUserId(receiveId);
noticeRecFlag = noticeReceiveMapper.insert(noticeReceive)>0;
if (!noticeRecFlag){
break;
}
}
return noticeFlag && noticeRecFlag;
}
}

View File

@@ -2,9 +2,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cfive.pinnacle.mapper.DepartmentMapper">
<select id="getDepartAndUser" resultMap="department">
select d.id,name,u.id,username from t_department d,t_user u where d.id=u.department_id and d.deleted=0 and u.deleted=0
select d.id did,name,u.id uid,username from t_department d,t_user u where d.id=u.department_id and d.deleted=0 and u.deleted=0
</select>
<resultMap id="department" type="department" autoMapping="true">
<id column="id" property="id"/>
<id column="did" property="id"/>
<collection property="userList" ofType="user" autoMapping="true">
<id column="uid" property="id"/>
<result column="uid" property="id"/>
</collection>
</resultMap>
</mapper>

View File

@@ -8,10 +8,10 @@
t_notice n,
t_notice_type type
where u.id = n.sender_id
and type.id=n.type_id
and type.id = n.type_id
and n.id = #{nid}
and n.deleted = 0
and n.old=0
and n.old = 0
</select>
<resultMap id="NoticeByIdResultMap" type="notice" autoMapping="true">
<association property="sender" javaType="user" autoMapping="true"/>
@@ -20,13 +20,9 @@
<!-- 查询所有公告 -->
<select id="selectAllNotice" resultMap="NoticeAllResultMap">
select u.id uid,
select u.id uid,
username,
passwd,
department_id,
u.deleted ude,
u.version uve,
n.id nid,
n.id nid,
title,
content,
type_id,
@@ -38,37 +34,62 @@
top,
modify_time,
origin_id,
old,
n.deleted nde,
n.version nve,
type.id typeId,
type.id typeId,
name,
type.enable,
type.deleted typeDe,
type.version typeVe
from t_user u,
t_notice n,
t_notice_type type
where u.id = n.sender_id
and type.id = n.type_id
and n.deleted = 0
type.enable
from t_notice n
left join t_notice_type type on n.type_id = type.id
left join t_user u on n.sender_id = u.id
where n.deleted = 0
and n.old = 0
order by create_time desc
</select>
<resultMap id="NoticeAllResultMap" type="notice" autoMapping="true">
<id property="id" column="nid"/>
<result property="deleted" column="nde"/>
<result property="version" column="nve"/>
<association property="sender" javaType="user" autoMapping="true">
<id property="id" column="uid"/>
<result property="deleted" column="ude"/>
<result property="version" column="uve"/>
</association>
<association property="noticeType" javaType="noticeType" autoMapping="true">
<id property="id" column="typeId"/>
<result property="deleted" column="typeDe"/>
<result property="version" column="typeVe"/>
</association>
</resultMap>
<!-- 模糊查询-->
<!-- 模糊查询-->
<select id="selectByCond" resultMap="NoticeAllResultMap">
select u.id uid,
username,
n.id nid,
title,
content,
type_id,
sender_id,
create_time,
send_time,
end_time,
priority,
top,
modify_time,
origin_id,
type.id typeId,
type.name,
type.enable
from t_notice n
left join t_notice_type type on n.type_id = type.id
left join t_user u on n.sender_id = u.id
<where>
<if test="null!=title and title!=''">
and instr(title,#{title})&gt;0
</if>
<if test="null!=type and type!=''">
and instr(type.name,#{type})&gt;0
</if>
<if test="null!=startTime">
and send_time &gt;= #{startTime}
</if>
<if test="null !=endTime">
and end_time &lt; #{endTime}
</if>
and n.deleted = 0
and n.old = 0
</where>
</select>
</mapper>

View File

@@ -1,5 +1,40 @@
<?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.cfive.pinnacle.mapper.NoticeReceiveMapper">
<select id="selectAllByUserId" parameterType="Long" resultMap="selectAllMap">
select u.id uid,
username,
n.id nid,
title,
content,
type_id,
sender_id,
create_time,
send_time,
end_time,
priority,
top,
modify_time,
origin_id,
type.id typeId,
name,
type.enable,
notice_receive.id receiveId,
notice_receive.already_read receiveRead
from t_notice_receive notice_receive
left join t_notice n on n.id = notice_receive.notice_id
left join t_notice_type type on type.id = n.type_id
left join t_user u on n.sender_id = u.id
where notice_receive.user_id=#{userId}
</select>
<resultMap id="selectAllMap" type="notice" autoMapping="true">
<id property="id" column="nid"/>
<result property="isRead" column="receiveRead"/>
<association property="noticeType" javaType="noticeType" autoMapping="true">
<id property="id" column="typeId"/>
</association>
<association property="sender" javaType="user" autoMapping="true">
<id property="id" column="uid"/>
</association>
</resultMap>
</mapper>

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cfive.pinnacle.controller.NoticeController;
import com.cfive.pinnacle.entity.*;
import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.mapper.NoticeMapper;
import com.cfive.pinnacle.service.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +20,8 @@ public class NoticeTest {
@Autowired
private NoticeController noticeController;
@Autowired
private NoticeMapper noticeMapper;
@Autowired
private INoticeService iNoticeService;
@Autowired
private INoticeTypeService iNoticeTypeService;
@@ -48,7 +51,7 @@ public class NoticeTest {
@Test
void insertNoticeTest() {
for (int i = 20; i < 40; i++) {
for (int i = 11; i < 40; i++) {
Notice notice = new Notice();
notice.setTitle("title" + i);
notice.setTypeId(1654069011361476609L);
@@ -59,7 +62,7 @@ public class NoticeTest {
notice.setSendTime(sendTime);
notice.setEndTime(endTime);
notice.setContent("Content" + i);
noticeController.addNotice(notice);
noticeMapper.insert(notice);
}
}
@@ -86,7 +89,7 @@ public class NoticeTest {
@Test
void insertNoticeRecTest() {
NoticeReceive receive = new NoticeReceive();
receive.setNoticeId(1654070031407886338L);
receive.setNoticeId(1655408487006437377L);
receive.setUserId(1652714496280469506L);
iNoticeReceiveService.save(receive);
}

View File

@@ -111,7 +111,7 @@ export default {
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
],
typeId: [
{ type:'array',required: true, message: '请选择公告类型', trigger: 'change' }
{ required: true, message: '请选择公告类型', trigger: 'change' }
],
sendTime: [
{ type: 'date', required: true, message: '请选择生效时间', trigger: 'change' }
@@ -167,12 +167,16 @@ export default {
}
if (this.noticeEdit) {
this.addData = this.noticeEdit
// 判断是否置顶
this.addData.top=this.noticeEdit.top===1;
console.log(this.addData)
}
},
updated() {
if (this.noticeEdit) {
this.addData = this.noticeEdit
// 判断是否置顶
this.addData.top=this.noticeEdit.top===1;
console.log(this.addData)
}
},

View File

@@ -65,7 +65,6 @@ export default {
return SIZE_ICON_MD
},
selectByCondition() {
console.log(this.timeRang)
if (!_.isEmpty(this.timeRang)) {
this.search_info.startTime = this.handleDateFormatUTC(this.timeRang[0])
this.search_info.endTime = this.handleDateFormatUTC(this.timeRang[1])

View File

@@ -6,7 +6,7 @@
>清除筛选条件
</el-button>
<el-table
v-loading="getLoading"
v-loading="loading"
element-loading-text="加载中..."
ref="tableRef"
:data="selectData"
@@ -27,7 +27,7 @@
:formatter="formatter"
show-overflow-tooltip
/>
<el-table-column prop="noticeType.name" label="公告类别" width="180">
<el-table-column prop="noticeType.name" label="公告类别" width="150">
<template #default="scope">
<el-tag
size="default"
@@ -38,7 +38,7 @@
</el-tag>
</template>
</el-table-column>
<el-table-column prop="priority" label="优先级" width="180" />
<el-table-column prop="priority" label="优先级" width="100" />
<el-table-column
prop="createTime"
label="创建时间"
@@ -77,7 +77,7 @@
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作">
<el-table-column label="操作" width="200">
<template #default="scope">
<el-button size="small" color="#626aef" @click="handleShow(scope.$index, scope.row)"
>查看
@@ -124,7 +124,7 @@ export default {
getLoading: true
}
},
props: ['noticeTypeList', 'selectData', 'departmentList', 'dialogUpdateVisible', 'getLoading'],
props: ['noticeTypeList', 'selectData', 'departmentList', 'dialogUpdateVisible', 'loading'],
methods: {
clearFilter() {
this.$refs.tableRef.clearFilter(['senderName'])
@@ -163,6 +163,7 @@ export default {
},
mounted() {},
updated() {
this.$refs.tableRef.clearFilter(['senderName'])
this.filterSenderName = []
const nameArray = []
for (let i = 0; i < this.selectData.length; i++) {

View File

@@ -0,0 +1,161 @@
<template>
<el-button
size="large"
@click="clearFilter"
style="background-color: rgba(71, 138, 173, 0.85); color: white"
>清除筛选条件
</el-button>
<el-table
v-loading="getLoading"
element-loading-text="加载中..."
ref="tableRef"
:data="selectData"
style="width: 100%"
border
highlight-current-row
:header-cell-style="{
background: 'darksalmon',
'text-align': 'center',
color: '#fff',
'font-size': '20px'
}"
>
<el-table-column
prop="title"
label="公告标题"
width="180"
:formatter="formatter"
show-overflow-tooltip
/>
<el-table-column prop="noticeType.name" label="公告类别" width="150">
<template #default="scope">
<el-tag
size="default"
:type="scope.row.noticeType.name === '通知公告' ? 'warning' : 'success'"
disable-transitions
>
{{ scope.row.noticeType.name }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="priority" label="优先级" width="100" />
<el-table-column prop="isRead" label="公告状态" width="180">
<template #default="scope">
<el-tag
size="large"
:type="scope.row.isRead === 0 ? 'danger' : 'success'"
disable-transitions
>
{{ scope.row.isRead === 0 ? '未读' : '已读' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
prop="sendTime"
label="生效时间"
sortable
width="180"
:formatter="formatDate"
/>
<el-table-column
prop="endTime"
label="失效时间"
sortable
width="180"
:formatter="formatDate"
/>
<el-table-column
prop="sender.username"
label="发布人"
width="100"
column-key="senderName"
:filters="filterSenderName"
:filter-method="filterTag"
filter-placement="bottom-end"
>
<template #default="scope">
<el-tag
:type="scope.row.sender.username === 'cyb' ? '' : 'success'"
disable-transitions
>{{ scope.row.sender.username }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="200">
<template #default="scope">
<el-button size="small" color="#626aef" @click="handleShow(scope.$index, scope.row)"
>查看
</el-button>
<el-button size="small" type="danger" @click="modifyStatus(scope.row)"
>标记为{{ scope.row.isRead === 0 ? '已读' : '未读' }}
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 查看会话框-->
<el-dialog v-model="dialogShowVisible" center>
<template #header>
<h2 style="color: red">查看公告</h2>
</template>
<notice-show-dialog @showDialogVisible="showDialogVisible" :noticeShow="noticeShow" />
</el-dialog>
</template>
<script lang="ts">
export default {
data() {
return {
filterSenderName: [],
dialogShowVisible: false,
noticeShow: {}
}
},
props: ['selectData', 'getLoading'],
methods: {
clearFilter() {
this.$refs.tableRef.clearFilter(['senderName'])
this.$emit('clearFilter')
},
formatter(row, column) {
return row.title
},
filterTag(value, row) {
return row.sender.username === value
},
formatDate(row, column) {
// 获取单元格数据
const data = row[column.property]
if (data == null) return null
return new Date(data).toLocaleString()
},
modifyStatus(row) {},
handleShow(index, row) {
this.dialogShowVisible = true
this.noticeShow = row
},
showDialogVisible(visible) {
this.dialogShowVisible = visible
}
},
mounted() {},
updated() {
this.$refs.tableRef.clearFilter(['senderName'])
this.filterSenderName = []
const nameArray = []
for (let i = 0; i < this.selectData.length; i++) {
nameArray.push(this.selectData[i].sender.username)
}
const newArr = nameArray.filter((item, i, arr) => {
return arr.indexOf(item) === i
})
for (let j = 0; j < newArr.length; j++) {
const senderName = { text: '', value: '' }
senderName.text = newArr[j]
senderName.value = newArr[j]
this.filterSenderName.push(senderName)
}
}
}
</script>
<style scoped></style>

View File

@@ -1,40 +1,38 @@
<template>
<div class="notice-home-layout">
<el-container>
<el-header>
<notice-head @selectByCond="selectByCond"></notice-head>
</el-header>
<el-main>
<el-button
size="large"
style="background-color: rgba(71, 138, 173, 0.85); color: white"
@click="dialogAddVisible = true"
>发布公告</el-button
>
<!-- 添加公告对话框-->
<el-dialog v-model="dialogAddVisible" center>
<template #header>
<h2 style="color: red">发布公告</h2>
</template>
<commitForm
:noticeTypeList="this.noticeTypeList"
:departmentList="this.departmentList"
@handleAddNotice="handleAddNotice"
></commitForm>
</el-dialog>
<notice-table
:selectData="selectData"
:noticeTypeList="noticeTypeList"
:departmentList="departmentList"
:dialogUpdateVisible="dialogUpdateVisible"
:getLoading="getLoading"
@handleDelete="handleDelete"
@clearFilter="clearFilter"
@handleUpdateNotice="handleUpdateNotice"
></notice-table>
</el-main>
</el-container>
</div>
<el-container>
<el-header>
<notice-head @selectByCond="selectByCond"></notice-head>
</el-header>
<el-main>
<el-button
size="large"
style="background-color: rgba(71, 138, 173, 0.85); color: white"
@click="openAddNoticeDialog"
>发布公告</el-button
>
<!-- 添加公告对话框-->
<el-dialog v-model="dialogAddVisible" center>
<template #header>
<h2 style="color: red">发布公告</h2>
</template>
<commitForm
:noticeTypeList="this.noticeTypeList"
:departmentList="this.departmentList"
@handleAddNotice="handleAddNotice"
></commitForm>
</el-dialog>
<notice-manage-table
:selectData="selectData"
:noticeTypeList="noticeTypeList"
:departmentList="departmentList"
:dialogUpdateVisible="dialogUpdateVisible"
:loading="loading"
@handleDelete="handleDelete"
@clearFilter="clearFilter"
@handleUpdateNotice="handleUpdateNotice"
></notice-manage-table>
</el-main>
</el-container>
</template>
<script lang="ts">
@@ -52,7 +50,7 @@ export default {
dialogAddVisible: false,
dialogUpdateVisible: false,
departmentList: [],
getLoading: true
loading: true
}
},
methods: {
@@ -83,7 +81,7 @@ export default {
request.get('http://localhost:8621/notice').then((response) => {
this.selectData = response.data.data
if (this.selectData) {
this.getLoading = false
this.loading = false
}
})
},
@@ -122,6 +120,11 @@ export default {
this.departmentList = response.data.data
})
},
openAddNoticeDialog() {
this.dialogAddVisible = true
this.selectNoticeType()
this.selectDepartment()
},
handleAddNotice(addFormData) {
request.post('http://localhost:8621/notice', addFormData).then((response) => {
if (response.data.code === 20022) {
@@ -164,21 +167,16 @@ export default {
},
mounted() {
this.selectAllNotice()
this.selectNoticeType()
this.selectDepartment()
}
}
</script>
<style scoped>
.el-container {
}
.el-header {
background-color: #fff;
//border: #9e9e9e solid 1px;
}
.el-main {
padding: 0px;
padding: 0;
margin-top: 20px;
}
</style>

View File

@@ -0,0 +1,56 @@
<template>
<el-container>
<el-header>
<notice-head></notice-head>
</el-header>
<el-main>
<el-menu
:default-active="activeIndex"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
>
<el-menu-item index="1">所有公告</el-menu-item>
<el-menu-item index="2">已读</el-menu-item>
<el-menu-item index="3"><a href="#">未读</a></el-menu-item>
</el-menu>
<notice-view-table
:selectData="selectData"
:getLoading="getLoading"
></notice-view-table>
</el-main>
</el-container>
</template>
<script lang="ts">
import request from '@/services'
export default {
name: 'NoticeView',
data() {
return {
activeIndex: '1',
selectData: [],
getLoading: true
}
},
methods: {
handleSelect(key, keyPath) {
console.log(key, keyPath)
},
selectAllNoticeByUserId() {
request.get('http://localhost:8621/notice/ByUserId').then((response) => {
this.selectData = response.data.data
if (this.selectData) {
this.getLoading = false
}
})
}
},
mounted() {
this.selectAllNoticeByUserId()
}
}
</script>
<style scoped></style>

View File

@@ -180,7 +180,29 @@ const router = createRouter({
icon: shallowRef(IconPinnacleSetting),
requiresScrollbar: false,
requiresPadding: true
}
},
children: [
{
path: 'noticeManage',
component: async () => await import('@/pages/notice/NoticeManage.vue'),
name: 'noticeManage',
meta: {
title: '公告管理',
requiresScrollbar: false,
requiresPadding: true
}
},
{
path: 'noticeView',
component: async () => await import('@/pages/notice/NoticeView.vue'),
name: 'noticeView',
meta: {
title: '公告查看',
requiresScrollbar: false,
requiresPadding: true
}
}
]
}
]
},