From e70e17efd46661558fc3be8769b81db32b5b7c67 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Wed, 20 May 2026 16:02:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E9=80=82=E9=85=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/{demand(需求).md => demand.md} | 70 +++++++++++++++++ docs/{funclist(功能清单).md => funclist.md} | 28 +++++++ docs/{tec(技术架构).md => tec.md} | 84 ++++++++++++++++++++- frontend/dist/index.html | 4 +- frontend/src/composables/useIsMobile.ts | 32 ++++++++ frontend/src/router/index.ts | 26 ++++++- frontend/src/views/ChatView.vue | 17 ++++- frontend/src/views/ProfileView.vue | 4 +- frontend/src/views/WorkspaceView.vue | 17 ++++- 9 files changed, 271 insertions(+), 11 deletions(-) rename docs/{demand(需求).md => demand.md} (73%) rename docs/{funclist(功能清单).md => funclist.md} (84%) rename docs/{tec(技术架构).md => tec.md} (85%) create mode 100644 frontend/src/composables/useIsMobile.ts diff --git a/docs/demand(需求).md b/docs/demand.md similarity index 73% rename from docs/demand(需求).md rename to docs/demand.md index 77f02776..eb592514 100644 --- a/docs/demand(需求).md +++ b/docs/demand.md @@ -266,3 +266,73 @@ 1. 打通 OA userID 查询 2. 打通 workflow=652 请假单提交 3. 打通请假单状态轮询与企微通知 + +--- + +## 14. 移动端适配需求 + +### 14.1 项目背景 + +当前系统前端布局仅针对 PC 端设计,未做移动端响应式适配。员工使用手机浏览器访问时,侧边栏、导航区域等 PC 端专属布局会占用大量屏幕空间,导致核心内容区域过窄,操作体验差。需要增加移动端自动识别与适配能力。 + +### 14.2 需求目标 + +1. 系统自动检测屏幕方向,当屏幕高度大于宽度时识别为手机端并自动适配 +2. 手机端未登录时仍先进入登录页面 +3. 登录后默认进入通用入口 Chat 页面 +4. PC 端左侧导航区域在移动端上不显示 +5. 移动端右上角增加一个按钮图标 +6. 点击右上角按钮进入个人管理设置页面 + +### 14.3 详细需求 + +#### MR-01 移动端自动识别 + +- 系统需根据 `window.innerHeight > window.innerWidth` 判定为手机竖屏状态 +- 识别需实时响应屏幕方向变化(旋转屏幕时自动切换布局模式) +- 不依赖 User-Agent 判断,纯粹依据屏幕方向 + +#### MR-02 登录流程保留 + +- 手机端未登录时,仍进入现有的登录页面(WorkspaceView 登录表单) +- 登录页面在手机端需保持正常可用,登录表单居中显示 +- 登录成功后自动跳转至 `/chat/{默认AgentID}` 页面 + +#### MR-03 登录后默认进入 Chat 页面 + +- 已登录用户访问根路径 `/` 时,自动重定向到 `/chat/16`(通用入口 Chat 页面) +- 未登录用户访问根路径 `/` 时,重定向到 `/workspace`(登录页) +- 受保护页面(如 `/chat/*`、`/profile`)未登录时重定向到登录页 + +#### MR-04 PC 端左侧导航移动端隐藏 + +- ChatView 的侧边栏(聊天记录、智能体列表等)在移动端完全隐藏 +- WorkspaceView 的左侧导航栏(个人中心、应用管理等)在移动端完全隐藏 +- 不再使用抽屉式或折叠式,直接不渲染侧边栏 DOM + +#### MR-05 移动端顶部栏与右上角按钮 + +- ChatView 在移动端显示紧凑顶部栏,包含 AI 图标+Agent 名称,右侧显示个人设置图标按钮 +- WorkspaceView 在移动端显示紧凑顶部栏,包含 AI 图标+「和信AI」标题,右侧显示个人设置图标按钮 +- 使用 `UserCircle` 图标作为右上角按钮 + +#### MR-06 点击右上角进入个人设置页面 + +- 点击移动端右上角图标按钮后,路由跳转至 `/profile`(ProfileView 个人设置页面) +- ProfileView 返回按钮在移动端返回 Chat 页面,PC 端返回 Workspace 页面 + +### 14.4 非功能需求 + +- 移动端适配不能影响 PC 端现有布局和行为 +- 屏幕方向变化需实时响应,无需刷新页面 +- 移动端登录表单需保持可用性和可读性 + +### 14.5 验收标准 + +1. 手机竖屏访问时自动进入适配布局 +2. 未登录时正确显示登录页 +3. 登录后默认跳转到 Chat 页面 +4. 移动端不显示 PC 端左侧导航/侧边栏 +5. 移动端右上角可见个人设置图标按钮 +6. 点击右上角按钮可进入个人设置页面 +7. PC 端布局与行为无任何变化 diff --git a/docs/funclist(功能清单).md b/docs/funclist.md similarity index 84% rename from docs/funclist(功能清单).md rename to docs/funclist.md index ff52554f..ae726b9d 100644 --- a/docs/funclist(功能清单).md +++ b/docs/funclist.md @@ -349,3 +349,31 @@ - 能收到企微通知 - 流程类问题仍走知识库 - 所有操作都有日志可追踪 + +--- + +## 7. 移动端适配功能清单 + +### 7.1 功能总览 + +| 功能项 | 说明 | 状态 | 优先级 | +| --- | --- | --- | --- | +| 移动端自动识别 | 屏幕高度>宽度时判定为手机端,实时响应方向变化 | 已完成 | P0 | +| 手机端登录流程 | 未登录仍进入登录页,登录表单移动端可用 | 已完成 | P0 | +| 登录后默认进 Chat | 已登录访问根路径自动跳转 `/chat/16` | 已完成 | P0 | +| 受保护页面认证守卫 | 未登录访问受保护页面重定向到登录页 | 已完成 | P0 | +| PC 侧边栏移动端隐藏 | ChatView/WorkspaceView 侧边栏在手机端不渲染 | 已完成 | P0 | +| 移动端顶部栏 | 紧凑 header 显示 AI 图标+标题 | 已完成 | P0 | +| 右上角个人设置按钮 | UserCircle 图标按钮,点击进入 /profile | 已完成 | P0 | +| ProfileView 移动端返回 | 返回按钮手机端回 Chat,PC 端回 Workspace | 已完成 | P1 | + +### 7.2 验收清单 + +- 手机竖屏访问时自动进入适配布局 +- 未登录时正确显示登录页 +- 登录后默认跳转到 Chat 页面 +- 移动端不显示 PC 端左侧导航/侧边栏 +- 移动端右上角可见个人设置图标按钮 +- 点击右上角按钮可进入个人设置页面 +- PC 端布局与行为无任何变化 +- 旋转屏幕后布局实时切换 diff --git a/docs/tec(技术架构).md b/docs/tec.md similarity index 85% rename from docs/tec(技术架构).md rename to docs/tec.md index 410dafd5..eb8f5cea 100644 --- a/docs/tec(技术架构).md +++ b/docs/tec.md @@ -646,8 +646,88 @@ OA_STATUS_SYNC_BATCH_SIZE=100 该需求技术上完全可落地,最关键的实现路径是: -1. 聊天侧做意图路由 +1.1. 聊天侧做意图路由 2. 数据侧打通 OA userID + WorkflowService + 状态查询 3. 平台侧补齐主记录表、状态日志表、轮询任务、通知模板 -现有项目已经具备聊天路由、SQL Server 查询、企微通知、最小任务调度四个核心基础能力,因此本需求适合采用“增量扩展”的方式推进,而不需要重做一套独立系统。 +现有项目已经具备聊天路由、SQL Server 查询、企微通知、最小任务调度四个核心基础能力,因此本需求适合采用"增量扩展"的方式推进,而不需要重做一套独立系统。 + +--- + +## 16. 移动端适配技术方案 + +### 16.1 设计目标 + +在现有 PC 端前端基础上,通过增量方式增加移动端自适应能力,不修改 PC 端的任何现有行为。 + +### 16.2 核心技术方案 + +#### 移动端识别:useIsMobile 组合函数 + +新增 `frontend/src/composables/useIsMobile.ts`,提供全局共享的移动端状态: + +- **判定规则**:`window.innerHeight > window.innerWidth`(竖屏 = 手机) +- **实现方式**:全局单例 `ref` + `resize` 事件监听 +- **声明周期管理**:引用计数自动挂载/卸载监听器,避免内存泄漏 +- **实时响应**:旋转屏幕时自动切换布局模式 + +```typescript +// 核心逻辑 +const isMobile = ref(false); +const update = () => { isMobile.value = window.innerHeight > window.innerWidth; }; +``` + +#### 路由守卫改造 + +修改 `frontend/src/router/index.ts`,增加认证与默认跳转逻辑: + +- 根路径 `/`:已登录 → `/chat/16`,未登录 → `/workspace` +- 受保护页面(`/chat/*`、`/profile`、`/admin`等):未登录重定向到 `/workspace` +- 公开路径白名单:`/`、`/workspace`、`/casdoor-callback`、`/reset-password` + +#### ChatView 移动端适配 + +- 侧边栏 `aside` 添加 `v-if="!isMobile"`,移动端不渲染侧边栏 DOM +- 侧边栏遮罩层添加 `&& !isMobile` 条件 +- 新增移动端顶部栏 `
`: + - 左侧:AI 图标 + Agent 名称 + - 右侧:`UserCircle` 图标按钮,点击 `router.push('/profile')` + +#### WorkspaceView 移动端适配 + +- 左侧导航 `aside` 添加 `v-if="!isMobile"`,移动端不渲染 +- 新增移动端顶部栏 `
`: + - 左侧:AI 图标 + 「和信AI」标题 + - 右侧:`User` 图标按钮,点击 `router.push('/profile')` +- 外层 `div` 包裹 grid 布局,移动端时 grid 列数为 1 + +#### ProfileView 移动端适配 + +- 引入 `useIsMobile` +- 返回按钮:手机端 → `/chat/16`,PC 端 → `/workspace` + +### 16.3 新增/修改文件清单 + +| 文件 | 变更类型 | 说明 | +| --- | --- | --- | +| `frontend/src/composables/useIsMobile.ts` | 新增 | 移动端识别组合函数 | +| `frontend/src/views/ChatView.vue` | 修改 | 移动端隐藏侧边栏,添加顶部栏+设置按钮 | +| `frontend/src/views/WorkspaceView.vue` | 修改 | 移动端隐藏左侧导航,添加顶部栏+设置按钮 | +| `frontend/src/views/ProfileView.vue` | 修改 | 移动端返回按钮差异化路由 | +| `frontend/src/router/index.ts` | 修改 | 根路径智能跳转+认证守卫 | + +### 16.4 关键设计决策 + +| 决策点 | 选择 | 理由 | +| --- | --- | --- | +| 移动端判定方式 | `innerHeight > innerWidth` | 不依赖 UA 字符串,纯屏幕方向判定,适配旋转 | +| 侧边栏处理方式 | `v-if` 不渲染 | 移动端无侧边栏需求,不渲染可减少 DOM 体积和事件监听 | +| 移动端设置入口 | 独立顶部栏按钮 | 不复用 PC 侧边栏底部按钮,交互更直观 | +| 状态共享方式 | 全局单例 ref | 多组件共享同一状态,避免各组件判定不一致 | +| 登录后默认页 | `/chat/16` | 移动端核心场景是聊天,直接进入 Chat 页面 | + +### 16.5 不影响 PC 端的保障 + +- 所有移动端适配逻辑均以 `v-if="isMobile"` 或三元表达式控制,`isMobile` 在 PC 横屏时始终为 `false` +- 路由守卫对 `/workspace` 等直接访问不做拦截,PC 端行为不变 +- PC 端侧边栏、导航栏、布局结构无任何 CSS 或 DOM 变更 diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 013c29fa..d2738eba 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -10,8 +10,8 @@ AI工作台 - - + +
diff --git a/frontend/src/composables/useIsMobile.ts b/frontend/src/composables/useIsMobile.ts new file mode 100644 index 00000000..2b746070 --- /dev/null +++ b/frontend/src/composables/useIsMobile.ts @@ -0,0 +1,32 @@ +import { ref, onMounted, onBeforeUnmount, readonly } from 'vue'; + +const isMobile = ref(false); + +let listeners = 0; + +const update = () => { + isMobile.value = window.innerHeight > window.innerWidth; +}; + +const startListening = () => { + if (listeners === 0) { + update(); + window.addEventListener('resize', update); + } + listeners++; +}; + +const stopListening = () => { + listeners--; + if (listeners <= 0) { + listeners = 0; + window.removeEventListener('resize', update); + } +}; + +export function useIsMobile() { + onMounted(() => startListening()); + onBeforeUnmount(() => stopListening()); + + return { isMobile: readonly(isMobile) }; +} diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 2613e8f1..7d2baf8b 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -14,7 +14,8 @@ import { getStoredAuthUser } from '../utils/auth'; const routes = [ { path: '/', - redirect: '/workspace' + name: 'Home', + component: WorkspaceView }, { path: '/workspace', @@ -67,14 +68,35 @@ const router = createRouter({ routes }); +const DEFAULT_CHAT_AGENT_ID = 16; + +const publicPaths = ['/', '/workspace', '/casdoor-callback', '/reset-password']; + router.beforeEach((to, _from, next) => { + const user = getStoredAuthUser(); + const isLoggedIn = !!user && user.role !== 'guest'; + if (to.path === '/admin') { - const user = getStoredAuthUser(); if (!user || user.role !== 'admin') { next('/workspace'); return; } } + + if (to.path === '/') { + if (isLoggedIn) { + next(`/chat/${DEFAULT_CHAT_AGENT_ID}`); + return; + } + next('/workspace'); + return; + } + + if (!isLoggedIn && !publicPaths.includes(to.path)) { + next('/workspace'); + return; + } + next(); }); diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 963b317f..6b303fa6 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -13,17 +13,19 @@ import { ref, onMounted, onBeforeUnmount, computed, watch, nextTick } from 'vue'; import { useI18n } from 'vue-i18n'; import { useChat } from '../composables/useChat'; -import { Send, Loader2, Plus, Copy, Edit2, RotateCw, Check, X, PanelLeftClose, PanelLeftOpen, Heart, Bell, Mail, Settings, ChevronDown, Sparkles, Database, Mic, LogOut, MessageSquareText, Globe, ExternalLink, Search, LayoutGrid } from 'lucide-vue-next'; +import { Send, Loader2, Plus, Copy, Edit2, RotateCw, Check, X, PanelLeftClose, PanelLeftOpen, Heart, Bell, Mail, Settings, ChevronDown, Sparkles, Database, Mic, LogOut, MessageSquareText, Globe, ExternalLink, Search, LayoutGrid, UserCircle, Menu } from 'lucide-vue-next'; import { marked } from 'marked'; import { useRoute, useRouter } from 'vue-router'; import { config } from '../config'; import FilePreviewModal from '../components/FilePreviewModal.vue'; import GeneralFeedbackDialog from '../components/GeneralFeedbackDialog.vue'; import { useGlobalMessageDialog } from '../composables/useGlobalMessageDialog'; +import { useIsMobile } from '../composables/useIsMobile'; import { getAuthHeaders, getStoredAuthUser, clearAuthUser } from '../utils/auth'; const { t } = useI18n(); const { showMessageDialog } = useGlobalMessageDialog(); +const { isMobile } = useIsMobile(); const currentUser = ref(getStoredAuthUser()); const showUserDropdown = ref(false); const userMenuRef = ref(null); @@ -1717,12 +1719,13 @@ const showChatRating = ref(false); +