perf: 优化websocket,实时获取数量

perf: 优化提示i18n

perf: remove yarn

..
This commit is contained in:
ibuler
2021-06-11 17:10:22 +08:00
committed by 老广
parent 3c36b50c35
commit 2aa363f6ce
4 changed files with 27 additions and 13 deletions

View File

@@ -214,6 +214,7 @@
"ReLogin": "重新登录"
},
"common": {
"ConnectWebSocketError": "连接 WebSocket 失败",
"Action": "动作",
"RequestTickets": "申请工单",
"Actions": "操作",

View File

@@ -213,6 +213,7 @@
"ReLogin": "Re-Login"
},
"common": {
"ConnectWebSocketError": "Connect Websocket failed",
"Nothing": "Nothing",
"Action": "Action",
"CustomCol":"Custom table col",

View File

@@ -121,7 +121,6 @@ export default {
}
},
markAsRead(msg) {
console.log(`${msg}`)
const url = `/api/v1/notifications/site-message/mark-as-read/`
this.$axios.patch(url, { ids: [msg.id] }).then(res => {
this.msgDetailVisible = false
@@ -133,19 +132,27 @@ export default {
cancelRead() {
this.msgDetailVisible = false
},
pullMsgCount() {
const url = '/api/v1/notifications/site-message/unread-total/'
this.$axios.get(url).then(res => {
this.unreadMsgCount = res.total
}).catch(err => {
this.$message(err.detail)
})
},
enablePullMsgCount() {
this.pullMsgCount()
setInterval(() => {
this.pullMsgCount()
}, 10000)
const ws = new WebSocket(`ws://localhost:9528/ws/notifications/site-msg/`)
ws.onopen = (event) => {
this.$log.debug('Websocket connected: ', event)
}
ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data)
this.$log.debug('Data: ', data)
const unreadCount = data['unread_count']
if (unreadCount !== undefined) {
this.unreadMsgCount = unreadCount
}
} catch (e) {
this.$log.debug('Recv site message error')
}
}
ws.onerror = (error) => {
this.$message.error(this.$t('common.ConnectWebSocketError'))
this.$log.debug('site message ws error: ', error)
}
}
}
}

View File

@@ -11288,6 +11288,11 @@ yargs@^11.0.0:
y18n "^3.2.1"
yargs-parser "^9.0.2"
yarn@^1.22.10:
version "1.22.10"
resolved "https://registry.npm.taobao.org/yarn/download/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c"
integrity sha1-yZ2qBiV8gPj6LD8UkHJOOUwmsYw=
yorkie@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/yorkie/-/yorkie-2.0.0.tgz#92411912d435214e12c51c2ae1093e54b6bb83d9"