初始模板

This commit is contained in:
fanbook-wangdage
2025-12-20 15:38:00 +08:00
commit d72f2e7159
23 changed files with 4275 additions and 0 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

3
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}

7
README.md Normal file
View File

@@ -0,0 +1,7 @@
# Snap.Hutao服务器管理后台
还没写完,写完后使用
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).

13
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>ht-web</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

3658
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

29
package.json Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "ht-web",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.13.2",
"element-plus": "^2.13.0",
"pinia": "^3.0.4",
"vue": "^3.5.24",
"vue-router": "^4.6.4"
},
"devDependencies": {
"@types/node": "^24.10.1",
"@vitejs/plugin-vue": "^6.0.1",
"@vue/tsconfig": "^0.8.1",
"eslint": "^9.39.2",
"prettier": "^3.7.4",
"sass": "^1.97.1",
"typescript": "~5.9.3",
"vite": "^7.2.4",
"vue-tsc": "^3.1.4"
}
}

1
public/vite.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="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

4
src/App.vue Normal file
View File

@@ -0,0 +1,4 @@
<template>
<router-view />
</template>

1
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,41 @@
<template>
<template v-for="item in routes" :key="item.path">
<!-- 有子路由 -->
<el-sub-menu
v-if="hasChildren(item)"
:index="item.path"
>
<template #title>
<el-icon v-if="item.meta?.icon">
<component :is="icons[item.meta.icon as keyof typeof icons]" />
</el-icon>
<span>{{ item.meta?.title }}</span>
</template>
<SidebarItem :routes="item.children!" />
</el-sub-menu>
<!-- 普通菜单 -->
<el-menu-item
v-else
:index="item.path"
>
<el-icon v-if="item.meta?.icon">
<component :is="icons[item.meta.icon as keyof typeof icons]" />
</el-icon>
<span>{{ item.meta?.title }}</span>
</el-menu-item>
</template>
</template>
<script setup lang="ts">
import type { RouteRecordRaw } from 'vue-router'
import * as icons from '@element-plus/icons-vue'
defineProps<{
routes: RouteRecordRaw[]
}>()
const hasChildren = (route: RouteRecordRaw) =>
route.children && route.children.length > 0
</script>

View File

@@ -0,0 +1,174 @@
<template>
<el-container class="layout">
<el-aside :width="isCollapse ? '64px' : '200px'" class="aside">
<div class="logo" :class="{ collapsed: isCollapse }">
<span v-if="!isCollapse">Vite Admin</span>
<span v-else>VA</span>
</div>
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
router
class="menu"
>
<SidebarItem :routes="menuRoutes" />
</el-menu>
</el-aside>
<el-container>
<el-header class="header">
<div class="header-left">
<el-icon class="toggle-btn" @click="toggle">
<Fold v-if="!isCollapse" />
<Expand v-else />
</el-icon>
</div>
<div class="header-right">
<div class="theme-toggle">
<el-switch
:model-value="themeStore.isDark"
class="dark-mode-switch"
:active-icon="Moon"
:inactive-icon="Sunny"
@change="themeStore.toggleTheme"
/>
</div>
</div>
</el-header>
<el-main class="main">
<router-view />
</el-main>
</el-container>
</el-container>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Fold, Expand, Moon, Sunny } from '@element-plus/icons-vue'
import SidebarItem from '../components/SidebarItem.vue'
import { useThemeStore } from '../stores/theme'
const isCollapse = ref(false)
const route = useRoute()
const router = useRouter()
const themeStore = useThemeStore()
const toggle = () => (isCollapse.value = !isCollapse.value)
const activeMenu = computed(() => route.path)
/**
* 获取菜单路由,直接使用配置的路由结构
*/
const menuRoutes = computed(() => {
// 直接返回路由配置中的子路由
const mainRoute = router.options.routes.find(r => r.path === '/')
return mainRoute?.children || []
})
</script>
<style scoped>
.layout {
height: 100vh;
}
.aside {
background-color: var(--aside-bg);
transition: width 0.3s;
overflow: hidden;
}
.logo {
height: 60px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 18px;
font-weight: bold;
background-color: var(--aside-hover);
transition: all 0.3s;
}
.logo.collapsed {
font-size: 16px;
}
.menu {
border-right: none;
background-color: var(--aside-bg);
}
.menu :deep(.el-menu-item) {
color: var(--aside-text);
background-color: var(--aside-bg);
}
.menu :deep(.el-menu-item:hover) {
background-color: var(--aside-hover) !important;
color: #fff;
}
.menu :deep(.el-menu-item.is-active) {
background-color: var(--aside-active) !important;
color: #fff;
}
.menu :deep(.el-sub-menu__title) {
color: var(--aside-text);
background-color: var(--aside-bg);
}
.menu :deep(.el-sub-menu__title:hover) {
background-color: var(--aside-hover) !important;
color: #fff;
}
.header {
background-color: var(--header-bg);
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
}
.header-left {
display: flex;
align-items: center;
}
.toggle-btn {
font-size: 20px;
cursor: pointer;
color: var(--text-color);
transition: color 0.3s;
}
.toggle-btn:hover {
color: var(--aside-active);
}
.header-right {
display: flex;
align-items: center;
}
.theme-toggle {
display: flex;
align-items: center;
}
.dark-mode-switch {
--el-switch-on-color: #409eff;
--el-switch-off-color: #dcdfe6;
}
.main {
background-color: var(--main-bg);
padding: 20px;
}
</style>

26
src/main.ts Normal file
View File

