feat: 初始化DevBox项目,完成基础框架搭建

1. 添加Tauri桌面应用所需的配置、构建脚本和图标资源
2. 搭建Vue3+TypeScript+Vite前端基础架构
3. 实现MySQL数据库连接与用户登录的后端命令
4. 完成登录页和仪表盘的基础UI页面开发
5. 配置CI发布工作流与项目基础文档
This commit is contained in:
sparksfly 2026-07-26 23:06:27 +08:00
commit 68d08dbc23
53 changed files with 9580 additions and 0 deletions

65
.github/workflows/release.yaml vendored Normal file
View File

@ -0,0 +1,65 @@
name: 'publish'
on:
push:
branches:
- release # 当代码推送到 release 分支时触发
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest' # 为 Apple Silicon (M1/M2) 构建
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest' # 为 Intel 芯片的 Mac 构建
args: '--target x86_64-apple-darwin'
- platform: 'ubuntu-22.04' # 为 Linux 构建 (x86_64)
args: ''
- platform: 'windows-latest' # 为 Windows 构建 (x86_64)
args: ''
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
# 1. 设置 Node.js 环境
- name: setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm' # 如果你用 yarn改成 'yarn';用 pnpm 改成 'pnpm'
# 2. 设置 Rust 环境
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
# 3. (仅 Linux) 安装系统依赖
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xdg-utils
# 4. 安装前端依赖并构建
- name: install frontend dependencies
run: pnpm install # 如果使用 yarn改为 yarn install
# 如果你的项目需要在构建前端后运行,可以添加以下步骤(可选)
# - name: build frontend
# run: npm run build
# 5. 核心步骤:使用 tauri-action 构建并发布
- uses: tauri-apps/tauri-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__ # Release 的标签名
releaseName: 'App v__VERSION__' # Release 的标题
releaseBody: '请查看附件下载此版本。' # Release 的描述
releaseDraft: true # 是否创建为草稿,建议设为 true 以便最后检查
prerelease: false # 是否为预发布版本
args: ${{ matrix.args }}

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?

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

@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}

112
README.md Normal file
View File

