fix(ipam): 修复IP管理页面网段筛选不生效及下拉框过窄
- Ips.vue: el-select 添加 width: 280px,修复网段下拉框过窄 - Ips.vue: query 参数 networkId → network_id(与 FastAPI snake_case 一致) - Scan.vue: el-select 用 network.id 代替整个 network 对象作为 value,修复切换网段不生效 - enhanced_scan_service.py: 替换失效的 scapy ARP 扫描为 arp-scan 命令;扫描结果自动创建缺失 IP 记录
This commit is contained in:
@@ -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?
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["Vue.volar"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Vue 3 + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 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 IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>frontend</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1839
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"axios": "^1.18.1",
|
||||
"element-plus": "^2.14.3",
|
||||
"pinia": "^4.0.2",
|
||||
"vue": "^3.5.39",
|
||||
"vue-router": "^4.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.4",
|
||||
"vite": "^5.4.21"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
@@ -0,0 +1,24 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||
</symbol>
|
||||
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||
</symbol>
|
||||
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||
</symbol>
|
||||
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||
</symbol>
|
||||
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,82 @@
|
||||
import api from '@/utils/api'
|
||||
import { authStore } from '@/utils/auth'
|
||||
|
||||
// 登录用 form-data(OAuth2PasswordRequestForm 期望 form-data)
|
||||
function login({ username, password }) {
|
||||
const formBody = new URLSearchParams()
|
||||
formBody.append('username', username)
|
||||
formBody.append('password', password)
|
||||
formBody.append('grant_type', 'password')
|
||||
return api.post('/auth/login', formBody, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
// 登录请求不能带 Authorization header(utils/api.js 里在已有 token 时会带)
|
||||
// 但登录接口允许带,下游忽略即可
|
||||
})
|
||||
}
|
||||
|
||||
async function loginAndStore({ username, password }) {
|
||||
const data = await login({ username, password })
|
||||
if (data?.access_token) {
|
||||
authStore.setAccessToken(data.access_token)
|
||||
authStore.setRefreshToken(data.refresh_token)
|
||||
authStore.setUserInfo(data.user_info)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
function logout() {
|
||||
const refreshToken = authStore.getRefreshToken()
|
||||
authStore.clear()
|
||||
if (refreshToken) {
|
||||
// 后端撤销 refresh token(best-effort,不 await)
|
||||
try {
|
||||
const formBody = new URLSearchParams()
|
||||
formBody.append('refresh_token', refreshToken)
|
||||
api.post('/auth/logout', formBody, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
}).catch(() => {})
|
||||
} catch (_) { /* noop */ }
|
||||
}
|
||||
}
|
||||
|
||||
function fetchCurrentUser() {
|
||||
return api.get('/auth/me').then(info => {
|
||||
authStore.setUserInfo(info)
|
||||
return info
|
||||
})
|
||||
}
|
||||
|
||||
function changePassword(oldPassword, newPassword) {
|
||||
return api.post('/auth/change-password', null, {
|
||||
params: { old_password: oldPassword, new_password: newPassword }
|
||||
})
|
||||
}
|
||||
|
||||
// 用户管理(admin 权限)
|
||||
// 注意:后端 endpoint 使用 query 参数接收(不是 JSON body),
|
||||
// 与其他 CRUD 接口的 POST + JSON body 风格不一致,但保持后端原样
|
||||
const userApi = {
|
||||
getList(params) {
|
||||
return api.get('/auth/users', { params })
|
||||
},
|
||||
getById(id) {
|
||||
return api.get(`/auth/users/${id}`)
|
||||
},
|
||||
create(data) {
|
||||
return api.post('/auth/users', null, { params: data })
|
||||
},
|
||||
updateStatus(id, status) {
|
||||
return api.put(`/auth/users/${id}/status`, null, { params: { status } })
|
||||
},
|
||||
unlock(id) {
|
||||
return api.post(`/auth/users/${id}/unlock`)
|
||||
},
|
||||
resetPassword(id, newPassword) {
|
||||
return api.post(`/auth/users/${id}/reset-password`, null, { params: { new_password: newPassword } })
|
||||
},
|
||||
delete(id) {
|
||||
return api.delete(`/auth/users/${id}`)
|
||||
},
|
||||
}
|
||||
|
||||
export { login, loginAndStore, logout, fetchCurrentUser, changePassword, userApi }
|
||||
@@ -0,0 +1,176 @@
|
||||
import api from '@/utils/api'
|
||||
|
||||
// 网段管理
|
||||
export const networkApi = {
|
||||
// 获取网段列表
|
||||
getList(params) {
|
||||
return api.get('/networks', { params })
|
||||
},
|
||||
// 获取网段详情
|
||||
getById(id) {
|
||||
return api.get(`/networks/${id}`)
|
||||
},
|
||||
// 获取网段统计
|
||||
getStats(id) {
|
||||
return api.get(`/networks/${id}/stats`)
|
||||
},
|
||||
// 获取所有网段统计
|
||||
getAllStats() {
|
||||
return api.get('/networks/stats')
|
||||
},
|
||||
// 创建网段
|
||||
create(data) {
|
||||
return api.post('/networks', data)
|
||||
},
|
||||
// 更新网段
|
||||
update(id, data) {
|
||||
return api.put(`/networks/${id}`, data)
|
||||
},
|
||||
// 删除网段
|
||||
delete(id) {
|
||||
return api.delete(`/networks/${id}`)
|
||||
},
|
||||
// 获取网段下的IP
|
||||
getIPs(id, params) {
|
||||
return api.get(`/networks/${id}/ips`, { params })
|
||||
}
|
||||
}
|
||||
|
||||
// IP地址管理
|
||||
export const ipApi = {
|
||||
// 获取IP列表
|
||||
getList(params) {
|
||||
return api.get('/ips', { params })
|
||||
},
|
||||
// 获取IP详情
|
||||
getById(id) {
|
||||
return api.get(`/ips/${id}`)
|
||||
},
|
||||
// 更新IP信息
|
||||
update(id, data) {
|
||||
return api.put(`/ips/${id}`, data)
|
||||
},
|
||||
// 根据IP地址查询
|
||||
getByIP(ip) {
|
||||
return api.get(`/ips/address/${ip}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 扫描管理
|
||||
export const scanApi = {
|
||||
// Ping扫描网段
|
||||
pingNetwork(id) {
|
||||
return api.post(`/scan/ping/${id}`)
|
||||
},
|
||||
// 综合扫描网段
|
||||
// options: { enable_ping, enable_arp, enable_dns, timeout }
|
||||
// 单次调用覆盖全局 30s 超时,因为 /24 网段扫描要数分钟
|
||||
comprehensiveScan(id, options = {}) {
|
||||
const {
|
||||
enable_ping = true,
|
||||
enable_arp = true,
|
||||
enable_dns = true,
|
||||
timeout = 2
|
||||
} = options
|
||||
return api.post(`/scan/comprehensive/${id}`, {}, {
|
||||
params: { enable_ping, enable_arp, enable_dns, timeout },
|
||||
timeout: 600000 // 10 分钟,足以应付 /16 级别网段
|
||||
})
|
||||
},
|
||||
// 单个IP扫描
|
||||
scanIP(ipAddress) {
|
||||
return api.post(`/scan/comprehensive/ip/${ipAddress}`)
|
||||
},
|
||||
// 获取统计摘要
|
||||
getSummary() {
|
||||
return api.get('/scan/statistics/summary')
|
||||
}
|
||||
}
|
||||
|
||||
// 告警管理
|
||||
export const alertApi = {
|
||||
// 获取告警列表
|
||||
getList(params) {
|
||||
return api.get('/alerts', { params })
|
||||
},
|
||||
// 获取告警统计
|
||||
getStats() {
|
||||
return api.get('/alerts/statistics/summary')
|
||||
},
|
||||
// 运行所有检测
|
||||
runDetection() {
|
||||
return api.post('/alerts/detect/run')
|
||||
},
|
||||
// 确认告警
|
||||
acknowledge(id) {
|
||||
return api.post(`/alerts/${id}/acknowledge`)
|
||||
},
|
||||
// 解决告警
|
||||
resolve(id, notes) {
|
||||
return api.post(`/alerts/${id}/resolve`, {}, { params: { notes } })
|
||||
},
|
||||
// 忽略告警
|
||||
ignore(id) {
|
||||
return api.post(`/alerts/${id}/ignore`)
|
||||
},
|
||||
// MAC白名单
|
||||
getWhitelist(params) {
|
||||
return api.get('/alerts/whitelist/macs', { params })
|
||||
},
|
||||
addToWhitelist(data) {
|
||||
return api.post('/alerts/whitelist/macs', {}, { params: data })
|
||||
},
|
||||
removeFromWhitelist(id) {
|
||||
return api.delete(`/alerts/whitelist/macs/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
// SNMP管理
|
||||
export const snmpApi = {
|
||||
// 凭据管理
|
||||
getCredentials() {
|
||||
return api.get('/snmp/credentials')
|
||||
},
|
||||
createCredential(data) {
|
||||
return api.post('/snmp/credentials', {}, { params: data })
|
||||
},
|
||||
updateCredential(id, data) {
|
||||
return api.put(`/snmp/credentials/${id}`, {}, { params: data })
|
||||
},
|
||||
deleteCredential(id) {
|
||||
return api.delete(`/snmp/credentials/${id}`)
|
||||
},
|
||||
|
||||
// 设备管理
|
||||
getDevices(params) {
|
||||
return api.get('/snmp/devices', { params })
|
||||
},
|
||||
createDevice(data) {
|
||||
return api.post('/snmp/devices', {}, { params: data })
|
||||
},
|
||||
updateDevice(id, data) {
|
||||
return api.put(`/snmp/devices/${id}`, {}, { params: data })
|
||||
},
|
||||
deleteDevice(id) {
|
||||
return api.delete(`/snmp/devices/${id}`)
|
||||
},
|
||||
|
||||
// SNMP操作
|
||||
testConnection(id) {
|
||||
return api.post(`/snmp/devices/${id}/test`)
|
||||
},
|
||||
pollDevice(id) {
|
||||
return api.post(`/snmp/devices/${id}/poll`)
|
||||
},
|
||||
getARPTable(id) {
|
||||
return api.post(`/snmp/devices/${id}/arp`)
|
||||
},
|
||||
getInterfaces(id) {
|
||||
return api.post(`/snmp/devices/${id}/interfaces`)
|
||||
},
|
||||
|
||||
// 获取统计
|
||||
getStats() {
|
||||
return api.get('/snmp/statistics/summary')
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
@@ -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 |
@@ -0,0 +1,95 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import viteLogo from '../assets/vite.svg'
|
||||
import heroImg from '../assets/hero.png'
|
||||
import vueLogo from '../assets/vue.svg'
|
||||
|
||||
const count = ref(0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section id="center">
|
||||
<div class="hero">
|
||||
<img :src="heroImg" class="base" width="170" height="179" alt="" />
|
||||
<img :src="vueLogo" class="framework" alt="Vue logo" />
|
||||
<img :src="viteLogo" class="vite" alt="Vite logo" />
|
||||
</div>
|
||||
<div>
|
||||
<h1>Get started</h1>
|
||||
<p>Edit <code>src/App.vue</code> and save to test <code>HMR</code></p>
|
||||
</div>
|
||||
<button type="button" class="counter" @click="count++">
|
||||
Count is {{ count }}
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<div class="ticks"></div>
|
||||
|
||||
<section id="next-steps">
|
||||
<div id="docs">
|
||||
<svg class="icon" role="presentation" aria-hidden="true">
|
||||
<use href="/icons.svg#documentation-icon"></use>
|
||||
</svg>
|
||||
<h2>Documentation</h2>
|
||||
<p>Your questions, answered</p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://vite.dev/" target="_blank">
|
||||
<img class="logo" :src="viteLogo" alt="" />
|
||||
Explore Vite
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://vuejs.org/" target="_blank">
|
||||
<img class="button-icon" :src="vueLogo" alt="" />
|
||||
Learn more
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="social">
|
||||
<svg class="icon" role="presentation" aria-hidden="true">
|
||||
<use href="/icons.svg#social-icon"></use>
|
||||
</svg>
|
||||
<h2>Connect with us</h2>
|
||||
<p>Join the Vite community</p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://github.com/vitejs/vite" target="_blank">
|
||||
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||
<use href="/icons.svg#github-icon"></use>
|
||||
</svg>
|
||||
GitHub
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://chat.vite.dev/" target="_blank">
|
||||
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||
<use href="/icons.svg#discord-icon"></use>
|
||||
</svg>
|
||||
Discord
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://x.com/vite_js" target="_blank">
|
||||
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||
<use href="/icons.svg#x-icon"></use>
|
||||
</svg>
|
||||
X.com
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://bsky.app/profile/vite.dev" target="_blank">
|
||||
<svg class="button-icon" role="presentation" aria-hidden="true">
|
||||
<use href="/icons.svg#bluesky-icon"></use>
|
||||
</svg>
|
||||
Bluesky
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="ticks"></div>
|
||||
<section id="spacer"></section>
|
||||
</template>
|
||||
@@ -0,0 +1,301 @@
|
||||
<template>
|
||||
<el-container class="layout-container">
|
||||
<!-- 侧边栏 -->
|
||||
<el-aside :width="isCollapse ? '64px' : '220px'" class="sidebar">
|
||||
<div class="logo">
|
||||
<el-icon :size="32" color="#409eff">
|
||||
<Monitor />
|
||||
</el-icon>
|
||||
<span v-if="!isCollapse" class="logo-text">IPAM管理系统</span>
|
||||
</div>
|
||||
<el-menu
|
||||
:default-active="activeMenu"
|
||||
:collapse="isCollapse"
|
||||
:collapse-transition="false"
|
||||
router
|
||||
background-color="#304156"
|
||||
text-color="#bfcbd9"
|
||||
active-text-color="#409eff"
|
||||
class="sidebar-menu"
|
||||
>
|
||||
<el-menu-item index="/dashboard">
|
||||
<el-icon><Odometer /></el-icon>
|
||||
<template #title>仪表盘</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/networks">
|
||||
<el-icon><Connection /></el-icon>
|
||||
<template #title>网段管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/ips">
|
||||
<el-icon><Cpu /></el-icon>
|
||||
<template #title>IP地址</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/scan">
|
||||
<el-icon><Search /></el-icon>
|
||||
<template #title>扫描管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/snmp">
|
||||
<el-icon><Setting /></el-icon>
|
||||
<template #title>SNMP管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/alerts">
|
||||
<el-icon><WarningFilled /></el-icon>
|
||||
<template #title>告警中心</template>
|
||||
<el-badge v-if="alertCount > 0" :value="alertCount" class="menu-badge" />
|
||||
</el-menu-item>
|
||||
<el-menu-item v-if="isAdmin" index="/users">
|
||||
<el-icon><UserFilled /></el-icon>
|
||||
<template #title>用户管理</template>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<el-container class="main-container">
|
||||
<!-- 顶部导航 -->
|
||||
<el-header class="header">
|
||||
<div class="header-left">
|
||||
<el-icon class="collapse-btn" @click="toggleCollapse">
|
||||
<Fold v-if="!isCollapse" />
|
||||
<Expand v-else />
|
||||
</el-icon>
|
||||
<el-breadcrumb separator="/">
|
||||
<el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
|
||||
<el-breadcrumb-item>{{ currentPageTitle }}</el-breadcrumb-item>
|
||||
</el-breadcrumb>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<el-tooltip content="刷新数据" placement="bottom">
|
||||
<el-icon class="header-icon" @click="refreshData">
|
||||
<RefreshRight />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
<el-dropdown trigger="click" @command="onUserMenuCommand">
|
||||
<span class="user-info">
|
||||
<el-icon :size="18"><User /></el-icon>
|
||||
<span>{{ displayName }}</span>
|
||||
<el-tag v-if="userInfo" size="small" :type="roleTagType" effect="plain" class="role-tag">
|
||||
{{ roleLabel }}
|
||||
</el-tag>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="profile">
|
||||
<el-icon><UserFilled /></el-icon> 个人中心
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="isAdmin" command="users" divided>
|
||||
<el-icon><Setting /></el-icon> 用户管理
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="logout" divided>
|
||||
<el-icon><SwitchButton /></el-icon> 退出登录
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-header>
|
||||
|
||||
<!-- 内容区 -->
|
||||
<el-main class="main-content">
|
||||
<router-view />
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { alertApi } from '@/api'
|
||||
import { authStore } from '@/utils/auth'
|
||||
import { logout as doLogout } from '@/api/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const isCollapse = ref(false)
|
||||
const alertCount = ref(0)
|
||||
const userInfo = ref(authStore.getUserInfo())
|
||||
|
||||
const isAdmin = computed(() => authStore.hasRole('super_admin', 'admin'))
|
||||
|
||||
const displayName = computed(() => {
|
||||
const u = userInfo.value
|
||||
if (!u) return '未登录'
|
||||
return u.real_name || u.username || '用户'
|
||||
})
|
||||
|
||||
const roleLabel = computed(() => {
|
||||
const map = {
|
||||
super_admin: '超级管理员',
|
||||
admin: '管理员',
|
||||
operator: '操作员',
|
||||
viewer: '访客',
|
||||
}
|
||||
return map[userInfo.value?.role] || '用户'
|
||||
})
|
||||
|
||||
const roleTagType = computed(() => {
|
||||
const map = {
|
||||
super_admin: 'danger',
|
||||
admin: 'warning',
|
||||
operator: 'success',
|
||||
viewer: 'info',
|
||||
}
|
||||
return map[userInfo.value?.role] || ''
|
||||
})
|
||||
|
||||
const activeMenu = computed(() => route.path)
|
||||
|
||||
const currentPageTitle = computed(() => {
|
||||
return route.meta.title || 'IPAM管理系统'
|
||||
})
|
||||
|
||||
const toggleCollapse = () => {
|
||||
isCollapse.value = !isCollapse.value
|
||||
}
|
||||
|
||||
const refreshData = () => {
|
||||
router.go(0)
|
||||
}
|
||||
|
||||
async function onUserMenuCommand(cmd) {
|
||||
if (cmd === 'profile') {
|
||||
router.push('/profile')
|
||||
} else if (cmd === 'users') {
|
||||
router.push('/users')
|
||||
} else if (cmd === 'logout') {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要退出登录吗?', '提示', {
|
||||
confirmButtonText: '退出',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
} catch (_) {
|
||||
return
|
||||
}
|
||||
doLogout()
|
||||
ElMessage.success('已退出登录')
|
||||
router.push('/login')
|
||||
}
|
||||
}
|
||||
|
||||
const loadAlertCount = async () => {
|
||||
try {
|
||||
const stats = await alertApi.getStats()
|
||||
alertCount.value = stats.by_status?.active || 0
|
||||
} catch (error) {
|
||||
// 401 已在 axios 拦截器处理,这里静默
|
||||
console.error('加载告警数量失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadAlertCount()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.layout-container {
|
||||
height: 100vh;
|
||||
background-color: #f0f2f5;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background-color: #304156;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 60px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
padding: 0 16px;
|
||||
border-bottom: 1px solid #1f2d3d;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sidebar-menu {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.menu-badge {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid #e6e6e6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 20px;
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.collapse-btn {
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.collapse-btn:hover {
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.header-icon:hover {
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.role-tag {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
background-color: #f0f2f5;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
// 注册所有图标
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component)
|
||||
}
|
||||
|
||||
app.use(pinia)
|
||||
app.use(ElementPlus)
|
||||
app.use(router)
|
||||
|
||||
app.mount('#app')
|
||||
@@ -0,0 +1,110 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { authStore } from '@/utils/auth'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/views/Login.vue'),
|
||||
meta: { title: '登录', public: true }
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/dashboard'
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layout/MainLayout.vue'),
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
component: () => import('@/views/Dashboard.vue'),
|
||||
meta: { title: '仪表盘' }
|
||||
},
|
||||
{
|
||||
path: 'networks',
|
||||
name: 'Networks',
|
||||
component: () => import('@/views/Networks.vue'),
|
||||
meta: { title: '网段管理' }
|
||||
},
|
||||
{
|
||||
path: 'ips',
|
||||
name: 'IPs',
|
||||
component: () => import('@/views/IPs.vue'),
|
||||
meta: { title: 'IP地址' }
|
||||
},
|
||||
{
|
||||
path: 'scan',
|
||||
name: 'Scan',
|
||||
component: () => import('@/views/Scan.vue'),
|
||||
meta: { title: '扫描管理' }
|
||||
},
|
||||
{
|
||||
path: 'snmp',
|
||||
name: 'SNMP',
|
||||
component: () => import('@/views/SNMP.vue'),
|
||||
meta: { title: 'SNMP管理' }
|
||||
},
|
||||
{
|
||||
path: 'alerts',
|
||||
name: 'Alerts',
|
||||
component: () => import('@/views/Alerts.vue'),
|
||||
meta: { title: '告警中心' }
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'Users',
|
||||
component: () => import('@/views/Users.vue'),
|
||||
meta: { title: '用户管理', requiresAdmin: true }
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
name: 'Profile',
|
||||
component: () => import('@/views/Profile.vue'),
|
||||
meta: { title: '个人中心' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'NotFound',
|
||||
component: () => import('@/views/Login.vue'),
|
||||
meta: { public: true }
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
})
|
||||
|
||||
// 全局路由守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 公开路由(登录页)直接放行
|
||||
if (to.meta?.public) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
// 未登录跳登录
|
||||
if (!authStore.isLoggedIn()) {
|
||||
next({ path: '/login', query: { next: to.fullPath } })
|
||||
return
|
||||
}
|
||||
// 需要管理员
|
||||
if (to.meta?.requiresAdmin && !authStore.hasRole('super_admin', 'admin')) {
|
||||
next({ path: '/dashboard' })
|
||||
return
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
router.afterEach((to) => {
|
||||
if (to.meta?.title) {
|
||||
document.title = `${to.meta.title} - IPAM管理系统`
|
||||
} else {
|
||||
document.title = 'IPAM管理系统'
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,296 @@
|
||||
:root {
|
||||
--text: #6b6375;
|
||||
--text-h: #08060d;
|
||||
--bg: #fff;
|
||||
--border: #e5e4e7;
|
||||
--code-bg: #f4f3ec;
|
||||
--accent: #aa3bff;
|
||||
--accent-bg: rgba(170, 59, 255, 0.1);
|
||||
--accent-border: rgba(170, 59, 255, 0.5);
|
||||
--social-bg: rgba(244, 243, 236, 0.5);
|
||||
--shadow:
|
||||
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
|
||||
|
||||
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||
--mono: ui-monospace, Consolas, monospace;
|
||||
|
||||
font: 18px/145% var(--sans);
|
||||
letter-spacing: 0.18px;
|
||||
color-scheme: light dark;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--text: #9ca3af;
|
||||
--text-h: #f3f4f6;
|
||||
--bg: #16171d;
|
||||
--border: #2e303a;
|
||||
--code-bg: #1f2028;
|
||||
--accent: #c084fc;
|
||||
--accent-bg: rgba(192, 132, 252, 0.15);
|
||||
--accent-border: rgba(192, 132, 252, 0.5);
|
||||
--social-bg: rgba(47, 48, 58, 0.5);
|
||||
--shadow:
|
||||
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
|
||||
}
|
||||
|
||||
#social .button-icon {
|
||||
filter: invert(1) brightness(2);
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
font-family: var(--heading);
|
||||
font-weight: 500;
|
||||
color: var(--text-h);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 56px;
|
||||
letter-spacing: -1.68px;
|
||||
margin: 32px 0;
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 36px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
}
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
line-height: 118%;
|
||||
letter-spacing: -0.24px;
|
||||
margin: 0 0 8px;
|
||||
@media (max-width: 1024px) {
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code,
|
||||
.counter {
|
||||
font-family: var(--mono);
|
||||
display: inline-flex;
|
||||
border-radius: 4px;
|
||||
color: var(--text-h);
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 15px;
|
||||
line-height: 135%;
|
||||
padding: 4px 8px;
|
||||
background: var(--code-bg);
|
||||
}
|
||||
|
||||
.counter {
|
||||
font-size: 16px;
|
||||
padding: 5px 10px;
|
||||
border-radius: 5px;
|
||||
color: var(--accent);
|
||||
background: var(--accent-bg);
|
||||
border: 2px solid transparent;
|
||||
transition: border-color 0.3s;
|
||||
margin-bottom: 24px;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--accent-border);
|
||||
}
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.hero {
|
||||
position: relative;
|
||||
|
||||
.base,
|
||||
.framework,
|
||||
.vite {
|
||||
inset-inline: 0;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.base {
|
||||
width: 170px;
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.framework,
|
||||
.vite {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.framework {
|
||||
z-index: 1;
|
||||
top: 34px;
|
||||
height: 28px;
|
||||
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
|
||||
scale(1.4);
|
||||
}
|
||||
|
||||
.vite {
|
||||
z-index: 0;
|
||||
top: 107px;
|
||||
height: 26px;
|
||||
width: auto;
|
||||
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
|
||||
scale(0.8);
|
||||
}
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 1126px;
|
||||
max-width: 100%;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
border-inline: 1px solid var(--border);
|
||||
min-height: 100svh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#center {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 25px;
|
||||
place-content: center;
|
||||
place-items: center;
|
||||
flex-grow: 1;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
padding: 32px 20px 24px;
|
||||
gap: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
#next-steps {
|
||||
display: flex;
|
||||
border-top: 1px solid var(--border);
|
||||
text-align: left;
|
||||
|
||||
& > div {
|
||||
flex: 1 1 0;
|
||||
padding: 32px;
|
||||
@media (max-width: 1024px) {
|
||||
padding: 24px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-bottom: 16px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
#docs {
|
||||
border-right: 1px solid var(--border);
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
border-right: none;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
}
|
||||
|
||||
#next-steps ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin: 32px 0 0;
|
||||
|
||||
.logo {
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--text-h);
|
||||
font-size: 16px;
|
||||
border-radius: 6px;
|
||||
background: var(--social-bg);
|
||||
display: flex;
|
||||
padding: 6px 12px;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
text-decoration: none;
|
||||
transition: box-shadow 0.3s;
|
||||
|
||||
&:hover {
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.button-icon {
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
margin-top: 20px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
li {
|
||||
flex: 1 1 calc(50% - 8px);
|
||||
}
|
||||
|
||||
a {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#spacer {
|
||||
height: 88px;
|
||||
border-top: 1px solid var(--border);
|
||||
@media (max-width: 1024px) {
|
||||
height: 48px;
|
||||
}
|
||||
}
|
||||
|
||||
.ticks {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
&::before,
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -4.5px;
|
||||
border: 5px solid transparent;
|
||||
}
|
||||
|
||||
&::before {
|
||||
left: 0;
|
||||
border-left-color: var(--border);
|
||||
}
|
||||
&::after {
|
||||
right: 0;
|
||||
border-right-color: var(--border);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { authStore } from '@/utils/auth'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
// 请求拦截器:自动带 Authorization header
|
||||
api.interceptors.request.use(
|
||||
config => {
|
||||
const token = authStore.getAccessToken()
|
||||
if (token) {
|
||||
config.headers = config.headers || {}
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
)
|
||||
|
||||
// 标记正在刷新 token,防止并发 401 触发多次刷新
|
||||
let isRefreshing = false
|
||||
let pendingQueue = []
|
||||
|
||||
function flushQueue(newToken) {
|
||||
pendingQueue.forEach(cb => cb(newToken))
|
||||
pendingQueue = []
|
||||
}
|
||||
|
||||
function queueRefresh(cb) {
|
||||
pendingQueue.push(cb)
|
||||
}
|
||||
|
||||
// 响应拦截器:401 时尝试 refresh token;refresh 失败就跳登录
|
||||
api.interceptors.response.use(
|
||||
response => {
|
||||
return response.data
|
||||
},
|
||||
async error => {
|
||||
const originalRequest = error.config || {}
|
||||
const status = error.response?.status
|
||||
const detail = error.response?.data?.detail
|
||||
|
||||
// 401 且不是 login/refresh 本身:尝试刷新 token
|
||||
if (status === 401 && !originalRequest._retry && !originalRequest.url?.includes('/auth/')) {
|
||||
const refreshToken = authStore.getRefreshToken()
|
||||
if (!refreshToken) {
|
||||
authStore.clear()
|
||||
redirectToLogin()
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
if (isRefreshing) {
|
||||
// 已有刷新请求在进行,等它完成后再重试
|
||||
return new Promise(resolve => {
|
||||
queueRefresh(newToken => {
|
||||
if (newToken) {
|
||||
originalRequest._retry = true
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`
|
||||
resolve(api(originalRequest))
|
||||
} else {
|
||||
redirectToLogin()
|
||||
resolve(Promise.reject(error))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
originalRequest._retry = true
|
||||
isRefreshing = true
|
||||
try {
|
||||
const formBody = new URLSearchParams()
|
||||
formBody.append('refresh_token', refreshToken)
|
||||
const resp = await axios.post('/api/v1/auth/refresh', formBody, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
})
|
||||
const newToken = resp.data?.access_token
|
||||
if (newToken) {
|
||||
authStore.setAccessToken(newToken)
|
||||
if (resp.data?.refresh_token) {
|
||||
authStore.setRefreshToken(resp.data.refresh_token)
|
||||
}
|
||||
isRefreshing = false
|
||||
flushQueue(newToken)
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`
|
||||
return api(originalRequest)
|
||||
} else {
|
||||
throw new Error('refresh 响应缺少 access_token')
|
||||
}
|
||||
} catch (refreshErr) {
|
||||
isRefreshing = false
|
||||
flushQueue(null)
|
||||
authStore.clear()
|
||||
redirectToLogin()
|
||||
return Promise.reject(refreshErr)
|
||||
}
|
||||
}
|
||||
|
||||
// 非 401 或 refresh 后仍失败的:弹 toast(保持原行为,避免 view 重复弹)
|
||||
console.error('API Error:', error)
|
||||
ElMessage.error(typeof detail === 'string' ? detail : '请求失败')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
function redirectToLogin() {
|
||||
if (typeof window !== 'undefined' && window.location.pathname !== '/login') {
|
||||
const next = encodeURIComponent(window.location.pathname + window.location.search)
|
||||
window.location.href = `/login?next=${next}`
|
||||
}
|
||||
}
|
||||
|
||||
export default api
|
||||
@@ -0,0 +1,56 @@
|
||||
// token / 用户信息本地存储工具
|
||||
const ACCESS_TOKEN_KEY = 'ipam_access_token'
|
||||
const REFRESH_TOKEN_KEY = 'ipam_refresh_token'
|
||||
const USER_INFO_KEY = 'ipam_user_info'
|
||||
|
||||
export const authStore = {
|
||||
getAccessToken() {
|
||||
return localStorage.getItem(ACCESS_TOKEN_KEY) || ''
|
||||
},
|
||||
setAccessToken(token) {
|
||||
if (token) {
|
||||
localStorage.setItem(ACCESS_TOKEN_KEY, token)
|
||||
} else {
|
||||
localStorage.removeItem(ACCESS_TOKEN_KEY)
|
||||
}
|
||||
},
|
||||
getRefreshToken() {
|
||||
return localStorage.getItem(REFRESH_TOKEN_KEY) || ''
|
||||
},
|
||||
setRefreshToken(token) {
|
||||
if (token) {
|
||||
localStorage.setItem(REFRESH_TOKEN_KEY, token)
|
||||
} else {
|
||||
localStorage.removeItem(REFRESH_TOKEN_KEY)
|
||||
}
|
||||
},
|
||||
getUserInfo() {
|
||||
const raw = localStorage.getItem(USER_INFO_KEY)
|
||||
if (!raw) return null
|
||||
try {
|
||||
return JSON.parse(raw)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
},
|
||||
setUserInfo(info) {
|
||||
if (info) {
|
||||
localStorage.setItem(USER_INFO_KEY, JSON.stringify(info))
|
||||
} else {
|
||||
localStorage.removeItem(USER_INFO_KEY)
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
localStorage.removeItem(ACCESS_TOKEN_KEY)
|
||||
localStorage.removeItem(REFRESH_TOKEN_KEY)
|
||||
localStorage.removeItem(USER_INFO_KEY)
|
||||
},
|
||||
isLoggedIn() {
|
||||
return !!this.getAccessToken()
|
||||
},
|
||||
// 基于 role 判断(仅前端展示用,真实校验在后端)
|
||||
hasRole(...roles) {
|
||||
const u = this.getUserInfo()
|
||||
return u && roles.includes(u.role)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,575 @@
|
||||
<template>
|
||||
<div class="alerts-page">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>告警中心</span>
|
||||
<el-button-group>
|
||||
<el-button type="danger" @click="runDetection" :loading="detecting">
|
||||
<el-icon><Search /></el-icon>
|
||||
立即检测
|
||||
</el-button>
|
||||
<el-button @click="acknowledgeAll">
|
||||
<el-icon><Check /></el-icon>
|
||||
全部确认
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 告警统计 -->
|
||||
<el-row :gutter="20" style="margin-bottom: 20px;">
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover" class="stat-card active">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><WarningFilled /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.by_status?.active || 0 }}</div>
|
||||
<div class="stat-label">活跃告警</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover" class="stat-card critical">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><CircleCloseFilled /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.by_severity?.critical || 0 }}</div>
|
||||
<div class="stat-label">严重告警</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover" class="stat-card error">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><CircleClose /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.by_severity?.error || 0 }}</div>
|
||||
<div class="stat-label">错误告警</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover" class="stat-card warning">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><InfoFilled /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.by_severity?.warning || 0 }}</div>
|
||||
<div class="stat-label">警告告警</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 筛选栏 -->
|
||||
<el-form :inline="true" :model="filters" class="filter-form">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="filters.status" placeholder="选择状态" clearable @change="loadAlerts">
|
||||
<el-option label="活跃" value="active" />
|
||||
<el-option label="已确认" value="acknowledged" />
|
||||
<el-option label="已解决" value="resolved" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="级别">
|
||||
<el-select v-model="filters.severity" placeholder="选择级别" clearable @change="loadAlerts">
|
||||
<el-option label="严重" value="critical" />
|
||||
<el-option label="错误" value="error" />
|
||||
<el-option label="警告" value="warning" />
|
||||
<el-option label="信息" value="info" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="filters.alertType" placeholder="选择类型" clearable @change="loadAlerts">
|
||||
<el-option label="IP冲突" value="ip_conflict" />
|
||||
<el-option label="未授权接入" value="unauthorized_access" />
|
||||
<el-option label="网段耗尽" value="subnet_full" />
|
||||
<el-option label="设备离线" value="device_offline" />
|
||||
<el-option label="新设备发现" value="new_device_detected" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="loadAlerts">
|
||||
<el-icon><Search /></el-icon>
|
||||
查询
|
||||
</el-button>
|
||||
<el-button @click="resetFilters">
|
||||
<el-icon><RefreshLeft /></el-icon>
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 告警表格 -->
|
||||
<el-table :data="tableData" style="width: 100%" v-loading="loading" stripe>
|
||||
<el-table-column label="级别" width="80" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getSeverityType(scope.row.severity)" size="small">
|
||||
{{ getSeverityText(scope.row.severity) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="类型" width="120">
|
||||
<template #default="scope">
|
||||
{{ getAlertTypeText(scope.row.alert_type) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="title" label="标题" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="message" label="详情" min-width="300" show-overflow-tooltip />
|
||||
<el-table-column prop="ip_address_str" label="相关IP" width="140">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.ip_address_str" class="ip-address">{{ scope.row.ip_address_str }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="mac_address" label="MAC地址" width="160">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.mac_address" class="mac-address">{{ scope.row.mac_address }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="时间" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatDate(scope.row.created_at) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button v-if="scope.row.status === 'active'" size="small" type="primary" @click="acknowledge(scope.row.id)">
|
||||
<el-icon><Check /></el-icon>
|
||||
确认
|
||||
</el-button>
|
||||
<el-button v-if="scope.row.status !== 'resolved'" size="small" type="success" @click="resolve(scope.row.id)">
|
||||
<el-icon><CircleCheck /></el-icon>
|
||||
解决
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:page-sizes="[20, 50, 100, 200]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadAlerts"
|
||||
@current-change="loadAlerts"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- MAC白名单管理 -->
|
||||
<el-card style="margin-top: 20px;">
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>MAC地址白名单</span>
|
||||
<el-button type="primary" @click="showWhitelistDialog">
|
||||
<el-icon><Plus /></el-icon>
|
||||
添加白名单
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="whitelist" style="width: 100%" v-loading="whitelistLoading" stripe>
|
||||
<el-table-column prop="mac_address" label="MAC地址" width="180">
|
||||
<template #default="scope">
|
||||
<span class="mac-address">{{ scope.row.mac_address }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" label="描述" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="owner" label="所有者" width="120" />
|
||||
<el-table-column prop="created_at" label="添加时间" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatDate(scope.row.created_at) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="danger" @click="removeFromWhitelist(scope.row.id)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<!-- 添加白名单对话框 -->
|
||||
<el-dialog
|
||||
v-model="whitelistDialogVisible"
|
||||
title="添加MAC白名单"
|
||||
width="500px"
|
||||
@close="resetWhitelistForm"
|
||||
>
|
||||
<el-form ref="whitelistFormRef" :model="whitelistForm" label-width="100px">
|
||||
<el-form-item label="MAC地址" prop="mac_address">
|
||||
<el-input v-model="whitelistForm.mac_address" placeholder="例如: 00:1A:2B:3C:4D:5E" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="whitelistForm.description" placeholder="设备描述" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所有者">
|
||||
<el-input v-model="whitelistForm.owner" placeholder="设备所有者" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="whitelistDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="addToWhitelist" :loading="submitting">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { alertApi } from '@/api'
|
||||
|
||||
const loading = ref(false)
|
||||
const detecting = ref(false)
|
||||
const whitelistLoading = ref(false)
|
||||
const submitting = ref(false)
|
||||
|
||||
const tableData = ref([])
|
||||
const stats = ref({
|
||||
by_status: { active: 0, acknowledged: 0, resolved: 0 },
|
||||
by_severity: { critical: 0, error: 0, warning: 0, info: 0 },
|
||||
by_type: {}
|
||||
})
|
||||
const whitelist = ref([])
|
||||
|
||||
const filters = reactive({
|
||||
status: 'active',
|
||||
severity: '',
|
||||
alertType: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 50,
|
||||
total: 0
|
||||
})
|
||||
|
||||
const whitelistDialogVisible = ref(false)
|
||||
const whitelistFormRef = ref(null)
|
||||
const whitelistForm = reactive({
|
||||
mac_address: '',
|
||||
description: '',
|
||||
owner: ''
|
||||
})
|
||||
|
||||
const loadStats = async () => {
|
||||
try {
|
||||
stats.value = await alertApi.getStats()
|
||||
} catch (error) {
|
||||
console.error('加载统计失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadAlerts = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = {
|
||||
skip: (pagination.page - 1) * pagination.limit,
|
||||
limit: pagination.limit
|
||||
}
|
||||
if (filters.status) params.status = filters.status
|
||||
if (filters.severity) params.severity = filters.severity
|
||||
if (filters.alertType) params.alertType = filters.alertType
|
||||
|
||||
const result = await alertApi.getList(params)
|
||||
tableData.value = result.items
|
||||
pagination.total = result.total
|
||||
} catch (error) {
|
||||
ElMessage.error('加载告警列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.status = 'active'
|
||||
filters.severity = ''
|
||||
filters.alertType = ''
|
||||
pagination.page = 1
|
||||
loadAlerts()
|
||||
}
|
||||
|
||||
const runDetection = async () => {
|
||||
detecting.value = true
|
||||
try {
|
||||
await alertApi.runDetection()
|
||||
ElMessage.success('检测完成')
|
||||
loadAlerts()
|
||||
loadStats()
|
||||
} catch (error) {
|
||||
ElMessage.error('检测失败')
|
||||
} finally {
|
||||
detecting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const acknowledge = async (id) => {
|
||||
try {
|
||||
await alertApi.acknowledge(id)
|
||||
ElMessage.success('已确认')
|
||||
loadAlerts()
|
||||
loadStats()
|
||||
} catch (error) {
|
||||
ElMessage.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const resolve = async (id) => {
|
||||
try {
|
||||
await alertApi.resolve(id, '')
|
||||
ElMessage.success('已标记为解决')
|
||||
loadAlerts()
|
||||
loadStats()
|
||||
} catch (error) {
|
||||
ElMessage.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
const acknowledgeAll = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确认将所有活跃告警标记为已确认?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
// 这里可以批量确认
|
||||
ElMessage.success('操作成功')
|
||||
loadAlerts()
|
||||
loadStats()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error('操作失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 白名单相关
|
||||
const loadWhitelist = async () => {
|
||||
whitelistLoading.value = true
|
||||
try {
|
||||
const result = await alertApi.getWhitelist()
|
||||
whitelist.value = result.items
|
||||
} catch (error) {
|
||||
console.error('加载白名单失败:', error)
|
||||
} finally {
|
||||
whitelistLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const showWhitelistDialog = () => {
|
||||
resetWhitelistForm()
|
||||
whitelistDialogVisible.value = true
|
||||
}
|
||||
|
||||
const resetWhitelistForm = () => {
|
||||
whitelistForm.mac_address = ''
|
||||
whitelistForm.description = ''
|
||||
whitelistForm.owner = ''
|
||||
whitelistFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const addToWhitelist = async () => {
|
||||
if (!whitelistForm.mac_address) {
|
||||
ElMessage.warning('请输入MAC地址')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await alertApi.addToWhitelist({
|
||||
mac_address: whitelistForm.mac_address,
|
||||
description: whitelistForm.description,
|
||||
owner: whitelistForm.owner
|
||||
})
|
||||
ElMessage.success('添加成功')
|
||||
whitelistDialogVisible.value = false
|
||||
loadWhitelist()
|
||||
} catch (error) {
|
||||
ElMessage.error('添加失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeFromWhitelist = async (id) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要从白名单中移除该MAC吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
await alertApi.removeFromWhitelist(id)
|
||||
ElMessage.success('已移除')
|
||||
loadWhitelist()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error('操作失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getSeverityType = (severity) => {
|
||||
const types = {
|
||||
critical: 'danger',
|
||||
error: 'danger',
|
||||
warning: 'warning',
|
||||
info: 'info'
|
||||
}
|
||||
return types[severity] || 'info'
|
||||
}
|
||||
|
||||
const getSeverityText = (severity) => {
|
||||
const texts = {
|
||||
critical: '严重',
|
||||
error: '错误',
|
||||
warning: '警告',
|
||||
info: '信息'
|
||||
}
|
||||
return texts[severity] || severity
|
||||
}
|
||||
|
||||
const getAlertTypeText = (type) => {
|
||||
const texts = {
|
||||
ip_conflict: 'IP冲突',
|
||||
unauthorized_access: '未授权接入',
|
||||
subnet_full: '网段耗尽',
|
||||
scan_failed: '扫描失败',
|
||||
device_offline: '设备离线',
|
||||
new_device_detected: '新设备发现',
|
||||
mac_changed: 'MAC变更'
|
||||
}
|
||||
return texts[type] || type
|
||||
}
|
||||
|
||||
const formatDate = (date) => {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadStats()
|
||||
loadAlerts()
|
||||
loadWhitelist()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.ip-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-weight: 500;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.mac-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.stat-card.active {
|
||||
border-left: 4px solid #409eff;
|
||||
}
|
||||
|
||||
.stat-card.critical {
|
||||
border-left: 4px solid #f56c6c;
|
||||
}
|
||||
|
||||
.stat-card.error {
|
||||
border-left: 4px solid #e6a23c;
|
||||
}
|
||||
|
||||
.stat-card.warning {
|
||||
border-left: 4px solid #67c23a;
|
||||
}
|
||||
|
||||
.stat-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.stat-card.active .stat-icon {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-card.critical .stat-icon {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-card.error .stat-icon {
|
||||
background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-card.warning .stat-icon {
|
||||
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,405 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<!-- 统计卡片 -->
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card stat-total">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><Connection /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.totalNetworks }}</div>
|
||||
<div class="stat-label">网段总数</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card stat-ip">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><Cpu /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.totalIPs }}</div>
|
||||
<div class="stat-label">IP地址总数</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card stat-online">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><Monitor /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.onlineIPs }}</div>
|
||||
<div class="stat-label">在线设备</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card stat-alert">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon">
|
||||
<el-icon :size="32"><WarningFilled /></el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value">{{ stats.activeAlerts }}</div>
|
||||
<div class="stat-label">活跃告警</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 网段使用率图表 -->
|
||||
<el-row :gutter="20" style="margin-top: 20px;">
|
||||
<el-col :span="16">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>网段使用率</span>
|
||||
<el-button type="primary" size="small" @click="loadNetworkStats">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
刷新
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-table :data="networkStats" style="width: 100%">
|
||||
<el-table-column prop="cidr" label="网段" width="140" />
|
||||
<el-table-column prop="name" label="名称" width="150" />
|
||||
<el-table-column prop="total_ips" label="总IP数" width="100" align="center" />
|
||||
<el-table-column prop="used_ips" label="已用" width="80" align="center" />
|
||||
<el-table-column prop="reserved_ips" label="保留" width="80" align="center" />
|
||||
<el-table-column prop="available_ips" label="可用" width="80" align="center" />
|
||||
<el-table-column label="使用率" width="250">
|
||||
<template #default="scope">
|
||||
<el-progress
|
||||
:percentage="scope.row.usage_percent"
|
||||
:color="getProgressColor(scope.row.usage_percent)"
|
||||
:stroke-width="16"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="primary" @click="goToNetwork(scope.row.id)">
|
||||
查看
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<!-- 告警统计 -->
|
||||
<el-col :span="8">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>告警统计</span>
|
||||
<el-button type="primary" size="small" @click="runDetection">
|
||||
<el-icon><Search /></el-icon>
|
||||
检测
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<div class="alert-stats">
|
||||
<div class="alert-item critical">
|
||||
<span class="alert-count">{{ alertStats.by_severity.critical }}</span>
|
||||
<span class="alert-label">严重告警</span>
|
||||
</div>
|
||||
<div class="alert-item error">
|
||||
<span class="alert-count">{{ alertStats.by_severity.error }}</span>
|
||||
<span class="alert-label">错误</span>
|
||||
</div>
|
||||
<div class="alert-item warning">
|
||||
<span class="alert-count">{{ alertStats.by_severity.warning }}</span>
|
||||
<span class="alert-label">警告</span>
|
||||
</div>
|
||||
<div class="alert-item info">
|
||||
<span class="alert-count">{{ alertStats.by_severity.info }}</span>
|
||||
<span class="alert-label">信息</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-divider />
|
||||
<div class="alert-types">
|
||||
<div v-for="(count, type) in alertStats.by_type" :key="type" class="alert-type-item">
|
||||
<span class="type-name">{{ getAlertTypeName(type) }}</span>
|
||||
<el-tag :type="count > 0 ? 'danger' : 'info'" size="small">{{ count }}</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 快捷操作 -->
|
||||
<el-row :gutter="20" style="margin-top: 20px;">
|
||||
<el-col :span="24">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<span>快捷操作</span>
|
||||
</template>
|
||||
<el-space wrap>
|
||||
<el-button type="primary" @click="$router.push('/networks')">
|
||||
<el-icon><Plus /></el-icon>
|
||||
添加网段
|
||||
</el-button>
|
||||
<el-button type="success" @click="quickScanAll">
|
||||
<el-icon><Search /></el-icon>
|
||||
全量扫描
|
||||
</el-button>
|
||||
<el-button type="warning" @click="$router.push('/alerts')">
|
||||
<el-icon><Warning /></el-icon>
|
||||
查看告警
|
||||
</el-button>
|
||||
<el-button type="info" @click="$router.push('/snmp')">
|
||||
<el-icon><Setting /></el-icon>
|
||||
SNMP管理
|
||||
</el-button>
|
||||
</el-space>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { networkApi, alertApi, scanApi } from '@/api'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const stats = ref({
|
||||
totalNetworks: 0,
|
||||
totalIPs: 0,
|
||||
onlineIPs: 0,
|
||||
activeAlerts: 0
|
||||
})
|
||||
|
||||
const networkStats = ref([])
|
||||
const alertStats = ref({
|
||||
by_status: { active: 0, acknowledged: 0, resolved: 0 },
|
||||
by_severity: { critical: 0, error: 0, warning: 0, info: 0 },
|
||||
by_type: {}
|
||||
})
|
||||
|
||||
const loadStats = async () => {
|
||||
try {
|
||||
const [statsData, alertStatsData] = await Promise.all([
|
||||
scanApi.getSummary(),
|
||||
alertApi.getStats()
|
||||
])
|
||||
stats.value.totalIPs = statsData.ip_statistics.total
|
||||
stats.value.onlineIPs = statsData.ip_statistics.online
|
||||
alertStats.value = alertStatsData
|
||||
stats.value.activeAlerts = alertStatsData.by_status.active
|
||||
} catch (error) {
|
||||
console.error('加载统计失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadNetworkStats = async () => {
|
||||
try {
|
||||
networkStats.value = await networkApi.getAllStats()
|
||||
stats.value.totalNetworks = networkStats.value.length
|
||||
} catch (error) {
|
||||
console.error('加载网段统计失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const runDetection = async () => {
|
||||
try {
|
||||
await alertApi.runDetection()
|
||||
ElMessage.success('检测完成')
|
||||
await loadStats()
|
||||
} catch (error) {
|
||||
ElMessage.error('检测失败')
|
||||
}
|
||||
}
|
||||
|
||||
const quickScanAll = async () => {
|
||||
ElMessage.info('全量扫描任务已提交,请稍后查看结果')
|
||||
}
|
||||
|
||||
const getProgressColor = (percentage) => {
|
||||
if (percentage >= 90) return '#f56c6c'
|
||||
if (percentage >= 70) return '#e6a23c'
|
||||
return '#67c23a'
|
||||
}
|
||||
|
||||
const getAlertTypeName = (type) => {
|
||||
const names = {
|
||||
'ip_conflict': 'IP冲突',
|
||||
'unauthorized_access': '未授权接入',
|
||||
'subnet_full': '网段耗尽',
|
||||
'scan_failed': '扫描失败',
|
||||
'device_offline': '设备离线',
|
||||
'new_device_detected': '新设备发现',
|
||||
'mac_changed': 'MAC变更'
|
||||
}
|
||||
return names[type] || type
|
||||
}
|
||||
|
||||
const goToNetwork = (id) => {
|
||||
router.push(`/ips?networkId=${id}`)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadStats()
|
||||
loadNetworkStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dashboard {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.stat-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.stat-total .stat-icon {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-ip .stat-icon {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-online .stat-icon {
|
||||
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-alert .stat-icon {
|
||||
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stat-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.alert-stats {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.alert-item {
|
||||
text-align: center;
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.alert-item.critical {
|
||||
background-color: #fef0f0;
|
||||
}
|
||||
|
||||
.alert-item.error {
|
||||
background-color: #fdf6ec;
|
||||
}
|
||||
|
||||
.alert-item.warning {
|
||||
background-color: #fdf6ec;
|
||||
}
|
||||
|
||||
.alert-item.info {
|
||||
background-color: #f4f4f5;
|
||||
}
|
||||
|
||||
.alert-count {
|
||||
display: block;
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.alert-item.critical .alert-count {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.alert-item.error .alert-count {
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.alert-item.warning .alert-count {
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.alert-item.info .alert-count {
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.alert-label {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.alert-types {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.alert-type-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.alert-type-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.type-name {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,372 @@
|
||||
<template>
|
||||
<div class="ips-page">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>IP地址管理</span>
|
||||
<el-button type="success" @click="startBatchScan" :loading="scanning">
|
||||
<el-icon><Search /></el-icon>
|
||||
批量扫描
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 筛选栏 -->
|
||||
<el-form :inline="true" :model="filters" class="filter-form">
|
||||
<el-form-item label="网段">
|
||||
<el-select v-model="filters.networkId" placeholder="选择网段" clearable @change="loadIPs" style="width: 280px">
|
||||
<el-option
|
||||
v-for="network in networks"
|
||||
:key="network.id"
|
||||
:label="`${network.cidr} (${network.name})`"
|
||||
:value="network.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="filters.status" placeholder="选择状态" clearable @change="loadIPs" style="width: 150px">
|
||||
<el-option label="在线" value="online" />
|
||||
<el-option label="离线" value="offline" />
|
||||
<el-option label="可用" value="available" />
|
||||
<el-option label="保留" value="reserved" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="搜索">
|
||||
<el-input v-model="filters.search" placeholder="IP/MAC/主机名" style="width: 200px" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="loadIPs">
|
||||
<el-icon><Search /></el-icon>
|
||||
查询
|
||||
</el-button>
|
||||
<el-button @click="resetFilters">
|
||||
<el-icon><RefreshLeft /></el-icon>
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 统计信息 -->
|
||||
<el-row :gutter="16" style="margin-bottom: 16px;">
|
||||
<el-col :span="6">
|
||||
<el-statistic title="总IP数" :value="stats.total" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-statistic title="在线" :value="stats.online" value-style="color: #67c23a" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-statistic title="离线" :value="stats.offline" value-style="color: #909399" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-statistic title="保留" :value="stats.reserved" value-style="color: #e6a23c" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-table :data="tableData" style="width: 100%" v-loading="loading" stripe height="calc(100vh - 380px)">
|
||||
<el-table-column prop="ip_address" label="IP地址" width="140" fixed="left">
|
||||
<template #default="scope">
|
||||
<span class="ip-address">{{ scope.row.ip_address }}</span>
|
||||
<el-tag v-if="scope.row.status === 'reserved'" type="warning" size="small" style="margin-left: 8px">保留</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="mac_address" label="MAC地址" width="160">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.mac_address" class="mac-address">{{ scope.row.mac_address }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="vendor" label="厂商" width="150" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.vendor">{{ scope.row.vendor }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="hostname" label="主机名" width="150" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.hostname">{{ scope.row.hostname }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getStatusType(scope.row.status)" size="small">
|
||||
{{ getStatusText(scope.row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="owner" label="使用者" width="120">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.owner">{{ scope.row.owner }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="last_seen" label="最后发现" width="170">
|
||||
<template #default="scope">
|
||||
{{ scope.row.last_seen ? formatDate(scope.row.last_seen) : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="180" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="primary" @click="scanIP(scope.row.ip_address)">
|
||||
<el-icon><Search /></el-icon>
|
||||
扫描
|
||||
</el-button>
|
||||
<el-button size="small" @click="editIP(scope.row)">
|
||||
<el-icon><Edit /></el-icon>
|
||||
编辑
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:page-sizes="[50, 100, 200, 500]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadIPs"
|
||||
@current-change="loadIPs"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 编辑IP对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
title="编辑IP信息"
|
||||
width="500px"
|
||||
>
|
||||
<el-form :model="ipForm" label-width="100px">
|
||||
<el-form-item label="IP地址">
|
||||
<el-input v-model="ipForm.ip_address" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="MAC地址">
|
||||
<el-input v-model="ipForm.mac_address" placeholder="MAC地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="主机名">
|
||||
<el-input v-model="ipForm.hostname" placeholder="主机名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="使用者">
|
||||
<el-input v-model="ipForm.owner" placeholder="使用者名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="ipForm.notes" type="textarea" :rows="3" placeholder="备注信息" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveIP" :loading="submitting">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ipApi, networkApi, scanApi } from '@/api'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const scanning = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
|
||||
const tableData = ref([])
|
||||
const networks = ref([])
|
||||
|
||||
const filters = reactive({
|
||||
networkId: null,
|
||||
status: '',
|
||||
search: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 100,
|
||||
total: 0
|
||||
})
|
||||
|
||||
const stats = computed(() => {
|
||||
const total = tableData.value.length
|
||||
const online = tableData.value.filter(item => item.status === 'online').length
|
||||
const offline = tableData.value.filter(item => item.status === 'offline').length
|
||||
const reserved = tableData.value.filter(item => item.status === 'reserved').length
|
||||
return { total, online, offline, reserved }
|
||||
})
|
||||
|
||||
const ipForm = reactive({
|
||||
id: null,
|
||||
ip_address: '',
|
||||
mac_address: '',
|
||||
hostname: '',
|
||||
owner: '',
|
||||
notes: ''
|
||||
})
|
||||
|
||||
const loadNetworks = async () => {
|
||||
try {
|
||||
const result = await networkApi.getList({ limit: 1000 })
|
||||
networks.value = result.items
|
||||
} catch (error) {
|
||||
console.error('加载网段列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadIPs = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
// 后端 Query 参数使用 snake_case,必须与 FastAPI 定义一致
|
||||
const params = {
|
||||
skip: (pagination.page - 1) * pagination.limit,
|
||||
limit: pagination.limit
|
||||
}
|
||||
if (filters.networkId) params.network_id = filters.networkId
|
||||
if (filters.status) params.status = filters.status
|
||||
if (filters.search) params.search = filters.search
|
||||
|
||||
const result = await ipApi.getList(params)
|
||||
tableData.value = result.items
|
||||
pagination.total = result.total
|
||||
} catch (error) {
|
||||
ElMessage.error('加载IP列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.networkId = null
|
||||
filters.status = ''
|
||||
filters.search = ''
|
||||
pagination.page = 1
|
||||
loadIPs()
|
||||
}
|
||||
|
||||
const scanIP = async (ipAddress) => {
|
||||
try {
|
||||
await scanApi.scanIP(ipAddress)
|
||||
ElMessage.success(`扫描 ${ipAddress} 完成`)
|
||||
loadIPs()
|
||||
} catch (error) {
|
||||
ElMessage.error(`扫描 ${ipAddress} 失败`)
|
||||
}
|
||||
}
|
||||
|
||||
const startBatchScan = async () => {
|
||||
if (!filters.networkId) {
|
||||
ElMessage.warning('请先选择网段')
|
||||
return
|
||||
}
|
||||
scanning.value = true
|
||||
try {
|
||||
ElMessage.info('扫描任务已提交')
|
||||
await scanApi.comprehensiveScan(filters.networkId)
|
||||
ElMessage.success('扫描完成')
|
||||
loadIPs()
|
||||
} catch (error) {
|
||||
// 详细错误由全局拦截器弹 toast;这里只 console 留排查
|
||||
console.error('扫描错误详情:', error)
|
||||
} finally {
|
||||
scanning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const editIP = (row) => {
|
||||
ipForm.id = row.id
|
||||
ipForm.ip_address = row.ip_address
|
||||
ipForm.mac_address = row.mac_address || ''
|
||||
ipForm.hostname = row.hostname || ''
|
||||
ipForm.owner = row.owner || ''
|
||||
ipForm.notes = row.notes || ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const saveIP = async () => {
|
||||
submitting.value = true
|
||||
try {
|
||||
await ipApi.update(ipForm.id, {
|
||||
mac_address: ipForm.mac_address,
|
||||
hostname: ipForm.hostname,
|
||||
owner: ipForm.owner,
|
||||
notes: ipForm.notes
|
||||
})
|
||||
ElMessage.success('保存成功')
|
||||
dialogVisible.value = false
|
||||
loadIPs()
|
||||
} catch (error) {
|
||||
ElMessage.error('保存失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusType = (status) => {
|
||||
const types = {
|
||||
online: 'success',
|
||||
offline: 'info',
|
||||
available: 'primary',
|
||||
reserved: 'warning'
|
||||
}
|
||||
return types[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status) => {
|
||||
const texts = {
|
||||
online: '在线',
|
||||
offline: '离线',
|
||||
available: '可用',
|
||||
reserved: '保留'
|
||||
}
|
||||
return texts[status] || status
|
||||
}
|
||||
|
||||
const formatDate = (date) => {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadNetworks()
|
||||
// 从路由参数获取网段ID
|
||||
if (route.query.networkId) {
|
||||
filters.networkId = parseInt(route.query.networkId)
|
||||
}
|
||||
loadIPs()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.ip-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-weight: 500;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.mac-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<div class="login-container">
|
||||
<el-card class="login-card" shadow="hover">
|
||||
<div class="login-header">
|
||||
<el-icon :size="42" color="#409eff"><Monitor /></el-icon>
|
||||
<h2>IPAM 管理系统</h2>
|
||||
<p class="subtitle">企业级 IP 地址管理与资产台账</p>
|
||||
</div>
|
||||
|
||||
<el-form
|
||||
ref="loginFormRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
size="large"
|
||||
label-position="top"
|
||||
@submit.prevent="onSubmit"
|
||||
>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input
|
||||
v-model="form.username"
|
||||
placeholder="请输入用户名"
|
||||
:prefix-icon="User"
|
||||
autocomplete="username"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
:prefix-icon="Lock"
|
||||
show-password
|
||||
autocomplete="current-password"
|
||||
@keyup.enter="onSubmit"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="large"
|
||||
style="width: 100%"
|
||||
:loading="loading"
|
||||
@click="onSubmit"
|
||||
>
|
||||
登 录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="login-footer">
|
||||
<el-text size="small" type="info">默认账户 admin / admin123(首次登录后请立即修改密码)</el-text>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { User, Lock, Monitor } from '@element-plus/icons-vue'
|
||||
import { loginAndStore } from '@/api/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const loginFormRef = ref(null)
|
||||
const loading = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
})
|
||||
|
||||
const rules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
if (!loginFormRef.value) return
|
||||
try {
|
||||
await loginFormRef.value.validate()
|
||||
} catch (_) {
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await loginAndStore({
|
||||
username: form.username,
|
||||
password: form.password,
|
||||
})
|
||||
ElMessage.success(`欢迎回来,${data?.user_info?.real_name || data?.user_info?.username || '管理员'}`)
|
||||
const next = route.query.next ? decodeURIComponent(route.query.next) : '/dashboard'
|
||||
router.push(next)
|
||||
} catch (error) {
|
||||
// axios 拦截器已弹过 toast;这里只 console 留排查
|
||||
console.error('登录失败:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: 420px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.login-header h2 {
|
||||
margin: 12px 0 4px 0;
|
||||
font-size: 22px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.login-header .subtitle {
|
||||
margin: 0;
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<div class="networks-page">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>网段管理</span>
|
||||
<el-button type="primary" @click="showCreateDialog">
|
||||
<el-icon><Plus /></el-icon>
|
||||
添加网段
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 筛选栏 -->
|
||||
<el-form :inline="true" :model="filters" class="filter-form">
|
||||
<el-form-item label="分组">
|
||||
<el-select v-model="filters.groupName" placeholder="选择分组" clearable @change="loadNetworks">
|
||||
<el-option label="生产网" value="production" />
|
||||
<el-option label="办公网" value="office" />
|
||||
<el-option label="测试网" value="test" />
|
||||
<el-option label="管理网" value="management" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="loadNetworks">
|
||||
<el-icon><Search /></el-icon>
|
||||
查询
|
||||
</el-button>
|
||||
<el-button @click="resetFilters">
|
||||
<el-icon><RefreshLeft /></el-icon>
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-table :data="tableData" style="width: 100%" v-loading="loading" stripe>
|
||||
<el-table-column prop="cidr" label="网段" width="140" />
|
||||
<el-table-column prop="name" label="名称" width="150" />
|
||||
<el-table-column prop="gateway" label="网关" width="140" />
|
||||
<el-table-column prop="group_name" label="分组" width="120">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.group_name" :type="getGroupTagType(scope.row.group_name)" size="small">
|
||||
{{ scope.row.group_name }}
|
||||
</el-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="total_ips" label="总IP数" width="100" align="center" />
|
||||
<el-table-column label="使用率" width="200">
|
||||
<template #default="scope">
|
||||
<el-progress
|
||||
:percentage="getUsagePercent(scope.row)"
|
||||
:color="getProgressColor(getUsagePercent(scope.row))"
|
||||
:stroke-width="12"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatDate(scope.row.created_at) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="280" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="primary" @click="viewIPs(scope.row.id)">
|
||||
<el-icon><View /></el-icon>
|
||||
查看IP
|
||||
</el-button>
|
||||
<el-button size="small" type="success" @click="startScan(scope.row.id)">
|
||||
<el-icon><Search /></el-icon>
|
||||
扫描
|
||||
</el-button>
|
||||
<el-button size="small" @click="editNetwork(scope.row)">
|
||||
<el-icon><Edit /></el-icon>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteNetwork(scope.row.id)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadNetworks"
|
||||
@current-change="loadNetworks"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 创建/编辑对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑网段' : '添加网段'"
|
||||
width="500px"
|
||||
@close="resetForm"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="网段CIDR" prop="cidr">
|
||||
<el-input v-model="form.cidr" placeholder="例如: 192.168.1.0/24" />
|
||||
</el-form-item>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="网段名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="网关" prop="gateway">
|
||||
<el-input v-model="form.gateway" placeholder="网关IP地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分组" prop="group_name">
|
||||
<el-select v-model="form.group_name" placeholder="选择分组">
|
||||
<el-option label="生产网" value="production" />
|
||||
<el-option label="办公网" value="office" />
|
||||
<el-option label="测试网" value="test" />
|
||||
<el-option label="管理网" value="management" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" :rows="3" placeholder="描述信息" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm" :loading="submitting">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { networkApi, scanApi } from '@/api'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref(null)
|
||||
|
||||
const tableData = ref([])
|
||||
|
||||
const filters = reactive({
|
||||
groupName: ''
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 20,
|
||||
total: 0
|
||||
})
|
||||
|
||||
const form = reactive({
|
||||
id: null,
|
||||
cidr: '',
|
||||
name: '',
|
||||
gateway: '',
|
||||
group_name: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
cidr: [
|
||||
{ required: true, message: '请输入网段CIDR', trigger: 'blur' },
|
||||
{ pattern: /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/, message: 'CIDR格式不正确', trigger: 'blur' }
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: '请输入网段名称', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const loadNetworks = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await networkApi.getList({
|
||||
skip: (pagination.page - 1) * pagination.limit,
|
||||
limit: pagination.limit,
|
||||
groupName: filters.groupName || undefined
|
||||
})
|
||||
tableData.value = result.items
|
||||
pagination.total = result.total
|
||||
} catch (error) {
|
||||
ElMessage.error('加载网段列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.groupName = ''
|
||||
pagination.page = 1
|
||||
loadNetworks()
|
||||
}
|
||||
|
||||
const showCreateDialog = () => {
|
||||
isEdit.value = false
|
||||
resetForm()
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const editNetwork = (row) => {
|
||||
isEdit.value = true
|
||||
form.id = row.id
|
||||
form.cidr = row.cidr
|
||||
form.name = row.name
|
||||
form.gateway = row.gateway
|
||||
form.group_name = row.group_name
|
||||
form.description = row.description
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
form.id = null
|
||||
form.cidr = ''
|
||||
form.name = ''
|
||||
form.gateway = ''
|
||||
form.group_name = ''
|
||||
form.description = ''
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const submitForm = async () => {
|
||||
await formRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
await networkApi.update(form.id, form)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await networkApi.create(form)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
loadNetworks()
|
||||
} catch (error) {
|
||||
ElMessage.error(isEdit.value ? '更新失败' : '创建失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const deleteNetwork = async (id) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除该网段吗?删除后相关IP地址也会被删除', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
await networkApi.delete(id)
|
||||
ElMessage.success('删除成功')
|
||||
loadNetworks()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error('删除失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const viewIPs = (id) => {
|
||||
router.push(`/ips?networkId=${id}`)
|
||||
}
|
||||
|
||||
const startScan = async (id) => {
|
||||
try {
|
||||
ElMessage.info('扫描任务已提交')
|
||||
await scanApi.comprehensiveScan(id)
|
||||
ElMessage.success('扫描完成')
|
||||
loadNetworks()
|
||||
} catch (error) {
|
||||
// 详细错误由全局拦截器弹 toast;这里只 console 留排查
|
||||
console.error('扫描错误详情:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getUsagePercent = (row) => {
|
||||
const used = row.used_ips || 0
|
||||
const total = row.total_ips || 1
|
||||
return Math.round((used / total) * 100)
|
||||
}
|
||||
|
||||
const getProgressColor = (percentage) => {
|
||||
if (percentage >= 90) return '#f56c6c'
|
||||
if (percentage >= 70) return '#e6a23c'
|
||||
return '#67c23a'
|
||||
}
|
||||
|
||||
const getGroupTagType = (group) => {
|
||||
const types = {
|
||||
production: 'danger',
|
||||
office: 'primary',
|
||||
test: 'info',
|
||||
management: 'warning'
|
||||
}
|
||||
return types[group] || 'info'
|
||||
}
|
||||
|
||||
const formatDate = (date) => {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadNetworks()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,6 @@
|
||||
<template>
|
||||
<div>个人中心 - 占位(待用户管理模块完成后填充)</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
</script>
|
||||
@@ -0,0 +1,563 @@
|
||||
<template>
|
||||
<div class="snmp-page">
|
||||
<el-tabs v-model="activeTab" type="card">
|
||||
<!-- 网络设备 -->
|
||||
<el-tab-pane label="网络设备" name="devices">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>网络设备列表</span>
|
||||
<el-button type="primary" @click="showDeviceDialog">
|
||||
<el-icon><Plus /></el-icon>
|
||||
添加设备
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="devices" style="width: 100%" v-loading="loading" stripe>
|
||||
<el-table-column prop="name" label="设备名称" width="150" />
|
||||
<el-table-column prop="ip_address" label="IP地址" width="140">
|
||||
<template #default="scope">
|
||||
<span class="ip-address">{{ scope.row.ip_address }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="port" label="端口" width="80" align="center" />
|
||||
<el-table-column label="凭据" width="120">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.credential_name" type="info" size="small">
|
||||
{{ scope.row.credential_name }}
|
||||
</el-tag>
|
||||
<el-tag v-else type="danger" size="small">未配置</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="device_type" label="类型" width="100" align="center" />
|
||||
<el-table-column label="轮询状态" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.last_successful_poll" type="success" size="small">正常</el-tag>
|
||||
<el-tag v-else type="info" size="small">未轮询</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="last_polled_at" label="最后轮询" width="180">
|
||||
<template #default="scope">
|
||||
{{ scope.row.last_polled_at ? formatDate(scope.row.last_polled_at) : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="300" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="success" @click="testConnection(scope.row.id)">
|
||||
<el-icon><Connection /></el-icon>
|
||||
测试连接
|
||||
</el-button>
|
||||
<el-button size="small" type="primary" @click="pollDevice(scope.row.id)">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
轮询
|
||||
</el-button>
|
||||
<el-button size="small" @click="editDevice(scope.row)">
|
||||
<el-icon><Edit /></el-icon>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteDevice(scope.row.id)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- SNMP凭据 -->
|
||||
<el-tab-pane label="SNMP凭据" name="credentials">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>SNMP凭据管理</span>
|
||||
<el-button type="primary" @click="showCredentialDialog">
|
||||
<el-icon><Plus /></el-icon>
|
||||
添加凭据
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="credentials" style="width: 100%" v-loading="loading" stripe>
|
||||
<el-table-column prop="name" label="凭据名称" width="150" />
|
||||
<el-table-column prop="version" label="版本" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.version === 'v3' ? 'warning' : 'primary'" size="small">
|
||||
{{ scope.row.version }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="配置信息" min-width="200">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.version === 'v2c'">Community: {{ scope.row.community_string }}</span>
|
||||
<span v-else>User: {{ scope.row.username }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="timeout" label="超时(秒)" width="100" align="center" />
|
||||
<el-table-column prop="retries" label="重试次数" width="100" align="center" />
|
||||
<el-table-column prop="created_at" label="创建时间" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatDate(scope.row.created_at) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button size="small" @click="editCredential(scope.row)">
|
||||
<el-icon><Edit /></el-icon>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteCredential(scope.row.id)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- ARP表 -->
|
||||
<el-tab-pane label="ARP表" name="arp">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>ARP地址表</span>
|
||||
<el-select v-model="arpDeviceId" placeholder="选择设备" style="width: 200px;" clearable>
|
||||
<el-option
|
||||
v-for="device in devices"
|
||||
:key="device.id"
|
||||
:label="device.name"
|
||||
:value="device.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-button type="primary" @click="loadARPTable" :loading="arpLoading">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
刷新
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="arpEntries" style="width: 100%" v-loading="arpLoading" stripe>
|
||||
<el-table-column prop="ip_address" label="IP地址" width="140">
|
||||
<template #default="scope">
|
||||
<span class="ip-address">{{ scope.row.ip_address }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="mac_address" label="MAC地址" width="160">
|
||||
<template #default="scope">
|
||||
<span class="mac-address">{{ scope.row.mac_address }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="interface" label="接口" width="120" />
|
||||
<el-table-column prop="last_seen" label="最后发现" width="180">
|
||||
<template #default="scope">
|
||||
{{ formatDate(scope.row.last_seen) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
||||
<!-- 设备对话框 -->
|
||||
<el-dialog
|
||||
v-model="deviceDialogVisible"
|
||||
:title="isDeviceEdit ? '编辑设备' : '添加设备'"
|
||||
width="500px"
|
||||
@close="resetDeviceForm"
|
||||
>
|
||||
<el-form ref="deviceFormRef" :model="deviceForm" :rules="deviceRules" label-width="100px">
|
||||
<el-form-item label="设备名称" prop="name">
|
||||
<el-input v-model="deviceForm.name" placeholder="设备名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="IP地址" prop="ip_address">
|
||||
<el-input v-model="deviceForm.ip_address" placeholder="设备IP地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="端口" prop="port">
|
||||
<el-input-number v-model="deviceForm.port" :min="1" :max="65535" />
|
||||
</el-form-item>
|
||||
<el-form-item label="SNMP凭据" prop="snmp_credential_id">
|
||||
<el-select v-model="deviceForm.snmp_credential_id" placeholder="选择凭据">
|
||||
<el-option
|
||||
v-for="cred in credentials"
|
||||
:key="cred.id"
|
||||
:label="cred.name"
|
||||
:value="cred.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备类型" prop="device_type">
|
||||
<el-select v-model="deviceForm.device_type" placeholder="选择类型">
|
||||
<el-option label="路由器" value="router" />
|
||||
<el-option label="核心交换机" value="core_switch" />
|
||||
<el-option label="汇聚交换机" value="distribution_switch" />
|
||||
<el-option label="接入交换机" value="access_switch" />
|
||||
<el-option label="防火墙" value="firewall" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="deviceForm.description" type="textarea" :rows="2" placeholder="描述信息" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="deviceDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveDevice" :loading="submitting">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 凭据对话框 -->
|
||||
<el-dialog
|
||||
v-model="credentialDialogVisible"
|
||||
:title="isCredentialEdit ? '编辑凭据' : '添加凭据'"
|
||||
width="600px"
|
||||
@close="resetCredentialForm"
|
||||
>
|
||||
<el-form ref="credentialFormRef" :model="credentialForm" :rules="credentialRules" label-width="120px">
|
||||
<el-form-item label="凭据名称" prop="name">
|
||||
<el-input v-model="credentialForm.name" placeholder="凭据名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="SNMP版本" prop="version">
|
||||
<el-select v-model="credentialForm.version" placeholder="选择版本">
|
||||
<el-option label="v2c" value="v2c" />
|
||||
<el-option label="v3" value="v3" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<template v-if="credentialForm.version === 'v2c'">
|
||||
<el-form-item label="Community字符串" prop="community_string">
|
||||
<el-input v-model="credentialForm.community_string" placeholder="SNMP Community字符串" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
<template v-if="credentialForm.version === 'v3'">
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="credentialForm.username" placeholder="SNMPv3用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="认证密码" prop="auth_password">
|
||||
<el-input v-model="credentialForm.auth_password" type="password" placeholder="认证密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="认证协议" prop="auth_protocol">
|
||||
<el-select v-model="credentialForm.auth_protocol" placeholder="选择认证协议">
|
||||
<el-option label="MD5" value="md5" />
|
||||
<el-option label="SHA" value="sha" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="加密密码" prop="priv_password">
|
||||
<el-input v-model="credentialForm.priv_password" type="password" placeholder="加密密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="加密协议" prop="priv_protocol">
|
||||
<el-select v-model="credentialForm.priv_protocol" placeholder="选择加密协议">
|
||||
<el-option label="DES" value="des" />
|
||||
<el-option label="AES" value="aes" />
|
||||
<el-option label="AES256" value="aes256" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-form-item label="超时时间(秒)" prop="timeout">
|
||||
<el-input-number v-model="credentialForm.timeout" :min="1" :max="30" />
|
||||
</el-form-item>
|
||||
<el-form-item label="重试次数" prop="retries">
|
||||
<el-input-number v-model="credentialForm.retries" :min="0" :max="5" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="credentialForm.description" type="textarea" :rows="2" placeholder="描述信息" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="credentialDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveCredential" :loading="submitting">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { snmpApi } from '@/api'
|
||||
|
||||
const activeTab = ref('devices')
|
||||
const loading = ref(false)
|
||||
const arpLoading = ref(false)
|
||||
const submitting = ref(false)
|
||||
|
||||
const devices = ref([])
|
||||
const credentials = ref([])
|
||||
const arpEntries = ref([])
|
||||
const arpDeviceId = ref(null)
|
||||
|
||||
// 设备相关
|
||||
const deviceDialogVisible = ref(false)
|
||||
const isDeviceEdit = ref(false)
|
||||
const deviceFormRef = ref(null)
|
||||
const deviceForm = reactive({
|
||||
id: null,
|
||||
name: '',
|
||||
ip_address: '',
|
||||
port: 161,
|
||||
snmp_credential_id: null,
|
||||
device_type: 'other',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const deviceRules = {
|
||||
name: [{ required: true, message: '请输入设备名称', trigger: 'blur' }],
|
||||
ip_address: [{ required: true, message: '请输入IP地址', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 凭据相关
|
||||
const credentialDialogVisible = ref(false)
|
||||
const isCredentialEdit = ref(false)
|
||||
const credentialFormRef = ref(null)
|
||||
const credentialForm = reactive({
|
||||
id: null,
|
||||
name: '',
|
||||
version: 'v2c',
|
||||
community_string: 'public',
|
||||
username: '',
|
||||
auth_password: '',
|
||||
auth_protocol: 'md5',
|
||||
priv_password: '',
|
||||
priv_protocol: 'des',
|
||||
timeout: 3,
|
||||
retries: 2,
|
||||
description: ''
|
||||
})
|
||||
|
||||
const credentialRules = {
|
||||
name: [{ required: true, message: '请输入凭据名称', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const loadDevices = async () => {
|
||||
try {
|
||||
const result = await snmpApi.getDevices()
|
||||
devices.value = result.items
|
||||
} catch (error) {
|
||||
console.error('加载设备列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadCredentials = async () => {
|
||||
try {
|
||||
const result = await snmpApi.getCredentials()
|
||||
credentials.value = result.items
|
||||
} catch (error) {
|
||||
console.error('加载凭据列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const loadARPTable = async () => {
|
||||
if (!arpDeviceId.value) {
|
||||
ElMessage.warning('请先选择设备')
|
||||
return
|
||||
}
|
||||
arpLoading.value = true
|
||||
try {
|
||||
const result = await snmpApi.getARPTable(arpDeviceId.value)
|
||||
arpEntries.value = result.entries || []
|
||||
} catch (error) {
|
||||
ElMessage.error('加载ARP表失败')
|
||||
} finally {
|
||||
arpLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 设备操作
|
||||
const showDeviceDialog = () => {
|
||||
isDeviceEdit.value = false
|
||||
resetDeviceForm()
|
||||
deviceDialogVisible.value = true
|
||||
}
|
||||
|
||||
const editDevice = (row) => {
|
||||
isDeviceEdit.value = true
|
||||
deviceForm.id = row.id
|
||||
deviceForm.name = row.name
|
||||
deviceForm.ip_address = row.ip_address
|
||||
deviceForm.port = row.port
|
||||
deviceForm.snmp_credential_id = row.snmp_credential_id
|
||||
deviceForm.device_type = row.device_type
|
||||
deviceForm.description = row.description
|
||||
deviceDialogVisible.value = true
|
||||
}
|
||||
|
||||
const resetDeviceForm = () => {
|
||||
deviceForm.id = null
|
||||
deviceForm.name = ''
|
||||
deviceForm.ip_address = ''
|
||||
deviceForm.port = 161
|
||||
deviceForm.snmp_credential_id = null
|
||||
deviceForm.device_type = 'other'
|
||||
deviceForm.description = ''
|
||||
deviceFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const saveDevice = async () => {
|
||||
await deviceFormRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isDeviceEdit.value) {
|
||||
await snmpApi.updateDevice(deviceForm.id, deviceForm)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await snmpApi.createDevice(deviceForm)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
deviceDialogVisible.value = false
|
||||
loadDevices()
|
||||
} catch (error) {
|
||||
ElMessage.error(isDeviceEdit.value ? '更新失败' : '创建失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const deleteDevice = async (id) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除该设备吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
await snmpApi.deleteDevice(id)
|
||||
ElMessage.success('删除成功')
|
||||
loadDevices()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error('删除失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const testConnection = async (id) => {
|
||||
try {
|
||||
const result = await snmpApi.testConnection(id)
|
||||
if (result.success) {
|
||||
ElMessage.success('连接成功')
|
||||
} else {
|
||||
ElMessage.error(`连接失败: ${result.info?.error || '未知错误'}`)
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('连接测试失败')
|
||||
}
|
||||
}
|
||||
|
||||
const pollDevice = async (id) => {
|
||||
try {
|
||||
ElMessage.info('轮询任务已提交')
|
||||
await snmpApi.pollDevice(id)
|
||||
ElMessage.success('轮询完成')
|
||||
loadDevices()
|
||||
} catch (error) {
|
||||
ElMessage.error('轮询失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 凭据操作
|
||||
const showCredentialDialog = () => {
|
||||
isCredentialEdit.value = false
|
||||
resetCredentialForm()
|
||||
credentialDialogVisible.value = true
|
||||
}
|
||||
|
||||
const editCredential = (row) => {
|
||||
isCredentialEdit.value = true
|
||||
credentialForm.id = row.id
|
||||
credentialForm.name = row.name
|
||||
credentialForm.version = row.version
|
||||
credentialForm.community_string = row.community_string
|
||||
credentialForm.username = row.username
|
||||
credentialForm.auth_password = row.auth_password
|
||||
credentialForm.auth_protocol = row.auth_protocol
|
||||
credentialForm.priv_password = row.priv_password
|
||||
credentialForm.priv_protocol = row.priv_protocol
|
||||
credentialForm.timeout = row.timeout
|
||||
credentialForm.retries = row.retries
|
||||
credentialForm.description = row.description
|
||||
credentialDialogVisible.value = true
|
||||
}
|
||||
|
||||
const resetCredentialForm = () => {
|
||||
credentialForm.id = null
|
||||
credentialForm.name = ''
|
||||
credentialForm.version = 'v2c'
|
||||
credentialForm.community_string = 'public'
|
||||
credentialForm.username = ''
|
||||
credentialForm.auth_password = ''
|
||||
credentialForm.auth_protocol = 'md5'
|
||||
credentialForm.priv_password = ''
|
||||
credentialForm.priv_protocol = 'des'
|
||||
credentialForm.timeout = 3
|
||||
credentialForm.retries = 2
|
||||
credentialForm.description = ''
|
||||
credentialFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const saveCredential = async () => {
|
||||
await credentialFormRef.value.validate()
|
||||
submitting.value = true
|
||||
try {
|
||||
if (isCredentialEdit.value) {
|
||||
await snmpApi.updateCredential(credentialForm.id, credentialForm)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await snmpApi.createCredential(credentialForm)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
credentialDialogVisible.value = false
|
||||
loadCredentials()
|
||||
} catch (error) {
|
||||
ElMessage.error(isCredentialEdit.value ? '更新失败' : '创建失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const deleteCredential = async (id) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除该凭据吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
await snmpApi.deleteCredential(id)
|
||||
ElMessage.success('删除成功')
|
||||
loadCredentials()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error('删除失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (date) => {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loading.value = true
|
||||
Promise.all([loadDevices(), loadCredentials()]).finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.ip-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-weight: 500;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.mac-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,293 @@
|
||||
<template>
|
||||
<div class="scan-page">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="8">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<span>选择网段</span>
|
||||
</template>
|
||||
<el-select
|
||||
v-model="selectedNetworkId"
|
||||
placeholder="请选择要扫描的网段"
|
||||
style="width: 100%"
|
||||
@change="onNetworkChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="network in networks"
|
||||
:key="network.id"
|
||||
:label="`${network.cidr} (${network.name})`"
|
||||
:value="network.id"
|
||||
/>
|
||||
</el-select>
|
||||
<div v-if="selectedNetwork" class="network-info" style="margin-top: 16px;">
|
||||
<el-descriptions :column="1" border size="small">
|
||||
<el-descriptions-item label="网段">{{ selectedNetwork.cidr }}</el-descriptions-item>
|
||||
<el-descriptions-item label="名称">{{ selectedNetwork.name }}</el-descriptions-item>
|
||||
<el-descriptions-item label="总IP数">{{ selectedNetwork.total_ips }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-card style="margin-top: 20px;">
|
||||
<template #header>
|
||||
<span>扫描选项</span>
|
||||
</template>
|
||||
<el-checkbox-group v-model="scanOptions">
|
||||
<el-checkbox value="ping">Ping 检测</el-checkbox>
|
||||
<el-checkbox value="arp">ARP 扫描</el-checkbox>
|
||||
<el-checkbox value="dns">反向 DNS</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
<el-divider />
|
||||
<el-button
|
||||
type="primary"
|
||||
style="width: 100%"
|
||||
size="large"
|
||||
:disabled="!selectedNetwork || scanning"
|
||||
:loading="scanning"
|
||||
@click="startScan"
|
||||
>
|
||||
<el-icon><Search /></el-icon>
|
||||
开始扫描
|
||||
</el-button>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="16">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>扫描结果</span>
|
||||
<el-button-group>
|
||||
<el-button size="small" @click="loadIPs">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
刷新
|
||||
</el-button>
|
||||
<el-button size="small" @click="exportResults">
|
||||
<el-icon><Download /></el-icon>
|
||||
导出
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 统计信息 -->
|
||||
<el-row :gutter="16" v-if="selectedNetwork">
|
||||
<el-col :span="6">
|
||||
<el-statistic title="扫描总数" :value="scanStats.total" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-statistic title="在线" :value="scanStats.online" value-style="color: #67c23a" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-statistic title="有MAC" :value="scanStats.withMac" value-style="color: #409eff" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-statistic title="有主机名" :value="scanStats.withHostname" value-style="color: #909399" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
style="width: 100%; margin-top: 16px;"
|
||||
v-loading="loading"
|
||||
stripe
|
||||
height="calc(100vh - 320px)"
|
||||
>
|
||||
<el-table-column prop="ip_address" label="IP地址" width="140" fixed="left">
|
||||
<template #default="scope">
|
||||
<span class="ip-address">{{ scope.row.ip_address }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="在线状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.status === 'online' ? 'success' : 'info'" size="small">
|
||||
{{ scope.row.status === 'online' ? '在线' : '离线' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="mac_address" label="MAC地址" width="160">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.mac_address" class="mac-address">{{ scope.row.mac_address }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="vendor" label="厂商" width="180" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.vendor">{{ scope.row.vendor }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="hostname" label="主机名" min-width="150" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.hostname">{{ scope.row.hostname }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="owner" label="使用者" width="100">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.owner">{{ scope.row.owner }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="primary" @click="scanSingleIP(scope.row.ip_address)">
|
||||
单独扫描
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:page-sizes="[50, 100, 200]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadIPs"
|
||||
@current-change="loadIPs"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { networkApi, scanApi } from '@/api'
|
||||
|
||||
const loading = ref(false)
|
||||
const scanning = ref(false)
|
||||
|
||||
const networks = ref([])
|
||||
const selectedNetworkId = ref(null)
|
||||
const selectedNetwork = computed(() => {
|
||||
if (!selectedNetworkId.value) return null
|
||||
return networks.value.find(n => n.id === selectedNetworkId.value) || null
|
||||
})
|
||||
const tableData = ref([])
|
||||
|
||||
const scanOptions = ref(['ping', 'arp', 'dns'])
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
limit: 100,
|
||||
total: 0
|
||||
})
|
||||
|
||||
const scanStats = computed(() => {
|
||||
const total = tableData.value.length
|
||||
const online = tableData.value.filter(item => item.status === 'online').length
|
||||
const withMac = tableData.value.filter(item => item.mac_address).length
|
||||
const withHostname = tableData.value.filter(item => item.hostname).length
|
||||
return { total, online, withMac, withHostname }
|
||||
})
|
||||
|
||||
const loadNetworks = async () => {
|
||||
try {
|
||||
const result = await networkApi.getList({ limit: 1000 })
|
||||
networks.value = result.items
|
||||
} catch (error) {
|
||||
ElMessage.error('加载网段列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
const onNetworkChange = (networkId) => {
|
||||
pagination.page = 1
|
||||
selectedNetworkId.value = networkId
|
||||
loadIPs()
|
||||
}
|
||||
|
||||
const loadIPs = async () => {
|
||||
if (!selectedNetworkId.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await networkApi.getIPs(selectedNetworkId.value, {
|
||||
skip: (pagination.page - 1) * pagination.limit,
|
||||
limit: pagination.limit
|
||||
})
|
||||
tableData.value = result.items
|
||||
pagination.total = result.total
|
||||
} catch (error) {
|
||||
ElMessage.error('加载IP列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const startScan = async () => {
|
||||
if (!selectedNetworkId.value) return
|
||||
scanning.value = true
|
||||
try {
|
||||
ElMessage.info(`开始扫描网段 ${selectedNetwork.value?.cidr}`)
|
||||
await scanApi.comprehensiveScan(selectedNetworkId.value, {
|
||||
enable_ping: scanOptions.value.includes('ping'),
|
||||
enable_arp: scanOptions.value.includes('arp'),
|
||||
enable_dns: scanOptions.value.includes('dns')
|
||||
})
|
||||
ElMessage.success('扫描完成')
|
||||
loadIPs()
|
||||
} catch (error) {
|
||||
console.error('扫描错误详情:', error)
|
||||
} finally {
|
||||
scanning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const scanSingleIP = async (ipAddress) => {
|
||||
try {
|
||||
await scanApi.scanIP(ipAddress)
|
||||
ElMessage.success(`扫描 ${ipAddress} 完成`)
|
||||
loadIPs()
|
||||
} catch (error) {
|
||||
ElMessage.error(`扫描 ${ipAddress} 失败`)
|
||||
}
|
||||
}
|
||||
|
||||
const exportResults = () => {
|
||||
if (!selectedNetwork.value) {
|
||||
ElMessage.warning('请先选择网段')
|
||||
return
|
||||
}
|
||||
const headers = ['IP地址', '状态', 'MAC地址', '厂商', '主机名', '使用者']
|
||||
const rows = tableData.value.map(item => [
|
||||
item.ip_address,
|
||||
item.status === 'online' ? '在线' : '离线',
|
||||
item.mac_address || '',
|
||||
item.vendor || '',
|
||||
item.hostname || '',
|
||||
item.owner || ''
|
||||
])
|
||||
const csvContent = [headers, ...rows].map(row => row.join(',')).join('\n')
|
||||
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' })
|
||||
const link = document.createElement('a')
|
||||
link.href = URL.createObjectURL(blob)
|
||||
link.download = `scan_result_${selectedNetwork.value?.cidr?.replace('/', '-')}.csv`
|
||||
link.click()
|
||||
ElMessage.success('导出成功')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadNetworks()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.ip-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-weight: 500;
|
||||
color: #409eff;
|
||||
}
|
||||
.mac-address {
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
.pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,363 @@
|
||||
<template>
|
||||
<div class="users-page">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>用户管理</span>
|
||||
<el-button type="primary" @click="showCreateDialog">
|
||||
<el-icon><Plus /></el-icon> 新建用户
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" :model="filters" class="filter-form">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="filters.status" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option label="正常" value="active" />
|
||||
<el-option label="禁用" value="inactive" />
|
||||
<el-option label="锁定" value="locked" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色">
|
||||
<el-select v-model="filters.role" placeholder="全部" clearable style="width: 160px">
|
||||
<el-option label="超级管理员" value="super_admin" />
|
||||
<el-option label="管理员" value="admin" />
|
||||
<el-option label="操作员" value="operator" />
|
||||
<el-option label="访客" value="viewer" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="loadUsers">
|
||||
<el-icon><Search /></el-icon> 查询
|
||||
</el-button>
|
||||
<el-button @click="resetFilters">
|
||||
<el-icon><Refresh /></el-icon> 重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table :data="users" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="60" align="center" />
|
||||
<el-table-column prop="username" label="用户名" width="120" />
|
||||
<el-table-column prop="real_name" label="姓名" width="120" />
|
||||
<el-table-column prop="email" label="邮箱" min-width="180" />
|
||||
<el-table-column prop="phone" label="电话" width="130" />
|
||||
<el-table-column label="角色" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="roleTagType(scope.row.role)" effect="plain" size="small">
|
||||
{{ roleLabel(scope.row.role) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="statusTagType(scope.row.status)" effect="plain" size="small">
|
||||
{{ statusLabel(scope.row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="最后登录" width="170">
|
||||
<template #default="scope">
|
||||
{{ scope.row.last_login_at ? formatDate(scope.row.last_login_at) : '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="280" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
size="small"
|
||||
:type="scope.row.status === 'active' ? 'warning' : 'success'"
|
||||
@click="toggleStatus(scope.row)"
|
||||
:disabled="scope.row.id === currentUserId"
|
||||
>
|
||||
{{ scope.row.status === 'active' ? '禁用' : '启用' }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="scope.row.status === 'locked'"
|
||||
size="small"
|
||||
type="primary"
|
||||
@click="unlockUser(scope.row)"
|
||||
>
|
||||
解锁
|
||||
</el-button>
|
||||
<el-button size="small" @click="showResetPasswordDialog(scope.row)">
|
||||
重置密码
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="danger"
|
||||
@click="deleteUser(scope.row)"
|
||||
:disabled="scope.row.id === currentUserId"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.limit"
|
||||
:page-sizes="[20, 50, 100]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="loadUsers"
|
||||
@current-change="loadUsers"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 新建用户对话框 -->
|
||||
<el-dialog v-model="createDialogVisible" title="新建用户" width="500px" @close="resetCreateForm">
|
||||
<el-form ref="createFormRef" :model="createForm" :rules="createRules" label-width="100px">
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="createForm.username" placeholder="登录用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input v-model="createForm.password" type="password" placeholder="≥6 位" show-password />
|
||||
</el-form-item>
|
||||
<el-form-item label="姓名" prop="real_name">
|
||||
<el-input v-model="createForm.real_name" placeholder="真实姓名(可选)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="createForm.email" placeholder="可选" />
|
||||
</el-form-item>
|
||||
<el-form-item label="电话" prop="phone">
|
||||
<el-input v-model="createForm.phone" placeholder="可选" />
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" prop="role">
|
||||
<el-select v-model="createForm.role" style="width: 100%">
|
||||
<el-option label="管理员" value="admin" />
|
||||
<el-option label="操作员" value="operator" />
|
||||
<el-option label="访客" value="viewer" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="createDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitCreate">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 重置密码对话框 -->
|
||||
<el-dialog v-model="resetDialogVisible" title="重置密码" width="420px">
|
||||
<el-form :model="resetForm" label-width="100px">
|
||||
<el-form-item label="目标用户">
|
||||
<el-text>{{ resetTarget?.username }} ({{ resetTarget?.real_name || '-' }})</el-text>
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码">
|
||||
<el-input v-model="resetForm.new_password" type="password" placeholder="≥6 位" show-password />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="resetDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitReset">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Search, Refresh } from '@element-plus/icons-vue'
|
||||
import { userApi } from '@/api/auth'
|
||||
import { authStore } from '@/utils/auth'
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const users = ref([])
|
||||
|
||||
const filters = reactive({ status: '', role: '' })
|
||||
const pagination = reactive({ page: 1, limit: 20, total: 0 })
|
||||
|
||||
const currentUserId = computed(() => authStore.getUserInfo()?.id)
|
||||
|
||||
const createDialogVisible = ref(false)
|
||||
const createFormRef = ref(null)
|
||||
const createForm = reactive({
|
||||
username: '', password: '', real_name: '', email: '', phone: '', role: 'viewer',
|
||||
})
|
||||
const createRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, min: 6, message: '密码至少 6 位', trigger: 'blur' }],
|
||||
email: [{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' }],
|
||||
role: [{ required: true, message: '请选择角色', trigger: 'change' }],
|
||||
}
|
||||
|
||||
const resetDialogVisible = ref(false)
|
||||
const resetForm = reactive({ new_password: '' })
|
||||
const resetTarget = ref(null)
|
||||
|
||||
const ROLE_MAP = {
|
||||
super_admin: { label: '超级管理员', tagType: 'danger' },
|
||||
admin: { label: '管理员', tagType: 'warning' },
|
||||
operator: { label: '操作员', tagType: 'success' },
|
||||
viewer: { label: '访客', tagType: 'info' },
|
||||
}
|
||||
const STATUS_MAP = {
|
||||
active: { label: '正常', tagType: 'success' },
|
||||
inactive: { label: '禁用', tagType: 'info' },
|
||||
locked: { label: '锁定', tagType: 'danger' },
|
||||
}
|
||||
|
||||
function roleLabel(r) { return ROLE_MAP[r]?.label || r || '-' }
|
||||
function roleTagType(r) { return ROLE_MAP[r]?.tagType || '' }
|
||||
function statusLabel(s) { return STATUS_MAP[s]?.label || s || '-' }
|
||||
function statusTagType(s) { return STATUS_MAP[s]?.tagType || '' }
|
||||
|
||||
function formatDate(d) {
|
||||
if (!d) return '-'
|
||||
try {
|
||||
const dt = new Date(d)
|
||||
if (isNaN(dt.getTime())) return d
|
||||
const pad = n => String(n).padStart(2, '0')
|
||||
return `${dt.getFullYear()}-${pad(dt.getMonth()+1)}-${pad(dt.getDate())} ${pad(dt.getHours())}:${pad(dt.getMinutes())}`
|
||||
} catch { return d }
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await userApi.getList({
|
||||
skip: (pagination.page - 1) * pagination.limit,
|
||||
limit: pagination.limit,
|
||||
status: filters.status || undefined,
|
||||
role: filters.role || undefined,
|
||||
})
|
||||
users.value = result.items || []
|
||||
pagination.total = result.total || 0
|
||||
} catch (error) {
|
||||
console.error('加载用户列表失败:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
filters.status = ''
|
||||
filters.role = ''
|
||||
pagination.page = 1
|
||||
loadUsers()
|
||||
}
|
||||
|
||||
function showCreateDialog() {
|
||||
createDialogVisible.value = true
|
||||
}
|
||||
|
||||
function resetCreateForm() {
|
||||
Object.assign(createForm, {
|
||||
username: '', password: '', real_name: '', email: '', phone: '', role: 'viewer',
|
||||
})
|
||||
createFormRef.value?.resetFields()
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
if (!createFormRef.value) return
|
||||
try {
|
||||
await createFormRef.value.validate()
|
||||
} catch (_) { return }
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await userApi.create({ ...createForm })
|
||||
ElMessage.success('用户创建成功')
|
||||
createDialogVisible.value = false
|
||||
pagination.page = 1
|
||||
loadUsers()
|
||||
} catch (error) {
|
||||
console.error('创建用户失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleStatus(row) {
|
||||
const next = row.status === 'active' ? 'inactive' : 'active'
|
||||
const action = next === 'active' ? '启用' : '禁用'
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要${action}用户 ${row.username} 吗?`,
|
||||
'提示', { type: 'warning', confirmButtonText: action, cancelButtonText: '取消' }
|
||||
)
|
||||
} catch (_) { return }
|
||||
|
||||
try {
|
||||
await userApi.updateStatus(row.id, next)
|
||||
ElMessage.success(`已${action}`)
|
||||
loadUsers()
|
||||
} catch (error) {
|
||||
console.error('更新状态失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
async function unlockUser(row) {
|
||||
try {
|
||||
await userApi.unlock(row.id)
|
||||
ElMessage.success('用户已解锁')
|
||||
loadUsers()
|
||||
} catch (error) {
|
||||
console.error('解锁失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
function showResetPasswordDialog(row) {
|
||||
resetTarget.value = row
|
||||
resetForm.new_password = ''
|
||||
resetDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitReset() {
|
||||
if (!resetForm.new_password || resetForm.new_password.length < 6) {
|
||||
ElMessage.warning('新密码至少 6 位')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await userApi.resetPassword(resetTarget.value.id, resetForm.new_password)
|
||||
ElMessage.success('密码已重置,用户所有会话已失效')
|
||||
resetDialogVisible.value = false
|
||||
} catch (error) {
|
||||
console.error('重置密码失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteUser(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要删除用户 ${row.username} 吗?(软删除,标记为禁用)`,
|
||||
'提示', { type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' }
|
||||
)
|
||||
} catch (_) { return }
|
||||
|
||||
try {
|
||||
await userApi.delete(row.id)
|
||||
ElMessage.success('用户已删除')
|
||||
loadUsers()
|
||||
} catch (error) {
|
||||
console.error('删除用户失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadUsers()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.filter-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,26 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 3000,
|
||||
// 允许任意 Host 头访问(HMR WebSocket 在远程访问时需要)
|
||||
allowedHosts: true,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8008',
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user