36 lines
1.2 KiB
Vue
36 lines
1.2 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import { darkTheme, NConfigProvider, NMessageProvider, zhCN, dateZhCN } from "naive-ui";
|
|
import LoginView from "./features/auth/LoginView.vue";
|
|
import Shell from "./shell/Shell.vue";
|
|
import type { UserInfo } from "./features/auth/api";
|
|
import { isDark, themeOverrides } from "./shared/theme";
|
|
import { clearUnauthorized, setUnauthorizedHandler } from "./shared/http";
|
|
|
|
const user = ref<UserInfo | null>(null);
|
|
const authNotice = ref("");
|
|
|
|
setUnauthorizedHandler(() => {
|
|
if (!user.value) return;
|
|
user.value = null;
|
|
authNotice.value = "登录已失效,请重新登录";
|
|
});
|
|
|
|
function onSuccess(next: UserInfo) {
|
|
authNotice.value = "";
|
|
clearUnauthorized();
|
|
user.value = next;
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
|
|
<n-message-provider class="app-root">
|
|
<div class="app-root">
|
|
<LoginView v-if="!user" :notice="authNotice" @success="onSuccess" />
|
|
<Shell v-else :user="user" @logout="user = null" />
|
|
</div>
|
|
</n-message-provider>
|
|
</n-config-provider>
|
|
</template>
|