This commit is contained in:
hptangxi
2025-07-01 22:52:48 +08:00
parent dcb862b11a
commit d48384af80
26 changed files with 3528 additions and 0 deletions

13
fe/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

1804
fe/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

25
fe/package.json Normal file
View File

@@ -0,0 +1,25 @@
{
"name": "tb-vite-demo",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.9.0",
"naive-ui": "^2.41.0",
"vue": "^3.5.13",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@types/node": "^22.15.24",
"@vitejs/plugin-vue": "^5.2.3",
"@vue/tsconfig": "^0.7.0",
"typescript": "~5.8.3",
"vite": "^6.3.5",
"vue-tsc": "^2.2.8"
}
}

1307
fe/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

7
fe/src/App.vue Normal file
View File

@@ -0,0 +1,7 @@
<script setup lang="ts">
import Layout from '@/components/Layout.vue'
</script>
<template>
<Layout />
</template>

1
fe/src/assets/vue.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

View File

@@ -0,0 +1,5 @@
<template>
<n-card title="基础统计">
<div>基础统计</div>
</n-card>
</template>

View File

@@ -0,0 +1,28 @@
<template>
<n-layout>
<n-layout-header class="flex items-center">
<h1 class="layout-header-title">T.COM</h1>
<nav-bar />
<logout />
</n-layout-header>
<n-layout-content class="layout-content" content-style="padding: 24px;">
<router-view />
</n-layout-content>
</n-layout>
</template>
<script setup lang="ts">
import NavBar from '@/components/NavBar.vue'
import Logout from '@/components/Logout.vue'
</script>
<style scoped>
.layout-header-title {
margin-top: 0;
margin-bottom: 8px;
margin-right: 20px;
}
.layout-content {
width: 100%;
}
</style>

View File

@@ -0,0 +1,5 @@
<template>
<n-card title="拆线图">
<div>拆线图</div>
</n-card>
</template>

View File

@@ -0,0 +1,5 @@
<template>
<n-button quaternary round>
退出
</n-button>
</template>

View File

@@ -0,0 +1,38 @@
<template>
<n-menu
mode="horizontal"
:options="menuOptions"
:value="activeMenu"
responsive
/>
</template>
<script setup lang="ts">
import { ref, h, computed } from 'vue'
import { RouterLink, useRoute } from 'vue-router'
const menuOptions: MenuOption[] = [
renderMenuItem('dashboard', '仪表盘'),
renderMenuItem('keys', '密钥管理'),
renderMenuItem('logs', '日志'),
renderMenuItem('settings', '系统设置'),
]
const route = useRoute()
const activeMenu = computed(() => route.name)
function renderMenuItem(key: string, label: string): MenuOption {
return {
label: () => h(
RouterLink,
{
to: {
name: key,
}
},
{ default: () => label }
),
key,
}
}
</script>

10
fe/src/main.ts Normal file
View File

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

82
fe/src/style.css Normal file
View File

@@ -0,0 +1,82 @@
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
#app {
max-width: 1280px;
width: 100%;
margin: 0 auto;
padding: 2rem;
min-height: 100vh;
}
.flex {
display: flex;
}
.flex-row {
flex-direction: row;
}
.flex-col {
flex-direction: column;
}
.justify-start {
justify-content: flex-start;
}
.justify-center {
justify-content: center;
}
.justify-end {
justify-content: flex-end;
}
.justify-between {
justify-content: space-between;
}
.items-start {
align-items: flex-start;
}
.items-center {
align-items: center;
}
.items-end {
align-items: flex-end;
}
.flex-wrap {
flex-wrap: wrap;
}
.flex-nowrap {
flex-wrap: nowrap;
}
.grow {
flex-grow: 1;
}
.shrink {
flex-shrink: 1;
}

27
fe/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

32
fe/src/utils/router.ts Normal file
View File

@@ -0,0 +1,32 @@
import { createRouter, createWebHistory } from 'vue-router'
import 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
fe/src/utils/state.ts Normal file
View File

@@ -0,0 +1,27 @@
import { reactive, toRef, isRef } from 'vue'
import type { Ref } from 'vue'
type IntializeFunc<T> = (() => T | Ref<T>)
type InitializeValue<T> = T | Ref<T> | IntializeFunc<T>
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
}

View File

@@ -0,0 +1,15 @@
<template>
<base-info-card />
<line-chart class="chart" />
</template>
<script setup lang="ts">
import BaseInfoCard from '@/components/BaseInfoCard.vue'
import LineChart from '@/components/LineChart.vue'
</script>
<style scoped>
.chart {
margin-top: 20px;
}
</style>

3
fe/src/views/Keys.vue Normal file
View File

@@ -0,0 +1,3 @@
<template>
<div>keys</div>
</template>

3
fe/src/views/Login.vue Normal file
View File

@@ -0,0 +1,3 @@
<template>
<h1>Login</h1>
</template>

3
fe/src/views/Logs.vue Normal file
View File

@@ -0,0 +1,3 @@
<template>
<div>logs</div>
</template>

View File

@@ -0,0 +1,3 @@
<template>
<div>settings</div>
</template>

1
fe/src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

15
fe/tsconfig.app.json Normal file
View File

@@ -0,0 +1,15 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}

13
fe/tsconfig.json Normal file
View File

@@ -0,0 +1,13 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
},
},
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

25
fe/tsconfig.node.json Normal file
View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

31
fe/vite.config.ts Normal file
View File

@@ -0,0 +1,31 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
// 解析配置
resolve: {
// 配置路径别名
alias: {
'@': path.resolve(__dirname, './src')
}
},
// 开发服务器配置
server: {
// 代理配置示例
proxy: {
'/api': {
target: 'http://api.example.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
// 构建配置
build: {
outDir: 'dist',
assetsDir: 'assets'
}
})