Browse Source

feat(workbench): 优化智能工作台切换入口与浏览器降级导航

- 「智能工作台」方向改为实心主题色按钮 + 机器人图标,增加待命跳动动效,
  并支持 prefers-reduced-motion 降级
- 顶栏切换高亮在浏览器单窗口下按当前路由判断(停在 /workbench 视为智能侧)
- 浏览器环境切回自主模式时直接导航回主界面,不再依赖窗口聚焦能力
cc 2 weeks ago
parent
commit
5173fefe3f

+ 11 - 3
ai-electron/frontend/src/core/components/Application/src/AppTopBar.vue

@@ -70,12 +70,13 @@
    * 模式切换的跳转口径也收在这里(与路由守卫一致):目标模式与当前页不匹配时才跳转。
    */
   import { computed } from 'vue';
+  import { useRoute } from 'vue-router';
   import AppLogo from '@/core/components/Application/src/AppLogo.vue';
   import UserDropdown from '@/core/layouts/default/header/components/user-dropdown/index.vue';
   import { AppWorkbenchToggle, WindowControls } from '@/core/components/Application';
   import { useElectronWindow } from '@/core/hooks/desktop/useElectronWindow';
   import { useWorkbenchModeSwitch } from '@/core/logics/workbenchMode';
-  import { isSmartWindow } from '@/core/logics/appWindow';
+  import { isSmartWindow, WORKBENCH_PATH } from '@/core/logics/appWindow';
 
   const props = withDefaults(
     defineProps<{
@@ -114,8 +115,15 @@
   }>();
 
   const { setMode } = useWorkbenchModeSwitch();
-  /** 开关高亮跟随当前窗口角色:不是「偏好」,而是「我现在在哪一侧」 */
-  const toggleCurrent = computed(() => (isSmartWindow() ? 'smart' : 'traditional'));
+  const route = useRoute();
+  /**
+   * 开关高亮跟随「我现在在哪一侧」,不是「偏好」:
+   * Electron 里窗口角色由 IPC 判定(isSmartWindow);
+   * 浏览器降级为单窗口没有窗口角色,改看当前路由——停在 /workbench 就算在智能侧。
+   */
+  const toggleCurrent = computed(() =>
+    isSmartWindow() || route.path === WORKBENCH_PATH ? 'smart' : 'traditional',
+  );
   /** 与 WindowControls 用同一判定:能渲染窗口控制,才需要这条分割线 */
   const { available: windowControlsAvailable } = useElectronWindow();
 </script>

+ 82 - 58
ai-electron/frontend/src/core/components/Application/src/AppWorkbenchToggle.vue

@@ -7,11 +7,12 @@
       :aria-label="tip"
       @click="switchMode"
     >
-      <Icon
-        :icon="targetIcon"
-        :size="targetMode === 'smart' ? 15 : 14"
-        :class="{ 'jeesite-workbench-switch__star': targetMode === 'smart' }"
-      />
+      <span
+        class="jeesite-workbench-switch__icon"
+        :class="{ 'jeesite-workbench-switch__ai': targetMode === 'smart' }"
+      >
+        <Icon :icon="targetIcon" :size="targetMode === 'smart' ? 16 : 14" />
+      </span>
       <span>{{ targetLabel }}</span>
     </button>
   </Tooltip>
@@ -25,8 +26,8 @@
    *  - 主窗口(自主)里显示「智能工作台」,点击打开/聚焦独立工作台窗口;
    *  - 智能窗口(智能)里显示「自主」,点击写偏好并把主窗口拉到前台(不关闭自己)。
    *
-   * 智能工作台是重点推广的入口,所以只有「去智能」方向用主题色加粗文字 + 红色闪动星标,
-   * 不铺背景也能从顶栏的搜索/下载/设置里区分出来;「回自主」是退路,仍保持灰色文字按钮,
+   * 智能工作台是重点推广的入口,所以只有「去智能」方向用实心主题色底 + AI 机器人图标,
+   * 在顶栏搜索/下载/设置等浅色图标之间一眼就能看到;「回自主」是退路,仍保持灰色文字按钮,
    * 两个方向都强调会互相抢焦点。用途靠 Tooltip 说明,避免只看到一个模式名不知道点下去会发生什么。
    */
   import { computed } from 'vue';
@@ -52,7 +53,7 @@
   const targetMode = computed<WorkbenchMode>(() => (mode.value === 'smart' ? 'traditional' : 'smart'));
   const targetLabel = computed(() => (targetMode.value === 'smart' ? '智能工作台' : '自主'));
   const targetIcon = computed(() =>
-    targetMode.value === 'smart' ? 'i-mdi:star-four-points' : 'i-mdi:view-dashboard-outline',
+    targetMode.value === 'smart' ? 'i-mdi:robot-outline' : 'i-mdi:view-dashboard-outline',
   );
 
   /** 提示写「点下去会发生什么」,而不是重复按钮上的模式名 */
@@ -77,6 +78,7 @@
     padding: 0 8px;
     font-size: 12.5px;
     font-weight: 500;
+
     /* 显式取文字色:布局壳给顶栏设过 color:#fff,继承下来会白字白底看不见 */
     color: @text-color-secondary;
     white-space: nowrap;
@@ -90,131 +92,153 @@
 
     &:hover {
       color: @text-color-base;
-      background: rgba(0, 0, 0, 0.045);
+      background: rgb(0 0 0 / 4.5%);
     }
 
     &:active {
-      background: rgba(0, 0, 0, 0.065);
+      background: rgb(0 0 0 / 6.5%);
     }
   }
 
   /* 顶栏主题为深色(菜单配色选择深色)时反白 */
   .app-topbar--dark .@{prefix-cls} {
-    color: rgba(255, 255, 255, 0.75);
+    color: rgb(255 255 255 / 75%);
 
     &:hover {
       color: #fff;
-      background: rgba(255, 255, 255, 0.1);
+      background: rgb(255 255 255 / 10%);
     }
 
     &:active {
-      background: rgba(255, 255, 255, 0.14);
+      background: rgb(255 255 255 / 14%);
     }
   }
 
   html[data-theme='dark'] .@{prefix-cls} {
-    color: rgba(255, 255, 255, 0.72);
+    color: rgb(255 255 255 / 72%);
 
     &:hover {
       color: #fff;
-      background: rgba(255, 255, 255, 0.1);
+      background: rgb(255 255 255 / 10%);
     }
 
     &:active {
-      background: rgba(255, 255, 255, 0.14);
+      background: rgb(255 255 255 / 14%);
     }
   }
 
   /* ===== 重点入口:去「智能工作台」方向 =====
-     描边按钮:不铺底色(顶栏保持干净),靠主题色文字/描边 + 红色闪动星标拉出层次;
-     微动画只做「悬停轻抬 + 投影、按下回弹、星标加速闪烁」,不改变布局。
+     实心主题色按钮:顶栏其余动作都是浅色图标/文字,只有它铺满主题色 + 白色 AI 图标与加粗文字。
+     动效只做一件事:机器人图标无规律地轻微跳动,像在「待命」,不铺任何外发光或光晕;
+     悬停轻抬增亮,按下回弹。prefers-reduced-motion 下停用图标动画。
      放在深色/暗色规则之后,靠源码顺序覆盖它们(同特异性后者生效),
-     深色场景单独补一遍 hover/active 选择器,保证特异性不输给上面的反白规则。 */
+     深色场景单独补一遍 hover/active,保证特异性不输给上面的反白规则。 */
   .@{prefix-cls}--primary {
+    gap: 6px;
     padding: 0 12px;
     font-size: 13px;
     font-weight: 600;
-    color: @primary-color;
-    background: transparent;
-    border: 1px solid fade(@primary-color, 45%);
-    border-radius: 6px;
+    letter-spacing: 0.02em;
+    color: #fff;
+    background: @primary-color;
+    border: none;
+    border-radius: 7px;
+    box-shadow: 0 2px 8px fade(@primary-color, 34%);
     transition:
-      color 0.2s ease-out,
-      border-color 0.2s ease-out,
+      background 0.15s ease-out,
       box-shadow 0.2s ease-out,
       transform 0.2s ease-out;
 
     &:hover {
-      color: darken(@primary-color, 8%);
-      background: transparent;
-      border-color: @primary-color;
-      box-shadow: 0 2px 8px fade(@primary-color, 20%);
+      color: #fff;
+      background: darken(@primary-color, 6%);
+      box-shadow: 0 4px 14px fade(@primary-color, 42%);
       transform: translateY(-1px);
     }
 
     &:active {
-      color: darken(@primary-color, 14%);
-      background: transparent;
-      box-shadow: none;
+      color: #fff;
+      background: darken(@primary-color, 10%);
+      box-shadow: 0 1px 4px fade(@primary-color, 35%);
       transform: translateY(0) scale(0.98);
     }
 
     /* 键盘聚焦才出环,鼠标点击不出现,避免顶栏上留一圈蓝边 */
     &:focus-visible {
-      outline: 2px solid fade(@primary-color, 40%);
+      outline: 2px solid fade(@primary-color, 45%);
       outline-offset: 2px;
     }
   }
 
