refactor(menu): improve template structure and readability

Consolidated template elements in menu.vue to enhance code clarity and maintainability. Adjusted formatting for better alignment and readability without altering existing functionality. This refactor aims to streamline the component's structure for future development.

Refs: #1303
This commit is contained in:
wizardchen
2026-05-16 11:56:44 +08:00
committed by lyingbug
parent 6c523144bf
commit a31d26153a
+90 -81
View File
@@ -6,13 +6,12 @@
<img class="logo" src="@/assets/img/weknora.png" alt=""> <img class="logo" src="@/assets/img/weknora.png" alt="">
<sup v-if="isLiteEdition" class="lite-badge">Lite</sup> <sup v-if="isLiteEdition" class="lite-badge">Lite</sup>
</div> </div>
<div class="sidebar-toggle" <div class="sidebar-toggle" @click="uiStore.toggleSidebar" :title="t('menu.collapseSidebar')">
@click="uiStore.toggleSidebar"
:title="t('menu.collapseSidebar')">
<svg viewBox="0 0 20 20" width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg viewBox="0 0 20 20" width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="1.5" y="1.5" width="17" height="17" rx="3" stroke="currentColor" stroke-width="1.2" /> <rect x="1.5" y="1.5" width="17" height="17" rx="3" stroke="currentColor" stroke-width="1.2" />
<line x1="7.5" y1="1.5" x2="7.5" y2="18.5" stroke="currentColor" stroke-width="1.2" /> <line x1="7.5" y1="1.5" x2="7.5" y2="18.5" stroke="currentColor" stroke-width="1.2" />
<line x1="4" y1="7.5" x2="4" y2="12.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" /> <line x1="4" y1="7.5" x2="4" y2="12.5" stroke="currentColor" stroke-width="1.2"
stroke-linecap="round" />
</svg> </svg>
</div> </div>
</div> </div>
@@ -21,11 +20,15 @@
<div class="menu_item sidebar-toggle-item" @click="uiStore.toggleSidebar"> <div class="menu_item sidebar-toggle-item" @click="uiStore.toggleSidebar">
<div class="menu_item-box"> <div class="menu_item-box">
<div class="menu_icon"> <div class="menu_icon">
<svg class="icon" viewBox="0 0 20 20" width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg class="icon" viewBox="0 0 20 20" width="20" height="20" fill="none"
<rect x="1.5" y="1.5" width="17" height="17" rx="3" stroke="currentColor" stroke-width="1.2" /> xmlns="http://www.w3.org/2000/svg">
<rect x="1.5" y="1.5" width="17" height="17" rx="3" stroke="currentColor"
stroke-width="1.2" />
<line x1="7.5" y1="1.5" x2="7.5" y2="18.5" stroke="currentColor" stroke-width="1.2" /> <line x1="7.5" y1="1.5" x2="7.5" y2="18.5" stroke="currentColor" stroke-width="1.2" />
<line x1="5" y1="10" x2="3" y2="8" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" /> <line x1="5" y1="10" x2="3" y2="8" stroke="currentColor" stroke-width="1.2"
<line x1="5" y1="10" x2="3" y2="12" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" /> stroke-linecap="round" />
<line x1="5" y1="10" x2="3" y2="12" stroke="currentColor" stroke-width="1.2"
stroke-linecap="round" />
</svg> </svg>
</div> </div>
</div> </div>
@@ -36,9 +39,7 @@
<TenantSelector v-if="canAccessAllTenants && !uiStore.sidebarCollapsed" /> <TenantSelector v-if="canAccessAllTenants && !uiStore.sidebarCollapsed" />
<!-- 折叠时右侧拖拽展开手柄 --> <!-- 折叠时右侧拖拽展开手柄 -->
<div v-if="uiStore.sidebarCollapsed" <div v-if="uiStore.sidebarCollapsed" class="sidebar-drag-handle" @mousedown="onDragHandleMouseDown" />
class="sidebar-drag-handle"
@mousedown="onDragHandleMouseDown" />
<!-- 上半部分:知识库和对话 --> <!-- 上半部分:知识库和对话 -->
<div class="menu_top"> <div class="menu_top">
@@ -61,30 +62,39 @@
</div> </div>
</t-tooltip> </t-tooltip>
</div> </div>
<div class="menu_box" :class="{ 'has-submenu': item.children }" v-for="(item, index) in topMenuItems" :key="index"> <div class="menu_box" :class="{ 'has-submenu': item.children }" v-for="(item, index) in topMenuItems"
:key="index">
<t-tooltip :content="item.title" placement="right" :disabled="!uiStore.sidebarCollapsed"> <t-tooltip :content="item.title" placement="right" :disabled="!uiStore.sidebarCollapsed">
<div @click="handleMenuClick(item.path)" <div @click="handleMenuClick(item.path)" @mouseenter="mouseenteMenu(item.path)"
@mouseenter="mouseenteMenu(item.path)" @mouseleave="mouseleaveMenu(item.path)" @mouseleave="mouseleaveMenu(item.path)"
:class="['menu_item', item.childrenPath && item.childrenPath == currentpath ? 'menu_item_c_active' : isMenuItemActive(item.path) ? 'menu_item_active' : '']"> :class="['menu_item', item.childrenPath && item.childrenPath == currentpath ? 'menu_item_c_active' : isMenuItemActive(item.path) ? 'menu_item_active' : '']">
<div class="menu_item-box"> <div class="menu_item-box">
<div class="menu_icon"> <div class="menu_icon">
<img class="icon" :src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'agent' ? agentIcon : item.icon == 'organization' ? organizationIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)" alt=""> <img class="icon"
:src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'agent' ? agentIcon : item.icon == 'organization' ? organizationIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)"
alt="">
</div> </div>
<template v-if="!uiStore.sidebarCollapsed"> <template v-if="!uiStore.sidebarCollapsed">
<span class="menu_title" :title="item.title">{{ item.title }}</span> <span class="menu_title" :title="item.title">{{ item.title }}</span>
<span v-if="item.path === 'organizations' && orgStore.totalPendingJoinRequestCount > 0" class="menu-pending-badge" :title="t('organization.settings.pendingJoinRequestsBadge')">{{ orgStore.totalPendingJoinRequestCount }}</span> <span v-if="item.path === 'organizations' && orgStore.totalPendingJoinRequestCount > 0"
<span v-if="item.path === 'creatChat' && batchMode" class="batch-cancel-hint" @click.stop="exitBatchMode">{{ t('batchManage.cancel') }}</span> class="menu-pending-badge"
:title="t('organization.settings.pendingJoinRequestsBadge')">{{
orgStore.totalPendingJoinRequestCount }}</span>
<span v-if="item.path === 'creatChat' && batchMode" class="batch-cancel-hint"
@click.stop="exitBatchMode">{{ t('batchManage.cancel') }}</span>
<t-icon v-else-if="item.path === 'creatChat'" name="add" class="menu-create-hint" /> <t-icon v-else-if="item.path === 'creatChat'" name="add" class="menu-create-hint" />
</template> </template>
</div> </div>
</div> </div>
</t-tooltip> </t-tooltip>
<div ref="submenuscrollContainer" @scroll="handleScroll" class="submenu" v-if="item.children && !uiStore.sidebarCollapsed"> <div ref="submenuscrollContainer" @scroll="handleScroll" class="submenu"
v-if="item.children && !uiStore.sidebarCollapsed">
<!-- 骨架屏占位 --> <!-- 骨架屏占位 -->
<template v-if="loading && groupedSessions.length === 0"> <template v-if="loading && groupedSessions.length === 0">
<div v-for="n in 5" :key="'skel-' + n" class="submenu_item_p"> <div v-for="n in 5" :key="'skel-' + n" class="submenu_item_p">
<div class="submenu_item"> <div class="submenu_item">
<t-skeleton animation="gradient" style="margin-left:18px;width:80%" :row-col="[{ width: '100%', height: '16px' }]" /> <t-skeleton animation="gradient" style="margin-left:14px;width:80%"
:row-col="[{ width: '100%', height: '14px' }]" />
</div> </div>
</div> </div>
</template> </template>
@@ -94,27 +104,21 @@
<div :class="['submenu_item', !batchMode && currentSecondpath == subitem.path ? 'submenu_item_active' : '', batchMode && batchSelectedIds.includes(subitem.id) ? 'submenu_item_selected' : '', batchMode ? 'submenu_item_batch' : '']" <div :class="['submenu_item', !batchMode && currentSecondpath == subitem.path ? 'submenu_item_active' : '', batchMode && batchSelectedIds.includes(subitem.id) ? 'submenu_item_selected' : '', batchMode ? 'submenu_item_batch' : '']"
@mouseenter="mouseenteBotDownr(subitem.id)" @mouseleave="mouseleaveBotDown" @mouseenter="mouseenteBotDownr(subitem.id)" @mouseleave="mouseleaveBotDown"
@click="batchMode ? toggleBatchSelect(subitem.id) : gotopage(subitem.path)"> @click="batchMode ? toggleBatchSelect(subitem.id) : gotopage(subitem.path)">
<t-checkbox v-if="batchMode" <t-checkbox v-if="batchMode" class="batch-checkbox"
class="batch-checkbox" :checked="batchSelectedIds.includes(subitem.id)" @click.stop
:checked="batchSelectedIds.includes(subitem.id)" @change="toggleBatchSelect(subitem.id)" />
@click.stop
@change="toggleBatchSelect(subitem.id)"
/>
<span class="submenu_title" <span class="submenu_title"
:style="batchMode ? 'margin-left:4px;max-width:170px;' : (currentSecondpath == subitem.path ? 'margin-left:18px;max-width:160px;' : 'margin-left:18px;max-width:185px;')"> :style="batchMode ? 'margin-left:4px;max-width:165px;' : (currentSecondpath == subitem.path ? 'margin-left:14px;max-width:155px;' : 'margin-left:14px;max-width:178px;')">
<t-icon v-if="subitem.is_pinned" name="pin" class="submenu_pin_icon" :title="t('menu.pinned')" /> <t-icon v-if="subitem.is_pinned" name="pin" class="submenu_pin_icon"
:title="t('menu.pinned')" />
<img v-if="subitem.im_platform && platformLogo(subitem.im_platform)" <img v-if="subitem.im_platform && platformLogo(subitem.im_platform)"
:src="platformLogo(subitem.im_platform)" :src="platformLogo(subitem.im_platform)" :alt="subitem.im_platform"
:alt="subitem.im_platform" :title="subitem.im_platform" class="submenu_source_icon" />
:title="subitem.im_platform"
class="submenu_source_icon" />
{{ subitem.title }} {{ subitem.title }}
</span> </span>
<t-dropdown v-if="!batchMode" <t-dropdown v-if="!batchMode" :options="buildSessionMenuOptions(subitem)"
:options="buildSessionMenuOptions(subitem)"
@click="handleSessionMenuClick($event, subitem.originalIndex, subitem)" @click="handleSessionMenuClick($event, subitem.originalIndex, subitem)"
placement="bottom-right" placement="bottom-right" trigger="click">
trigger="click">
<div @click.stop class="menu-more-wrap"> <div @click.stop class="menu-more-wrap">
<t-icon name="ellipsis" class="menu-more" /> <t-icon name="ellipsis" class="menu-more" />
</div> </div>
@@ -123,24 +127,16 @@
</div> </div>
</template> </template>
</div> </div>
<div v-if="batchMode && item.path === 'creatChat' && !uiStore.sidebarCollapsed" class="batch-inline-footer"> <div v-if="batchMode && item.path === 'creatChat' && !uiStore.sidebarCollapsed"
class="batch-inline-footer">
<div class="batch-footer-left"> <div class="batch-footer-left">
<t-checkbox <t-checkbox :checked="isAllBatchSelected" :indeterminate="isBatchIndeterminate"
:checked="isAllBatchSelected" @change="toggleBatchSelectAll">
:indeterminate="isBatchIndeterminate"
@change="toggleBatchSelectAll"
>
{{ t('batchManage.selectAll') }} {{ t('batchManage.selectAll') }}
</t-checkbox> </t-checkbox>
</div> </div>
<t-button <t-button size="small" theme="danger" variant="base" :disabled="batchSelectedIds.length === 0"
size="small" :loading="batchDeleting" @click="handleInlineBatchDelete">
theme="danger"
variant="base"
:disabled="batchSelectedIds.length === 0"
:loading="batchDeleting"
@click="handleInlineBatchDelete"
>
{{ t('batchManage.delete') }}{{ batchSelectedIds.length > 0 ? `(${batchDisplayCount})` : '' }} {{ t('batchManage.delete') }}{{ batchSelectedIds.length > 0 ? `(${batchDisplayCount})` : '' }}
</t-button> </t-button>
</div> </div>
@@ -911,11 +907,13 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
.menu_item { .menu_item {
justify-content: center; justify-content: center;
padding: 13px 0; padding: 10px 0;
.menu_item-box { .menu_item-box {
justify-content: center; justify-content: center;
width: auto; width: auto;
} }
.menu_icon { .menu_icon {
margin-right: 0; margin-right: 0;
} }
@@ -979,6 +977,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
width: 134px; width: 134px;
height: auto; height: auto;
} }
.lite-badge { .lite-badge {
margin-left: 2px; margin-left: 2px;
align-self: flex-start; align-self: flex-start;
@@ -1081,8 +1080,8 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
} }
.menu_p { .menu_p {
height: 56px; height: 50px;
padding: 6px 0; padding: 4px 0;
box-sizing: border-box; box-sizing: border-box;
} }
@@ -1091,10 +1090,10 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
height: 48px; height: 42px;
padding: 13px 8px 13px 16px; padding: 10px 8px 10px 14px;
box-sizing: border-box; box-sizing: border-box;
margin-bottom: 4px; margin-bottom: 3px;
border-radius: 4px; border-radius: 4px;
transition: background-color 0.2s ease; transition: background-color 0.2s ease;
@@ -1116,12 +1115,12 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
.menu_icon { .menu_icon {
display: flex; display: flex;
margin-right: 10px; margin-right: 8px;
color: var(--td-text-color-secondary); color: var(--td-text-color-secondary);
.icon { .icon {
width: 20px; width: 18px;
height: 20px; height: 18px;
overflow: hidden; overflow: hidden;
} }
} }
@@ -1133,7 +1132,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
font-size: 14px; font-size: 14px;
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
line-height: 22px; line-height: 20px;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
max-width: 120px; max-width: 120px;
@@ -1179,29 +1178,36 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
} }
@keyframes menuItemFadeIn { @keyframes menuItemFadeIn {
from { opacity: 0; transform: translateX(-4px); } from {
to { opacity: 1; transform: translateX(0); } opacity: 0;
transform: translateX(-4px);
}
to {
opacity: 1;
transform: translateX(0);
}
} }
.timeline_header { .timeline_header {
font-family: var(--app-font-family); font-family: var(--app-font-family);
font-size: 12px; font-size: 11px;
font-weight: 600; font-weight: 600;
color: var(--td-text-color-disabled); color: var(--td-text-color-disabled);
padding: 12px 18px 6px 18px; padding: 8px 14px 4px 14px;
margin-top: 8px; margin-top: 6px;
line-height: 20px; line-height: 18px;
user-select: none; user-select: none;
animation: menuItemFadeIn 0.25s ease-out; animation: menuItemFadeIn 0.25s ease-out;
&:first-child { &:first-child {
margin-top: 4px; margin-top: 2px;
} }
} }
.submenu_item_p { .submenu_item_p {
height: 44px; height: 38px;
padding: 4px 0px 4px 0px; padding: 2px 0px 2px 0px;
box-sizing: border-box; box-sizing: border-box;
animation: menuItemFadeIn 0.25s ease-out; animation: menuItemFadeIn 0.25s ease-out;
} }
@@ -1213,10 +1219,10 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
align-items: center; align-items: center;
color: var(--td-text-color-primary); color: var(--td-text-color-primary);
font-weight: 400; font-weight: 400;
line-height: 22px; line-height: 20px;
height: 36px; height: 32px;
padding-left: 0px; padding-left: 0px;
padding-right: 14px; padding-right: 10px;
position: relative; position: relative;
.submenu_title { .submenu_title {
@@ -1244,7 +1250,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
&:hover { &:hover {
background: var(--td-bg-color-container-hover); background: var(--td-bg-color-container-hover);
color: var(--td-text-color-primary); color: var(--td-text-color-primary);
border-radius: 8px; border-radius: 6px;
.menu-more { .menu-more {
color: var(--td-text-color-primary); color: var(--td-text-color-primary);
@@ -1255,7 +1261,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
} }
.submenu_title { .submenu_title {
max-width: 160px !important; max-width: 155px !important;
} }
} }
@@ -1264,7 +1270,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
.submenu_item_active { .submenu_item_active {
background: var(--td-brand-color-light) !important; background: var(--td-brand-color-light) !important;
color: var(--td-brand-color) !important; color: var(--td-brand-color) !important;
border-radius: 8px; border-radius: 6px;
.menu-more { .menu-more {
color: var(--td-brand-color) !important; color: var(--td-brand-color) !important;
@@ -1275,19 +1281,19 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
} }
.submenu_title { .submenu_title {
max-width: 160px !important; max-width: 155px !important;
} }
} }
.submenu_item_batch { .submenu_item_batch {
padding-left: 10px; padding-left: 8px;
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
} }
.submenu_item_selected { .submenu_item_selected {
background: rgba(7, 192, 95, 0.05) !important; background: rgba(7, 192, 95, 0.05) !important;
border-radius: 8px; border-radius: 6px;
} }
.batch-checkbox { .batch-checkbox {
@@ -1315,7 +1321,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 8px 14px; padding: 6px 12px;
border-top: 1px solid var(--td-component-stroke); border-top: 1px solid var(--td-component-stroke);
background: var(--td-bg-color-container); background: var(--td-bg-color-container);
@@ -1411,8 +1417,8 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
.menu-create-hint { .menu-create-hint {
margin-left: auto; margin-left: auto;
margin-right: 8px; margin-right: 6px;
font-size: 16px; font-size: 15px;
color: var(--td-brand-color); color: var(--td-brand-color);
opacity: 0.7; opacity: 0.7;
transition: opacity 0.2s ease; transition: opacity 0.2s ease;
@@ -1425,7 +1431,7 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
.menu-cmdk-hint { .menu-cmdk-hint {
margin-left: auto; margin-left: auto;
margin-right: 8px; margin-right: 6px;
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
gap: 2px; gap: 2px;
@@ -1482,14 +1488,17 @@ html[theme-mode="dark"] .aside_box .menu_icon img.icon {
filter: invert(1); filter: invert(1);
opacity: 0.55; opacity: 0.55;
} }
// Hover state: brighter icon like text // Hover state: brighter icon like text
html[theme-mode="dark"] .aside_box .menu_item:hover .menu_icon img.icon { html[theme-mode="dark"] .aside_box .menu_item:hover .menu_icon img.icon {
opacity: 0.9; opacity: 0.9;
} }
// menu_item_c_active: text is primary, so icon should match // menu_item_c_active: text is primary, so icon should match
html[theme-mode="dark"] .aside_box .menu_item_c_active .menu_icon img.icon { html[theme-mode="dark"] .aside_box .menu_item_c_active .menu_icon img.icon {
opacity: 0.9; opacity: 0.9;
} }
// Active (green) icons should not be inverted // Active (green) icons should not be inverted
html[theme-mode="dark"] .aside_box .menu_item_active .menu_icon img.icon { html[theme-mode="dark"] .aside_box .menu_item_active .menu_icon img.icon {
filter: none; filter: none;