@@ -0,0 +1,26 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import '@/styles/index.scss'
import App from './App.vue'
import router from './router'
import { useThemeStore } from './stores/theme'
const app = createApp(App)
const pinia = createPinia()
app.use(pinia)
app.use(router)
app.use(ElementPlus)
// 初始化主题
const themeStore = useThemeStore(pinia)
// 确保在应用挂载前应用正确的主题
if (themeStore.isDark) {
document.documentElement.classList.add('dark')
}
app.mount('#app')

50
src/router/index.ts Normal file
View File

@@ -0,0 +1,50 @@
import { createRouter, createWebHistory } from 'vue-router'
import DefaultLayout from '@/layouts/DefaultLayout.vue'
const routes = [
{
path: '/login',
component: () => import('@/views/login/index.vue'),
meta: { hidden: true }
},
{
path: '/',
component: DefaultLayout,
redirect: '/dashboard',
children: [
{
path: 'dashboard',
component: () => import('@/views/dashboard/index.vue'),
meta: { title: '首页', icon: 'House' },
},
{
path: 'user',
component: () => import('@/views/dashboard/index.vue'),
meta: { title: '用户管理', icon: 'User' },
},
{
path: 'system',
meta: { title: '系统管理', icon: 'Setting' },
children: [
{
path: 'menu',
component: () => import('@/views/dashboard/index.vue'),
meta: { title: '菜单管理', icon: 'Menu' },
},
{
path: 'role',
component: () => import('@/views/dashboard/index.vue'),
meta: { title: '角色管理', icon: 'UserFilled' },
},
],
},
],
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
export default router

38
src/stores/theme.ts Normal file
View File

@@ -0,0 +1,38 @@
import { defineStore } from 'pinia'
import { ref, watch } from 'vue'
export const useThemeStore = defineStore('theme', () => {
// 从localStorage读取初始主题状态默认为light
const savedTheme = localStorage.getItem('theme') || 'light'
const isDark = ref(savedTheme === 'dark')
// 切换主题
const toggleTheme = () => {
isDark.value = !isDark.value
}
// 设置主题
const setTheme = (theme: 'light' | 'dark') => {
isDark.value = theme === 'dark'
}
// 监听主题变化同步到localStorage和html元素
watch(isDark, (newValue) => {
const theme = newValue ? 'dark' : 'light'
localStorage.setItem('theme', theme)
// 在html元素上添加或移除dark类
const html = document.documentElement
if (newValue) {
html.classList.add('dark')
} else {
html.classList.remove('dark')
}
}, { immediate: true })
return {
isDark,
toggleTheme,
setTheme
}
})

0
src/style.css Normal file
View File

99
src/styles/index.scss Normal file
View File

@@ -0,0 +1,99 @@
/* src/styles/index.scss */
* {
box-sizing: border-box;
}
html,
body,
#app {
height: 100%;
margin: 0;
padding: 0;
}
// CSS 变量定义 - 亮色模式
:root {
--bg-color: #f5f7fa;
--text-color: #303133;
--border-color: #e4e7ed;
--header-bg: #fff;
--aside-bg: #304156;
--aside-text: #bfcbd9;
--aside-hover: #263445;
--aside-active: #409eff;
--main-bg: #f5f7fa;
}
// CSS 变量定义 - 暗色模式
html.dark {
--bg-color: #1a1a1a;
--text-color: #e4e7ed;
--border-color: #4c4d4f;
--header-bg: #2b2b2b;
--aside-bg: #1f1f1f;
--aside-text: #a8abb2;
--aside-hover: #363636;
--aside-active: #409eff;
--main-bg: #141414;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, 'Helvetica Neue', Arial;
background-color: var(--bg-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}
// 暗黑模式下的全局样式调整
html.dark {
.el-header {
background-color: var(--header-bg) !important;
border-bottom-color: var(--border-color) !important;
}
.el-main {
background-color: var(--main-bg) !important;
}
.el-aside {
background-color: var(--aside-bg) !important;
}
.el-menu {
background-color: var(--aside-bg) !important;
.el-menu-item {
color: var(--aside-text) !important;
background-color: var(--aside-bg) !important;
&:hover {
background-color: var(--aside-hover) !important;
color: #fff !important;
}
&.is-active {
background-color: var(--aside-active) !important;
color: #fff !important;
}
}
.el-sub-menu__title {
color: var(--aside-text) !important;
background-color: var(--aside-bg) !important;
&:hover {
background-color: var(--aside-hover) !important;
color: #fff !important;
}
}
}
.toggle-btn {
color: var(--text-color) !important;
&:hover {
color: var(--aside-active) !important;
}
}
}

18
src/utils/request.ts Normal file
View File

@@ -0,0 +1,18 @@
import axios from 'axios'
const request = axios.create({
baseURL: '/api',
timeout: 10000,
})
request.interceptors.request.use((config) => {
// 可加 token
return config
})
request.interceptors.response.use(
(res) => res.data,
(err) => Promise.reject(err)
)
export default request

View File

@@ -0,0 +1,5 @@
<template>
<el-card>
<h2>欢迎进入管理后台</h2>
</el-card>
</template>

View File

@@ -0,0 +1,7 @@
<template>
<div class="login-container">
<h1>Login Page</h1>
<!-- Login form goes here -->
</div>
</template>

20
tsconfig.app.json Normal file
View File

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

18
tsconfig.json Normal file
View File

@@ -0,0 +1,18 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}

26
tsconfig.node.json Normal file
View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"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"]
}

13
vite.config.ts Normal file
View File

@@ -0,0 +1,13 @@
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'),
},
},
})