@ -0,0 +1,112 @@
# DevBox
面向开发者的轻量级一站式工作台桌面应用,基于 **Tauri 2** 构建,兼具原生性能与 Web 技术灵活性。
## 技术栈
| 层 | 技术 |
|------|------|
| 桌面框架 | [Tauri 2](https://tauri.app/)Rust 后端 + Web 前端) |
| 前端 | Vue 3 + TypeScript + Vite |
| UI 组件 | [Naive UI](https://www.naiveui.com/) |
| 路由 | Vue Router 5 |
| 数据库 | MySQL通过 [SQLx](https://github.com/launchbadge/sqlx) 异步连接 |
| 系统信息 | [sysinfo](https://github.com/GuillaumeGomez/sysinfo) |
| 图标 | [Ionicons 5](https://ionic.io/ionicons) |
## 功能
- **用户登录** — 支持 MySQL 验证的登录界面
- **仪表盘** — 项目概览、统计卡片、活跃度趋势图、仓库列表
- **系统信息** — 实时采集 CPU、内存等核心指标
- **侧边栏导航** — 仓库、成员、服务、插件、设置等模块入口
## 快速开始
### 环境要求
- Node.js 18+
- pnpm 8+
- Rust 最新稳定版
- MySQL 8.0+(运行中)
### 安装依赖
```bash
pnpm install
```
### 配置数据库
`src-tauri/` 目录下创建 `.env` 文件:
```
DATABASE_URL=mysql://用户名:密码@127.0.0.1:3306/数据库名
```
然后导入初始表结构:
```sql
CREATE TABLE IF NOT EXISTS sys_user (
id INT AUTO_INCREMENT PRIMARY KEY,
nick_name VARCHAR(100) NOT NULL,
avatar VARCHAR(255) DEFAULT '',
user_name VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
email VARCHAR(200) DEFAULT '',
phone VARCHAR(20) DEFAULT '',
age INT DEFAULT 0,
sex INT DEFAULT 0,
creater INT DEFAULT 0,
create_time VARCHAR(50) DEFAULT ''
);
```
### 启动开发服务器
```bash
pnpm tauri dev
```
### 构建桌面安装包
```bash
pnpm tauri build
```
## 项目结构
```
DevBox/
├── src/ # Vue 前端
│ ├── api/system/ # 后端 API 调用
│ ├── views/
│ │ ├── home/Login.vue # 登录页
│ │ └── dashboard/ # 仪表盘
│ ├── router/ # 路由配置
│ ├── types/ # TypeScript 类型
│ └── assets/ # 静态资源
├── src-tauri/ # Rust 后端
│ ├── src/
│ │ ├── lib.rs # Tauri 入口 & 命令注册
│ │ ├── main.rs # 主函数
│ │ ├── models.rs # 数据结构
│ │ ├── services/db.rs # 数据库连接池
│ │ └── commands/ # Tauri 命令
│ ├── Cargo.toml # Rust 依赖
│ └── tauri.conf.json # Tauri 配置
├── package.json
└── index.html
```
## 技术亮点
- **异步数据库访问** — SQLx 连接池自动注入 Tauri 命令,无阻塞 UI
- **泛型响应结构**`ApiResponse<T>` 统一前后端数据契约
- **玻璃态 UI** — 登录页采用 backdrop-filter 毛玻璃卡片设计
- **响应式骨架** — 仪表盘适配 375px ~ 1440px 全宽度区间
- **系统减动画偏好** — 完整支持 `prefers-reduced-motion`
## 许可
MIT

17
index.html Normal file
View File

@ -0,0 +1,17 @@
<!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>DevBox</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

31
package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "DevBox",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-opener": "^2",
"@vicons/ionicons5": "^0.13.0",
"axios": "^1.18.1",
"naive-ui": "^2.44.1",
"vue": "^3.5.13",
"vue-router": "^5.2.0"
},
"devDependencies": {
"@tauri-apps/cli": "^2",
"@types/node": "^26.1.1",
"@vitejs/plugin-vue": "^5.2.1",
"typescript": "~5.6.2",
"unplugin-auto-import": "^21.0.0",
"unplugin-vue-components": "^32.1.0",
"vite": "^6.0.3",
"vue-tsc": "^2.1.10"
}
}

2043
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load Diff

2
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,2 @@
allowBuilds:
esbuild: false

6
public/tauri.svg Normal file
View File

@ -0,0 +1,6 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

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

7
src-tauri/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

5610
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

32
src-tauri/Cargo.toml Normal file
View File

@ -0,0 +1,32 @@
[package]
name = "DevBox"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "DevBox_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sysinfo = "0.39.6"
chrono = { version = "0.4", features = ["serde"] }
sqlx = { version = "0.9.0", features = [
"runtime-tokio",
"mysql",
"tls-native-tls",
"chrono",
] }

3
src-tauri/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View File

@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
]
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1 @@
pub mod user;

View File

@ -0,0 +1,70 @@
use serde::{Deserialize, Serialize};
use sqlx::MySqlPool;
use tauri::State;
use crate::models::ApiResponse;
#[derive(Debug, Serialize, sqlx::FromRow)]
struct SysUser {
id: i32,
nick_name: String,
avatar: String,
user_name: String,
password: String,
email: String,
phone: String,
age: i32,
sex: i32,
creater: i32,
create_time: chrono::NaiveDateTime,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UserInfo {
id: i32,
nick_name: String,
avatar: String,
user_name: String,
email: String,
phone: String,
age: i32,
sex: i32,
}
impl From<SysUser> for UserInfo {
fn from(user: SysUser) -> UserInfo {
UserInfo {
id: user.id,
nick_name: user.nick_name,
avatar: user.avatar,
user_name: user.user_name,
email: user.email,
phone: user.phone,
age: user.age,
sex: user.sex,
}
}
}
#[tauri::command]
pub async fn login(
pool: State<'_, MySqlPool>,
user_name: &str,
password: &str,
) -> Result<ApiResponse<UserInfo>, String> {
let user = sqlx::query_as::<_, SysUser>("SELECT * FROM sys_user WHERE user_name = ?")
.bind(&user_name)
.fetch_optional(&*pool)
.await
.map_err(|e| e.to_string())?;
let user = match user {
Some(user) => user,
None => {
return Ok(ApiResponse::error(1001, "用户不存在"));
}
};
if user.password != password.to_string() {
return Ok(ApiResponse::error(1002, "用户名或密码错误"));
}
let user_info: UserInfo = UserInfo::from(user);
Ok(ApiResponse::success(user_info))
}

26
src-tauri/src/lib.rs Normal file
View File

@ -0,0 +1,26 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
pub mod commands;
pub mod services;
pub mod models;
use services::db::create_db_pool;
use tauri::Manager;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
// 初始化数据库连接池
.setup(|app| {
let pool = tauri::async_runtime::block_on(async {
create_db_pool().await.expect("连接Mysql数据库出错!")
});
app.manage(pool);
Ok(())
})
.invoke_handler(tauri::generate_handler![
commands::user::login
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
DevBox_lib::run()
}

34
src-tauri/src/models.rs Normal file
View File

@ -0,0 +1,34 @@
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ApiResponse<T> {
success: bool,
code: i32,
message: String,
data: Option<T>,
}
impl<T: Serialize> ApiResponse<T> {
// 成功响应
pub fn success(data: T) -> Self {
Self {
success: true,
code: 200,
message: "操作成功".to_string(),
data: Some(data),
}
}
// 成功响应,数据为空
pub fn success_empty() -> ApiResponse<()> {
ApiResponse { success: true, code: 200, message: "操作成功".to_string(), data: None }
}
// 错误响应
pub fn error(code: i32, message: &str) -> Self {
Self {
success: false,
code,
message: message.to_string(),
data: None,
}
}
}

View File

@ -0,0 +1,9 @@
use sqlx::MySqlPool;
use sqlx::pool::PoolOptions;
// 创建数据库连接池
pub async fn create_db_pool() -> Result<MySqlPool, sqlx::Error> {
let db_url = "mysql://root:123456@127.0.0.1:3306/rust";
PoolOptions::new().max_connections(5).connect(db_url).await
}

View File

@ -0,0 +1 @@
pub mod db;

35
src-tauri/tauri.conf.json Normal file
View File

@ -0,0 +1,35 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "DevBox",
"version": "0.1.0",
"identifier": "com.sparksfly.DevBox",
"build": {
"beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "pnpm build",
"frontendDist": "../dist"
},
"app": {
"windows": [
{
"title": "DevBox",
"width": 1440,
"height": 900
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}

18
src/App.vue Normal file
View File

@ -0,0 +1,18 @@
<template>
<n-message-provider>
<div class="container">
<router-view />
</div>
</n-message-provider>
</template>
<script setup lang="ts">
</script>
<style scoped>
.container {
width: 100%;
height: 100vh;
}
</style>

24
src/api/system/user.ts Normal file
View File

@ -0,0 +1,24 @@
import { invoke } from "@tauri-apps/api/core";
import { ApiResponse } from "@/types";
interface UserInfo {
id: number;
nickName: string;
avatar: string;
userName: string;
email: string;
phone: string;
age: number;
sex: number;
}
const UserApi = {
login: async (
userName: string,
password: string,
): Promise<ApiResponse<UserInfo>> => {
return await invoke("login", { userName, password });
},
};
export default UserApi;

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

9
src/main.ts Normal file
View File

@ -0,0 +1,9 @@
import { createApp } from "vue";
import App from "./App.vue";
import naive from "naive-ui";
import router from "@/router";
const app = createApp(App);
app.use(naive);
app.use(router);
app.mount("#app");

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

@ -0,0 +1,25 @@
import { createRouter, createWebHistory } from "vue-router";
const routes = [
{
path: "/",
redirect: "/login"
},
{
path: "/login",
name: "Login",
component: () => import("@/views/home/Login.vue")
},
{
path: "/dashboard",
name: "Dashboard",
component: () => import("@/views/dashboard/Dashboard.vue")
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
export default router;

78
src/types/auto-imports.d.ts vendored Normal file
View File

@ -0,0 +1,78 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import
// biome-ignore lint: disable
export {}
declare global {
const EffectScope: typeof import('vue').EffectScope
const computed: typeof import('vue').computed
const createApp: typeof import('vue').createApp
const customRef: typeof import('vue').customRef
const defineAsyncComponent: typeof import('vue').defineAsyncComponent
const defineComponent: typeof import('vue').defineComponent
const effectScope: typeof import('vue').effectScope
const getCurrentInstance: typeof import('vue').getCurrentInstance
const getCurrentScope: typeof import('vue').getCurrentScope
const getCurrentWatcher: typeof import('vue').getCurrentWatcher
const h: typeof import('vue').h
const inject: typeof import('vue').inject
const isProxy: typeof import('vue').isProxy
const isReactive: typeof import('vue').isReactive
const isReadonly: typeof import('vue').isReadonly
const isRef: typeof import('vue').isRef
const isShallow: typeof import('vue').isShallow
const markRaw: typeof import('vue').markRaw
const nextTick: typeof import('vue').nextTick
const onActivated: typeof import('vue').onActivated
const onBeforeMount: typeof import('vue').onBeforeMount
const onBeforeRouteLeave: typeof import('vue-router').onBeforeRouteLeave
const onBeforeRouteUpdate: typeof import('vue-router').onBeforeRouteUpdate
const onBeforeUnmount: typeof import('vue').onBeforeUnmount
const onBeforeUpdate: typeof import('vue').onBeforeUpdate
const onDeactivated: typeof import('vue').onDeactivated
const onErrorCaptured: typeof import('vue').onErrorCaptured
const onMounted: typeof import('vue').onMounted
const onRenderTracked: typeof import('vue').onRenderTracked
const onRenderTriggered: typeof import('vue').onRenderTriggered
const onScopeDispose: typeof import('vue').onScopeDispose
const onServerPrefetch: typeof import('vue').onServerPrefetch
const onUnmounted: typeof import('vue').onUnmounted
const onUpdated: typeof import('vue').onUpdated
const onWatcherCleanup: typeof import('vue').onWatcherCleanup
const provide: typeof import('vue').provide
const reactive: typeof import('vue').reactive
const readonly: typeof import('vue').readonly
const ref: typeof import('vue').ref
const resolveComponent: typeof import('vue').resolveComponent
const shallowReactive: typeof import('vue').shallowReactive
const shallowReadonly: typeof import('vue').shallowReadonly
const shallowRef: typeof import('vue').shallowRef
const toRaw: typeof import('vue').toRaw
const toRef: typeof import('vue').toRef
const toRefs: typeof import('vue').toRefs
const toValue: typeof import('vue').toValue
const triggerRef: typeof import('vue').triggerRef
const unref: typeof import('vue').unref
const useAttrs: typeof import('vue').useAttrs
const useCssModule: typeof import('vue').useCssModule
const useCssVars: typeof import('vue').useCssVars
const useId: typeof import('vue').useId
const useLink: typeof import('vue-router').useLink
const useModel: typeof import('vue').useModel
const useRoute: typeof import('vue-router').useRoute
const useRouter: typeof import('vue-router').useRouter
const useSlots: typeof import('vue').useSlots
const useTemplateRef: typeof import('vue').useTemplateRef
const watch: typeof import('vue').watch
const watchEffect: typeof import('vue').watchEffect
const watchPostEffect: typeof import('vue').watchPostEffect
const watchSyncEffect: typeof import('vue').watchSyncEffect
}
// for type re-export
declare global {
// @ts-ignore
export type { Component, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, ShallowRef, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
import('vue')
}

17
src/types/components.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
/* eslint-disable */
// @ts-nocheck
// biome-ignore lint: disable
// oxlint-disable
// ------
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}

8
src/types/index.ts Normal file
View File

@ -0,0 +1,8 @@
interface ApiResponse<T> {
success: boolean;
code: number;
message: string;
data: T;
}
export type { ApiResponse };

View File

@ -0,0 +1,735 @@
<template>
<div class="dashboard-layout">
<!-- 侧边栏遮罩移动端 -->
<div
v-if="sidebarOpen"
class="sidebar-overlay"
@click="sidebarOpen = false"
/>
<!-- 侧边栏 -->
<aside class="sidebar" :class="{ open: sidebarOpen }">
<!-- 侧边栏 Logo -->
<div class="sidebar-brand">
<svg class="sidebar-logo" viewBox="0 0 40 40" fill="none">
<rect width="40" height="40" rx="12" fill="url(#sb-grad)" />
<path d="M12 26V14l8 8 8-8v12" stroke="#fff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" />
<defs>
<linearGradient id="sb-grad" x1="0" y1="0" x2="40" y2="40">
<stop stop-color="#0891B2" />
<stop offset="1" stop-color="#06B6D4" />
</linearGradient>
</defs>
</svg>
<span class="sidebar-title">DevBox</span>
</div>
<!-- 导航菜单 -->
<nav class="sidebar-nav">
<a
v-for="item in menuItems"
:key="item.key"
class="nav-item"
:class="{ active: activeMenu === item.key }"
href="javascript:;"
@click="activeMenu = item.key"
>
<n-icon size="20" :component="item.icon" />
<span class="nav-label">{{ item.label }}</span>
</a>
</nav>
<!-- 底部用户区 -->
<div class="sidebar-footer">
<div class="user-chip">
<n-avatar round size="small" :style="{ backgroundColor: '#0891B2' }">
{{ userInitial }}
</n-avatar>
<div class="user-meta">
<span class="user-name">{{ currentUser }}</span>
<span class="user-role">开发者</span>
</div>
</div>
</div>
</aside>
<!-- 主区域 -->
<div class="main-area">
<!-- 顶部栏 -->
<header class="topbar">
<button class="menu-trigger" @click="sidebarOpen = !sidebarOpen">
<n-icon size="22" :component="MenuOutline" />
</button>
<div class="topbar-right">
<n-badge dot :show="true" processing>
<n-icon size="20" :component="NotificationsOutline" class="topbar-icon" />
</n-badge>
<n-avatar round size="small" :style="{ backgroundColor: '#0891B2' }" class="topbar-avatar">
{{ userInitial }}
</n-avatar>
</div>
</header>
<!-- 内容区域 -->
<main class="content">
<div class="content-inner">
<!-- 页面标题 -->
<div class="page-header">
<h2 class="page-title">概览</h2>
<p class="page-subtitle">欢迎回来来看看你的项目近况</p>
</div>
<!-- 统计卡片行 -->
<div class="stat-grid">
<div v-for="stat in stats" :key="stat.label" class="stat-card">
<div class="stat-icon" :style="{ backgroundColor: stat.bg }">
<n-icon size="22" :component="stat.icon" :color="stat.color" />
</div>
<div class="stat-info">
<span class="stat-value">{{ stat.value }}</span>
<span class="stat-label">{{ stat.label }}</span>
</div>
<div class="stat-badge" :class="stat.trend > 0 ? 'up' : 'down'">
<n-icon size="14" :component="stat.trend > 0 ? ArrowUpOutline : ArrowDownOutline" />
{{ Math.abs(stat.trend) }}%
</div>
</div>
</div>
<!-- 下半部分图表占位 + 列表占位 -->
<div class="content-grid">
<div class="card card-chart">
<div class="card-header">
<h3 class="card-title">项目活跃度</h3>
<n-tag size="small" :bordered="false" type="info">最近 7 </n-tag>
</div>
<div class="chart-placeholder">
<svg class="chart-dummy" viewBox="0 0 400 160" preserveAspectRatio="none">
<polyline
fill="none"
stroke="#0891B2"
stroke-width="2.5"
stroke-linecap="round"
stroke-linejoin="round"
points="0,120 50,100 100,110 150,40 200,60 250,20 300,50 350,10 400,35"
/>
<polyline
fill="url(#area-grad)"
stroke="none"
points="0,120 50,100 100,110 150,40 200,60 250,20 300,50 350,10 400,35 400,160 0,160"
/>
<defs>
<linearGradient id="area-grad" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#0891B2" stop-opacity="0.15" />
<stop offset="1" stop-color="#0891B2" stop-opacity="0.01" />
</linearGradient>
</defs>
</svg>
<span class="chart-note">连接数据源以查看完整图表</span>
</div>
</div>
<div class="card card-list">
<div class="card-header">
<h3 class="card-title">最近仓库</h3>
<a class="card-link" href="javascript:;">查看全部</a>
</div>
<div class="repo-list">
<div v-for="repo in repos" :key="repo.name" class="repo-item">
<div class="repo-icon" :style="{ color: repo.color }">
<n-icon size="20" :component="GitBranchOutline" />
</div>
<div class="repo-info">
<span class="repo-name">{{ repo.name }}</span>
<span class="repo-desc">{{ repo.desc }}</span>
</div>
<n-tag size="small" :bordered="false" round :type="repo.statusType">
{{ repo.status }}
</n-tag>
</div>
</div>
<!-- 空态骨架 -->
<div v-if="!repos.length" class="empty-state">
<n-icon size="40" :component="FolderOpenOutline" color="#CBD5E1" />
<p>暂无仓库数据</p>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import {
GridOutline,
GitBranchOutline,
PeopleOutline,
ServerOutline,
NotificationsOutline,
MenuOutline,
ArrowUpOutline,
ArrowDownOutline,
FolderOpenOutline,
ExtensionPuzzleOutline,
SettingsOutline,
} from '@vicons/ionicons5'
//
const sidebarOpen = ref(false)
const activeMenu = ref('overview')
const menuItems = [
{ key: 'overview', label: '概览', icon: GridOutline },
{ key: 'repos', label: '仓库', icon: GitBranchOutline },
{ key: 'members', label: '成员', icon: PeopleOutline },
{ key: 'services', label: '服务', icon: ServerOutline },
{ key: 'plugins', label: '插件', icon: ExtensionPuzzleOutline },
{ key: 'settings', label: '设置', icon: SettingsOutline },
]
//
const currentUser = ref('SparksFly')
const userInitial = computed(() => currentUser.value.charAt(0).toUpperCase())
//
const stats = [
{
label: '仓库总数',
value: 12,
trend: 8,
icon: GitBranchOutline,
color: '#0891B2',
bg: 'rgba(8, 145, 178, 0.10)',
},
{
label: '团队成员',
value: 5,
trend: 0,
icon: PeopleOutline,
color: '#22C55E',
bg: 'rgba(34, 197, 94, 0.10)',
},
{
label: '活跃服务',
value: 3,
trend: -2,
icon: ServerOutline,
color: '#F59E0B',
bg: 'rgba(245, 158, 11, 0.10)',
},
{
label: '本周提交',
value: 86,
trend: 12,
icon: ArrowUpOutline,
color: '#8B5CF6',
bg: 'rgba(139, 92, 246, 0.10)',
},
]
//
const repos = ref([
{ name: 'DevBox', desc: '开发者工作台', status: 'Active', color: '#0891B2', statusType: 'success' as const },
{ name: 'api-gateway', desc: 'API 网关服务', status: 'Idle', color: '#22C55E', statusType: 'default' as const },
{ name: 'task-runner', desc: '异步任务调度', status: 'Active', color: '#F59E0B', statusType: 'success' as const },
])
</script>
<style scoped>
/* ─── 设计令牌 ─── */
.dashboard-layout {
--color-primary: #0891B2;
--color-primary-light: #ECFEFF;
--color-secondary: #22D3EE;
--color-bg: #F8FAFC;
--color-surface: #FFFFFF;
--color-text: #164E63;
--color-text-muted: #64748B;
--color-border: #E2E8F0;
--sidebar-width: 250px;
--topbar-height: 60px;
--font-heading: 'Space Grotesk', system-ui, sans-serif;
--font-body: 'DM Sans', system-ui, sans-serif;
display: flex;
width: 100%;
height: 100vh;
font-family: var(--font-body);
color: var(--color-text);
background: var(--color-bg);
overflow: hidden;
}
/* ─── 侧边栏 ─── */
.sidebar {
position: fixed;
inset: 0 auto 0 0;
z-index: 100;
width: var(--sidebar-width);
display: flex;
flex-direction: column;
background: var(--color-surface);
border-right: 1px solid var(--color-border);
transition: transform 0.25s ease;
}
.sidebar-brand {
display: flex;
align-items: center;
gap: 12px;
height: var(--topbar-height);
padding: 0 20px;
border-bottom: 1px solid var(--color-border);
}
.sidebar-logo {
display: block;
width: 36px;
height: 36px;
flex-shrink: 0;
}
.sidebar-title {
font-family: var(--font-heading);
font-size: 17px;
font-weight: 600;
color: var(--color-text);
white-space: nowrap;
}
/* 导航 */
.sidebar-nav {
flex: 1;
display: flex;
flex-direction: column;
gap: 2px;
padding: 16px 12px;
overflow-y: auto;
}
.nav-item {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border-radius: 10px;
color: var(--color-text-muted);
text-decoration: none;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.nav-item:hover {
background: var(--color-primary-light);
color: var(--color-primary);
}
.nav-item.active {
background: rgba(8, 145, 178, 0.12);
color: var(--color-primary);
font-weight: 600;
}
.nav-label {
white-space: nowrap;
}
/* 底部用户 */
.sidebar-footer {
padding: 16px 16px;
border-top: 1px solid var(--color-border);
}
.user-chip {
display: flex;
align-items: center;
gap: 10px;
padding: 4px;
}
.user-meta {
display: flex;
flex-direction: column;
min-width: 0;
}
.user-name {
font-size: 13px;
font-weight: 600;
color: var(--color-text);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.user-role {
font-size: 12px;
color: var(--color-text-muted);
}
/* ─── 侧边栏遮罩(移动端) ─── */
.sidebar-overlay {
position: fixed;
inset: 0;
z-index: 99;
background: rgba(15, 23, 42, 0.3);
backdrop-filter: blur(2px);
}
/* ─── 主区域 ─── */
.main-area {
flex: 1;
margin-left: var(--sidebar-width);
display: flex;
flex-direction: column;
min-width: 0;
transition: margin-left 0.25s ease;
}
/* ─── 顶部栏 ─── */
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
height: var(--topbar-height);
padding: 0 24px;
background: var(--color-surface);
border-bottom: 1px solid var(--color-border);
flex-shrink: 0;
}
.menu-trigger {
display: none;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border: none;
border-radius: 8px;
background: transparent;
color: var(--color-text-muted);
cursor: pointer;
transition: background 0.15s ease;
}
.menu-trigger:hover {
background: var(--color-bg);
}
.topbar-right {
display: flex;
align-items: center;
gap: 16px;
margin-left: auto;
}
.topbar-icon {
color: var(--color-text-muted);
cursor: pointer;
transition: color 0.15s ease;
}
.topbar-icon:hover {
color: var(--color-text);
}
.topbar-avatar {
cursor: pointer;
}
/* ─── 内容 ─── */
.content {
flex: 1;
overflow-y: auto;
}
.content-inner {
max-width: 1200px;
margin: 0 auto;
padding: 28px 24px;
}
/* 页面标题 */
.page-header {
margin-bottom: 28px;
}
.page-title {
margin: 0;
font-family: var(--font-heading);
font-size: 26px;
font-weight: 700;
color: var(--color-text);
letter-spacing: -0.3px;
}
.page-subtitle {
margin: 4px 0 0;
font-size: 14px;
color: var(--color-text-muted);
}
/* ─── 统计卡片 ─── */
.stat-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin-bottom: 28px;
}
.stat-card {
position: relative;
display: flex;
align-items: flex-start;
gap: 16px;
padding: 20px;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 16px;
transition: box-shadow 0.2s ease, transform 0.2s ease;
cursor: pointer;
}
.stat-card:hover {
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
transform: translateY(-2px);
}
.stat-icon {
display: flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
border-radius: 12px;
flex-shrink: 0;
}
.stat-info {
display: flex;
flex-direction: column;
min-width: 0;
}
.stat-value {
font-family: var(--font-heading);
font-size: 24px;
font-weight: 700;
color: var(--color-text);
line-height: 1.1;
}
.stat-label {
margin-top: 2px;
font-size: 13px;
color: var(--color-text-muted);
}
.stat-badge {
position: absolute;
top: 20px;
right: 20px;
display: inline-flex;
align-items: center;
gap: 2px;
padding: 2px 8px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
}
.stat-badge.up {
color: #16A34A;
background: rgba(34, 197, 94, 0.10);
}
.stat-badge.down {
color: #DC2626;
background: rgba(239, 68, 68, 0.10);
}
/* ─── 内容双栏 ─── */
.content-grid {
display: grid;
grid-template-columns: 1.5fr 1fr;
gap: 24px;
}
.card {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 16px;
overflow: hidden;
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 24px 0;
}
.card-title {
margin: 0;
font-family: var(--font-heading);
font-size: 17px;
font-weight: 600;
color: var(--color-text);
}
.card-link {
font-size: 13px;
font-weight: 500;
color: var(--color-primary);
text-decoration: none;
cursor: pointer;
}
.card-link:hover {
text-decoration: underline;
}
/* 图表占位 */
.card-chart {
padding-bottom: 24px;
}
.chart-placeholder {
padding: 20px 24px;
}
.chart-dummy {
width: 100%;
height: 160px;
}
.chart-note {
display: block;
text-align: center;
margin-top: 8px;
font-size: 12px;
color: var(--color-text-muted);
}
/* 仓库列表 */
.repo-list {
padding: 4px 24px 20px;
}
.repo-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 0;
border-bottom: 1px solid var(--color-border);
cursor: pointer;
transition: background 0.15s ease;
}
.repo-item:last-child {
border-bottom: none;
}
.repo-icon {
display: flex;
align-items: center;
flex-shrink: 0;
}
.repo-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.repo-name {
font-size: 14px;
font-weight: 600;
color: var(--color-text);
}
.repo-desc {
font-size: 12px;
color: var(--color-text-muted);
margin-top: 1px;
}
/* 空态 */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 20px;
text-align: center;
color: var(--color-text-muted);
font-size: 14px;
}
.empty-state p {
margin: 12px 0 0;
}
/* ─── 响应式(桌面端) ─── */
@media (max-width: 1024px) {
.stat-grid {
grid-template-columns: repeat(2, 1fr);
}
.content-grid {
grid-template-columns: 1fr;
}
}
/* ─── 响应式(移动端) ─── */
@media (max-width: 768px) {
.sidebar {
transform: translateX(-100%);
}
.sidebar.open {
transform: translateX(0);
}
.main-area {
margin-left: 0 !important;
}
.menu-trigger {
display: flex;
}
.stat-grid {
grid-template-columns: 1fr;
gap: 12px;
}
.content-inner {
padding: 20px 16px;
}
.page-title {
font-size: 22px;
}
}
/* ─── 减少动画 ─── */
@media (prefers-reduced-motion: reduce) {
.sidebar,
.stat-card,
.nav-item {
transition: none !important;
}
.stat-card:hover {
transform: none;
}
}
</style>

418
src/views/home/Login.vue Normal file
View File

@ -0,0 +1,418 @@
<template>
<div class="login-page">
<!-- 背景几何装饰 -->
<div class="bg-decor">
<div class="geo-shape geo-1" />
<div class="geo-shape geo-2" />
<div class="geo-shape geo-3" />
<div class="geo-circle circle-1" />
<div class="geo-circle circle-2" />
</div>
<!-- 登录卡片 -->
<div class="login-card">
<!-- 品牌区 -->
<div class="brand-area">
<div class="brand-icon">
<svg viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="40" height="40" rx="12" fill="url(#brand-grad)" />
<path d="M12 26V14l8 8 8-8v12" stroke="#fff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" />
<defs>
<linearGradient id="brand-grad" x1="0" y1="0" x2="40" y2="40">
<stop stop-color="#0891B2" />
<stop offset="1" stop-color="#06B6D4" />
</linearGradient>
</defs>
</svg>
</div>
<h1 class="brand-name">DevBox</h1>
<p class="brand-desc">开发者一站式工作台</p>
</div>
<!-- 表单区 -->
<n-form
ref="formRef"
:model="formData"
:rules="rules"
label-placement="left"
label-width="auto"
size="large"
>
<n-form-item path="username">
<n-input
v-model:value="formData.username"
placeholder="请输入用户名"
:input-props="{ autocomplete: 'username' }"
round
@keyup.enter="handleLogin"
>
<template #prefix>
<n-icon :component="PersonOutline" />
</template>
</n-input>
</n-form-item>
<n-form-item path="password">
<n-input
v-model:value="formData.password"
type="password"
show-password-on="click"
placeholder="请输入密码"
:input-props="{ autocomplete: 'current-password' }"
round
@keyup.enter="handleLogin"
>
<template #prefix>
<n-icon :component="LockClosedOutline" />
</template>
</n-input>
</n-form-item>
<div class="form-actions">
<n-button
type="primary"
block
round
size="large"
:loading="loading"
:disabled="loading"
class="login-btn"
@click="handleLogin"
>
{{ loading ? '登录中...' : '登 录' }}
</n-button>
</div>
</n-form>
<!-- 底部提示 -->
<p class="footer-tip">
<span>首次使用</span>
<a class="footer-link" href="javascript:;">联系管理员开通</a>
</p>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useMessage } from 'naive-ui'
import UserApi from '@/api/system/user'
import { PersonOutline, LockClosedOutline } from '@vicons/ionicons5'
import type { FormInst, FormRules } from 'naive-ui'
const router = useRouter()
const message = useMessage()
const formRef = ref<FormInst | null>(null)
const loading = ref(false)
const formData = reactive({
username: '',
password: '',
})
const rules: FormRules = {
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 6, message: '密码长度不少于6位', trigger: 'blur' },
],
}
const handleLogin = () => {
formRef.value?.validate(async (errors) => {
if (errors) return
loading.value = true
try {
const res = await UserApi.login(formData.username, formData.password)
if (res.success === true) {
message.success('登录成功')
router.push('/dashboard')
} else {
message.error(res.message || '登录失败')
}
} catch {
message.error('登录失败,请检查网络连接')
} finally {
loading.value = false
}
})
}
</script>
<style scoped>
/* ─── 全局变量(设计系统配色) ─── */
.login-page {
--color-primary: #0891B2;
--color-primary-hover: #06B6D4;
--color-secondary: #22D3EE;
--color-cta: #22C55E;
--color-cta-hover: #16A34A;
--color-bg-start: #ECFEFF;
--color-bg-end: #F0F9FF;
--color-text: #164E63;
--color-text-muted: #64748B;
--font-heading: 'Space Grotesk', system-ui, sans-serif;
--font-body: 'DM Sans', system-ui, sans-serif;
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: 100vh;
background: linear-gradient(160deg, var(--color-bg-start) 0%, #E0F2FE 40%, #F0F9FF 100%);
font-family: var(--font-body);
overflow: hidden;
}
/* ─── 背景几何装饰 ─── */
.bg-decor {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.geo-shape {
position: absolute;
border-radius: 24px;
opacity: 0.10;
}
.geo-1 {
top: -80px;
right: -60px;
width: 420px;
height: 420px;
background: var(--color-primary);
transform: rotate(35deg);
animation: float-geo-1 18s ease-in-out infinite;
}
.geo-2 {
bottom: -120px;
left: -80px;
width: 360px;
height: 360px;
background: var(--color-secondary);
transform: rotate(-25deg);
animation: float-geo-2 22s ease-in-out infinite;
}
.geo-3 {
top: 40%;
left: 5%;
width: 180px;
height: 180px;
background: var(--color-cta);
border-radius: 50%;
opacity: 0.06;
animation: float-geo-3 15s ease-in-out infinite;
}
.geo-circle {
position: absolute;
border-radius: 50%;
border: 2px solid;
}
.circle-1 {
top: 15%;
left: 10%;
width: 300px;
height: 300px;
border-color: var(--color-primary);
opacity: 0.06;
animation: float-circle-1 20s ease-in-out infinite;
}
.circle-2 {
bottom: 10%;
right: 8%;
width: 240px;
height: 240px;
border-color: var(--color-secondary);
opacity: 0.07;
animation: float-circle-2 24s ease-in-out infinite;
}
@keyframes float-geo-1 {
0%, 100% { transform: rotate(35deg) translate(0, 0); }
33% { transform: rotate(38deg) translate(-30px, 20px); }
66% { transform: rotate(32deg) translate(15px, -25px); }
}
@keyframes float-geo-2 {
0%, 100% { transform: rotate(-25deg) translate(0, 0); }
50% { transform: rotate(-20deg) translate(25px, -30px); }
}
@keyframes float-geo-3 {
0%, 100% { transform: translate(0, 0) scale(1); }
50% { transform: translate(20px, -20px) scale(1.3); }
}
@keyframes float-circle-1 {
0%, 100% { transform: translate(0, 0); }
50% { transform: translate(15px, -15px); }
}
@keyframes float-circle-2 {
0%, 100% { transform: translate(0, 0); }
50% { transform: translate(-20px, 15px); }
}
/* ─── 登录卡片 ─── */
.login-card {
position: relative;
z-index: 1;
width: 420px;
padding: 48px 44px 40px;
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(8, 145, 178, 0.12);
border-radius: 24px;
box-shadow:
0 4px 6px rgba(8, 145, 178, 0.04),
0 10px 30px rgba(8, 145, 178, 0.06),
0 30px 80px rgba(8, 145, 178, 0.08);
transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.login-card:hover {
box-shadow:
0 4px 6px rgba(8, 145, 178, 0.04),
0 15px 40px rgba(8, 145, 178, 0.08),
0 40px 100px rgba(8, 145, 178, 0.10);
}
/* ─── 品牌区 ─── */
.brand-area {
text-align: center;
margin-bottom: 40px;
}
.brand-icon {
display: inline-flex;
margin-bottom: 16px;
animation: brand-pop 0.6s ease-out;
}
.brand-icon svg {
width: 48px;
height: 48px;
}
@keyframes brand-pop {
0% { transform: scale(0.5); opacity: 0; }
60% { transform: scale(1.08); }
100% { transform: scale(1); opacity: 1; }
}
.brand-name {
margin: 0;
font-family: var(--font-heading);
font-size: 30px;
font-weight: 700;
color: var(--color-text);
letter-spacing: -0.5px;
line-height: 1.2;
}
.brand-desc {
margin: 8px 0 0;
font-family: var(--font-body);
font-size: 15px;
color: var(--color-text-muted);
}
/* ─── 表单 ─── */
.login-card :deep(.n-form-item) {
margin-bottom: 18px;
}
.login-card :deep(.n-input) {
--n-border-radius: 24px;
}
.login-card :deep(.n-input__prefix) {
padding-left: 4px;
}
.form-actions {
margin-top: 10px;
}
.login-btn {
height: 46px;
font-size: 16px;
font-weight: 600;
letter-spacing: 2px;
--n-border-radius: 24px;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.login-btn:not(:disabled):hover {
transform: translateY(-1px);
box-shadow: 0 8px 24px rgba(8, 145, 178, 0.30);
}
.login-btn:not(:disabled):active {
transform: translateY(0);
}
/* ─── 底部提示 ─── */
.footer-tip {
margin: 24px 0 0;
text-align: center;
font-size: 13px;
color: var(--color-text-muted);
}
.footer-link {
color: var(--color-primary);
text-decoration: none;
font-weight: 500;
margin-left: 2px;
cursor: pointer;
transition: color 0.2s ease;
}
.footer-link:hover {
color: var(--color-primary-hover);
}
/* ─── 响应式 ─── */
@media (max-width: 480px) {
.login-card {
width: calc(100vw - 40px);
padding: 36px 28px 32px;
border-radius: 20px;
}
.brand-name {
font-size: 26px;
}
.login-btn {
height: 44px;
font-size: 15px;
}
}
/* ─── 减少动画偏好 ─── */
@media (prefers-reduced-motion: reduce) {
.geo-shape,
.geo-circle,
.brand-icon,
.login-btn {
animation: none !important;
transition: none !important;
}
}
</style>

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

@ -0,0 +1,7 @@
/// <reference types="vite/client" />
declare module "*.vue" {
import type { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any>;
export default component;
}

29
tsconfig.json Normal file
View File

@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}

10
tsconfig.node.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}

49
vite.config.ts Normal file
View File

@ -0,0 +1,49 @@
import { resolve } from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
const host = process.env.TAURI_DEV_HOST;
// https://vite.dev/config/
export default defineConfig(async () => ({
plugins: [
vue(),
AutoImport({
imports: ['vue', 'vue-router'],
dts: "src/types/auto-imports.d.ts"
}),
Components({
dts: "src/types/components.d.ts"
}),
],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
// 3. tell Vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
},
},
}));