From 20c5ce355a807705d01e790e0a37dbc7c4254139 Mon Sep 17 00:00:00 2001 From: Jeason Date: Sun, 7 Dec 2025 10:12:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E5=92=8C=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加统一的导航菜单到所有页面 - 修复页面路由映射和高亮状态 - 创建 navigation.js 统一管理页面跳转 - 添加 test_navigation.py 路由测试工具 - 支持仪表板、预警管理、智能对话、HTTP对话页面间无缝切换 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .vscode/settings.json | 3 +- convert_encoding.bat | 94 +++++++++++++++++ fix_git_push.bat | 168 +++++++++++++++++++------------ requirements.txt | 80 ++++++--------- simple_git_push.bat | 66 ++++++------ src/web/static/js/navigation.js | 142 ++++++++++++++++++++++++++ src/web/templates/chat.html | 45 +++++++++ src/web/templates/chat_http.html | 45 +++++++++ src/web/templates/dashboard.html | 13 +-- src/web/templates/index.html | 40 +++++++- test_git_push.bat | 52 +++++----- test_navigation.py | 121 ++++++++++++++++++++++ 12 files changed, 685 insertions(+), 184 deletions(-) create mode 100644 convert_encoding.bat create mode 100644 src/web/static/js/navigation.js create mode 100644 test_navigation.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 048bfc1..baced16 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,5 +21,6 @@ "[markdown]": { "files.encoding": "utf8" }, - "python.defaultInterpreterPath": "${workspaceFolder}/.venv/Scripts/python.exe" + "python.defaultInterpreterPath": "${workspaceFolder}/.venv/Scripts/python.exe", + "Codegeex.RepoIndex": true } diff --git a/convert_encoding.bat b/convert_encoding.bat new file mode 100644 index 0000000..a976581 --- /dev/null +++ b/convert_encoding.bat @@ -0,0 +1,94 @@ +@echo off +setlocal enabledelayedexpansion +chcp 65001 >nul 2>&1 +echo ======================================== +echo 代码文件编码批量转换工具 +echo ======================================== +echo. + +:: 设置要扫描的文件扩展名 +set "extensions=*.py *.java *.js *.ts *.html *.css *.xml *.json *.md *.txt *.bat *.cmd *.ps1 *.sh *.yml *.yaml *.ini *.cfg *.conf *.properties" + +:: 设置目标目录(默认为当前目录) +set "target_dir=%cd%" +if not "%~1"=="" set "target_dir=%~1" + +echo 目标目录: %target_dir% +echo. + +:: 检查目录是否存在 +if not exist "%target_dir%" ( + echo 错误:指定的目录不存在 + pause + exit /b 1 +) + +:: 创建临时目录 +set "temp_dir=%temp%\encoding_convert_%random%" +mkdir "%temp_dir%" + +:: 统计变量 +set "total_files=0" +set "converted_files=0" +set "skipped_files=0" + +echo 开始扫描文件... +echo. + +:: 遍历所有指定扩展名的文件 +for %%e in (%extensions%) do ( + for /r "%target_dir%" %%f in (%%e) do ( + set /a total_files+=1 + call :process_file "%%f" + ) +) + +echo. +echo ======================================== +echo 转换完成 +echo ======================================== +echo 总文件数: %total_files% +echo 已转换: %converted_files% +echo 已跳过: %skipped_files% +echo. + +:: 清理临时目录 +rd /s /q "%temp_dir%" 2>nul + +pause +exit /b + +:process_file +set "file=%~1" +set "is_utf8=0" + +:: 检查文件是否已经是UTF-8编码 +powershell -Command "try { $content = [System.IO.File]::ReadAllText('%file%', [System.Text.Encoding]::UTF8); $content | Out-Null; exit 0 } catch { exit 1 }" >nul 2>&1 +if %errorlevel% equ 0 set "is_utf8=1" + +if %is_utf8% equ 1 ( + echo [跳过] %file% (已经是UTF-8) + set /a skipped_files+=1 +) else ( + echo [转换] %file% + + :: 尝试检测并转换编码 + powershell -Command ^ + "$path = '%file%'; ^ + try { ^ + $bytes = [System.IO.File]::ReadAllBytes($path); ^ + $encoding = [System.Text.Encoding]::GetEncoding('GB2312'); ^ + $content = $encoding.GetString($bytes); ^ + [System.IO.File]::WriteAllText($path, $content, [System.Text.Encoding]::UTF8); ^ + exit 0 ^ + } catch { ^ + exit 1 ^ + }" + + if %errorlevel% equ 0 ( + set /a converted_files+=1 + ) else ( + echo [警告] 无法转换 %file% + ) +) +goto :eof diff --git a/fix_git_push.bat b/fix_git_push.bat index 3d47641..942c84e 100644 --- a/fix_git_push.bat +++ b/fix_git_push.bat @@ -1,117 +1,154 @@ @echo off -chcp 65001 >nul +setlocal enabledelayedexpansion +chcp 65001 >nul 2>&1 echo ======================================== -echo GitϺ޸ +echo Git推送问题诊断和修复工具 echo ======================================== echo. -:: 1. Git״̬ -echo [1] Git״̬... -git status +:: 1. 检查Git状态 +echo [1] 检查Git状态... +git status >nul 2>&1 if %errorlevel% neq 0 ( - echo ? Gitδʼ + echo ? Git未初始化或不可用 + echo 请确保: + echo 1. 已安装Git + echo 2. 当前目录是Git仓库 pause exit /b 1 ) +echo ? Git状态正常 echo. -:: 2. Զֿ̲ -echo [2] Զֿ̲... +:: 2. 检查远程仓库配置 +echo [2] 检查远程仓库配置... +git remote -v >nul 2>&1 +if %errorlevel% neq 0 ( + echo ? 未配置远程仓库 + echo 请先运行: git remote add origin ^<仓库地址^> + pause + exit /b 1 +) +echo ? 远程仓库配置正常 git remote -v -if %errorlevel% neq 0 ( - echo ? δԶֿ̲ - echo : git remote add origin <ַֿ> +echo. + +:: 3. 检查当前分支 +echo [3] 检查当前分支... +for /f "tokens=*" %%b in ('git branch --show-current 2^>nul') do set current_branch=%%b +if "!current_branch!"=="" ( + echo ? 无法获取当前分支信息 pause exit /b 1 ) +echo 当前分支: !current_branch! echo. -:: 3. 鵱ǰ֧ -echo [3] 鵱ǰ֧... -git branch --show-current -echo. - -:: 4. Ƿδύĸ -echo [4] δύĸ... -git status --porcelain +:: 4. 检查是否有未提交的更改 +echo [4] 检查未提交的更改... +git status --porcelain >nul 2>&1 if %errorlevel% equ 0 ( - echo ?? δύĸ - set /p commit="Ƿύ? (y/n): " - if /i "%commit%"=="y" ( - git add . - set /p msg="ύϢ: " - if "%msg%"=="" set msg=Զύ - git commit -m "%msg%" + git status --porcelain | findstr /r "." >nul + if !errorlevel! equ 0 ( + echo ?? 有未提交的更改 + set /p commit="是否先提交更改? (y/n): " + if /i "!commit!"=="y" ( + git add . + set /p msg="请输入提交信息: " + if "!msg!"=="" set msg=自动提交 + git commit -m "!msg!" + if !errorlevel! neq 0 ( + echo ? 提交失败 + pause + exit /b 1 + ) + ) ) ) +echo ? 暂存区状态正常 echo. -:: 5. ԻȡԶ̷֧Ϣ -echo [5] ȡԶ̷֧Ϣ... -git fetch origin +:: 5. 尝试获取远程分支信息 +echo [5] 获取远程分支信息... +git fetch origin >nul 2>&1 if %errorlevel% neq 0 ( - echo ? ޷ӵԶֿ̲ + echo ? 无法连接到远程仓库 echo. - echo ܵԭ: - echo 1. - echo 2. Զַֿ̲ - echo 3. Ҫ֤ǷSSHԿToken + echo 可能的原因: + echo 1. 网络连接问题 + echo 2. 远程仓库地址错误 + echo 3. 需要认证(请检查是否已配置SSH密钥或Token) echo. - echo Զַֿ̲: + echo 远程仓库地址: git config --get remote.origin.url + echo. + echo 解决建议: + echo 1. 检查网络连接 + echo 2. 验证远程仓库地址 + echo 3. 配置SSH密钥或访问令牌 pause exit /b 1 ) -echo ? Զֿ̲ӳɹ +echo ? 远程仓库连接成功 echo. -:: 6. ֧ٹϵ -echo [6] ֧ٹϵ... +:: 6. 检查分支跟踪关系 +echo [6] 检查分支跟踪关系... git branch -vv echo. -:: 7. ͵Զ -echo [7] ... -set current_branch= -for /f "tokens=*" %%b in ('git branch --show-current') do set current_branch=%%b - -echo ǰ֧: %current_branch% +:: 7. 尝试推送到远程 +echo [7] 尝试推送... +echo 当前分支: !current_branch! echo. -:: ԶǷڸ÷֧ -git ls-remote --heads origin %current_branch% >nul 2>&1 +:: 检查远程是否存在该分支 +git ls-remote --heads origin !current_branch! >nul 2>&1 if %errorlevel% equ 0 ( - echo Զ̷֧ %current_branch% Ѵ + echo 远程分支 !current_branch! 已存在 echo. - echo ʹõǰ֧... - git push origin %current_branch% + echo 尝试使用当前分支名称推送... + git push origin !current_branch! + if !errorlevel! neq 0 ( + echo. + echo ? 推送失败,尝试拉取最新更改... + git pull origin !current_branch! --rebase + if !errorlevel! equ 0 ( + echo ? 重新尝试推送... + git push origin !current_branch! + ) else ( + echo ? 拉取失败,请检查冲突 + pause + exit /b 1 + ) + ) ) else ( - echo Զ̷֧ %current_branch% + echo 远程分支 !current_branch! 不存在 echo. - echo β... - git push -u origin %current_branch% + echo 尝试设置上游并推送... + git push -u origin !current_branch! ) if %errorlevel% equ 0 ( echo. - echo ? ͳɹ + echo ? 推送成功! ) else ( echo. - echo ? ʧ + echo ? 推送失败 echo. - echo ? ͽ: + echo ? 常见问题和解决方案: echo. - echo 1. ֤: - echo - SSHԿ: ssh -T git@github.com (GitHub) ssh -T git@gitee.com (Gitee) - echo - ʹHTTPS + Tokenʽ + echo 1. 如果是认证问题: + echo - 检查SSH密钥: ssh -T git@github.com (GitHub) 或 ssh -T git@gitee.com (Gitee) + echo - 或使用HTTPS + Token方式 echo. - echo 2. Ƿ֧ͻ: - echo - : git pull origin %current_branch% --rebase - echo - ͻ: git push origin %current_branch% + echo 2. 如果是分支冲突: + echo - 运行: git pull origin !current_branch! --rebase + echo - 解决冲突后: git push origin !current_branch! echo. - echo 3. Զ̷֧Ʋͬ: - echo - Զ̷֧: git branch -r - echo - Ҫ֧: git push origin main git push origin master + echo 3. 如果远程分支名称不同: + echo - 检查远程分支: git branch -r + echo - 可能需要推送主分支: git push origin main 或 git push origin master echo. pause exit /b 1 @@ -119,7 +156,6 @@ if %errorlevel% equ 0 ( echo. echo ======================================== -echo ? ɣ +echo ? 诊断完成! echo ======================================== pause - diff --git a/requirements.txt b/requirements.txt index be271b0..a5f6d78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,80 +1,66 @@ # 核心依赖 -sqlalchemy>=2.0.32 -requests>=2.32.3 -numpy>=1.26.4 -scikit-learn>=1.4.2 +sqlalchemy==2.0.32 +requests==2.32.3 +numpy==1.26.4 +scikit-learn==1.4.2 # 数据库驱动 -pymysql>=1.1.1 -cryptography>=43.0.1 -flask>=3.0.3 -flask-cors>=5.0.0 -websockets>=15.0.1 +pymysql==1.1.1 +cryptography==43.0.1 +flask==3.0.3 +flask-cors==5.0.0 +websockets==15.0.1 # 中文处理 -jieba>=0.42.1 +jieba==0.42.1 # 系统监控 -psutil>=5.9.8 +psutil==5.9.8 # 数据处理 -pandas>=2.2.2 -openpyxl>=3.1.5 +pandas==2.2.2 +openpyxl==3.1.5 -# 向量化(可选,如果不需要可以注释掉以节省空间) -# sentence-transformers>=2.7.1 -# transformers>=4.43.2 -# torch>=2.4.1 # 日志和配置 -python-dotenv>=1.0.1 -structlog>=24.4.0 +python-dotenv==1.0.1 +structlog==24.4.0 # 时间处理 -python-dateutil>=2.9.0 +python-dateutil==2.9.0 # JSON处理 -ujson>=5.10.0 +ujson==5.10.0 # 异步支持 -aiohttp>=3.10.10 +aiohttp==3.10.10 # asyncio是Python内置模块,不需要安装 # Redis缓存 -redis>=5.2.0 -redis-py-cluster>=2.1.3 # 测试框架 -pytest>=8.3.3 -pytest-asyncio>=0.24.0 -pytest-cov>=6.0.0 +pytest==8.3.3 +pytest-asyncio==0.24.0 +pytest-cov==6.0.0 # 代码质量 -black>=24.8.0 -flake8>=7.1.1 -mypy>=1.11.1 -isort>=5.13.2 +black==24.8.0 +flake8==7.1.1 +mypy==1.11.1 +isort==5.13.2 # 安全 -bcrypt>=4.2.1 -pyjwt>=2.9.0 +bcrypt==4.2.1 +pyjwt==2.9.0 # 文件处理 -python-magic>=0.4.27 -pillow>=11.0.0 +python-magic==0.4.27 +pillow==11.0.0 # 网络工具 -urllib3>=2.2.3 -httpx>=0.27.2 +urllib3==2.2.3 +httpx==0.27.2 # 数据验证 -pydantic>=2.9.2 -marshmallow>=3.21.4 - -# 任务队列(可选) -# celery>=5.4.0 -# kombu>=5.4.1 - -# 文档生成(可选) -# sphinx>=7.5.0 -# sphinx-rtd-theme>=2.0.0 +pydantic==2.9.2 +marshmallow==3.23.3 \ No newline at end of file diff --git a/simple_git_push.bat b/simple_git_push.bat index 7b09b7c..2e9ac70 100644 --- a/simple_git_push.bat +++ b/simple_git_push.bat @@ -3,56 +3,56 @@ chcp 65001 >nul setlocal enabledelayedexpansion echo ======================================== -echo Git͹ +echo 简单Git推送工具 echo ======================================== echo. -:: 1. ʾGit״̬ -echo [1] Git״̬: +:: 1. 显示Git状态 +echo [1] Git状态: git status --short echo. -:: 2. ʾԶֿ̲ -echo [2] Զֿ̲: +:: 2. 显示远程仓库 +echo [2] 远程仓库: git remote -v if %errorlevel% neq 0 ( - echo : δԶֿ̲ + echo 错误: 未配置远程仓库 pause exit /b 1 ) echo. -:: 3. ʾǰ֧ -echo [3] ǰ֧: +:: 3. 显示当前分支 +echo [3] 当前分支: for /f "tokens=*" %%b in ('git branch --show-current 2^>nul') do set branch=%%b if "!branch!"=="" ( - echo : ޷ȡ֧ƣʹmain + echo 警告: 无法获取分支名称,尝试使用main set branch=main ) -echo ֧: !branch! +echo 分支: !branch! echo. -:: 4. Ƿδύĸ -echo [4] δύĸ... +:: 4. 检查是否有未提交的更改 +echo [4] 检查未提交的更改... git diff --quiet set has_uncommitted=%errorlevel% git diff --cached --quiet set has_staged=%errorlevel% if %has_uncommitted% neq 0 ( - echo δݴĸ + echo 有未暂存的更改 ) if %has_staged% neq 0 ( - echo ݴĸ + echo 有已暂存的更改 ) if %has_uncommitted% equ 0 if %has_staged% equ 0 ( - echo иύ + echo 所有更改已提交 ) echo. -:: 5. -echo [5] ʼ... -echo : git push origin !branch! +:: 5. 尝试推送 +echo [5] 开始推送... +echo 命令: git push origin !branch! echo. git push origin !branch! 2>&1 | findstr /v "^$" @@ -61,44 +61,44 @@ set push_error=!errorlevel! if !push_error! equ 0 ( echo. echo ======================================== - echo ͳɹ + echo 推送成功! echo ======================================== ) else ( echo. echo ======================================== - echo ʧܣ: !push_error! + echo 推送失败!错误码: !push_error! echo ======================================== echo. - echo β... + echo 尝试设置上游并推送... git push -u origin !branch! 2>&1 | findstr /v "^$" set push_u_error=!errorlevel! if !push_u_error! equ 0 ( echo. echo ======================================== - echo ͳɹΣ + echo 推送成功(已设置上游)! echo ======================================== ) else ( echo. echo ======================================== - echo Ȼʧ + echo 推送仍然失败 echo ======================================== echo. - echo ͽ: + echo 常见问题和解决方案: echo. - echo 1. ֤: - echo - SSHԿ: ssh -T git@github.com (GitHub) - echo - SSHԿ: ssh -T git@gitee.com (Gitee) - echo - ʹHTTPS + Personal Access Token + echo 1. 认证问题: + echo - 检查SSH密钥: ssh -T git@github.com (GitHub) + echo - 检查SSH密钥: ssh -T git@gitee.com (Gitee) + echo - 或使用HTTPS + Personal Access Token echo. - echo 2. Զַֿ̲: + echo 2. 远程仓库地址: git config --get remote.origin.url echo. - echo 3. ֧ͻ: - echo - ȡ: git pull origin !branch! --rebase - echo - ͻ: git push origin !branch! + echo 3. 分支冲突: + echo - 先拉取: git pull origin !branch! --rebase + echo - 解决冲突后推送: git push origin !branch! echo. - echo 4. ӺԶֿ̲Ȩ + echo 4. 检查网络连接和远程仓库权限 echo. ) ) diff --git a/src/web/static/js/navigation.js b/src/web/static/js/navigation.js new file mode 100644 index 0000000..cbe1b7c --- /dev/null +++ b/src/web/static/js/navigation.js @@ -0,0 +1,142 @@ +/** + * 通用导航管理脚本 + * 用于处理页面间导航和活动状态 + */ + +class NavigationManager { + constructor() { + this.currentPage = this.getCurrentPage(); + this.init(); + } + + init() { + // 设置当前页面的活动状态 + this.setActiveNavigation(); + + // 添加导航点击事件监听 + this.addNavigationListeners(); + + // 添加页面加载完成后的处理 + this.addPageLoadHandlers(); + } + + getCurrentPage() { + const path = window.location.pathname; + if (path === '/' || path === '/dashboard') return 'dashboard'; + if (path === '/alerts') return 'alerts'; + if (path === '/chat') return 'chat'; + if (path === '/chat-http') return 'chat-http'; + return 'dashboard'; + } + + setActiveNavigation() { + // 清除所有活动状态 + document.querySelectorAll('.nav-link').forEach(link => { + link.classList.remove('active'); + }); + + // 设置当前页面的活动状态 + const activeSelectors = { + 'dashboard': 'a.nav-link[href="/dashboard"]', + 'alerts': 'a.nav-link[href="/alerts"]', + 'chat': 'a.nav-link[href="/chat"]', + 'chat-http': 'a.nav-link[href="/chat-http"]' + }; + + const selector = activeSelectors[this.currentPage]; + if (selector) { + document.querySelectorAll(selector).forEach(link => { + link.classList.add('active'); + }); + } + } + + addNavigationListeners() { + // 对导航链接添加点击处理 + document.querySelectorAll('a.nav-link[href^="/"]').forEach(link => { + link.addEventListener('click', (e) => { + const href = link.getAttribute('href'); + + // 如果是当前页面,阻止默认行为 + if (href === window.location.pathname) { + e.preventDefault(); + return; + } + + // 显示加载状态 + this.showLoadingState(); + + // 正常跳转 + // 注意:这里不阻止默认行为,让浏览器正常跳转 + }); + }); + + // 对 dashboard.html 的侧边栏导航特殊处理 + document.querySelectorAll('.sidebar a.nav-link[href^="/"]').forEach(link => { + link.addEventListener('click', (e) => { + this.showLoadingState(); + }); + }); + } + + showLoadingState() { + // 显示加载提示 + const loadingHtml = ` + + `; + + document.body.insertAdjacentHTML('beforeend', loadingHtml); + } + + addPageLoadHandlers() { + // 页面加载完成后移除加载状态 + window.addEventListener('load', () => { + const loading = document.getElementById('navigation-loading'); + if (loading) { + loading.remove(); + } + }); + + // 处理浏览器前进后退 + window.addEventListener('popstate', () => { + this.currentPage = this.getCurrentPage(); + this.setActiveNavigation(); + }); + } + + // 手动导航到指定页面 + navigateTo(page) { + const urls = { + 'dashboard': '/dashboard', + 'alerts': '/alerts', + 'chat': '/chat', + 'chat-http': '/chat-http' + }; + + const url = urls[page]; + if (url && url !== window.location.pathname) { + this.showLoadingState(); + window.location.href = url; + } + } +} + +// 页面加载完成后初始化导航管理器 +document.addEventListener('DOMContentLoaded', () => { + window.navigationManager = new NavigationManager(); +}); + +// 导航函数,可以在控制台或页面中使用 +window.navigateTo = (page) => { + if (window.navigationManager) { + window.navigationManager.navigateTo(page); + } +}; \ No newline at end of file diff --git a/src/web/templates/chat.html b/src/web/templates/chat.html index e46166b..7c0e2ac 100644 --- a/src/web/templates/chat.html +++ b/src/web/templates/chat.html @@ -179,6 +179,50 @@ + + +
@@ -327,6 +371,7 @@
+ diff --git a/src/web/templates/chat_http.html b/src/web/templates/chat_http.html index c8cbf95..7b0ea8c 100644 --- a/src/web/templates/chat_http.html +++ b/src/web/templates/chat_http.html @@ -179,6 +179,50 @@ + + +
@@ -327,6 +371,7 @@
+ diff --git a/src/web/templates/dashboard.html b/src/web/templates/dashboard.html index b207884..6f76924 100644 --- a/src/web/templates/dashboard.html +++ b/src/web/templates/dashboard.html @@ -387,11 +387,11 @@ 控制面板