Skip to content

Commit

Permalink
[*] Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 29, 2024
1 parent b26e50b commit 5515634
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
25 changes: 0 additions & 25 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,34 @@ declare module 'vue' {
NAvatar: typeof import('naive-ui')['NAvatar']
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard']
NCode: typeof import('naive-ui')['NCode']
NCollapse: typeof import('naive-ui')['NCollapse']
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
NDivider: typeof import('naive-ui')['NDivider']
NDrawer: typeof import('naive-ui')['NDrawer']
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
NEl: typeof import('naive-ui')['NEl']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NEmpty: typeof import('naive-ui')['NEmpty']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NGi: typeof import('naive-ui')['NGi']
NGradientText: typeof import('naive-ui')['NGradientText']
NGrid: typeof import('naive-ui')['NGrid']
NGridItem: typeof import('naive-ui')['NGridItem']
NH1: typeof import('naive-ui')['NH1']
NH2: typeof import('naive-ui')['NH2']
NH3: typeof import('naive-ui')['NH3']
NH4: typeof import('naive-ui')['NH4']
NH5: typeof import('naive-ui')['NH5']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NInput: typeof import('naive-ui')['NInput']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutContent: typeof import('naive-ui')['NLayoutContent']
NLayoutHeader: typeof import('naive-ui')['NLayoutHeader']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NLi: typeof import('naive-ui')['NLi']
NList: typeof import('naive-ui')['NList']
NListItem: typeof import('naive-ui')['NListItem']
NMenu: typeof import('naive-ui')['NMenu']
NModal: typeof import('naive-ui')['NModal']
NNumberAnimation: typeof import('naive-ui')['NNumberAnimation']
NP: typeof import('naive-ui')['NP']
NQrCode: typeof import('naive-ui')['NQrCode']
NRadio: typeof import('naive-ui')['NRadio']
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
NSkeleton: typeof import('naive-ui')['NSkeleton']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NStatistic: typeof import('naive-ui')['NStatistic']
NStep: typeof import('naive-ui')['NStep']
NSteps: typeof import('naive-ui')['NSteps']
NTabPane: typeof import('naive-ui')['NTabPane']
NTabs: typeof import('naive-ui')['NTabs']
NTag: typeof import('naive-ui')['NTag']
NText: typeof import('naive-ui')['NText']
NThing: typeof import('naive-ui')['NThing']
NTooltip: typeof import('naive-ui')['NTooltip']
NUl: typeof import('naive-ui')['NUl']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
TheDialog: typeof import('./src/components/TheDialog.vue')['default']
Expand Down
30 changes: 26 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import Notification from '@/utils/notification'
import { logout } from '@/utils/profile'
import router from '@router'
import { useRoute, useRouter } from 'vue-router'
import logger from '@/utils/logger'
const notification = new Notification()
Expand Down Expand Up @@ -120,14 +121,25 @@ vRouter.afterEach(() => {
// initFinished = true
// }
let reconnecting = false
let connectionLostInstance
async function fetchUserInfo() {
let rs
try {
rs = await api.v2.user.info.root.get(userData.getters.get_user_id)
} catch (e) {
notification.warning('查询用户信息失败', e + ',请重新登录后台!')
reconnecting = true
if (connectionLostInstance == undefined) {
connectionLostInstance = window.$notification.create({
title: '连接已断开',
content: '正在重新连接...',
closable: false
})
}
return false
}
if (!rs) return
if (!rs) return false
if (rs.status === 200) {
// console.log(rs)
userData.commit('set_user_email', rs.data.email)
Expand All @@ -145,7 +157,7 @@ async function fetchUserInfo() {
}
if (rs.status === 401) {
notification.warning('授权失效', '请重新登录后台!')
logout()
// logout()
}
return false
}
Expand Down Expand Up @@ -186,7 +198,17 @@ onMounted(async () => {
setInterval(async () => {
if (userData.getters.get_token !== '') {
const valid = await fetchUserInfo()
if (!valid) {
// 有效
// connectionLostInstance 已订阅
if (valid && connectionLostInstance != undefined) {
connectionLostInstance.destroy()
// 重置对象
connectionLostInstance = undefined
reconnecting = false
}
// 无效
// 未重连
if (!valid && !reconnecting) {
logout()
router.push({
name: 'Login',
Expand Down
2 changes: 1 addition & 1 deletion src/components/TheNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useNotification } from 'naive-ui'
// content
export default defineComponent({
setup() {
window.notification = useNotification()
window.$notification = useNotification()
}
})
</script>
8 changes: 4 additions & 4 deletions src/utils/notification.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
class Notification {
info(title, message) {
window.notification['info']({
window.$notification['info']({
content: title,
meta: message,
duration: 2500,
keepAliveOnHover: true
})
}
success(title, message) {
window.notification['success']({
window.$notification['success']({
content: title,
meta: message,
duration: 2500,
keepAliveOnHover: true
})
}
warning(title, message) {
window.notification['warning']({
window.$notification['warning']({
content: title,
meta: message,
duration: 2500,
keepAliveOnHover: true
})
}
error(title, message) {
window.notification['error']({
window.$notification['error']({
content: title,
meta: message,
duration: 2500,
Expand Down

0 comments on commit 5515634

Please sign in to comment.