feat: 重构前端

This commit is contained in:
tbphp
2025-07-02 17:15:10 +08:00
parent 6a96c4464b
commit f15d0dd8da
102 changed files with 5392 additions and 10344 deletions

27
web/src/utils/http.ts Normal file
View File

@@ -0,0 +1,27 @@
import axios from 'axios'
const http = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL,
timeout: 10000,
headers: { 'Content-Type': 'application/json' },
})
// 请求拦截器
http.interceptors.request.use(config => {
const token = localStorage.getItem('token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
// 响应拦截器
http.interceptors.response.use(
response => response.data,
error => {
console.error('API Error:', error)
return Promise.reject(error)
}
)
export default http

31
web/src/utils/router.ts Normal file
View File

@@ -0,0 +1,31 @@
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'dashboard',
component: () => import('@/views/Dashboard.vue'),
},
{
path: '/keys',
name: 'keys',
component: () => import('@/views/Keys.vue'),
},
{
path: '/logs',
name: 'logs',
component: () => import('@/views/Logs.vue'),
},
{
path: '/settings',
name: 'settings',
component: () => import('@/views/Settings.vue'),
},
]
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes,
})
export default router

27
web/src/utils/state.ts Normal file
View File

@@ -0,0 +1,27 @@
import { isRef, reactive, toRef, type Ref } from 'vue'
type IntializeFunc<T> = () => T | Ref<T>
type InitializeValue<T> = T | Ref<T> | IntializeFunc<T>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type GlobalState = Record<string, any>
const globalState = reactive<GlobalState>({})
export function useState<T>(key: string, init?: InitializeValue<T>): Ref<T> {
const state = toRef(globalState, key)
if (state.value === undefined && init !== undefined) {
const initialValue = init instanceof Function ? init() : init
if (isRef(initialValue)) {
// vue will unwrap the ref for us
globalState[key] = initialValue
return initialValue
}
state.value = initialValue
}
return state
}