-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2464275
commit 80e1d32
Showing
16 changed files
with
662 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
NODE_ENV = 'development' | ||
VITE_SOCKET_ROOM = 'http://127.0.0.1:7001/room' | ||
VITE_SOCKET_NOTICE = 'http://127.0.0.1:7001/notice' | ||
VITE_HTTP_BASE = 'http://127.0.0.1:7001/api/v1/' | ||
VITE_ANCHOR_DEFAULT_AVATAR = 'https://picgo-1259000609.cos.ap-shanghai.myqcloud.com/picgo/[email protected]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
NODE_ENV = 'production' | ||
VITE_SOCKET_ROOM = 'http://127.0.0.1:7001/room' | ||
VITE_SOCKET_NOTICE = 'http://127.0.0.1:7001/notice' | ||
VITE_ANCHOR_DEFAULT_AVATAR = 'https://picgo-1259000609.cos.ap-shanghai.myqcloud.com/picgo/[email protected]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* @Date: 2022-09-25 21:48:02 | ||
* @Author: 枫 | ||
* @LastEditors: 枫 | ||
* @description: 个人中心接口层 | ||
* @LastEditTime: 2022-10-04 13:12:34 | ||
*/ | ||
|
||
import { request } from "@/utils/request"; | ||
import type { NoticeDTO } from "#/notice"; | ||
import type { PaginationResponseData } from "#/util"; | ||
|
||
/* | ||
* notice 通知相关 | ||
*/ | ||
|
||
/** | ||
* 获取未读消息 | ||
* @returns | ||
*/ | ||
export async function getNewNotice(): Promise<NoticeDTO[]> { | ||
return request.get("/message/list"); | ||
} | ||
|
||
/** | ||
* 获取读取的消息 | ||
* @param page 页码 | ||
* @returns | ||
*/ | ||
export async function getOldNotice( | ||
page: number | ||
): Promise<PaginationResponseData<NoticeDTO>> { | ||
return request.get(`/message/list/read?page=${page}`); | ||
} | ||
|
||
/** | ||
* 已读消息 | ||
* @param id 消息 ID | ||
* @returns | ||
*/ | ||
export async function readNotice(id: number): Promise<boolean> { | ||
return request.put(`/message/read/${id}`); | ||
} | ||
|
||
/** | ||
* 全部已读 | ||
* @returns | ||
*/ | ||
export async function readAllNotice(): Promise<boolean> { | ||
return request.put(`/message/read/all`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* @Date: 2022-09-25 21:24:05 | ||
* @Author: 枫 | ||
* @LastEditors: 枫 | ||
* @description: 消息通知 store | ||
* @LastEditTime: 2022-10-04 20:31:04 | ||
*/ | ||
|
||
import type { NoticeDTO } from "#/notice"; | ||
import { defineStore } from "pinia"; | ||
import { getNewNotice, getOldNotice } from "@/services/member"; | ||
|
||
export const useNoticeStore = defineStore({ | ||
id: "notice", | ||
state: () => ({ | ||
newNotice: [] as NoticeDTO[], | ||
notice: [] as NoticeDTO[], | ||
page: 1, | ||
loading: false, | ||
total: 0, | ||
}), | ||
actions: { | ||
// 从服务器获取未读消息 | ||
async getNotice() { | ||
this.loading = true; | ||
this.newNotice = await getNewNotice(); | ||
this.loading = false; | ||
}, | ||
async getOldNotice() { | ||
this.loading = true; | ||
const notice = await getOldNotice(this.page); | ||
this.total = notice.total; | ||
this.notice = notice.content; | ||
this.loading = false; | ||
}, | ||
// 插入新消息 | ||
insertNoticeAtHead(notice: NoticeDTO) { | ||
this.newNotice.unshift(notice); | ||
}, | ||
// 已读某条消息 | ||
readNoticeById(id: number) { | ||
// const success = await readNotice(id); | ||
// if (success) { | ||
const idx = this.newNotice.findIndex((i) => i.messageId === id); | ||
this.newNotice.splice(idx, 1); | ||
// } | ||
}, | ||
// 全部已读 | ||
readAll() { | ||
// const success = await readAllNotice(); | ||
// if (success) | ||
this.newNotice = []; | ||
}, | ||
// 设置页码 | ||
setPage(page: number) { | ||
this.page = page; | ||
}, | ||
}, | ||
getters: { | ||
// 未读消息数 | ||
notReadNumber(): number { | ||
return this.newNotice.length; | ||
}, | ||
// 已读消息数 | ||
readNoticeNumber(): number { | ||
return this.notice.length; | ||
}, | ||
isAllLoad(): boolean { | ||
return this.total === this.notice.length; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.