diff --git a/src/api/notice-status.ts b/src/api/notice-status.ts new file mode 100644 index 00000000..03433c37 --- /dev/null +++ b/src/api/notice-status.ts @@ -0,0 +1,73 @@ +import request from "@/utils/request"; + +const NOTICESTATUS_BASE_URL = "/api/v1/noticeStatuss"; + +class NoticeStatusAPI { + /** 获取用户公告状态分页数据 */ + static getPage(queryParams?: NoticeStatusPageQuery) { + return request>({ + url: `${NOTICESTATUS_BASE_URL}/page`, + method: "get", + params: queryParams, + }); + } + + /** + * 获取用户公告状态表单数据 + * + * @param id NoticeStatusID + * @returns NoticeStatus表单数据 + */ + static getFormData(id: number) { + return request({ + url: `${NOTICESTATUS_BASE_URL}/${id}/form`, + method: "get", + }); + } + + /** 添加用户公告状态*/ + static add(data: NoticeStatusForm) { + return request({ + url: `${NOTICESTATUS_BASE_URL}`, + method: "post", + data: data, + }); + } + + /** + * 更新用户公告状态 + * + * @param id NoticeStatusID + * @param data NoticeStatus表单数据 + */ + static update(id: number, data: NoticeStatusForm) { + return request({ + url: `${NOTICESTATUS_BASE_URL}/${id}`, + method: "put", + data: data, + }); + } + + /** + * 批量删除用户公告状态,多个以英文逗号(,)分割 + * + * @param ids 用户公告状态ID字符串,多个以英文逗号(,)分割 + */ + static deleteByIds(ids: string) { + return request({ + url: `${NOTICESTATUS_BASE_URL}/${ids}`, + method: "delete", + }); + } +} + +export default NoticeStatusAPI; + +/** 用户公告状态分页查询参数 */ +export interface NoticeStatusPageQuery extends PageQuery {} + +/** 用户公告状态表单对象 */ +export interface NoticeStatusForm {} + +/** 用户公告状态分页对象 */ +export interface NoticeStatusPageVO {} diff --git a/src/api/notice.ts b/src/api/notice.ts new file mode 100644 index 00000000..cb73bff0 --- /dev/null +++ b/src/api/notice.ts @@ -0,0 +1,141 @@ +import request from "@/utils/request"; + +const NOTICE_BASE_URL = "/api/v1/notices"; + +class NoticeAPI { + /** 获取通知公告分页数据 */ + static getPage(queryParams?: NoticePageQuery) { + return request>({ + url: `${NOTICE_BASE_URL}/page`, + method: "get", + params: queryParams, + }); + } + + /** + * 获取通知公告表单数据 + * + * @param id NoticeID + * @returns Notice表单数据 + */ + static getFormData(id: number) { + return request({ + url: `${NOTICE_BASE_URL}/${id}/form`, + method: "get", + }); + } + + /** 添加通知公告*/ + static add(data: NoticeForm) { + return request({ + url: `${NOTICE_BASE_URL}`, + method: "post", + data: data, + }); + } + + /** + * 更新通知公告 + * + * @param id NoticeID + * @param data Notice表单数据 + */ + static update(id: number, data: NoticeForm) { + return request({ + url: `${NOTICE_BASE_URL}/${id}`, + method: "put", + data: data, + }); + } + + /** + * 批量删除通知公告,多个以英文逗号(,)分割 + * + * @param ids 通知公告ID字符串,多个以英文逗号(,)分割 + */ + static deleteByIds(ids: string) { + return request({ + url: `${NOTICE_BASE_URL}/${ids}`, + method: "delete", + }); + } +} + +export default NoticeAPI; + +/** 通知公告分页查询参数 */ +export interface NoticePageQuery extends PageQuery { + id?: bigint; + /** 通知标题 */ + title?: string; + /** 通知内容 */ + content?: string; + /** 通知类型 */ + noticeType?: number; + /** 发布人 */ + releaseBy?: bigint; + /** 优先级(0-低 1-中 2-高) */ + priority?: number; + /** 目标类型(0-全体 1-指定) */ + tarType?: number; + /** 发布状态(0-未发布 1已发布 2已撤回) */ + sendStatus?: number; + /** 发布时间 */ + sendTime?: [string, string]; + /** 撤回时间 */ + recallTime?: [string, string]; + /** 创建时间 */ + createTime?: Date; + /** 更新时间 */ + updateTime?: Date; +} + +/** 通知公告表单对象 */ +export interface NoticeForm { + id?: bigint; + /** 通知标题 */ + title?: string; + /** 通知内容 */ + content?: string; + /** 通知类型 */ + noticeType?: number; + /** 发布人 */ + releaseBy?: bigint; + /** 优先级(0-低 1-中 2-高) */ + priority?: number; + /** 目标类型(0-全体 1-指定) */ + tarType?: number; + /** 发布状态(0-未发布 1已发布 2已撤回) */ + sendStatus?: number; + /** 发布时间 */ + sendTime?: Date; + /** 撤回时间 */ + recallTime?: Date; +} + +/** 通知公告分页对象 */ +export interface NoticePageVO { + id?: bigint; + /** 通知标题 */ + title?: string; + /** 通知内容 */ + content?: string; + /** 通知类型 */ + noticeType?: number; + /** 发布人 */ + releaseBy?: bigint; + /** 优先级(0-低 1-中 2-高) */ + priority?: number; + /** 目标类型(0-全体 1-指定) */ + tarType?: number; + /** 发布状态(0-未发布 1已发布 2已撤回) */ + sendStatus?: number; + /** 发布时间 */ + sendTime?: Date; + /** 撤回时间 */ + recallTime?: Date; + /** 创建时间 */ + createTime?: Date; + /** 更新时间 */ + updateTime?: Date; +} diff --git a/src/enums/MessageTypeEnum.ts b/src/enums/MessageTypeEnum.ts index 42a6fb94..5dbefb41 100644 --- a/src/enums/MessageTypeEnum.ts +++ b/src/enums/MessageTypeEnum.ts @@ -10,6 +10,6 @@ export const enum MessageTypeEnum { export const MessageTypeLabels = { [MessageTypeEnum.MESSAGE]: "消息", - [MessageTypeEnum.NOTICE]: "通知", - [MessageTypeEnum.TODO]: "待办", + // [MessageTypeEnum.NOTICE]: "通知", + // [MessageTypeEnum.TODO]: "待办", }; diff --git a/src/layout/components/NavBar/components/NavbarAction.vue b/src/layout/components/NavBar/components/NavbarAction.vue index f1b79e2d..3f6a4273 100644 --- a/src/layout/components/NavBar/components/NavbarAction.vue +++ b/src/layout/components/NavBar/components/NavbarAction.vue @@ -55,7 +55,9 @@
查看更多 - + + + 全部已读 @@ -114,6 +116,8 @@ import { import defaultSettings from "@/settings"; import { DeviceEnum } from "@/enums/DeviceEnum"; import { MessageTypeEnum, MessageTypeLabels } from "@/enums/MessageTypeEnum"; +import { Client } from "@stomp/stompjs"; +import { TOKEN_KEY } from "@/enums/CacheEnum"; const appStore = useAppStore(); const tagsViewStore = useTagsViewStore(); @@ -122,7 +126,8 @@ const settingStore = useSettingsStore(); const route = useRoute(); const router = useRouter(); - +const isConnected = ref(false); +const socketEndpoint = ref(import.meta.env.VITE_APP_WS_ENDPOINT); const isMobile = computed(() => appStore.device === DeviceEnum.MOBILE); const { isFullscreen, toggle } = useFullscreen(); @@ -192,6 +197,56 @@ function logout() { }); }); } + +let stompClient: Client; + +function connectWebSocket() { + stompClient = new Client({ + brokerURL: socketEndpoint.value, + connectHeaders: { + Authorization: localStorage.getItem(TOKEN_KEY) || "", + }, + debug: (str) => { + console.log(str); + }, + onConnect: () => { + console.log("连接成功"); + isConnected.value = true; + messages.value.push({ + sender: "Server", + content: "Websocket 已连接", + type: "tip", + }); + // 订阅 /topic/chat 主题 + stompClient.subscribe("/topic/chat", (res) => { + debugger; + console.log("收到消息:" + res.body); + // messages.value.push({ + // sender: "Server", + // content: res.body, + // }); + }); + }, + onStompError: (frame) => { + console.error("Broker reported error: " + frame.headers["message"]); + console.error("Additional details: " + frame.body); + }, + onDisconnect: () => { + isConnected.value = false; + messages.value.push({ + sender: "Server", + content: "Websocket 已断开", + type: "tip", + }); + }, + }); + + stompClient.activate(); +} + +onMounted(() => { + connectWebSocket(); +});