feat: format

This commit is contained in:
tbphp
2025-07-02 17:24:33 +08:00
parent f15d0dd8da
commit 9c597e6a74
11 changed files with 138 additions and 138 deletions

View File

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

View File

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

View File

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