refactor(sidebar): streamline ListSpaceSidebar template for improved readability

Consolidated and formatted the template structure in ListSpaceSidebar.vue to enhance code clarity and maintainability. Adjusted the layout of various elements for better alignment without altering existing functionality. This refactor aims to improve the overall readability of the component for future development.

Refs: #1303
This commit is contained in:
wizardchen
2026-05-16 17:18:46 +08:00
committed by lyingbug
parent dc0671899e
commit b905f18ebc
4 changed files with 1626 additions and 1606 deletions
+28 -56
View File
@@ -1,14 +1,11 @@
<template> <template>
<div <div ref="sidebarRef" class="list-space-sidebar" :class="{ expanded: isExpanded, dragging: isDragging }"
ref="sidebarRef" :style="{ width: isDragging ? `${dragWidth}px` : undefined }">
class="list-space-sidebar"
:class="{ expanded: isExpanded, dragging: isDragging }"
:style="{ width: isDragging ? `${dragWidth}px` : undefined }"
>
<!-- Collapsed: icon strip --> <!-- Collapsed: icon strip -->
<div v-if="!isExpanded" class="icon-strip"> <div v-if="!isExpanded" class="icon-strip">
<template v-if="mode === 'resource'"> <template v-if="mode === 'resource'">
<t-tooltip v-if="!hideAll" :content="tooltipText($t('listSpaceSidebar.all'), countAll)" placement="right" :show-arrow="false"> <t-tooltip v-if="!hideAll" :content="tooltipText($t('listSpaceSidebar.all'), countAll)" placement="right"
:show-arrow="false">
<div class="icon-item-labeled" :class="{ active: selected === 'all' }" @click="select('all')"> <div class="icon-item-labeled" :class="{ active: selected === 'all' }" @click="select('all')">
<t-icon name="layers" size="16px" /> <t-icon name="layers" size="16px" />
<span class="icon-label">{{ $t('listSpaceSidebar.all') }}</span> <span class="icon-label">{{ $t('listSpaceSidebar.all') }}</span>
@@ -20,7 +17,8 @@
<span class="icon-label">{{ $t('listSpaceSidebar.mine') }}</span> <span class="icon-label">{{ $t('listSpaceSidebar.mine') }}</span>
</div> </div>
</t-tooltip> </t-tooltip>
<t-tooltip v-if="!hideShared" :content="tooltipText($t('listSpaceSidebar.sharedToMe'), countShared)" placement="right" :show-arrow="false"> <t-tooltip v-if="!hideShared" :content="tooltipText($t('listSpaceSidebar.sharedToMe'), countShared)"
placement="right" :show-arrow="false">
<div class="icon-item-labeled" :class="{ active: selected === 'shared' }" @click="select('shared')"> <div class="icon-item-labeled" :class="{ active: selected === 'shared' }" @click="select('shared')">
<t-icon name="share" size="16px" /> <t-icon name="share" size="16px" />
<span class="icon-label">{{ $t('listSpaceSidebar.sharedToMe') }}</span> <span class="icon-label">{{ $t('listSpaceSidebar.sharedToMe') }}</span>
@@ -28,7 +26,8 @@
</t-tooltip> </t-tooltip>
<template v-if="organizationsWithCount.length"> <template v-if="organizationsWithCount.length">
<div class="icon-strip-divider" /> <div class="icon-strip-divider" />
<t-tooltip v-for="org in organizationsWithCount" :key="org.id" :content="tooltipText(org.name, getOrgCount(org.id))" placement="right" :show-arrow="false"> <t-tooltip v-for="org in organizationsWithCount" :key="org.id"
:content="tooltipText(org.name, getOrgCount(org.id))" placement="right" :show-arrow="false">
<div class="icon-item-labeled" :class="{ active: selected === org.id }" @click="select(org.id)"> <div class="icon-item-labeled" :class="{ active: selected === org.id }" @click="select(org.id)">
<SpaceAvatar :name="org.name" :avatar="org.avatar" size="small" /> <SpaceAvatar :name="org.name" :avatar="org.avatar" size="small" />
<span class="icon-label">{{ truncateLabel(org.name) }}</span> <span class="icon-label">{{ truncateLabel(org.name) }}</span>
@@ -44,13 +43,15 @@
<span class="icon-label">{{ $t('listSpaceSidebar.all') }}</span> <span class="icon-label">{{ $t('listSpaceSidebar.all') }}</span>
</div> </div>
</t-tooltip> </t-tooltip>
<t-tooltip :content="tooltipText($t('organization.createdByMe'), countCreated)" placement="right" :show-arrow="false"> <t-tooltip :content="tooltipText($t('organization.createdByMe'), countCreated)" placement="right"
:show-arrow="false">
<div class="icon-item-labeled" :class="{ active: selected === 'created' }" @click="select('created')"> <div class="icon-item-labeled" :class="{ active: selected === 'created' }" @click="select('created')">
<t-icon name="usergroup-add" size="16px" /> <t-icon name="usergroup-add" size="16px" />
<span class="icon-label">{{ $t('organization.createdByMe') }}</span> <span class="icon-label">{{ $t('organization.createdByMe') }}</span>
</div> </div>
</t-tooltip> </t-tooltip>
<t-tooltip :content="tooltipText($t('organization.joinedByMe'), countJoined)" placement="right" :show-arrow="false"> <t-tooltip :content="tooltipText($t('organization.joinedByMe'), countJoined)" placement="right"
:show-arrow="false">
<div class="icon-item-labeled" :class="{ active: selected === 'joined' }" @click="select('joined')"> <div class="icon-item-labeled" :class="{ active: selected === 'joined' }" @click="select('joined')">
<t-icon name="usergroup" size="16px" /> <t-icon name="usergroup" size="16px" />
<span class="icon-label">{{ $t('organization.joinedByMe') }}</span> <span class="icon-label">{{ $t('organization.joinedByMe') }}</span>
@@ -61,12 +62,7 @@
<!-- Expanded: full nav panel --> <!-- Expanded: full nav panel -->
<nav v-else class="expanded-panel"> <nav v-else class="expanded-panel">
<div <div v-if="!hideAll" class="sidebar-item" :class="{ active: selected === 'all' }" @click="select('all')">
v-if="!hideAll"
class="sidebar-item"
:class="{ active: selected === 'all' }"
@click="select('all')"
>
<div class="item-left"> <div class="item-left">
<t-icon name="layers" class="item-icon" /> <t-icon name="layers" class="item-icon" />
<span class="item-label">{{ $t('listSpaceSidebar.all') }}</span> <span class="item-label">{{ $t('listSpaceSidebar.all') }}</span>
@@ -75,23 +71,15 @@
</div> </div>
<template v-if="mode === 'resource'"> <template v-if="mode === 'resource'">
<div <div class="sidebar-item" :class="{ active: selected === 'mine' }" @click="select('mine')">
class="sidebar-item"
:class="{ active: selected === 'mine' }"
@click="select('mine')"
>
<div class="item-left"> <div class="item-left">
<t-icon name="user" class="item-icon" /> <t-icon name="user" class="item-icon" />
<span class="item-label">{{ $t('listSpaceSidebar.mine') }}</span> <span class="item-label">{{ $t('listSpaceSidebar.mine') }}</span>
</div> </div>
<span v-if="countMine !== undefined" class="item-count">{{ countMine }}</span> <span v-if="countMine !== undefined" class="item-count">{{ countMine }}</span>
</div> </div>
<div <div v-if="!hideShared" class="sidebar-item" :class="{ active: selected === 'shared' }"
v-if="!hideShared" @click="select('shared')">
class="sidebar-item"
:class="{ active: selected === 'shared' }"
@click="select('shared')"
>
<div class="item-left"> <div class="item-left">
<t-icon name="share" class="item-icon" /> <t-icon name="share" class="item-icon" />
<span class="item-label">{{ $t('listSpaceSidebar.sharedToMe') }}</span> <span class="item-label">{{ $t('listSpaceSidebar.sharedToMe') }}</span>
@@ -102,13 +90,8 @@
<div class="sidebar-section"> <div class="sidebar-section">
<span class="section-title">{{ $t('listSpaceSidebar.spaces') }}</span> <span class="section-title">{{ $t('listSpaceSidebar.spaces') }}</span>
</div> </div>
<div <div v-for="org in organizationsWithCount" :key="org.id" class="sidebar-item org-item"
v-for="org in organizationsWithCount" :class="{ active: selected === org.id }" @click="select(org.id)">
:key="org.id"
class="sidebar-item org-item"
:class="{ active: selected === org.id }"
@click="select(org.id)"
>
<div class="item-left"> <div class="item-left">
<SpaceAvatar :name="org.name" :avatar="org.avatar" size="small" class="item-avatar" /> <SpaceAvatar :name="org.name" :avatar="org.avatar" size="small" class="item-avatar" />
<span class="item-label" :title="org.name">{{ org.name }}</span> <span class="item-label" :title="org.name">{{ org.name }}</span>
@@ -119,22 +102,14 @@
</template> </template>
<template v-else> <template v-else>
<div <div class="sidebar-item" :class="{ active: selected === 'created' }" @click="select('created')">
class="sidebar-item"
:class="{ active: selected === 'created' }"
@click="select('created')"
>
<div class="item-left"> <div class="item-left">
<t-icon name="usergroup-add" class="item-icon" /> <t-icon name="usergroup-add" class="item-icon" />
<span class="item-label">{{ $t('organization.createdByMe') }}</span> <span class="item-label">{{ $t('organization.createdByMe') }}</span>
</div> </div>
<span v-if="countCreated !== undefined" class="item-count">{{ countCreated }}</span> <span v-if="countCreated !== undefined" class="item-count">{{ countCreated }}</span>
</div> </div>
<div <div class="sidebar-item" :class="{ active: selected === 'joined' }" @click="select('joined')">
class="sidebar-item"
:class="{ active: selected === 'joined' }"
@click="select('joined')"
>
<div class="item-left"> <div class="item-left">
<t-icon name="usergroup" class="item-icon" /> <t-icon name="usergroup" class="item-icon" />
<span class="item-label">{{ $t('organization.joinedByMe') }}</span> <span class="item-label">{{ $t('organization.joinedByMe') }}</span>
@@ -145,10 +120,7 @@
</nav> </nav>
<!-- Drag handle on the right edge --> <!-- Drag handle on the right edge -->
<div <div class="resize-handle" @mousedown.prevent="onDragStart">
class="resize-handle"
@mousedown.prevent="onDragStart"
>
<div class="resize-handle-line" /> <div class="resize-handle-line" />
</div> </div>
</div> </div>
@@ -321,7 +293,7 @@ onBeforeUnmount(() => {
align-items: center; align-items: center;
gap: 4px; gap: 4px;
width: 56px; width: 56px;
padding: 16px 0 8px; padding: 12px 0 6px;
flex: 1; flex: 1;
min-height: 0; min-height: 0;
overflow-y: auto; overflow-y: auto;
@@ -335,7 +307,7 @@ onBeforeUnmount(() => {
.icon-item-labeled { .icon-item-labeled {
width: 46px; width: 46px;
padding: 6px 0 3px; padding: 5px 0 2px;
border-radius: 8px; border-radius: 8px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -389,7 +361,7 @@ onBeforeUnmount(() => {
width: 24px; width: 24px;
height: 1px; height: 1px;
background: var(--td-bg-color-secondarycontainer); background: var(--td-bg-color-secondarycontainer);
margin: 4px 0; margin: 3px 0;
flex-shrink: 0; flex-shrink: 0;
} }
@@ -398,7 +370,7 @@ onBeforeUnmount(() => {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 2px; gap: 2px;
padding: 16px 10px; padding: 12px 8px;
flex: 1; flex: 1;
min-height: 0; min-height: 0;
overflow-y: auto; overflow-y: auto;
@@ -416,7 +388,7 @@ onBeforeUnmount(() => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 8px 10px; padding: 6px 8px;
border-radius: 7px; border-radius: 7px;
color: var(--td-text-color-primary); color: var(--td-text-color-primary);
cursor: pointer; cursor: pointer;
@@ -428,7 +400,7 @@ onBeforeUnmount(() => {
.item-left { .item-left {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 8px; gap: 6px;
min-width: 0; min-width: 0;
flex: 1; flex: 1;
} }
@@ -507,7 +479,7 @@ onBeforeUnmount(() => {
} }
.sidebar-section { .sidebar-section {
padding: 10px 8px 3px; padding: 8px 6px 2px;
margin-top: 2px; margin-top: 2px;
border-top: 1px solid var(--td-component-stroke); border-top: 1px solid var(--td-component-stroke);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff