feat(MainView): 添加实时日期和时间显示功能

- 在 MainView 组件中添加了实时更新的日期和时间显示
- 实现了页面加载时初始化日期和时间,并设置每秒更新的定时器
- 优化了组件卸载时清除定时器的逻辑
- 添加了用户信息显示和退出系统的功能
This commit is contained in:
zhoumengru
2025-09-12 09:43:35 +08:00
parent 1a22f45b26
commit 7bb53a6ea6

View File

@@ -58,68 +58,13 @@ export default {
currentKey: '',
subCurrentKey: '',
menuList: [],
// menuList: [
// {
// name: '系统总览',
// path: '/home'
// },
// {
// name: '运行监控',
// path: '/monitor'
// },
// {
// name: '预测管理',
// path: '/predict'
// },
// {
// name: '统计分析',
// path: '/statisticalAnalysis'
// },
// {
// name: '系统管理',
// path: '/system',
// children: [
// {
// name: '用户管理',
// path: '/user'
// },
// {
// name: '角色管理',
// path: '/role'
// },
// {
// name: '权限管理',
// icon: 'icon-caidanguanli'
// },
// {
// name: '场站管理',
// path: '/station',
// icon: 'icon-caidanguanli'
// },
// {
// name: '服务管理',
// icon: 'icon-bumenguanli'
// },
// {
// name: '策略管理',
// path: '/policy'
// },
// {
// name: '设备管理',
// path: '/device '
// },
// {
// name: '告警日志',
// path: '/log'
// },
// {
// name: '系统日志',
// path: '/syslog'
// }
// ]
// }
// ],
subMenu: []
subMenu: [],
currentTime: '',
timer: null,
dateVal: moment().locale('zh-cn').format('ll') + ' ',
weekVal: moment().locale('zh-cn').format('dddd'),
user:localStorage.getItem('account').replace(/^"|"$/g, '')
}
},
computed: {
@@ -149,9 +94,35 @@ export default {
},
mounted() {
// this.initRoute()
this.getDateTime()
this.timer = setInterval(() => {
this.getDateTime()
}, 1000)
},
unmounted() {
clearInterval(this.timer)
},
methods: {
logout(){
const that=this
this.$Modal.confirm({
title: '你确认退出系统吗?',
icon: createVNode(ExclamationCircleOutlined),
async onOk() {
localStorage.clear()
that.$router.push('/login')
},
onCancel() {
},
class: 'test'
})
},
//getDateTime
getDateTime() {
this.currentTime = moment().locale('zh-cn').format('LTS')
},
// 新增子菜单处理方法
handleSubMenu(pathSegments,to) {
// 查找当前激活的主菜单项