Commit 91dd4a32b1aa7b93252ccbbce12bfaf652882b76
1 parent
8cdae12b
站内信模块:vue3 站内信弹板
Showing
4 changed files
with
87 additions
and
56 deletions
yudao-ui-admin-vue3/src/api/system/notify/message/index.ts
| @@ -31,3 +31,38 @@ export const getNotifyMessagePageApi = async (params: NotifyMessagePageReqVO) => | @@ -31,3 +31,38 @@ export const getNotifyMessagePageApi = async (params: NotifyMessagePageReqVO) => | ||
| 31 | export const getNotifyMessageApi = async (id: number) => { | 31 | export const getNotifyMessageApi = async (id: number) => { |
| 32 | return await request.get({ url: '/system/notify-message/get?id=' + id }) | 32 | return await request.get({ url: '/system/notify-message/get?id=' + id }) |
| 33 | } | 33 | } |
| 34 | + | ||
| 35 | +// 获得我的站内信分页 | ||
| 36 | +// export function getMyNotifyMessagePage(query) { | ||
| 37 | +// return request({ | ||
| 38 | +// url: '/system/notify-message/my-page', | ||
| 39 | +// method: 'get', | ||
| 40 | +// params: query | ||
| 41 | +// }) | ||
| 42 | +// } | ||
| 43 | + | ||
| 44 | +// 批量标记已读 | ||
| 45 | +// export function updateNotifyMessageRead(ids) { | ||
| 46 | +// return request({ | ||
| 47 | +// url: '/system/notify-message/update-read?' + qs.stringify({ids: ids}, { indices: false }), | ||
| 48 | +// method: 'put' | ||
| 49 | +// }) | ||
| 50 | +// } | ||
| 51 | + | ||
| 52 | +// 标记所有站内信为已读 | ||
| 53 | +// export function updateAllNotifyMessageRead() { | ||
| 54 | +// return request({ | ||
| 55 | +// url: '/system/notify-message/update-all-read', | ||
| 56 | +// method: 'put' | ||
| 57 | +// }) | ||
| 58 | +// } | ||
| 59 | + | ||
| 60 | +// 获取当前用户的最新站内信列表 | ||
| 61 | +export const getUnreadNotifyMessageListApi = async () => { | ||
| 62 | + return await request.get({ url: '/system/notify-message/get-unread-list' }) | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +// 获得当前用户的未读站内信数量 | ||
| 66 | +export const getUnreadNotifyMessageCountApi = async () => { | ||
| 67 | + return await request.get({ url: '/system/notify-message/get-unread-count' }) | ||
| 68 | +} |
yudao-ui-admin-vue3/src/layout/components/Message/src/Message.vue
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | +import dayjs from 'dayjs' | ||
| 3 | +import * as NotifyMessageApi from '@/api/system/notify/message' | ||
| 4 | + | ||
| 5 | +const { push } = useRouter() | ||
| 2 | const activeName = ref('notice') | 6 | const activeName = ref('notice') |
| 7 | +const count = ref(0) // 未读消息数量 | ||
| 8 | +const list = ref([]) // 消息列表 | ||
| 9 | + | ||
| 10 | +// 获得消息列表 | ||
| 11 | +const getList = async () => { | ||
| 12 | + list.value = await NotifyMessageApi.getUnreadNotifyMessageListApi() | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +// 获得未读消息数 | ||
| 16 | +const getUnreadCount = async () => { | ||
| 17 | + NotifyMessageApi.getUnreadNotifyMessageCountApi().then((data) => { | ||
| 18 | + count.value = data | ||
| 19 | + }) | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +// 跳转我的站内信 | ||
| 23 | +const goMyList = () => { | ||
| 24 | + push({ | ||
| 25 | + name: 'MyNotifyMessage' | ||
| 26 | + }) | ||
| 27 | +} | ||
| 3 | 28 | ||
| 4 | -const noticeList = ref([ | ||
| 5 | - { id: 1, title: '版本升级1', date: '2022-12-12 10:00:00' }, | ||
| 6 | - { id: 2, title: '版本升级2', date: '2022-12-12 10:00:00' }, | ||
| 7 | - { id: 3, title: '版本升级3', date: '2022-12-12 10:00:00' }, | ||
| 8 | - { id: 4, title: '版本升级4', date: '2022-12-12 10:00:00' }, | ||
| 9 | - { id: 5, title: '版本升级5', date: '2022-12-12 10:00:00' } | ||
| 10 | -]) | ||
| 11 | -const messageList = ref([ | ||
| 12 | - { id: 1, title: '加班1', date: '2022-12-12 10:00:00' }, | ||
| 13 | - { id: 2, title: '加班2', date: '2022-12-12 10:00:00' }, | ||
| 14 | - { id: 3, title: '加班3', date: '2022-12-12 10:00:00' }, | ||
| 15 | - { id: 4, title: '加班4', date: '2022-12-12 10:00:00' }, | ||
| 16 | - { id: 5, title: '加班5', date: '2022-12-12 10:00:00' } | ||
| 17 | -]) | ||
| 18 | -const needList = ref([ | ||
| 19 | - { id: 1, title: '审批1', date: '2022-12-12 10:00:00' }, | ||
| 20 | - { id: 2, title: '审批2', date: '2022-12-12 10:00:00' }, | ||
| 21 | - { id: 3, title: '审批3', date: '2022-12-12 10:00:00' }, | ||
| 22 | - { id: 4, title: '审批4', date: '2022-12-12 10:00:00' }, | ||
| 23 | - { id: 5, title: '审批5', date: '2022-12-12 10:00:00' } | ||
| 24 | -]) | 29 | +// ========== 初始化 ========= |
| 30 | +onMounted(() => { | ||
| 31 | + // 首次加载小红点 | ||
| 32 | + getUnreadCount() | ||
| 33 | + // 轮询刷新小红点 | ||
| 34 | + setInterval(() => { | ||
| 35 | + getUnreadCount() | ||
| 36 | + }, 1000 * 60 * 2) | ||
| 37 | +}) | ||
| 25 | </script> | 38 | </script> |
| 26 | <template> | 39 | <template> |
| 27 | <div class="message"> | 40 | <div class="message"> |
| 28 | - <ElPopover placement="bottom" :width="310" trigger="click"> | 41 | + <ElPopover placement="bottom" :width="400" trigger="click"> |
| 29 | <template #reference> | 42 | <template #reference> |
| 30 | - <ElBadge :value="noticeList.length" class="item"> | ||
| 31 | - <Icon icon="ep:bell" :size="18" class="cursor-pointer" /> | 43 | + <ElBadge :is-dot="count > 0" class="item"> |
| 44 | + <Icon icon="ep:bell" :size="18" class="cursor-pointer" @click="getList" /> | ||
| 32 | </ElBadge> | 45 | </ElBadge> |
| 33 | </template> | 46 | </template> |
| 34 | <ElTabs v-model="activeName"> | 47 | <ElTabs v-model="activeName"> |
| 35 | - <ElTabPane label="通知(5)" name="notice"> | ||
| 36 | - <div class="message-list"> | ||
| 37 | - <template v-for="item in noticeList" :key="item.id"> | ||
| 38 | - <div class="message-item"> | ||
| 39 | - <img src="@/assets/imgs/avatar.gif" alt="" class="message-icon" /> | ||
| 40 | - <div class="message-content"> | ||
| 41 | - <span class="message-title">{{ item.title }}</span> | ||
| 42 | - <span class="message-date">{{ item.date }}</span> | ||
| 43 | - </div> | ||
| 44 | - </div> | ||
| 45 | - </template> | ||
| 46 | - </div> | ||
| 47 | - </ElTabPane> | ||
| 48 | - <ElTabPane label="消息(0)" name="message"> | ||
| 49 | - <div class="message-list"> | ||
| 50 | - <template v-for="item in messageList" :key="item.id"> | ||
| 51 | - <div class="message-item"> | ||
| 52 | - <img src="@/assets/imgs/avatar.gif" alt="" class="message-icon" /> | ||
| 53 | - <div class="message-content"> | ||
| 54 | - <span class="message-title">{{ item.title }}</span> | ||
| 55 | - <span class="message-date">{{ item.date }}</span> | ||
| 56 | - </div> | ||
| 57 | - </div> | ||
| 58 | - </template> | ||
| 59 | - </div> | ||
| 60 | - </ElTabPane> | ||
| 61 | - <ElTabPane label="代办(0)" name="need"> | 48 | + <ElTabPane label="我的站内信" name="notice"> |
| 62 | <div class="message-list"> | 49 | <div class="message-list"> |
| 63 | - <template v-for="item in needList" :key="item.id"> | 50 | + <template v-for="item in list" :key="item.id"> |
| 64 | <div class="message-item"> | 51 | <div class="message-item"> |
| 65 | <img src="@/assets/imgs/avatar.gif" alt="" class="message-icon" /> | 52 | <img src="@/assets/imgs/avatar.gif" alt="" class="message-icon" /> |
| 66 | <div class="message-content"> | 53 | <div class="message-content"> |
| 67 | - <span class="message-title">{{ item.title }}</span> | ||
| 68 | - <span class="message-date">{{ item.date }}</span> | 54 | + <span class="message-title"> |
| 55 | + {{ item.templateNickname }}:{{ item.templateContent }} | ||
| 56 | + </span> | ||
| 57 | + <span class="message-date"> | ||
| 58 | + {{ dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') }} | ||
| 59 | + </span> | ||
| 69 | </div> | 60 | </div> |
| 70 | </div> | 61 | </div> |
| 71 | </template> | 62 | </template> |
| 72 | </div> | 63 | </div> |
| 73 | </ElTabPane> | 64 | </ElTabPane> |
| 74 | </ElTabs> | 65 | </ElTabs> |
| 66 | + <!-- 更多 --> | ||
| 67 | + <div style="text-align: right; margin-top: 10px"> | ||
| 68 | + <XButton type="primary" preIcon="ep:view" title="查看全部" @click="goMyList" /> | ||
| 69 | + </div> | ||
| 75 | </ElPopover> | 70 | </ElPopover> |
| 76 | </div> | 71 | </div> |
| 77 | </template> | 72 | </template> |
yudao-ui-admin/src/api/system/notify/message.js
| @@ -43,6 +43,7 @@ export function getUnreadNotifyMessageList() { | @@ -43,6 +43,7 @@ export function getUnreadNotifyMessageList() { | ||
| 43 | }) | 43 | }) |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | +// 获得当前用户的未读站内信数量 | ||
| 46 | export function getUnreadNotifyMessageCount() { | 47 | export function getUnreadNotifyMessageCount() { |
| 47 | return request({ | 48 | return request({ |
| 48 | url: '/system/notify-message/get-unread-count', | 49 | url: '/system/notify-message/get-unread-count', |
yudao-ui-admin/src/layout/components/Message/index.vue
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | <!-- 弹出列表 --> | 9 | <!-- 弹出列表 --> |
| 10 | <el-table v-loading="loading" :data="list"> | 10 | <el-table v-loading="loading" :data="list"> |
| 11 | <el-table-column width="120" property="templateNickname" label="发送人" /> | 11 | <el-table-column width="120" property="templateNickname" label="发送人" /> |
| 12 | - <el-table-column width="180" property="title" label="发送时间"> | 12 | + <el-table-column width="180" property="createTime" label="发送时间"> |
| 13 | <template slot-scope="scope"> | 13 | <template slot-scope="scope"> |
| 14 | <span>{{ parseTime(scope.row.createTime) }}</span> | 14 | <span>{{ parseTime(scope.row.createTime) }}</span> |
| 15 | </template> | 15 | </template> |
| @@ -49,7 +49,7 @@ export default { | @@ -49,7 +49,7 @@ export default { | ||
| 49 | // 首次加载小红点 | 49 | // 首次加载小红点 |
| 50 | this.getUnreadCount() | 50 | this.getUnreadCount() |
| 51 | // 轮询刷新小红点 | 51 | // 轮询刷新小红点 |
| 52 | - window.timer = setInterval(()=>{ | 52 | + setInterval(() => { |
| 53 | this.getUnreadCount() | 53 | this.getUnreadCount() |
| 54 | },1000 * 60 * 2) | 54 | },1000 * 60 * 2) |
| 55 | }, | 55 | }, |