增加版本更新功能
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
<template>
|
||||
<div id="app" @mousemove="moveEvent" @click="moveEvent">
|
||||
<router-view />
|
||||
<version-notification ref="versionDialog" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VersionNotification from '@/components/VersionNotification/VersionNotification.vue'
|
||||
import { getCurrentVersion } from '@/api/system/version'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
VersionNotification
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
timmer: null
|
||||
timmer: null,
|
||||
pollTimer: null,
|
||||
pollIntervalMs: 30000
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$bus.on('version_update', (msg) => {
|
||||
this.checkVersion(msg.version)
|
||||
})
|
||||
this.startPolling()
|
||||
this.checkVersionOnLogin()
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearInterval(this.pollTimer)
|
||||
this.$bus.off('version_update')
|
||||
},
|
||||
methods: {
|
||||
moveEvent: function() {
|
||||
const path = ['/login']
|
||||
@@ -24,12 +44,46 @@ export default {
|
||||
this.timmer = setTimeout(() => {
|
||||
sessionStorage.clear()
|
||||
this.logout()
|
||||
}, 1000 * 60 * 151) // 15分钟 https://blog.csdn.net/qq_42345108/article/details/103496456
|
||||
}, 1000 * 60 * 151)
|
||||
},
|
||||
logout() {
|
||||
this.$store.dispatch('LogOut').then(() => {
|
||||
location.reload()
|
||||
})
|
||||
},
|
||||
checkVersion(serverVersion) {
|
||||
const lastSeen = localStorage.getItem('lastSeenVersion')
|
||||
if (!serverVersion || serverVersion === lastSeen) {
|
||||
return
|
||||
}
|
||||
this.$refs.versionDialog.show(serverVersion)
|
||||
},
|
||||
checkVersionOnLogin() {
|
||||
const token = localStorage.getItem('token') || sessionStorage.getItem('token')
|
||||
if (!token) return
|
||||
getCurrentVersion().then(res => {
|
||||
if (!res.enabled) return
|
||||
this.checkVersion(res.version)
|
||||
})
|
||||
},
|
||||
startPolling() {
|
||||
this.pollTimer = setInterval(() => {
|
||||
getCurrentVersion().then(res => {
|
||||
if (!res.enabled) return
|
||||
this.checkVersion(res.version)
|
||||
const interval = (res.pollInterval || 30) * 1000
|
||||
if (interval !== this.pollIntervalMs) {
|
||||
this.pollIntervalMs = interval
|
||||
clearInterval(this.pollTimer)
|
||||
this.pollTimer = setInterval(() => {
|
||||
getCurrentVersion().then(r => {
|
||||
if (!r.enabled) return
|
||||
this.checkVersion(r.version)
|
||||
})
|
||||
}, interval)
|
||||
}
|
||||
})
|
||||
}, this.pollIntervalMs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,22 @@ export default {
|
||||
'disk': 'Disk Utilization',
|
||||
'cpu_monitoring': 'Cpu Utilization Monitoring',
|
||||
'memory_monitoring': 'Memory Utilization Monitoring'
|
||||
},
|
||||
'version': {
|
||||
'title': 'System Version Update',
|
||||
'versionNo': 'Version',
|
||||
'releaseTime': 'Release Time',
|
||||
'content': 'Update Content',
|
||||
'confirm': 'I Know',
|
||||
'releaseTitle': 'Publish Version Notice',
|
||||
'noticeTitle': 'Notice Title',
|
||||
'release': 'Publish',
|
||||
'currentInfo': 'Current Version Info',
|
||||
'switch': 'Notification Switch',
|
||||
'pollInterval': 'Polling Interval',
|
||||
'enabled': 'Enabled',
|
||||
'disabled': 'Disabled',
|
||||
'seconds': 's'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,22 @@ export default {
|
||||
'disk': 'Kadar penggunaan disk',
|
||||
'cpu_monitoring': 'Monitor penggunaan CPU',
|
||||
'memory_monitoring': 'Monitor penggunaan memori'
|
||||
},
|
||||
'version': {
|
||||
'title': 'Update Versi Sistem',
|
||||
'versionNo': 'Versi',
|
||||
'releaseTime': 'Waktu Rilis',
|
||||
'content': 'Konten Update',
|
||||
'confirm': 'Saya Mengerti',
|
||||
'releaseTitle': 'Terbitkan Notifikasi Versi',
|
||||
'noticeTitle': 'Judul Notifikasi',
|
||||
'release': 'Terbitkan',
|
||||
'currentInfo': 'Info Versi Saat Ini',
|
||||
'switch': 'Sakelar Notifikasi',
|
||||
'pollInterval': 'Interval Polling',
|
||||
'enabled': 'Diaktifkan',
|
||||
'disabled': 'Dinonaktifkan',
|
||||
'seconds': 'detik'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,22 @@ export default {
|
||||
'disk': '磁盘使用率',
|
||||
'cpu_monitoring': 'CPU使用率监控',
|
||||
'memory_monitoring': '内存使用率监控'
|
||||
},
|
||||
'version': {
|
||||
'title': '系统版本更新',
|
||||
'versionNo': '版本号',
|
||||
'releaseTime': '发布时间',
|
||||
'content': '更新内容',
|
||||
'confirm': '我知道了',
|
||||
'releaseTitle': '发布版本通知',
|
||||
'noticeTitle': '通知标题',
|
||||
'release': '发布',
|
||||
'currentInfo': '当前版本信息',
|
||||
'switch': '通知开关',
|
||||
'pollInterval': '轮询间隔',
|
||||
'enabled': '已启用',
|
||||
'disabled': '已禁用',
|
||||
'seconds': '秒'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,8 +168,11 @@ export default {
|
||||
webSocketOnMessage(e) {
|
||||
const data = JSON.parse(e.data)
|
||||
if (data.msgType === 'INFO') {
|
||||
console.log('data', data)
|
||||
this.$bus.emit(data.msg.data, data.msg.msgType)
|
||||
if (data.msg.data === 'notice_message_update') {
|
||||
this.$bus.emit(data.msg.data, data.msg.msgType)
|
||||
} else if (data.msg.data === 'version_update') {
|
||||
this.$bus.emit('version_update', data.msg)
|
||||
}
|
||||
} else if (data.msgType === 'ERROR') {
|
||||
this.$notify({
|
||||
title: '',
|
||||
|
||||
@@ -13,3 +13,6 @@ export const NOTICE_MESSAGE_UPDATE = 'notice_message_update'
|
||||
* ws测试事件
|
||||
*/
|
||||
export const EVENT_TEST_WEBSOCKET = 'event_test_websocket'
|
||||
|
||||
/** 版本更新 */
|
||||
export const VERSION_UPDATE = 'version_update'
|
||||
|
||||
Reference in New Issue
Block a user