From 990e8cf2957c1fcdc692f14134f5b8881868e494 Mon Sep 17 00:00:00 2001 From: Connor <9174814+connorxia618@user.noreply.gitee.com> Date: Thu, 8 Jul 2021 13:51:06 +0800 Subject: [PATCH] =?UTF-8?q?Notice=20=E5=86=8D=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/DataFilter/Entity/FilterInfo.cs | 1 + .../Service/Notice/SysNoticeService.cs | 8 ++- web-react/src/pages/system/notice/form.jsx | 1 - web-react/src/pages/system/notice/index.jsx | 25 ++++--- .../src/pages/system/noticeReceived/form.jsx | 65 ++++++++++++++++- .../src/pages/system/noticeReceived/index.jsx | 53 ++++++++------ .../src/views/main/_layout/header/notice.jsx | 71 ++++++++++++++++++- 7 files changed, 186 insertions(+), 38 deletions(-) diff --git a/Api/Ewide.Core/Extension/DataFilter/Entity/FilterInfo.cs b/Api/Ewide.Core/Extension/DataFilter/Entity/FilterInfo.cs index a7087be..42b1d2d 100644 --- a/Api/Ewide.Core/Extension/DataFilter/Entity/FilterInfo.cs +++ b/Api/Ewide.Core/Extension/DataFilter/Entity/FilterInfo.cs @@ -34,6 +34,7 @@ namespace Ewide.Core.Extension.DataFilter.Entity /// public void SetSearchInfo(SearchInfo[] searchInfo, IEnumerable filterFields) { + if (searchInfo == null) return; try { foreach (var elem in searchInfo) diff --git a/Api/Ewide.Core/Service/Notice/SysNoticeService.cs b/Api/Ewide.Core/Service/Notice/SysNoticeService.cs index dba5165..b182d18 100644 --- a/Api/Ewide.Core/Service/Notice/SysNoticeService.cs +++ b/Api/Ewide.Core/Service/Notice/SysNoticeService.cs @@ -232,7 +232,7 @@ WHERE SNU.UserId = @UserId AND SN.Status = @Status"; }, new[] { - "Type","Title" + "Type","Title","ReadStatus" } ); @@ -254,8 +254,10 @@ WHERE SNU.UserId = @UserId AND SN.Status = @Status"; [HttpGet("/sysNotice/unread")] public async Task GetUnreadCount() { - var noticeList = await _sysNoticeRep.Where(u => u.Status != (int)NoticeStatus.DELETED).Select(s => s.Id).ToListAsync(); - return await _sysNoticeUserRep.Where(u => u.UserId == _userManager.UserId && noticeList.Contains(u.NoticeId) && u.ReadStatus == (int)NoticeUserStatus.UNREAD).CountAsync(); + //删除 或者 草稿都不让显示 + var noticeList = await _sysNoticeRep.Where(u => u.Status != (int)NoticeStatus.DELETED&& u.Status != (int)NoticeStatus.DRAFT).Select(s => s.Id).ToListAsync(); + var noticeUserList = await _sysNoticeUserRep.Where(u => u.UserId == _userManager.UserId && noticeList.Contains(u.NoticeId) && u.ReadStatus == (int)NoticeUserStatus.UNREAD).ToListAsync(); + return noticeUserList.Count(); } /// diff --git a/web-react/src/pages/system/notice/form.jsx b/web-react/src/pages/system/notice/form.jsx index b4ae8fc..13c8fe4 100644 --- a/web-react/src/pages/system/notice/form.jsx +++ b/web-react/src/pages/system/notice/form.jsx @@ -139,7 +139,6 @@ export default class form extends Component { */ async getData() { const form = this.form.current - console.log(this.record) const valid = await form.validateFields() if (valid) { const postData = form.getFieldsValue() diff --git a/web-react/src/pages/system/notice/index.jsx b/web-react/src/pages/system/notice/index.jsx index 555fe0e..0f43dfa 100644 --- a/web-react/src/pages/system/notice/index.jsx +++ b/web-react/src/pages/system/notice/index.jsx @@ -56,28 +56,38 @@ export default class index extends Component { { title: '标题', dataIndex: 'title', + width: 300, + sorter: true, }, { title: '发布人', dataIndex: 'publicUserName', + width: 120, + sorter: true, }, { title: '发布时间', dataIndex: 'createdTime', + width: 150, + sorter: true, }, { title: '发布单位', dataIndex: 'publicOrgName', - width: 200, + width: 150, + sorter: true, }, { title: '类型', dataIndex: 'type', + width: 120, + sorter: true, render: text => this.bindCodeValue(text, 'notice_type'), }, { title: '状态', dataIndex: 'status', + width: 120, render: text => this.bindCodeValue(text, 'notice_status'), }, ] @@ -94,7 +104,7 @@ export default class index extends Component { if (flag) { this.columns.push({ title: '操作', - width: 150, + width: 200, dataIndex: 'actions', render: (text, record) => ( @@ -178,6 +188,7 @@ export default class index extends Component { }) }) } + subUniqueKey(text, index) { return text.substr(index, 5) } @@ -252,26 +263,23 @@ export default class index extends Component { * @param {*} id */ onDelete(id) { - this.onAction(apiAction.Status({ id, Status: 3 }), '删除成功') + this.onAction(apiAction.Status({ id, status: 3 }), '删除成功') } /** * 发布 * @param {*} id */ onPublish(id) { - this.onAction(apiAction.Status({ id, Status: 1 }), '发布成功') + this.onAction(apiAction.Status({ id, status: 1 }), '发布成功') } /** * 撤回 * @param {*} id */ onGoBack(id) { - this.onAction(apiAction.Status({ id, Status: 2 }), '撤回成功') + this.onAction(apiAction.Status({ id, status: 2 }), '撤回成功') } // - //#region 自定义方法 - //#endregion - render() { const { codes } = this.state return ( @@ -280,7 +288,6 @@ export default class index extends Component { record.id} autoLoad={false} loadData={this.loadData} columns={this.columns} diff --git a/web-react/src/pages/system/noticeReceived/form.jsx b/web-react/src/pages/system/noticeReceived/form.jsx index e4d73c9..44465b1 100644 --- a/web-react/src/pages/system/noticeReceived/form.jsx +++ b/web-react/src/pages/system/noticeReceived/form.jsx @@ -1,15 +1,18 @@ import React, { Component } from 'react' -import { Spin, Divider, Modal, Row } from 'antd' +import { Spin, Divider, Modal, Row, Form, Upload } from 'antd' import { api } from 'common/api' import { AntIcon } from 'components' +import { BlobToBase64, GetFileName, PreviewFile } from 'util/file' export default class form extends Component { state = { detailVisible: false, detailLoading: false, detailData: {}, + fileValue: false, } + filedu = React.createRef() /** * mount后回调 */ @@ -20,12 +23,57 @@ export default class form extends Component { async onOpenDetail(id) { this.setState({ detailLoading: true, detailVisible: true }) const { data } = await api.sysNoticeDetail({ id }) + this.setState({ detailLoading: false, detailData: data, + fileValue: false, }) + + if (data) { + const { attachments } = data + if (attachments) { + const fileValue = [] + const fileList = attachments.split(',') + for (const fileId of fileList) { + try { + const file = await PreviewFile(fileId) + const base64 = await BlobToBase64(file) + fileValue.push({ + uid: fileId, + response: fileId, + name: file.name, + url: base64, + status: 'done', + }) + } catch { + const { data: file } = await api.sysFileInfoDetail({ id: fileId }) + fileValue.push({ + uid: fileId, + response: '文件已丢失', + name: file.fileOriginName, + status: 'error', + }) + } + } + this.setState({ + fileValue, + }) + } + } } + async onFileDownload(file) { + const { data, headers } = await api.sysFileInfoDownload({ id: file.response }) + const url = window.URL.createObjectURL(data) + const fileName = GetFileName(headers['content-disposition']) + const a = document.createElement('a') + a.href = url + a.download = fileName + a.click() + window.URL.revokeObjectURL(url) + a.remove() + } render() { const { detailLoading, detailVisible, detailData } = this.state return ( @@ -43,6 +91,21 @@ export default class form extends Component { dangerouslySetInnerHTML={{ __html: detailData.content }} > + {this.state.fileValue && ( + + + 查看附件 + this.onFileDownload(file)} + > + + + )} + 发布人:{detailData.publicUserName} 发布时间:{detailData.publicTime} diff --git a/web-react/src/pages/system/noticeReceived/index.jsx b/web-react/src/pages/system/noticeReceived/index.jsx index 3c5452f..d4b580f 100644 --- a/web-react/src/pages/system/noticeReceived/index.jsx +++ b/web-react/src/pages/system/noticeReceived/index.jsx @@ -20,6 +20,7 @@ export default class index extends Component { codes: { noticeStatus: [], noticeType: [], + readStatus: [], }, } @@ -33,25 +34,39 @@ export default class index extends Component { { title: '标题', dataIndex: 'title', + width: 300, + sorter: true, }, { title: '发布人', dataIndex: 'publicUserName', + width: 150, + sorter: true, }, { title: '发布时间', dataIndex: 'createdTime', + width: 200, + sorter: true, }, { title: '发布单位', dataIndex: 'publicOrgName', width: 200, + sorter: true, }, { title: '类型', dataIndex: 'type', + width: 120, render: text => this.bindCodeValue(text, 'notice_type'), }, + { + title: '已读未读', + dataIndex: 'readStatus', + width: 120, + render: text => this.bindCodeValue(text, 'read_status'), + }, ] /** @@ -94,33 +109,13 @@ export default class index extends Component { componentDidMount() { const { onLoading, onLoadData } = this.table.current onLoading() - getDictData('notice_status', 'notice_type').then(codes => { + getDictData('notice_status', 'notice_type', 'read_status').then(codes => { this.setState({ codes }, () => { onLoadData() }) }) } - /** - * 对表格上的操作进行统一处理 - * [异步] - * @param {*} action - * @param {*} successMessage - */ - async onAction(action, successMessage) { - const { onLoading, onLoaded, onReloadData } = this.table.current - onLoading() - try { - if (action) { - await action - } - if (successMessage) { - Message.success(successMessage) - } - onReloadData() - } catch { - onLoaded() - } - } + /** * 调用加载数据接口,可在调用前对query进行处理 * [异步,必要] @@ -134,6 +129,7 @@ export default class index extends Component { queryType: { type: QueryType.Equal, title: QueryType.Like, + readStatus: QueryType.Equal, }, }) @@ -200,6 +196,19 @@ export default class index extends Component { ))} + + + } /> diff --git a/web-react/src/views/main/_layout/header/notice.jsx b/web-react/src/views/main/_layout/header/notice.jsx index d0d2ec6..58abf17 100644 --- a/web-react/src/views/main/_layout/header/notice.jsx +++ b/web-react/src/views/main/_layout/header/notice.jsx @@ -1,8 +1,9 @@ import React, { Component } from 'react' -import { Badge, Button, Divider, List, Menu, Modal, Popover, Row, Spin } from 'antd' +import { Badge, Button, Divider, List, Menu, Modal, Popover, Row, Spin, Upload, Tag } from 'antd' import { AntIcon, Image } from 'components' import { api } from 'common/api' import InfiniteScroll from 'react-infinite-scroller' +import { BlobToBase64, GetFileName, PreviewFile } from 'util/file' import moment from 'moment' export default class notice extends Component { @@ -16,6 +17,7 @@ export default class notice extends Component { detailVisible: false, detailLoading: false, detailData: {}, + fileValue: false, } async componentDidMount() { @@ -42,7 +44,6 @@ export default class notice extends Component { sortField: 'createdTime', sortOrder: 'descend', }) - if (!items.length) { return this.finish() } @@ -59,7 +60,51 @@ export default class notice extends Component { this.setState({ detailLoading: false, detailData: data, + fileValue: false, }) + + if (data) { + const { attachments } = data + if (attachments) { + const fileValue = [] + const fileList = attachments.split(',') + for (const fileId of fileList) { + try { + const file = await PreviewFile(fileId) + const base64 = await BlobToBase64(file) + fileValue.push({ + uid: fileId, + response: fileId, + name: file.name, + url: base64, + status: 'done', + }) + } catch { + const { data: file } = await api.sysFileInfoDetail({ id: fileId }) + fileValue.push({ + uid: fileId, + response: '文件已丢失', + name: file.fileOriginName, + status: 'error', + }) + } + } + this.setState({ + fileValue, + }) + } + } + } + async onFileDownload(file) { + const { data, headers } = await api.sysFileInfoDownload({ id: file.response }) + const url = window.URL.createObjectURL(data) + const fileName = GetFileName(headers['content-disposition']) + const a = document.createElement('a') + a.href = url + a.download = fileName + a.click() + window.URL.revokeObjectURL(url) + a.remove() } renderList() { @@ -88,6 +133,13 @@ export default class notice extends Component { } + description={ + item.readStatus == 0 ? ( + 未读 + ) : ( + 已读 + ) + } />
{item.content}
@@ -140,6 +192,21 @@ export default class notice extends Component { dangerouslySetInnerHTML={{ __html: detailData.content }} > + {this.state.fileValue && ( + + + 查看附件 + this.onFileDownload(file)} + > + + + )} + 发布人:{detailData.publicUserName} 发布时间:{detailData.publicTime}