This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/App.vue

66 lines
2.0 KiB
Vue
Raw Normal View History

2021-05-26 17:34:13 +08:00
<template>
2021-06-07 18:35:16 +08:00
<div id="app">
<router-view/>
</div>
2021-05-26 17:34:13 +08:00
</template>
<script>
import { storageKey } from '@/utils/constants'
import router from '@/router'
import { post } from '@/utils/http'
import { api } from '@/utils/api'
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const advancedFormat = require('dayjs/plugin/advancedFormat')
const weekday = require('dayjs/plugin/weekday')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(advancedFormat)
dayjs.extend(weekday)
window.$dayJs = dayjs
2021-05-26 17:34:13 +08:00
export default {
2021-06-11 10:00:22 +08:00
name: 'App',
setup () {
// 处理刷新后 $dayJs的时区变为默认的问题
const timezone = localStorage.getItem(storageKey.sysTimezone) || ''
if (timezone) {
window.$dayJs.tz.setDefault(timezone)
2021-06-16 10:02:54 +08:00
} else {
window.$dayJs.tz.setDefault()
2021-06-16 10:02:54 +08:00
}
},
mounted () {
this.loginAlready()
},
methods: {
/**
* 已经登录判断
* 如果已经登录新打开页面按url打开否则进入首页
*/
loginAlready () {
// 登录判断在router/index.js下操作更合适但该文件内引入post等方法会导致路由报错
// 目前不知道其原因后续解决该问题后将登录操作移入router
const url = window.location.href
const currentPath = url.match(/#(\S*)/)[1]
2021-06-16 10:02:54 +08:00
if (currentPath === '/' || currentPath === '/login') {
if (localStorage.getItem(storageKey.token) !== null) {
// 刚进入会请求失败,故采用延时,请求成功清除延时器,避免内存泄漏
const timer = setTimeout(() => {
post(api.permissions, { token: localStorage.getItem(storageKey.token) }).then(res => {
if (res.code === 200) {
router.push({
path: '/panel/networkOverview'
})
clearTimeout(timer)
}
})
}, 10)
}
}
}
}
2021-05-26 17:34:13 +08:00
}
</script>