diff --git a/.agents/skills/frontend-design/LICENSE.txt b/.agents/skills/frontend-design/LICENSE.txt new file mode 100644 index 0000000..f433b1a --- /dev/null +++ b/.agents/skills/frontend-design/LICENSE.txt @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/.agents/skills/frontend-design/SKILL.md b/.agents/skills/frontend-design/SKILL.md new file mode 100644 index 0000000..5be498e --- /dev/null +++ b/.agents/skills/frontend-design/SKILL.md @@ -0,0 +1,42 @@ +--- +name: frontend-design +description: Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics. +license: Complete terms in LICENSE.txt +--- + +This skill guides creation of distinctive, production-grade frontend interfaces that avoid generic "AI slop" aesthetics. Implement real working code with exceptional attention to aesthetic details and creative choices. + +The user provides frontend requirements: a component, page, application, or interface to build. They may include context about the purpose, audience, or technical constraints. + +## Design Thinking + +Before coding, understand the context and commit to a BOLD aesthetic direction: +- **Purpose**: What problem does this interface solve? Who uses it? +- **Tone**: Pick an extreme: brutally minimal, maximalist chaos, retro-futuristic, organic/natural, luxury/refined, playful/toy-like, editorial/magazine, brutalist/raw, art deco/geometric, soft/pastel, industrial/utilitarian, etc. There are so many flavors to choose from. Use these for inspiration but design one that is true to the aesthetic direction. +- **Constraints**: Technical requirements (framework, performance, accessibility). +- **Differentiation**: What makes this UNFORGETTABLE? What's the one thing someone will remember? + +**CRITICAL**: Choose a clear conceptual direction and execute it with precision. Bold maximalism and refined minimalism both work - the key is intentionality, not intensity. + +Then implement working code (HTML/CSS/JS, React, Vue, etc.) that is: +- Production-grade and functional +- Visually striking and memorable +- Cohesive with a clear aesthetic point-of-view +- Meticulously refined in every detail + +## Frontend Aesthetics Guidelines + +Focus on: +- **Typography**: Choose fonts that are beautiful, unique, and interesting. Avoid generic fonts like Arial and Inter; opt instead for distinctive choices that elevate the frontend's aesthetics; unexpected, characterful font choices. Pair a distinctive display font with a refined body font. +- **Color & Theme**: Commit to a cohesive aesthetic. Use CSS variables for consistency. Dominant colors with sharp accents outperform timid, evenly-distributed palettes. +- **Motion**: Use animations for effects and micro-interactions. Prioritize CSS-only solutions for HTML. Use Motion library for React when available. Focus on high-impact moments: one well-orchestrated page load with staggered reveals (animation-delay) creates more delight than scattered micro-interactions. Use scroll-triggering and hover states that surprise. +- **Spatial Composition**: Unexpected layouts. Asymmetry. Overlap. Diagonal flow. Grid-breaking elements. Generous negative space OR controlled density. +- **Backgrounds & Visual Details**: Create atmosphere and depth rather than defaulting to solid colors. Add contextual effects and textures that match the overall aesthetic. Apply creative forms like gradient meshes, noise textures, geometric patterns, layered transparencies, dramatic shadows, decorative borders, custom cursors, and grain overlays. + +NEVER use generic AI-generated aesthetics like overused font families (Inter, Roboto, Arial, system fonts), cliched color schemes (particularly purple gradients on white backgrounds), predictable layouts and component patterns, and cookie-cutter design that lacks context-specific character. + +Interpret creatively and make unexpected choices that feel genuinely designed for the context. No design should be the same. Vary between light and dark themes, different fonts, different aesthetics. NEVER converge on common choices (Space Grotesk, for example) across generations. + +**IMPORTANT**: Match implementation complexity to the aesthetic vision. Maximalist designs need elaborate code with extensive animations and effects. Minimalist or refined designs need restraint, precision, and careful attention to spacing, typography, and subtle details. Elegance comes from executing the vision well. + +Remember: Claude is capable of extraordinary creative work. Don't hold back, show what can truly be created when thinking outside the box and committing fully to a distinctive vision. diff --git a/.claude/skills/frontend-design b/.claude/skills/frontend-design new file mode 120000 index 0000000..712f694 --- /dev/null +++ b/.claude/skills/frontend-design @@ -0,0 +1 @@ +../../.agents/skills/frontend-design \ No newline at end of file diff --git a/backend/app/api/v1/check.py b/backend/app/api/v1/check.py index 4a0adc6..5eb20a1 100644 --- a/backend/app/api/v1/check.py +++ b/backend/app/api/v1/check.py @@ -80,7 +80,7 @@ def discover_olt(olt_id: int, db: Session = Depends(get_db)): """扫描单台 OLT 并将新发现的 MAC 自动入库关联""" try: service = CheckService(db) - result = asyncio.run(service.check_olt_devices(olt_id)) + result = service.scan_and_discover(olt_id) return result except Exception as e: raise HTTPException(status_code=500, detail=str(e)) diff --git a/backend/app/api/v1/olt.py b/backend/app/api/v1/olt.py index f3af8f4..eb55b21 100644 --- a/backend/app/api/v1/olt.py +++ b/backend/app/api/v1/olt.py @@ -400,3 +400,46 @@ def loopback_detection(db: Session = Depends(get_db)): # 按原始顺序返回 return [results_map[olt.id] for olt in olts] + + +class TogglePortRequest(BaseModel): + action: str # "shutdown" 或 "undo shutdown" + + +@router.get("/devices/{olt_id}/ports") +def get_olt_ports(olt_id: int, db: Session = Depends(get_db)): + """获取指定 OLT 的所有 Olt 端口状态""" + from app.services.ssh_service import SSHService + olt = db.query(OLTDevice).filter(OLTDevice.id == olt_id).first() + if not olt: + raise HTTPException(status_code=404, detail="OLT 不存在") + ssh = SSHService(olt.ip_address, olt.username, olt.password) + try: + ssh.connect() + ports = ssh.get_olt_ports() + return {"ports": ports} + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + finally: + ssh.close() + + +@router.post("/devices/{olt_id}/ports/toggle") +def toggle_olt_port(olt_id: int, body: TogglePortRequest, port_name: str, db: Session = Depends(get_db)): + """开启或关闭指定 OLT 端口""" + from app.services.ssh_service import SSHService + if body.action not in ("shutdown", "undo shutdown"): + raise HTTPException(status_code=400, detail="action 必须为 shutdown 或 undo shutdown") + olt = db.query(OLTDevice).filter(OLTDevice.id == olt_id).first() + if not olt: + raise HTTPException(status_code=404, detail="OLT 不存在") + ssh = SSHService(olt.ip_address, olt.username, olt.password) + try: + ssh.connect() + ssh.toggle_olt_port(port_name, body.action) + return {"message": f"端口 {port_name} 已{'关闭' if body.action == 'shutdown' else '开启'}"} + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + finally: + ssh.close() + diff --git a/backend/app/services/check_service.py b/backend/app/services/check_service.py index dac6e17..8a89bf2 100644 --- a/backend/app/services/check_service.py +++ b/backend/app/services/check_service.py @@ -39,17 +39,18 @@ class CheckService: online_count = 0 offline_count = 0 - # 全局 MAC → id 索引,只取需要的字段 + # 全局 MAC → (id, model) 索引 existing = { - row.mac_address.lower(): row.id - for row in self.db.query(ONUDevice.mac_address, ONUDevice.id).all() + row.mac_address.lower(): (row.id, row.model) + for row in self.db.query(ONUDevice.mac_address, ONUDevice.id, ONUDevice.model).all() } for mac, onu_info in onu_info_dict.items(): - onu_id = existing.get(mac) - if onu_id is None: + entry = existing.get(mac) + if entry is None: continue # 不在库中,跳过 + onu_id, onu_model = entry status = onu_info.status distance_m = parse_distance(onu_info.distance_str) if status == 'online': @@ -57,6 +58,9 @@ class CheckService: else: offline_count += 1 + if onu_info.model and not onu_model: + self.db.query(ONUDevice).filter(ONUDevice.id == onu_id).update({"model": onu_info.model}) + self.db.add(DeviceStatusHistory( onu_device_id=onu_id, status=status, @@ -88,32 +92,30 @@ class CheckService: raise Exception("关联的 OLT 不存在") mac = device.mac_address.lower() - base_cmd = olt.slot_command # e.g. "display onu slot" - if device.slot_number is not None: - cmd = f"{base_cmd} {device.slot_number} | include {mac}" - else: - cmd = f"{base_cmd} | include {mac}" + cmd = f"{olt.slot_command} | include {mac}" ssh = SSHService(olt.ip_address, olt.username, olt.password) try: ssh.connect() output = ssh.execute_command(cmd) - # 从输出中找到包含该 MAC 的行并解析 + # 跳过命令回显行(含 MAC 但无端口标识),只接受有 port_id 的行 info = None for line in output.splitlines(): if mac in line.lower(): - info = ssh._parse_device_line(line, device.slot_number) - if info: + parsed = ssh._parse_device_line(line, device.slot_number) + if parsed and parsed.port_id: + info = parsed break if info is None: - # 未找到该 MAC,视为离线 status = 'offline' distance_m = None else: status = info.status distance_m = parse_distance(info.distance_str) + if info.model and not device.model: + device.model = info.model self.db.add(DeviceStatusHistory( onu_device_id=device.id, @@ -123,7 +125,7 @@ class CheckService: response_data=None, )) self.db.commit() - return {"status": status, "distance_m": distance_m} + return {"status": status, "distance_m": distance_m, "model": device.model} finally: ssh.close() @@ -147,14 +149,14 @@ class CheckService: new_count = 0 existing = { - row.mac_address.lower(): row.id - for row in self.db.query(ONUDevice.mac_address, ONUDevice.id).all() + row.mac_address.lower(): (row.id, row.model) + for row in self.db.query(ONUDevice.mac_address, ONUDevice.id, ONUDevice.model).all() } for mac, onu_info in onu_info_dict.items(): - onu_id = existing.get(mac) + entry = existing.get(mac) - if onu_id is None: + if entry is None: # 新设备:只入库在线的 if onu_info.status != 'online': continue @@ -171,8 +173,12 @@ class CheckService: self.db.add(onu) self.db.flush() self.db.add(NewDevice(onu_device_id=onu.id, olt_id=olt_id)) - onu_id = onu.id new_count += 1 + onu_id = onu.id + else: + onu_id, onu_model = entry + if onu_info.model and not onu_model: + self.db.query(ONUDevice).filter(ONUDevice.id == onu_id).update({"model": onu_info.model}) status = onu_info.status distance_m = parse_distance(onu_info.distance_str) diff --git a/backend/app/services/ssh_service.py b/backend/app/services/ssh_service.py index b9a59d3..f7a0dc3 100644 --- a/backend/app/services/ssh_service.py +++ b/backend/app/services/ssh_service.py @@ -276,6 +276,66 @@ class SSHService: model=model ) + def get_olt_ports(self) -> list: + """获取所有 Olt 端口状态,返回 [{'name': 'Olt1/0/1', 'status': 'up'}, ...]""" + output = self.execute_command("display interface brief") + ports = [] + for line in output.splitlines(): + line = line.strip() + if not line.startswith("Olt"): + continue + parts = line.split() + if len(parts) < 2: + continue + name = parts[0] + link = parts[1].upper() + # ADM 表示 administratively down(手动关闭) + if link == "ADM": + status = "adm-down" + elif link == "UP": + status = "up" + else: + status = "down" + ports.append({"name": name, "status": status}) + return ports + + def toggle_olt_port(self, port_name: str, action: str) -> bool: + """开启或关闭 OLT 端口 + action: 'shutdown' 或 'undo shutdown' + 流程: system-view -> interface {port_name} -> shutdown/undo shutdown -> quit -> quit + """ + if not self.shell: + raise Exception("SSH 未连接") + + def send_and_wait(cmd: str, expect: str, timeout: int = 10) -> str: + self.shell.send(cmd + "\n") + buf = "" + deadline = time.time() + timeout + while time.time() < deadline: + if self.shell.recv_ready(): + buf += self.shell.recv(4096).decode('utf-8', errors='ignore') + if expect in buf: + return buf + else: + time.sleep(0.2) + return buf + + out = send_and_wait("system-view", "]") + if "]" not in out: + raise Exception("进入 system-view 失败") + + out = send_and_wait(f"interface {port_name}", "]") + if "]" not in out: + raise Exception(f"进入端口 {port_name} 失败") + + out = send_and_wait(action, "]") + if "]" not in out: + raise Exception(f"执行 {action} 失败") + + send_and_wait("quit", "]", timeout=5) + send_and_wait("quit", ">", timeout=5) + return True + def close(self): """关闭 SSH 连接""" if self.client: diff --git a/frontend/src/components/Layout.vue b/frontend/src/components/Layout.vue index 7232932..4670df8 100644 --- a/frontend/src/components/Layout.vue +++ b/frontend/src/components/Layout.vue @@ -1,34 +1,176 @@ diff --git a/frontend/src/main.js b/frontend/src/main.js index 6760c11..5445566 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -2,6 +2,7 @@ import { createApp } from 'vue' import { createPinia } from 'pinia' import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' +import './styles/theme.css' import App from './App.vue' import router from './router' diff --git a/frontend/src/stores/theme.js b/frontend/src/stores/theme.js new file mode 100644 index 0000000..4699520 --- /dev/null +++ b/frontend/src/stores/theme.js @@ -0,0 +1,27 @@ +import { defineStore } from 'pinia' +import { ref, watch } from 'vue' + +export const useThemeStore = defineStore('theme', () => { + const STORAGE_KEY = 'onu-theme' + const theme = ref(localStorage.getItem(STORAGE_KEY) || 'dark') + + const applyTheme = (t) => { + document.documentElement.setAttribute('data-theme', t) + } + + // 初始化时立即应用 + applyTheme(theme.value) + + // 切换 + const toggle = () => { + theme.value = theme.value === 'dark' ? 'light' : 'dark' + } + + // 监听变化:同步到 DOM + localStorage + watch(theme, (t) => { + applyTheme(t) + localStorage.setItem(STORAGE_KEY, t) + }) + + return { theme, toggle } +}) diff --git a/frontend/src/styles/theme.css b/frontend/src/styles/theme.css new file mode 100644 index 0000000..b9b6a15 --- /dev/null +++ b/frontend/src/styles/theme.css @@ -0,0 +1,732 @@ +/* ============================================================ + H3C ONU 管理系统 — 全局主题 + 工业深色风格 · 深海蓝黑 + 青绿主调 + ============================================================ */ + +@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap'); + +:root { + /* ── 基础色板 ── */ + --bg-base: #0a0e1a; + --bg-surface: #0f1525; + --bg-elevated: #141c30; + --bg-card: #18213a; + --bg-hover: #1e2a42; + --bg-active: #1a3050; + + /* ── 边框 ── */ + --border-subtle: rgba(255,255,255,0.05); + --border-default: rgba(255,255,255,0.10); + --border-strong: rgba(255,255,255,0.18); + --border-accent: rgba(0,210,180,0.35); + + /* ── 主色调:青绿 ── */ + --accent: #00d2b4; + --accent-dim: rgba(0,210,180,0.15); + --accent-glow: rgba(0,210,180,0.30); + --accent-dark: #009e88; + + /* ── 状态色 ── */ + --success: #22c55e; + --success-dim: rgba(34,197,94,0.15); + --danger: #ef4444; + --danger-dim: rgba(239,68,68,0.15); + --warning: #f59e0b; + --warning-dim: rgba(245,158,11,0.15); + --info: #3b82f6; + --info-dim: rgba(59,130,246,0.15); + + /* ── 文字 ── */ + --text-primary: #e8edf5; + --text-secondary: #8a9ab8; + --text-muted: #4a5a78; + --text-accent: #00d2b4; + + /* ── 字体 ── */ + --font-sans: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif; + --font-mono: 'JetBrains Mono', 'Consolas', monospace; + + /* ── 圆角 ── */ + --radius-sm: 4px; + --radius-md: 8px; + --radius-lg: 12px; + + /* ── 阴影 ── */ + --shadow-card: 0 4px 24px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3); + --shadow-glow: 0 0 20px rgba(0,210,180,0.15); +} + +/* ── 全局重置 ── */ +*, *::before, *::after { box-sizing: border-box; } + +html, body, #app { + height: 100%; + margin: 0; + padding: 0; + background: var(--bg-base); + color: var(--text-primary); + font-family: var(--font-sans); + font-size: 14px; + -webkit-font-smoothing: antialiased; +} + +/* ── Element Plus 深色覆盖 ── */ + +/* 容器 */ +.el-container { background: var(--bg-base) !important; } +.el-main { background: var(--bg-base) !important; padding: 24px !important; } + +/* 卡片 */ +.el-card { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-lg) !important; + box-shadow: var(--shadow-card) !important; + color: var(--text-primary) !important; +} +.el-card__header { + background: transparent !important; + border-bottom: 1px solid var(--border-subtle) !important; + padding: 14px 20px !important; + color: var(--text-primary) !important; +} +.el-card__body { color: var(--text-primary) !important; } + +/* 表格 */ +.el-table { + background: transparent !important; + color: var(--text-primary) !important; + border-radius: var(--radius-md) !important; + overflow: hidden !important; + border: 1px solid var(--border-default) !important; +} +.el-table th.el-table__cell { + background: var(--bg-elevated) !important; + color: var(--text-secondary) !important; + font-size: 12px !important; + font-weight: 600 !important; + letter-spacing: 0.05em !important; + text-transform: uppercase !important; + border-bottom: 1px solid var(--border-default) !important; +} +.el-table td.el-table__cell { + background: transparent !important; + border-bottom: 1px solid var(--border-subtle) !important; + color: var(--text-primary) !important; +} +.el-table tr { background: transparent !important; } +.el-table--striped .el-table__body tr.el-table__row--striped td.el-table__cell { + background: rgba(255,255,255,0.02) !important; +} +.el-table__body tr:hover > td.el-table__cell { + background: var(--bg-hover) !important; +} +.el-table__empty-block { background: transparent !important; } +.el-table__empty-text { color: var(--text-muted) !important; } +.el-table__inner-wrapper::before { background: var(--border-default) !important; } + +/* 分页 */ +.el-pagination { + color: var(--text-secondary) !important; +} +.el-pagination .el-pager li { + background: var(--bg-elevated) !important; + color: var(--text-secondary) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-sm) !important; + margin: 0 2px !important; +} +.el-pagination .el-pager li.is-active { + background: var(--accent-dim) !important; + color: var(--accent) !important; + border-color: var(--border-accent) !important; +} +.el-pagination .el-pager li:hover { + color: var(--accent) !important; +} +.el-pagination button { + background: var(--bg-elevated) !important; + color: var(--text-secondary) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-sm) !important; +} +.el-pagination button:hover { color: var(--accent) !important; } +.el-pagination .el-select .el-input__wrapper { + background: var(--bg-elevated) !important; + border-color: var(--border-default) !important; +} +.el-pagination .el-select .el-input__inner { color: var(--text-secondary) !important; } + +/* 输入框 */ +.el-input__wrapper { + background: var(--bg-elevated) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-sm) !important; + box-shadow: none !important; + transition: border-color 0.2s !important; +} +.el-input__wrapper:hover { border-color: var(--border-strong) !important; } +.el-input__wrapper.is-focus { + border-color: var(--accent) !important; + box-shadow: 0 0 0 2px var(--accent-dim) !important; +} +.el-input__inner { + color: var(--text-primary) !important; + background: transparent !important; +} +.el-input__inner::placeholder { color: var(--text-muted) !important; } +.el-textarea__inner { + background: var(--bg-elevated) !important; + border-color: var(--border-default) !important; + color: var(--text-primary) !important; +} +.el-textarea__inner:focus { + border-color: var(--accent) !important; + box-shadow: 0 0 0 2px var(--accent-dim) !important; +} + +/* Select 下拉 */ +.el-select-dropdown { + background: var(--bg-elevated) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-md) !important; + box-shadow: var(--shadow-card) !important; +} +.el-select-dropdown__item { + color: var(--text-secondary) !important; +} +.el-select-dropdown__item:hover, +.el-select-dropdown__item.hover { + background: var(--bg-hover) !important; + color: var(--text-primary) !important; +} +.el-select-dropdown__item.selected { + color: var(--accent) !important; + background: var(--accent-dim) !important; +} + +/* 按钮 */ +.el-button { + border-radius: var(--radius-sm) !important; + font-family: var(--font-sans) !important; + font-weight: 500 !important; + transition: all 0.2s !important; +} +.el-button--default { + background: var(--bg-elevated) !important; + border-color: var(--border-default) !important; + color: var(--text-secondary) !important; +} +.el-button--default:hover { + background: var(--bg-hover) !important; + border-color: var(--border-strong) !important; + color: var(--text-primary) !important; +} +.el-button--primary { + background: var(--accent) !important; + border-color: var(--accent) !important; + color: #0a0e1a !important; + font-weight: 600 !important; +} +.el-button--primary:hover { + background: #00f0cc !important; + border-color: #00f0cc !important; + box-shadow: 0 0 12px var(--accent-glow) !important; +} +.el-button--success { + background: var(--success) !important; + border-color: var(--success) !important; + color: #fff !important; +} +.el-button--danger { + background: var(--danger) !important; + border-color: var(--danger) !important; + color: #fff !important; +} +.el-button--warning { + background: var(--warning) !important; + border-color: var(--warning) !important; + color: #0a0e1a !important; +} +.el-button--info { + background: var(--info) !important; + border-color: var(--info) !important; + color: #fff !important; +} +.el-button.is-plain.el-button--danger { + background: var(--danger-dim) !important; + border-color: var(--danger) !important; + color: var(--danger) !important; +} +.el-button.is-plain.el-button--warning { + background: var(--warning-dim) !important; + border-color: var(--warning) !important; + color: var(--warning) !important; +} +.el-button.is-plain.el-button--primary { + background: var(--accent-dim) !important; + border-color: var(--accent) !important; + color: var(--accent) !important; +} + +/* 标签 */ +.el-tag { + border-radius: var(--radius-sm) !important; + font-size: 11px !important; + font-weight: 600 !important; + letter-spacing: 0.03em !important; +} +.el-tag--success { + background: var(--success-dim) !important; + border-color: rgba(34,197,94,0.3) !important; + color: var(--success) !important; +} +.el-tag--danger { + background: var(--danger-dim) !important; + border-color: rgba(239,68,68,0.3) !important; + color: var(--danger) !important; +} +.el-tag--warning { + background: var(--warning-dim) !important; + border-color: rgba(245,158,11,0.3) !important; + color: var(--warning) !important; +} +.el-tag--info { + background: rgba(255,255,255,0.06) !important; + border-color: var(--border-default) !important; + color: var(--text-secondary) !important; +} + +/* 对话框 */ +.el-dialog { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-lg) !important; + box-shadow: 0 24px 64px rgba(0,0,0,0.6) !important; +} +.el-dialog__header { + background: var(--bg-elevated) !important; + border-bottom: 1px solid var(--border-subtle) !important; + padding: 16px 20px !important; + border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important; +} +.el-dialog__title { + color: var(--text-primary) !important; + font-weight: 600 !important; + font-size: 15px !important; +} +.el-dialog__headerbtn .el-dialog__close { color: var(--text-muted) !important; } +.el-dialog__headerbtn:hover .el-dialog__close { color: var(--text-primary) !important; } +.el-dialog__body { color: var(--text-primary) !important; padding: 20px !important; } +.el-dialog__footer { + border-top: 1px solid var(--border-subtle) !important; + padding: 14px 20px !important; +} +.el-overlay { background: rgba(0,0,0,0.7) !important; } + +/* 表单 */ +.el-form-item__label { color: var(--text-secondary) !important; } +.el-form--inline .el-form-item { margin-bottom: 0 !important; } + +/* 描述列表 */ +.el-descriptions__header { color: var(--text-primary) !important; } +.el-descriptions__body { background: transparent !important; } +.el-descriptions__body .el-descriptions__table { background: transparent !important; } +.el-descriptions__cell { background: transparent !important; } +.el-descriptions--bordered .el-descriptions__cell { + border-color: var(--border-default) !important; + color: var(--text-primary) !important; +} +.el-descriptions--bordered .el-descriptions__label { + background: var(--bg-elevated) !important; + color: var(--text-secondary) !important; + font-size: 12px !important; +} + +/* 进度条 */ +.el-progress-bar__outer { + background: var(--bg-elevated) !important; + border-radius: 2px !important; +} + +/* 统计数字 */ +.el-statistic__head { color: var(--text-muted) !important; font-size: 12px !important; } +.el-statistic__content { color: var(--text-primary) !important; } +.el-statistic__number { color: var(--text-primary) !important; } + +/* 警告框 */ +.el-alert { + border-radius: var(--radius-md) !important; + border: 1px solid !important; +} +.el-alert--success { + background: var(--success-dim) !important; + border-color: rgba(34,197,94,0.3) !important; +} +.el-alert--error { + background: var(--danger-dim) !important; + border-color: rgba(239,68,68,0.3) !important; +} +.el-alert--warning { + background: var(--warning-dim) !important; + border-color: rgba(245,158,11,0.3) !important; +} +.el-alert__title { color: var(--text-primary) !important; } +.el-alert__description { color: var(--text-secondary) !important; } + +/* 链接 */ +.el-link { font-weight: 500 !important; } +.el-link--primary { color: var(--accent) !important; } +.el-link--primary:hover { color: #00f0cc !important; } + +/* 分割线 */ +.el-divider { border-color: var(--border-subtle) !important; } +.el-divider__text { + background: var(--bg-card) !important; + color: var(--text-muted) !important; + font-size: 11px !important; +} + +/* 消息提示 */ +.el-message { + background: var(--bg-elevated) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-md) !important; + box-shadow: var(--shadow-card) !important; +} +.el-message__content { color: var(--text-primary) !important; } + +/* 确认框 */ +.el-message-box { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + border-radius: var(--radius-lg) !important; +} +.el-message-box__header { background: var(--bg-elevated) !important; border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important; } +.el-message-box__title { color: var(--text-primary) !important; } +.el-message-box__content { color: var(--text-secondary) !important; } + +/* 滚动条 */ +::-webkit-scrollbar { width: 6px; height: 6px; } +::-webkit-scrollbar-track { background: transparent; } +::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; } +::-webkit-scrollbar-thumb:hover { background: var(--text-muted); } + +/* 上传 */ +.el-upload { display: inline-block !important; } + +/* 徽章 */ +.el-badge__content { font-size: 10px !important; } + + +/* ============================================================ + 浅色主题 — 精工白瓷 · 云白 + 深青绿主调 + [data-theme="light"] 挂载在 上,覆盖 :root 变量 + ============================================================ */ + +[data-theme="light"] { + /* ── 基础色板 ── */ + --bg-base: #f4f6f9; + --bg-surface: #ffffff; + --bg-elevated: #f0f2f7; + --bg-card: #ffffff; + --bg-hover: #e8ecf4; + --bg-active: #dde5f5; + + /* ── 边框 ── */ + --border-subtle: rgba(0,0,0,0.06); + --border-default: rgba(0,0,0,0.10); + --border-strong: rgba(0,0,0,0.18); + --border-accent: rgba(0,160,140,0.35); + + /* ── 主色调:深青绿(比深色版略深,在白底上有足够对比) ── */ + --accent: #00a08c; + --accent-dim: rgba(0,160,140,0.10); + --accent-glow: rgba(0,160,140,0.25); + --accent-dark: #007a6b; + + /* ── 状态色(加深版,确保白底可读性) ── */ + --success: #16a34a; + --success-dim: rgba(22,163,74,0.10); + --danger: #dc2626; + --danger-dim: rgba(220,38,38,0.08); + --warning: #d97706; + --warning-dim: rgba(217,119,6,0.10); + --info: #2563eb; + --info-dim: rgba(37,99,235,0.10); + + /* ── 文字 ── */ + --text-primary: #111827; + --text-secondary: #374151; + --text-muted: #9ca3af; + --text-accent: #00a08c; + + /* ── 阴影(浅色版用更细腻的阴影) ── */ + --shadow-card: 0 1px 4px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.06); + --shadow-glow: 0 0 16px rgba(0,160,140,0.12); +} + +/* ── 浅色主题下的全局背景 ── */ +[data-theme="light"] body, +[data-theme="light"] #app { + background: var(--bg-base); + color: var(--text-primary); +} + +/* ── 浅色主题下的 Element Plus 覆盖 ── */ + +/* 容器 */ +[data-theme="light"] .el-container { background: var(--bg-base) !important; } +[data-theme="light"] .el-main { background: var(--bg-base) !important; } + +/* 卡片 */ +[data-theme="light"] .el-card { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + box-shadow: var(--shadow-card) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-card__header { + border-bottom: 1px solid var(--border-subtle) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-card__body { color: var(--text-primary) !important; } + +/* 表格 */ +[data-theme="light"] .el-table { + background: var(--bg-card) !important; + color: var(--text-primary) !important; + border: 1px solid var(--border-default) !important; +} +[data-theme="light"] .el-table th.el-table__cell { + background: var(--bg-elevated) !important; + color: var(--text-secondary) !important; + border-bottom: 1px solid var(--border-default) !important; +} +[data-theme="light"] .el-table td.el-table__cell { + background: var(--bg-card) !important; + border-bottom: 1px solid var(--border-subtle) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-table tr { background: var(--bg-card) !important; } +[data-theme="light"] .el-table--striped .el-table__body tr.el-table__row--striped td.el-table__cell { + background: #f8fafc !important; +} +[data-theme="light"] .el-table__body tr:hover > td.el-table__cell { + background: var(--bg-hover) !important; +} +[data-theme="light"] .el-table__empty-block { background: var(--bg-card) !important; } +[data-theme="light"] .el-table__empty-text { color: var(--text-muted) !important; } +[data-theme="light"] .el-table__inner-wrapper::before { background: var(--border-default) !important; } + +/* 分页 */ +[data-theme="light"] .el-pagination { color: var(--text-secondary) !important; } +[data-theme="light"] .el-pagination .el-pager li { + background: var(--bg-card) !important; + color: var(--text-secondary) !important; + border: 1px solid var(--border-default) !important; +} +[data-theme="light"] .el-pagination .el-pager li.is-active { + background: var(--accent-dim) !important; + color: var(--accent) !important; + border-color: var(--border-accent) !important; +} +[data-theme="light"] .el-pagination .el-pager li:hover { color: var(--accent) !important; } +[data-theme="light"] .el-pagination button { + background: var(--bg-card) !important; + color: var(--text-secondary) !important; + border: 1px solid var(--border-default) !important; +} +[data-theme="light"] .el-pagination button:hover { color: var(--accent) !important; } +[data-theme="light"] .el-pagination .el-select .el-input__wrapper { + background: var(--bg-card) !important; + border-color: var(--border-default) !important; +} +[data-theme="light"] .el-pagination .el-select .el-input__inner { color: var(--text-secondary) !important; } + +/* 输入框 */ +[data-theme="light"] .el-input__wrapper { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + box-shadow: none !important; +} +[data-theme="light"] .el-input__wrapper:hover { border-color: var(--border-strong) !important; } +[data-theme="light"] .el-input__wrapper.is-focus { + border-color: var(--accent) !important; + box-shadow: 0 0 0 2px var(--accent-dim) !important; +} +[data-theme="light"] .el-input__inner { + color: var(--text-primary) !important; + background: transparent !important; +} +[data-theme="light"] .el-input__inner::placeholder { color: var(--text-muted) !important; } +[data-theme="light"] .el-textarea__inner { + background: var(--bg-card) !important; + border-color: var(--border-default) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-textarea__inner:focus { + border-color: var(--accent) !important; + box-shadow: 0 0 0 2px var(--accent-dim) !important; +} + +/* Select 下拉 */ +[data-theme="light"] .el-select-dropdown { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + box-shadow: 0 8px 32px rgba(0,0,0,0.12) !important; +} +[data-theme="light"] .el-select-dropdown__item { color: var(--text-secondary) !important; } +[data-theme="light"] .el-select-dropdown__item:hover, +[data-theme="light"] .el-select-dropdown__item.hover { + background: var(--bg-hover) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-select-dropdown__item.selected { + color: var(--accent) !important; + background: var(--accent-dim) !important; +} + +/* 按钮 */ +[data-theme="light"] .el-button--default { + background: var(--bg-card) !important; + border-color: var(--border-default) !important; + color: var(--text-secondary) !important; +} +[data-theme="light"] .el-button--default:hover { + background: var(--bg-hover) !important; + border-color: var(--border-strong) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-button--primary { + background: var(--accent) !important; + border-color: var(--accent) !important; + color: #ffffff !important; +} +[data-theme="light"] .el-button--primary:hover { + background: #00c4aa !important; + border-color: #00c4aa !important; + box-shadow: 0 0 10px var(--accent-glow) !important; +} +[data-theme="light"] .el-button.is-plain.el-button--danger { + background: var(--danger-dim) !important; + border-color: var(--danger) !important; + color: var(--danger) !important; +} +[data-theme="light"] .el-button.is-plain.el-button--warning { + background: var(--warning-dim) !important; + border-color: var(--warning) !important; + color: var(--warning) !important; +} +[data-theme="light"] .el-button.is-plain.el-button--primary { + background: var(--accent-dim) !important; + border-color: var(--accent) !important; + color: var(--accent) !important; +} + +/* 标签 */ +[data-theme="light"] .el-tag--info { + background: rgba(0,0,0,0.04) !important; + border-color: var(--border-default) !important; + color: var(--text-secondary) !important; +} + +/* 对话框 */ +[data-theme="light"] .el-dialog { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + box-shadow: 0 24px 64px rgba(0,0,0,0.15) !important; +} +[data-theme="light"] .el-dialog__header { + background: var(--bg-elevated) !important; + border-bottom: 1px solid var(--border-subtle) !important; +} +[data-theme="light"] .el-dialog__title { color: var(--text-primary) !important; } +[data-theme="light"] .el-dialog__headerbtn .el-dialog__close { color: var(--text-muted) !important; } +[data-theme="light"] .el-dialog__headerbtn:hover .el-dialog__close { color: var(--text-primary) !important; } +[data-theme="light"] .el-dialog__body { color: var(--text-primary) !important; } +[data-theme="light"] .el-dialog__footer { border-top: 1px solid var(--border-subtle) !important; } +[data-theme="light"] .el-overlay { background: rgba(0,0,0,0.4) !important; } + +/* 表单 */ +[data-theme="light"] .el-form-item__label { color: var(--text-secondary) !important; } + +/* 描述列表 */ +[data-theme="light"] .el-descriptions__body { background: transparent !important; } +[data-theme="light"] .el-descriptions__body .el-descriptions__table { background: transparent !important; } +[data-theme="light"] .el-descriptions--bordered .el-descriptions__cell { + border-color: var(--border-default) !important; + color: var(--text-primary) !important; +} +[data-theme="light"] .el-descriptions--bordered .el-descriptions__label { + background: var(--bg-elevated) !important; + color: var(--text-secondary) !important; +} + +/* 进度条 */ +[data-theme="light"] .el-progress-bar__outer { background: var(--bg-elevated) !important; } + +/* 统计数字 */ +[data-theme="light"] .el-statistic__head { color: var(--text-muted) !important; } +[data-theme="light"] .el-statistic__content { color: var(--text-primary) !important; } +[data-theme="light"] .el-statistic__number { color: var(--text-primary) !important; } + +/* 警告框 */ +[data-theme="light"] .el-alert__title { color: var(--text-primary) !important; } +[data-theme="light"] .el-alert__description { color: var(--text-secondary) !important; } +[data-theme="light"] .el-alert--success { + background: var(--success-dim) !important; + border-color: rgba(22,163,74,0.25) !important; +} +[data-theme="light"] .el-alert--error { + background: var(--danger-dim) !important; + border-color: rgba(220,38,38,0.25) !important; +} +[data-theme="light"] .el-alert--warning { + background: var(--warning-dim) !important; + border-color: rgba(217,119,6,0.25) !important; +} + +/* 链接 */ +[data-theme="light"] .el-link--primary { color: var(--accent) !important; } +[data-theme="light"] .el-link--primary:hover { color: var(--accent-dark) !important; } + +/* 分割线 */ +[data-theme="light"] .el-divider { border-color: var(--border-subtle) !important; } +[data-theme="light"] .el-divider__text { + background: var(--bg-card) !important; + color: var(--text-muted) !important; +} + +/* 消息提示 */ +[data-theme="light"] .el-message { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; + box-shadow: 0 4px 20px rgba(0,0,0,0.12) !important; +} +[data-theme="light"] .el-message__content { color: var(--text-primary) !important; } + +/* 确认框 */ +[data-theme="light"] .el-message-box { + background: var(--bg-card) !important; + border: 1px solid var(--border-default) !important; +} +[data-theme="light"] .el-message-box__header { + background: var(--bg-elevated) !important; +} +[data-theme="light"] .el-message-box__title { color: var(--text-primary) !important; } +[data-theme="light"] .el-message-box__content { color: var(--text-secondary) !important; } + +/* 滚动条(浅色版) */ +[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); } +[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); } + +/* 主题过渡动画 */ +html { + transition: background-color 0.25s ease, color 0.25s ease; +} +*, *::before, *::after { + transition-property: background-color, border-color, color, box-shadow; + transition-duration: 0.2s; + transition-timing-function: ease; +} diff --git a/frontend/src/views/Charts.vue b/frontend/src/views/Charts.vue index 357f127..c57815b 100644 --- a/frontend/src/views/Charts.vue +++ b/frontend/src/views/Charts.vue @@ -1,14 +1,37 @@ @@ -20,34 +43,114 @@ import { getTrend, getByRegion } from '../api/stats' const trendChart = ref(null) const regionChart = ref(null) +const chartTheme = { + backgroundColor: 'transparent', + textStyle: { color: '#8a9ab8', fontFamily: 'Noto Sans SC, sans-serif', fontSize: 12 }, + grid: { left: '3%', right: '4%', bottom: '3%', top: '12%', containLabel: true }, + tooltip: { + backgroundColor: '#141c30', + borderColor: 'rgba(255,255,255,0.10)', + textStyle: { color: '#e8edf5' }, + extraCssText: 'border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,0.4);' + }, + axisLine: { lineStyle: { color: 'rgba(255,255,255,0.08)' } }, + axisTick: { lineStyle: { color: 'rgba(255,255,255,0.08)' } }, + splitLine: { lineStyle: { color: 'rgba(255,255,255,0.05)', type: 'dashed' } }, +} + const initTrendChart = async () => { const { data } = await getTrend(7) const chart = echarts.init(trendChart.value) - chart.setOption({ - tooltip: { trigger: 'axis' }, - legend: { data: ['在线', '离线'] }, - xAxis: { type: 'category', data: data.map(d => d.date) }, - yAxis: { type: 'value' }, + ...chartTheme, + tooltip: { ...chartTheme.tooltip, trigger: 'axis' }, + legend: { + data: ['在线', '离线'], + textStyle: { color: '#8a9ab8' }, + top: 4, + }, + xAxis: { + type: 'category', + data: data.map(d => d.date), + axisLine: chartTheme.axisLine, + axisTick: chartTheme.axisTick, + axisLabel: { color: '#8a9ab8', fontSize: 11 }, + }, + yAxis: { + type: 'value', + axisLine: { show: false }, + axisTick: { show: false }, + axisLabel: { color: '#8a9ab8', fontSize: 11 }, + splitLine: chartTheme.splitLine, + }, series: [ - { name: '在线', type: 'line', data: data.map(d => d.online), smooth: true }, - { name: '离线', type: 'line', data: data.map(d => d.offline), smooth: true } - ] + { + name: '在线', + type: 'line', + data: data.map(d => d.online), + smooth: true, + symbol: 'circle', + symbolSize: 5, + lineStyle: { color: '#00d2b4', width: 2 }, + itemStyle: { color: '#00d2b4' }, + areaStyle: { + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ + { offset: 0, color: 'rgba(0,210,180,0.20)' }, + { offset: 1, color: 'rgba(0,210,180,0.00)' }, + ]) + }, + }, + { + name: '离线', + type: 'line', + data: data.map(d => d.offline), + smooth: true, + symbol: 'circle', + symbolSize: 5, + lineStyle: { color: '#ef4444', width: 2 }, + itemStyle: { color: '#ef4444' }, + areaStyle: { + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ + { offset: 0, color: 'rgba(239,68,68,0.15)' }, + { offset: 1, color: 'rgba(239,68,68,0.00)' }, + ]) + }, + }, + ], }) } const initRegionChart = async () => { const { data } = await getByRegion() const chart = echarts.init(regionChart.value) - + const colors = ['#00d2b4', '#3b82f6', '#a855f7', '#f59e0b', '#22c55e', '#ef4444', '#ec4899'] chart.setOption({ - tooltip: { trigger: 'item' }, - legend: { orient: 'vertical', left: 'left' }, + ...chartTheme, + tooltip: { ...chartTheme.tooltip, trigger: 'item', formatter: '{b}: {c} ({d}%)' }, + legend: { + orient: 'vertical', + right: '5%', + top: 'middle', + textStyle: { color: '#8a9ab8', fontSize: 12 }, + itemWidth: 12, + itemHeight: 12, + }, series: [{ type: 'pie', - radius: '50%', - data: data.map(d => ({ value: d.total, name: d.region })) - }] + radius: ['40%', '68%'], + center: ['38%', '52%'], + data: data.map((d, i) => ({ + value: d.total, + name: d.region, + itemStyle: { color: colors[i % colors.length] }, + })), + label: { show: false }, + labelLine: { show: false }, + emphasis: { + itemStyle: { shadowBlur: 16, shadowColor: 'rgba(0,0,0,0.4)' }, + scaleSize: 6, + }, + }], }) } @@ -58,17 +161,60 @@ onMounted(() => { diff --git a/frontend/src/views/Dashboard.vue b/frontend/src/views/Dashboard.vue index 2e9f2e1..9ae1764 100644 --- a/frontend/src/views/Dashboard.vue +++ b/frontend/src/views/Dashboard.vue @@ -1,102 +1,190 @@