mirror of https://gitee.com/xiaonuobase/snowy
【更新】更新消息通知功能细节
parent
d3375c259c
commit
7d62c31ceb
|
@ -40,7 +40,7 @@ export default {
|
||||||
},
|
},
|
||||||
//站内信全部标记已读
|
//站内信全部标记已读
|
||||||
indexMessageAllMarkRead(data) {
|
indexMessageAllMarkRead(data) {
|
||||||
return request('message/allMessageMarkRead', data, 'get')
|
return request('message/allMessageMarkRead', data)
|
||||||
},
|
},
|
||||||
// 获取当前用户访问日志列表
|
// 获取当前用户访问日志列表
|
||||||
indexVisLogList(data) {
|
indexVisLogList(data) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<a-badge :count="unreadMessageNum" class="badge">
|
<a-badge :count="unreadMessageNum" class="badge">
|
||||||
<comment-outlined />
|
<comment-outlined />
|
||||||
</a-badge>
|
</a-badge>
|
||||||
<a-drawer v-model:visible="msgVisible" title="新消息" placement="right">
|
<a-drawer v-model:visible="msgVisible" title="新消息" placement="right" :width="500">
|
||||||
<a-list :data-source="messageList" size="small" class="mb-3" :loading="miniMessageLoading">
|
<a-list :data-source="messageList" size="small" class="mb-3" :loading="miniMessageLoading">
|
||||||
<template #renderItem="{ item }">
|
<template #renderItem="{ item }">
|
||||||
<a-list-item>
|
<a-list-item>
|
||||||
|
@ -15,12 +15,11 @@
|
||||||
</a-list-item>
|
</a-list-item>
|
||||||
</template>
|
</template>
|
||||||
</a-list>
|
</a-list>
|
||||||
<a-space>
|
<a-space style="float: right">
|
||||||
|
<a-button v-if="unreadMessageNum > 0" @click="markRead">全部设为已读</a-button>
|
||||||
<a-button type="primary" @click="leaveFor('/usercenter')">消息中心</a-button>
|
<a-button type="primary" @click="leaveFor('/usercenter')">消息中心</a-button>
|
||||||
<a-button @click="markRead">全部设为已读</a-button>
|
|
||||||
</a-space>
|
</a-space>
|
||||||
</a-drawer>
|
</a-drawer>
|
||||||
</div>
|
|
||||||
<xn-form-container
|
<xn-form-container
|
||||||
title="详情"
|
title="详情"
|
||||||
:width="700"
|
:width="700"
|
||||||
|
@ -58,15 +57,17 @@
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</xn-form-container>
|
</xn-form-container>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="devUserMessage">
|
<script setup name="devUserMessage">
|
||||||
import indexApi from '@/api/sys/indexApi'
|
import indexApi from '@/api/sys/indexApi'
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import {onMounted} from "vue";
|
import { onMounted } from 'vue'
|
||||||
import sysConfig from "@/config";
|
import sysConfig from '@/config'
|
||||||
import { EventSourcePolyfill } from "event-source-polyfill";
|
import { EventSourcePolyfill } from 'event-source-polyfill'
|
||||||
import tool from "@/utils/tool";
|
import tool from '@/utils/tool'
|
||||||
|
|
||||||
const miniMessageLoading = ref(false)
|
const miniMessageLoading = ref(false)
|
||||||
const msgVisible = ref(false)
|
const msgVisible = ref(false)
|
||||||
|
@ -80,41 +81,31 @@
|
||||||
// 创建sse连接
|
// 创建sse连接
|
||||||
const createSseConnect = () => {
|
const createSseConnect = () => {
|
||||||
if (window.EventSource) {
|
if (window.EventSource) {
|
||||||
let clientId = tool.data.get("CLIENTID") ? tool.data.get("CLIENTID") : "";
|
let clientId = tool.data.get('CLIENTID') ? tool.data.get('CLIENTID') : ''
|
||||||
let url = sysConfig.API_URL+'/dev/message/createSseConnect?clientId='+clientId;
|
let url = sysConfig.API_URL + '/dev/message/createSseConnect?clientId=' + clientId
|
||||||
// heartbeatTimeout:心跳超时监测 30s
|
// heartbeatTimeout:心跳超时监测 30s
|
||||||
let source = new EventSourcePolyfill(url, { headers: { token: tool.data.get('TOKEN') }, heartbeatTimeout: 30000 })
|
let source = new EventSourcePolyfill(url, { headers: { token: tool.data.get('TOKEN') }, heartbeatTimeout: 30000 })
|
||||||
// 监听打开事件
|
// 监听打开事件
|
||||||
source.addEventListener('open', (e) => {
|
source.addEventListener('open', (e) => {})
|
||||||
//console.log("设备连接成功",e)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 监听消息事件
|
// 监听消息事件
|
||||||
source.addEventListener("message", (e) => {
|
source.addEventListener('message', (e) => {
|
||||||
const result = JSON.parse(e.data)
|
const result = JSON.parse(e.data)
|
||||||
const code = result.code
|
const code = result.code
|
||||||
const msg = result.msg
|
|
||||||
const data = result.data
|
const data = result.data
|
||||||
|
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
console.log("see推送消息:",data)
|
unreadMessageNum.value = data
|
||||||
unreadMessageNum.value = data;
|
|
||||||
} else if (code === 0) {
|
} else if (code === 0) {
|
||||||
// 初次建立连接,客户端id储存本地
|
// 初次建立连接,客户端id储存本地
|
||||||
tool.data.set("CLIENTID", data)
|
tool.data.set('CLIENTID', data)
|
||||||
console.log("客户端id:",data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听错误事件
|
// 监听错误事件
|
||||||
source.addEventListener("error", (e) => {
|
source.addEventListener('error', (e) => {
|
||||||
console.log("发生错误,已断开与服务器的连接:",e)
|
console.error('发生错误,消息事实获取已断开与服务器的连接')
|
||||||
source.close();
|
source.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("该浏览器不支持sse")
|
message.warning('该浏览器不支持消息功能')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +130,9 @@
|
||||||
const markRead = () => {
|
const markRead = () => {
|
||||||
messageList.value = []
|
messageList.value = []
|
||||||
unreadMessageNum.value = 0
|
unreadMessageNum.value = 0
|
||||||
indexApi.indexMessageAllMarkRead().then((data) => {})
|
indexApi.indexMessageAllMarkRead().then((data) => {
|
||||||
|
message.success('操作成功')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// 跳转,用于点击消息中心
|
// 跳转,用于点击消息中心
|
||||||
const leaveFor = (url = '/') => {
|
const leaveFor = (url = '/') => {
|
||||||
|
@ -158,7 +151,7 @@
|
||||||
receiveInfoList.value = data.receiveInfoList
|
receiveInfoList.value = data.receiveInfoList
|
||||||
table.value.refresh(true)
|
table.value.refresh(true)
|
||||||
})
|
})
|
||||||
unreadMessageNum.value = Math.max(unreadMessageNum.value - 1, 0);
|
unreadMessageNum.value = Math.max(unreadMessageNum.value - 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadData = () => {
|
const loadData = () => {
|
||||||
|
@ -188,11 +181,12 @@
|
||||||
visible.value = false
|
visible.value = false
|
||||||
formData.value = {}
|
formData.value = {}
|
||||||
receiveInfoList.value = []
|
receiveInfoList.value = []
|
||||||
|
getMessageList()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/deep/ .ant-badge-count{
|
:deep(.ant-badge-count) {
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
min-width: 15px;
|
min-width: 15px;
|
||||||
height: 15px;
|
height: 15px;
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
</s-table>
|
</s-table>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
|
||||||
<detail ref="detailRef" @refresh="refresh" />
|
<detail ref="detailRef" @refresh="refresh" />
|
||||||
|
</a-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="userMessage">
|
<script setup name="userMessage">
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
<script setup name="messageDetail">
|
<script setup name="messageDetail">
|
||||||
import userCenterApi from '@/api/sys/userCenterApi'
|
import userCenterApi from '@/api/sys/userCenterApi'
|
||||||
const emits = defineEmits(["refresh"]);
|
const emits = defineEmits(['refresh'])
|
||||||
const receiveInfoList = ref([])
|
const receiveInfoList = ref([])
|
||||||
|
|
||||||
// 默认是关闭状态
|
// 默认是关闭状态
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
receiveInfoList.value = []
|
receiveInfoList.value = []
|
||||||
visible = false
|
visible = false
|
||||||
emits("refresh");
|
emits('refresh')
|
||||||
}
|
}
|
||||||
// 调用这个函数将子组件的一些数据和方法暴露出去
|
// 调用这个函数将子组件的一些数据和方法暴露出去
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class SysIndexController {
|
||||||
*/
|
*/
|
||||||
@ApiOperationSupport(order = 6)
|
@ApiOperationSupport(order = 6)
|
||||||
@ApiOperation("站内信全部标记已读")
|
@ApiOperation("站内信全部标记已读")
|
||||||
@GetMapping("/dev/message/allMessageMarkRead")
|
@PostMapping("/sys/index/message/allMessageMarkRead")
|
||||||
public CommonResult<String> allMessageMarkRead() {
|
public CommonResult<String> allMessageMarkRead() {
|
||||||
sysIndexService.allMessageMarkRead();
|
sysIndexService.allMessageMarkRead();
|
||||||
return CommonResult.ok();
|
return CommonResult.ok();
|
||||||
|
|
Loading…
Reference in New Issue