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,5 +1,5 @@
<script setup lang="ts">
import Layout from '@/components/Layout.vue'
import Layout from "@/components/Layout.vue";
</script>
<template>

View File

@@ -12,8 +12,8 @@
</template>
<script setup lang="ts">
import NavBar from '@/components/NavBar.vue'
import Logout from '@/components/Logout.vue'
import NavBar from "@/components/NavBar.vue";
import Logout from "@/components/Logout.vue";
</script>
<style scoped>

View File

@@ -3,19 +3,19 @@
</template>
<script setup lang="ts">
import type { MenuOption } from 'naive-ui'
import { h, computed } from 'vue'
import { RouterLink, useRoute } from 'vue-router'
import type { MenuOption } from "naive-ui";
import { h, computed } from "vue";
import { RouterLink, useRoute } from "vue-router";
const menuOptions: MenuOption[] = [
renderMenuItem('dashboard', '仪表盘'),
renderMenuItem('keys', '密钥管理'),
renderMenuItem('logs', '日志'),
renderMenuItem('settings', '系统设置'),
]
renderMenuItem("dashboard", "仪表盘"),
renderMenuItem("keys", "密钥管理"),
renderMenuItem("logs", "日志"),
renderMenuItem("settings", "系统设置"),
];
const route = useRoute()
const activeMenu = computed(() => route.name)
const route = useRoute();
const activeMenu = computed(() => route.name);
function renderMenuItem(key: string, label: string): MenuOption {
return {
@@ -30,6 +30,6 @@ function renderMenuItem(key: string, label: string): MenuOption {
{ default: () => label }
),
key,
}
};
}
</script>

View File

@@ -1,7 +1,7 @@
import naive from 'naive-ui'
import { createApp } from 'vue'
import App from './App.vue'
import './style.css'
import router from './utils/router'
import naive from "naive-ui";
import { createApp } from "vue";
import App from "./App.vue";
import "./style.css";
import router from "./utils/router";
createApp(App).use(router).use(naive).mount('#app')
createApp(App).use(router).use(naive).mount("#app");

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;
}

View File

@@ -4,8 +4,8 @@
</template>
<script setup lang="ts">
import BaseInfoCard from '@/components/BaseInfoCard.vue'
import LineChart from '@/components/LineChart.vue'
import BaseInfoCard from "@/components/BaseInfoCard.vue";
import LineChart from "@/components/LineChart.vue";
</script>
<style scoped>