fix: 补上清单里还没对上的登录拒绝、会话回退和代理清理
This commit is contained in:
+20
-7
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { apiFetch, setSessionDenied } from "./shared/http";
|
||||
import { darkTheme, dateZhCN, NButton, NConfigProvider, NDialogProvider, zhCN } from "naive-ui";
|
||||
import LoginView from "./features/auth/LoginView.vue";
|
||||
import Shell from "./shell/Shell.vue";
|
||||
@@ -18,7 +19,7 @@ function applyPayload(payload: unknown) {
|
||||
|
||||
async function loadSession() {
|
||||
try {
|
||||
const response = await fetch("/api/session");
|
||||
const response = await apiFetch("/api/session");
|
||||
if (response.status === 401) {
|
||||
session.value = null;
|
||||
sessionError.value = "";
|
||||
@@ -43,12 +44,24 @@ async function loadSession() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
setSessionDenied(() => {
|
||||
void loadSession();
|
||||
});
|
||||
void loadSession();
|
||||
window.addEventListener("focus", onWindowFocus);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener("focus", onWindowFocus);
|
||||
});
|
||||
|
||||
function onWindowFocus() {
|
||||
void loadSession();
|
||||
}
|
||||
|
||||
async function exitSystem() {
|
||||
try {
|
||||
const response = await fetch("/api/logout", { method: "POST" });
|
||||
const response = await apiFetch("/api/logout", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
sessionError.value = "没有退出。";
|
||||
return;
|
||||
@@ -62,7 +75,7 @@ async function exitSystem() {
|
||||
|
||||
async function revokeAccount() {
|
||||
try {
|
||||
const response = await fetch("/api/revoke", { method: "POST" });
|
||||
const response = await apiFetch("/api/revoke", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
sessionError.value = "没有注销。";
|
||||
return;
|
||||
@@ -76,7 +89,7 @@ async function revokeAccount() {
|
||||
|
||||
async function exitAdmin() {
|
||||
try {
|
||||
const response = await fetch("/api/admin/logout", { method: "POST" });
|
||||
const response = await apiFetch("/api/admin/logout", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
sessionError.value = "没有退出。";
|
||||
return;
|
||||
@@ -111,8 +124,8 @@ function onLogin(next: AppSession) {
|
||||
<n-button size="small" @click="loadSession">重试</n-button>
|
||||
</div>
|
||||
<LoginView v-if="!session" @success="onLogin" />
|
||||
<Shell v-else-if="session.kind === 'user'" :employee-id="session.employeeId" @logout="exitSystem" @revoke="revokeAccount" />
|
||||
<AdminShell v-else-if="session.kind === 'admin'" :username="session.username" @logout="exitAdmin" @refresh="loadSession" />
|
||||
<Shell v-else-if="session.kind === 'user'" :key="session.employeeId" :employee-id="session.employeeId" @logout="exitSystem" @revoke="revokeAccount" />
|
||||
<AdminShell v-else-if="session.kind === 'admin'" :key="session.username" :username="session.username" @logout="exitAdmin" @refresh="loadSession" />
|
||||
</div>
|
||||
</n-dialog-provider>
|
||||
</n-config-provider>
|
||||
|
||||
Reference in New Issue
Block a user