diff --git a/backend/.env b/backend/.env index f33b2036..ed979b96 100644 --- a/backend/.env +++ b/backend/.env @@ -29,6 +29,8 @@ AUTH_LOCAL_JWT_ISSUER=hxops-backend AUTH_LOCAL_JWT_AUDIENCE=hxops-frontend AUTH_LOCAL_JWT_EXPIRES_HOURS=12 +DATABASE_URL=postgresql://postgres:@localhost:5432/hxops_db + # SiliconFlow API Configuration GJL_API_KEY=sk-umfzicwjcvwampzblqczckkqojiscyybtaljzbsvpdwdvxlu GJL_API_BASE=https://api.siliconflow.cn/v1 diff --git a/backend/run.py b/backend/run.py index 357a983c..c85db9f4 100644 --- a/backend/run.py +++ b/backend/run.py @@ -13,5 +13,6 @@ def make_shell_context(): return {'db': db, 'User': User, 'Agent': Agent} if __name__ == '__main__': - # MacOS ControlCenter uses port 5000, so we use 5002 - app.run(host='0.0.0.0', port=5002) + # MacOS ControlCenter uses port 5000, so we use 5052 + # (原5002易被Trae IDE自动端口转发劫持) + app.run(host='0.0.0.0', port=5052) diff --git a/backend/test_login_api.py b/backend/test_login_api.py index 0ad28069..036aef47 100644 --- a/backend/test_login_api.py +++ b/backend/test_login_api.py @@ -17,7 +17,7 @@ username = sys.argv[1] password = sys.argv[2] # 测试登录 API -url = "http://localhost:5002/api/user/login" +url = "http://localhost:5052/api/user/login" headers = {"Content-Type": "application/json"} data = {"username": username, "password": password} diff --git a/backend/tests/test_auth_format.py b/backend/tests/test_auth_format.py index 85e76d20..c5bf4942 100644 --- a/backend/tests/test_auth_format.py +++ b/backend/tests/test_auth_format.py @@ -6,7 +6,7 @@ import requests import json -BASE_URL = "http://127.0.0.1:5002" +BASE_URL = "http://127.0.0.1:5052" def test_auth_header_format(): """测试不同的认证头格式""" diff --git a/backend/tests/test_chat_api.py b/backend/tests/test_chat_api.py index 9bdc0929..b16f4b36 100644 --- a/backend/tests/test_chat_api.py +++ b/backend/tests/test_chat_api.py @@ -7,7 +7,7 @@ import requests import json import sys -BASE_URL = "http://127.0.0.1:5002" +BASE_URL = "http://127.0.0.1:5052" def test_login(): """测试登录 API""" diff --git a/docker-compose.yml b/docker-compose.yml index 36710f7d..7a6318f8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: - "host.docker.internal:host-gateway" # 如果需要在宿主机调试,可暴露端口;生产环境建议只在网络内暴露 ports: - - "5002:5002" + - "5052:5052" # 持久化运行时可写文件: # - backend/.env 用于保存管理员后台修改的企业微信等配置(与数据库双写, # 防止容器重建后从镜像基线读取丢失修改)。文件不存在时 docker 会自动 diff --git a/docs/project_context.md b/docs/project_context.md index 007a0ac1..566485f5 100644 --- a/docs/project_context.md +++ b/docs/project_context.md @@ -77,7 +77,7 @@ hxops/ - 运行 Flask 应用。 - **Worker**: `gevent` (异步模式)。 - **并发**: `workers = CPU * 2 + 1`, `worker_connections = 1000+`。 - - 监听 `127.0.0.1:5002`。 + - 监听 `127.0.0.1:5052`。 4. **PostgreSQL (数据层)**: - 存储用户、应用配置及审计日志。 diff --git a/docs/新人环境搭建与配置文档.md b/docs/新人环境搭建与配置文档.md index 74df69df..179b3d6a 100644 --- a/docs/新人环境搭建与配置文档.md +++ b/docs/新人环境搭建与配置文档.md @@ -129,7 +129,7 @@ python init_db.py python run.py ``` -后端本地开发端口:`5002`(`backend/run.py`)。 +后端本地开发端口:`5052`(`backend/run.py`)。 ### 5.2 前端(本地) @@ -140,7 +140,7 @@ npm run dev ``` 前端本地开发端口:`8881`(`frontend/vite.config.ts`)。 -本地开发时前端 `/api` 已代理到 `http://127.0.0.1:5002`。 +本地开发时前端 `/api` 已代理到 `http://127.0.0.1:5052`。 ### 5.3 Docker 启动(可选) @@ -151,9 +151,9 @@ docker compose up -d --build 当前对外端口映射(`docker-compose.yml`): - 前端:`8890:80` -- 后端:`5002:5002` +- 后端:`5052:5052` -注意:当前项目中后端端口存在 `5000` 与 `5002` 并存配置,若容器联调异常,优先统一端口配置。 +注意:当前项目中后端端口存在 `5000` 与 `5052` 并存配置,若容器联调异常,优先统一端口配置。 ## 6. 项目登录环境与账号配置 @@ -167,7 +167,7 @@ docker compose up -d --build | 环境 | 前端地址 | 后端地址 | 登录方式 | 备注 | | ------- | ------------------------------ | ----------------------- | ----------------------- | ---- | -| 本地 | `http://localhost:8881` | `http://localhost:5002` | 密码/企业微信(按配置) | | +| 本地 | `http://localhost:8881` | `http://localhost:5052` | 密码/企业微信(按配置) | | | 测试 | `待定` | `待定` | 密码/企业微信(按配置) | | | 生产 | `http://192.168.100.230:8881/` ;域名 `http://ai.well-trust.com:8881/` | | Casdoor 密码 / 企业微信(经 Casdoor,按配置) | | | Jenkins | `http://8.152.207.171:10240/` | | 密码 | | diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 152d1f81..ae7db409 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -542,6 +542,7 @@ "integrity": "sha512-oH72nZRfDv9lADUBSo104Aq7gPHpQZc4BTx38r9xf9pg5LfP6EzSyH2n7qFmmxRQXh7YlUXODcYsg6PuTDSxGg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -948,6 +949,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -2038,6 +2040,7 @@ "resolved": "https://mirrors.tencent.com/npm/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -2082,6 +2085,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -2440,6 +2444,7 @@ "resolved": "https://mirrors.tencent.com/npm/tailwindcss/-/tailwindcss-3.4.17.tgz", "integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==", "license": "MIT", + "peer": true, "dependencies": { "@alloc/quick-lru": "^5.2.0", "arg": "^5.0.2", @@ -2541,6 +2546,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -2599,6 +2605,7 @@ "integrity": "sha512-RHX7IvsJlEfjyA1rS7MY0UsmF91etdLAamslHR5lfuO3W/BXRdXm2tRE64ztpSPZbKqB4wAAZ0AwtF6QzfKZLA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@oxc-project/runtime": "0.114.0", "lightningcss": "^1.31.1", @@ -2684,6 +2691,7 @@ "resolved": "https://mirrors.tencent.com/npm/vue/-/vue-3.5.28.tgz", "integrity": "sha512-BRdrNfeoccSoIZeIhyPBfvWSLFP4q8J3u8Ju8Ug5vu3LdD+yTM13Sg4sKtljxozbnuMu1NB1X5HBHRYUzFocKg==", "license": "MIT", + "peer": true, "dependencies": { "@vue/compiler-dom": "3.5.28", "@vue/compiler-sfc": "3.5.28", diff --git a/frontend/src/main.ts b/frontend/src/main.ts index b298fcf5..ef28d191 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -22,6 +22,10 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise { + if (to.path === '/admin') { + const user = getStoredAuthUser(); + if (!user || user.role !== 'admin') { + next('/workspace'); + return; + } + } + next(); +}); + router.afterEach((to) => { const baseTitle = config.appTitle || 'AI工作台'; if (to.meta.title) { diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 000d4695..9b3e8f28 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -13,7 +13,7 @@ import { ref, onMounted, onBeforeUnmount, computed } from 'vue'; import { useI18n } from 'vue-i18n'; import { useChat } from '../composables/useChat'; -import { Send, Bot, Loader2, Plus, Copy, Edit2, RotateCw, Check, X, PanelLeftClose, PanelLeftOpen, Heart, Bell, Mail, Settings, Crown, ChevronDown, Sparkles, User, Database, Mic, LogOut, MessageSquareText, Globe, ExternalLink } from 'lucide-vue-next'; +import { Send, Bot, Loader2, Plus, Copy, Edit2, RotateCw, Check, X, PanelLeftClose, PanelLeftOpen, Heart, Bell, Mail, Settings, ChevronDown, Sparkles, User, Database, Mic, LogOut, MessageSquareText, Globe, ExternalLink } from 'lucide-vue-next'; import { marked } from 'marked'; import { useRoute, useRouter } from 'vue-router'; import { config } from '../config'; @@ -429,6 +429,63 @@ const { messages, isThinking, conversationId, sendMessage } = useChat(); const input = ref(''); const currentAgent = ref(null); const showGeneralFeedbackDialog = ref(false); +const showOALoginModal = ref(false); +const oaLoginForm = ref({ username: '', password: '' }); + +const openOALoginModal = () => { + oaLoginForm.value = { + username: currentUserEmployeeId.value || currentUser.value?.username || '', + password: '' + }; + showOALoginModal.value = true; +}; + +const submitOALogin = () => { + if (!oaLoginForm.value.username || !oaLoginForm.value.password) { + showMessageDialog('error', '请输入账号和密码'); + return; + } + + // 要跳转的目标 OA 页面 + const targetUrl = '/workflow/request/AddRequest.jsp?workflowid=652&isagent=0&beagenter=0&f_weaver_belongto_userid='; + + // 创建隐藏表单进行 POST 提交到 OA 登录接口 + const form = document.createElement('form'); + form.action = 'http://192.168.100.221:8888/login/VerifyLogin.jsp'; + form.method = 'POST'; + form.target = '_blank'; + + const inputLoginId = document.createElement('input'); + inputLoginId.type = 'hidden'; + inputLoginId.name = 'loginid'; + inputLoginId.value = oaLoginForm.value.username; + form.appendChild(inputLoginId); + + const inputPassword = document.createElement('input'); + inputPassword.type = 'hidden'; + inputPassword.name = 'userpassword'; + inputPassword.value = oaLoginForm.value.password; + form.appendChild(inputPassword); + + const inputGoPage = document.createElement('input'); + inputGoPage.type = 'hidden'; + inputGoPage.name = 'gopage'; + inputGoPage.value = targetUrl; + form.appendChild(inputGoPage); + + const inputLogintype = document.createElement('input'); + inputLogintype.type = 'hidden'; + inputLogintype.name = 'logintype'; + inputLogintype.value = '1'; + form.appendChild(inputLogintype); + + document.body.appendChild(form); + form.submit(); + document.body.removeChild(form); + + showOALoginModal.value = false; +}; + const activeFeedbackMessageIndex = ref(null); const browserPanelOpen = ref(false); const browserDraftUrl = ref(''); @@ -586,7 +643,7 @@ const startLocalLeaveFlow = (content: string) => { messages.value.push({ role: 'assistant', type: 'leave-form', - content: '已为你生成请假申请表,请直接在下方填写并提交。', + content: '已为你生成请假申请表,请直接在下方填写并提交。或登录OA系统直接申请', payload, local_id: formId, local_only: true, @@ -1089,7 +1146,7 @@ const showChatRating = ref(false);
- +
@@ -1196,7 +1254,14 @@ const showChatRating = ref(false); >{{ msg.content }}
-
{{ msg.content }}
+
+ + +