Skip to content

Commit 8129609

Browse files
authored
Merge pull request #5 from tbphp/fix-auth-web-auth-error
Fix Auth web auth error
2 parents a0abea1 + 96c8943 commit 8129609

File tree

8 files changed

+50
-42
lines changed

8 files changed

+50
-42
lines changed

web/src/App.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<script setup lang="ts">
22
import GlobalProviders from "@/components/GlobalProviders.vue";
3-
import Layout from "@/components/Layout.vue";
4-
import { useAuthKey } from "@/services/auth";
5-
import { computed } from "vue";
6-
7-
const authKey = useAuthKey();
8-
const isLoggedIn = computed(() => !!authKey.value);
93
</script>
104

115
<template>
126
<global-providers>
137
<div id="app-root">
14-
<layout v-if="isLoggedIn" key="layout" />
15-
<router-view v-else key="auth" />
8+
<router-view />
169
</div>
1710
</global-providers>
1811
</template>

web/src/components/GlobalProviders.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const Message = defineComponent({
7171
<template>
7272
<n-config-provider :theme-overrides="themeOverrides">
7373
<n-loading-bar-provider>
74-
<n-message-provider>
74+
<n-message-provider placement="top-right">
7575
<n-dialog-provider>
7676
<slot />
7777
<loading-bar />

web/src/components/GlobalTaskProgressBar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ function handleClose() {
136136
<style scoped>
137137
.global-task-progress {
138138
position: fixed;
139-
top: 20px;
140-
right: 20px;
139+
bottom: 62px;
140+
right: 10px;
141141
z-index: 9999;
142-
width: 360px;
142+
width: 350px;
143143
background: white;
144144
border-radius: var(--border-radius-md);
145145
box-shadow: var(--shadow-lg);

web/src/components/keys/KeyTable.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ async function testKey(_key: KeyRow) {
176176
if (curValid.is_valid) {
177177
window.$message.success("密钥测试成功");
178178
} else {
179-
window.$message.error(curValid.error || "密钥测试失败: 无效的API密钥");
179+
window.$message.error(curValid.error || "密钥测试失败: 无效的API密钥", {
180+
keepAliveOnHover: true,
181+
duration: 5000,
182+
closable: true,
183+
});
180184
}
181185
} catch (_error) {
182186
console.error("测试失败");

web/src/components/logs/LogTable.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ const loadLogs = async () => {
7272
} else {
7373
logs.value = [];
7474
total.value = 0;
75-
window.$message.error(res.message || "加载日志失败");
75+
window.$message.error(res.message || "加载日志失败", {
76+
keepAliveOnHover: true,
77+
duration: 5000,
78+
closable: true,
79+
});
7680
}
7781
} catch (_error) {
7882
window.$message.error("加载日志请求失败");

web/src/router/index.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
import { useAuthService } from "@/services/auth";
22
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
3+
import Layout from "@/components/Layout.vue";
34

45
const routes: Array<RouteRecordRaw> = [
56
{
67
path: "/",
7-
name: "dashboard",
8-
component: () => import("@/views/Dashboard.vue"),
9-
},
10-
{
11-
path: "/keys",
12-
name: "keys",
13-
component: () => import("@/views/Keys.vue"),
14-
},
15-
{
16-
path: "/logs",
17-
name: "logs",
18-
component: () => import("@/views/Logs.vue"),
19-
},
20-
{
21-
path: "/settings",
22-
name: "settings",
23-
component: () => import("@/views/Settings.vue"),
8+
component: Layout,
9+
children: [
10+
{
11+
path: "",
12+
name: "dashboard",
13+
component: () => import("@/views/Dashboard.vue"),
14+
},
15+
{
16+
path: "keys",
17+
name: "keys",
18+
component: () => import("@/views/Keys.vue"),
19+
},
20+
{
21+
path: "logs",
22+
name: "logs",
23+
component: () => import("@/views/Logs.vue"),
24+
},
25+
{
26+
path: "settings",
27+
name: "settings",
28+
component: () => import("@/views/Settings.vue"),
29+
},
30+
],
2431
},
2532
{
2633
path: "/login",

web/src/utils/http.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,28 @@ http.interceptors.response.use(
3535
response => {
3636
appState.loading = false;
3737
if (response.config.method !== "get" && !response.config.hideMessage) {
38-
window.$message.success("操作成功");
38+
window.$message.success(response.data.message ?? "操作成功");
3939
}
4040
return response.data;
4141
},
4242
error => {
4343
appState.loading = false;
4444
if (error.response) {
45-
// The request was made and the server responded with a status code
46-
// that falls out of the range of 2xx
4745
if (error.response.status === 401) {
48-
const { logout } = useAuthService();
49-
logout();
50-
window.location.href = "/login";
46+
if (window.location.pathname !== "/login") {
47+
const { logout } = useAuthService();
48+
logout();
49+
window.location.href = "/login";
50+
}
5151
}
52-
window.$message.error(error.response.data?.message || `请求失败: ${error.response.status}`);
52+
window.$message.error(error.response.data?.message || `请求失败: ${error.response.status}`, {
53+
keepAliveOnHover: true,
54+
duration: 5000,
55+
closable: true,
56+
});
5357
} else if (error.request) {
54-
// The request was made but no response was received
5558
window.$message.error("网络错误,请检查您的连接");
5659
} else {
57-
// Something happened in setting up the request that triggered an Error
5860
window.$message.error("请求设置错误");
5961
}
6062
return Promise.reject(error);

web/src/views/Login.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const handleLogin = async () => {
2222
loading.value = false;
2323
if (success) {
2424
router.push("/");
25-
} else {
26-
message.error("登录失败,请检查您的授权密钥");
2725
}
2826
};
2927
</script>

0 commit comments

Comments
 (0)