-  /* 红色星标 + 缓速闪烁:页面静止时也能被余光扫到;悬停时闪得更快,给出"可点"的反馈 */
-  .@{prefix-cls}__star {
-    color: @error-color;
-    transform-origin: center;
-    animation: workbench-star-twinkle 2.4s ease-in-out infinite;
+  /* 机器人图标包裹层:inline-flex 保证 transform 生效(inline 元素不接受 transform) */
+  .@{prefix-cls}__icon {
+    display: inline-flex;
+    align-items: center;
+    justify-content: center;
+    line-height: 1;
   }
 
-  .@{prefix-cls}--primary:hover .@{prefix-cls}__star {
-    animation-duration: 1.1s;
+  /* 机器人图标:慢速全方位漂浮,像在失重太空里持续漂着。
+     两个动画作用于不同属性(translate 漂移 + rotate 摇摆),周期 3.8s 与 5.4s 互质,
+     组合轨迹每次循环都不重样,不会有机械的「来回弹」感;悬停不改变节奏 */
+  .@{prefix-cls}__ai {
+    animation:
+      workbench-robot-drift 3.8s ease-in-out infinite,
+      workbench-robot-tilt 5.4s ease-in-out infinite;
   }
 
-  @keyframes workbench-star-twinkle {
+  /* 漂移路径:中心 → 右上 → 左上 → 左下 → 回中,每段 ease-in-out,转向柔和 */
+  @keyframes workbench-robot-drift {
     0%,
     100% {
-      transform: scale(1) rotate(0deg);
-      opacity: 0.9;
+      translate: 0 0;
+    }
+
+    25% {
+      translate: 2px -2.5px;
     }
 
     50% {
-      transform: scale(1.18) rotate(12deg);
-      opacity: 1;
+      translate: -1.5px -3px;
+    }
+
+    75% {
+      translate: -2.5px -0.5px;
     }
   }
 
-  .app-topbar--dark .@{prefix-cls}--primary {
-    color: lighten(@primary-color, 22%);
-    border-color: fade(lighten(@primary-color, 22%), 45%);
+  /* 摇摆:与漂移无关的慢速左右倾角,叠加出失重感 */
+  @keyframes workbench-robot-tilt {
+    0%,
+    100% {
+      rotate: 0deg;
+    }
 
-    &:hover {
-      color: lighten(@primary-color, 32%);
-      border-color: lighten(@primary-color, 32%);
+    33% {
+      rotate: 3deg;
     }
 
-    &:active {
-      color: lighten(@primary-color, 38%);
+    66% {
+      rotate: -2.5deg;
     }
   }
 
+  /* 深色顶栏 / 暗色主题:底色同样偏深,改用更亮的纯色蓝并加强外投影,避免按钮「沉」下去 */
+  .app-topbar--dark .@{prefix-cls}--primary,
   html[data-theme='dark'] .@{prefix-cls}--primary {
-    color: lighten(@primary-color, 22%);
-    border-color: fade(lighten(@primary-color, 22%), 45%);
+    color: #fff;
+    background: #4a6cff;
+    box-shadow: 0 2px 12px rgb(0 0 0 / 38%);
 
     &:hover {
-      color: lighten(@primary-color, 32%);
-      border-color: lighten(@primary-color, 32%);
+      color: #fff;
+      background: #5c7aff;
+      box-shadow: 0 4px 18px rgb(0 0 0 / 42%);
     }
 
     &:active {
-      color: lighten(@primary-color, 38%);
+      color: #fff;
+      background: #3a5cf0;
     }
   }
 </style>

+ 10 - 2
ai-electron/frontend/src/core/logics/workbenchMode.ts

@@ -1,7 +1,9 @@
 import { APP_WORKBENCH_VIEW_KEY } from '@/core/enums/cacheEnum';
+import { PageEnum } from '@/core/enums/pageEnum';
 import { useMessage } from '@/core/hooks/web/useMessage';
 import { useAppStoreWithOut, type WorkbenchMode } from '@/core/store/modules/app';
-import { WORKBENCH_PATH, focusMainWindow, isSmartWindow, openSmartWindow } from './appWindow';
+import { router } from '@/core/router';
+import { WORKBENCH_PATH, focusMainWindow, isDesktop, isSmartWindow, openSmartWindow } from './appWindow';
 
 /**
  * 智能工作台最后停留的视图(chat / model / agent / plugin)。
@@ -54,7 +56,13 @@ export function useWorkbenchModeSwitch() {
       return;
     }
 
-    // 自主:只切偏好;人还在智能窗口里时把主窗口拉到前台,方便去主窗口操作
+    // 自主:只切偏好。浏览器降级为单窗口,没有主窗口可聚焦,直接导航回主界面(与去智能方向对称)
+    if (!isDesktop()) {
+      await router.replace(PageEnum.BASE_HOME);
+      return;
+    }
+
+    // 人还在智能窗口里时把主窗口拉到前台,方便去主窗口操作(不关闭智能窗口)
     if (isSmartWindow()) {
       await focusMainWindow();
     }