Skip to content

Commit

Permalink
🐛 修复通知已读操作未生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
evil0th authored and Hccake committed Jan 31, 2024
1 parent 8ba043a commit 33185e1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/api/notify/announcement/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import httpClient from '@/utils/axios'
import type { ApiResult } from '@/api/types'
import type {
Announcement,
AnnouncementDTO,
AnnouncementPageParam,
AnnouncementPageVO
AnnouncementPageVO,
UserAnnouncementVO
} from './types'
import type { FileObject } from '@/components/CropperModal/types'

Expand Down Expand Up @@ -71,7 +71,7 @@ export function uploadAnnouncementImage(resultFiles: FileObject[]) {
}

export function getUserAnnouncements() {
return httpClient.get<ApiResult<Announcement[]>>('/notify/announcement/user')
return httpClient.get<ApiResult<UserAnnouncementVO[]>>('/notify/user-announcement/list')
}

export function readAnnouncement(announcementId: number) {
Expand Down
32 changes: 32 additions & 0 deletions src/api/notify/announcement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ export enum AnnouncementStatusEnum {
UNPUBLISHED = 2
}

/**
* 用户公告状态
*/
export enum UserAnnouncementStateEnum {
// 未读(0)
UNREAD = 0,
// 已读(1)
READ = 1
}

/**
* 公告信息查询对象
*/
Expand Down Expand Up @@ -75,6 +85,28 @@ export type AnnouncementPageVO = Announcement & {
updateTime: string
}

/**
* 用户公告信息
*/
export type UserAnnouncementVO = {
//公告ID
id: number
//标题
title: string
//内容
content: string
//状态
state: UserAnnouncementStateEnum
// 创建人ID
createBy: number
// 创建人名称
createUsername: string
// 创建时间
createTime: string
// 更新时间
updateTime: string
}

/**
* 公告 websocket 推送消息体
*/
Expand Down
14 changes: 10 additions & 4 deletions src/components/Notify/AnnouncementModal.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Modal } from 'ant-design-vue'
import { readAnnouncement } from '@/api/notify/announcement'
import type { AnnouncementDTO } from '@/api/notify/announcement/types'
import { UserAnnouncementStateEnum, type UserAnnouncementVO } from '@/api/notify/announcement/types'
import { NotificationOutlined } from '@ant-design/icons-vue'
import { defineComponent } from 'vue'
import '@wangeditor/editor/dist/css/style.css'
import '@/components/Editor/view.less'
import { emitter } from '@/hooks/mitt'

export const AnnouncementModal = defineComponent({
name: 'AnnouncementModal',
setup(props, { expose }) {
function show(announcement: AnnouncementDTO, isPreview = false) {
function show(announcement: UserAnnouncementVO, isPreview = false) {
Modal.info({
title: announcement.title,
width: 800,
Expand All @@ -18,8 +19,13 @@ export const AnnouncementModal = defineComponent({
content: () => <div class="editor-content-view" innerHTML={announcement.content}></div>,
onOk: function () {
// 不是预览且状态是未读
if (!isPreview && announcement.status === 0) {
return readAnnouncement(announcement.id!)
if (!isPreview && announcement.state === UserAnnouncementStateEnum.UNREAD) {
return readAnnouncement(announcement.id!).then(() => {
emitter.emit('announcement-close', {
id: announcement.id!,
type: 'announcement-close'
})
})
}
}
})
Expand Down
4 changes: 3 additions & 1 deletion src/components/Notify/AnnouncementRibbon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
AnnouncementCloseMessage,
AnnouncementPushMessage
} from '@/api/notify/announcement/types'
import { UserAnnouncementStateEnum } from '@/api/notify/announcement/types'
const announcementModalRef = ref()
Expand All @@ -43,7 +44,8 @@ const onAnnouncementPush = (data: AnnouncementPushMessage) => {
const announcement = {
id: data.id,
title: data.title,
content: data.content
content: data.content,
state: UserAnnouncementStateEnum.UNREAD
}
announcements.value.push(announcement)
}
Expand Down

0 comments on commit 33185e1

Please sign in to comment.