feat: 初始化项目基础架构和核心功能

- 添加项目基础结构:Cargo.toml、.gitignore、设备UID和密钥文件
- 实现前端Vue3项目结构:路由、登录页面、设备管理页面
- 添加核心协议定义(crates/protocol):设备状态、资产、USB事件等
- 实现客户端监控模块:系统状态收集、资产收集
- 实现服务端基础API和插件系统
- 添加数据库迁移脚本:设备管理、资产跟踪、告警系统等
- 实现前端设备状态展示和基本交互
- 添加使用时长统计和水印功能插件
This commit is contained in:
iven
2026-04-05 00:57:51 +08:00
commit fd6fb5cca0
87 changed files with 19576 additions and 0 deletions

87
web/src/stores/devices.ts Normal file
View File

@@ -0,0 +1,87 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import axios from 'axios'
const api = axios.create({
baseURL: '/api',
headers: {
'Content-Type': 'application/json',
},
})
// Add auth token to requests
api.interceptors.request.use((config) => {
const token = localStorage.getItem('token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
export interface Device {
id: number
device_uid: string
hostname: string
ip_address: string
mac_address: string | null
os_version: string | null
client_version: string | null
status: 'online' | 'offline'
last_heartbeat: string | null
registered_at: string
group_name: string
}
export interface DeviceStatusDetail {
cpu_usage: number
memory_usage: number
memory_total: number
disk_usage: number
disk_total: number
running_procs: number
top_processes: Array<{ name: string; pid: number; cpu_usage: number; memory_mb: number }>
}
export const useDeviceStore = defineStore('devices', () => {
const devices = ref<Device[]>([])
const loading = ref(false)
const total = ref(0)
async function fetchDevices(params?: Record<string, string>) {
loading.value = true
try {
const { data } = await api.get('/devices', { params })
if (data.success) {
devices.value = data.data.devices
total.value = data.data.total ?? devices.value.length
}
} finally {
loading.value = false
}
}
async function fetchDeviceStatus(uid: string): Promise<DeviceStatusDetail | null> {
const { data } = await api.get(`/devices/${uid}/status`)
return data.success ? data.data : null
}
async function fetchDeviceHistory(uid: string, params?: Record<string, string>) {
const { data } = await api.get(`/devices/${uid}/history`, { params })
return data.success ? data.data : null
}
async function removeDevice(uid: string) {
await api.delete(`/devices/${uid}`)
devices.value = devices.value.filter((d) => d.device_uid !== uid)
}
return {
devices,
loading,
total,
fetchDevices,
fetchDeviceStatus,
fetchDeviceHistory,
removeDevice,
}
})