feat: 优化店铺和公司侧边栏

This commit is contained in:
2026-08-18 21:26:54 +08:00
parent 24ef58a217
commit 9dd4977e09
14 changed files with 414 additions and 376 deletions
@@ -0,0 +1,87 @@
import { computed, ref } from 'vue';
import { defineStore } from 'pinia';
/** 三套业务侧栏各自一份布局,互不影响 */
export type ColSidebarKind = 'company' | 'ec-shop' | 'pdd-shop';
export interface ColSidebarLayout {
/** 展开宽度(百分比) */
width: number;
collapsed: boolean;
}
const DEFAULT_LAYOUT: ColSidebarLayout = {
width: 22,
collapsed: false,
};
function createDefaultLayouts(): Record<ColSidebarKind, ColSidebarLayout> {
return {
'ec-shop': { ...DEFAULT_LAYOUT },
'pdd-shop': { ...DEFAULT_LAYOUT },
company: { ...DEFAULT_LAYOUT },
};
}
function clampWidth(width: number) {
if (!Number.isFinite(width)) return DEFAULT_LAYOUT.width;
return Math.min(50, Math.max(10, Math.round(width * 10) / 10));
}
/**
* 内部店铺 / 拼多多 / 公司侧栏的展开与宽度,localStorage 持久化。
*/
export const useColSidebarLayoutStore = defineStore(
'col-sidebar-layout',
() => {
const layouts = ref(createDefaultLayouts());
function layoutOf(kind: ColSidebarKind): ColSidebarLayout {
const current = layouts.value[kind];
if (current) return current;
const created = { ...DEFAULT_LAYOUT };
layouts.value[kind] = created;
return created;
}
function setWidth(kind: ColSidebarKind, width: number) {
layoutOf(kind).width = clampWidth(width);
}
function setCollapsed(kind: ColSidebarKind, collapsed: boolean) {
layoutOf(kind).collapsed = collapsed;
}
function $reset() {
// 本机布局偏好,登出不清
}
return {
layouts,
layoutOf,
setWidth,
setCollapsed,
$reset,
};
},
{
persist: {
pick: ['layouts'],
},
},
);
/** 给 ColPage 用的双向绑定(宽 + 收起) */
export function useColSidebarLayout(kind: ColSidebarKind) {
const store = useColSidebarLayoutStore();
const width = computed({
get: () => store.layoutOf(kind).width,
set: (value) => store.setWidth(kind, value),
});
const collapsed = computed({
get: () => store.layoutOf(kind).collapsed,
set: (value) => store.setCollapsed(kind, value),
});
return { width, collapsed };
}
@@ -1,3 +1,4 @@
export * from './auth';
export * from './col-sidebar-layout';
export * from './import-task';
export * from './realtime';
@@ -3,17 +3,19 @@ import type { PddShopVO } from '#/api/channel/pdd/shop';
import { ColPage } from '@vben/common-ui';
import { useColSidebarLayout } from '#/store/col-sidebar-layout';
import PddShopSidebarList from '#/views/channel/pdd/components/PddShopSidebarList.vue';
defineOptions({ name: 'PddShopColPage' });
/** 拼多多渠道店侧栏:展开/宽度走全局持久化,跨页面共用 */
withDefaults(
defineProps<{
/** undefined = 全部渠道店铺 */
selectedShopId?: number;
showAddAction?: boolean;
autoContentHeight?: boolean;
leftWidth?: number;
leftMinWidth?: number;
leftMaxWidth?: number;
leftCollapsedWidth?: number;
@@ -25,10 +27,9 @@ withDefaults(
{
showAddAction: false,
autoContentHeight: true,
leftWidth: 22,
leftMinWidth: 16,
leftMaxWidth: 36,
leftCollapsedWidth: 5,
leftCollapsedWidth: 3,
leftCollapsible: true,
resizable: true,
splitHandle: false,
@@ -41,39 +42,64 @@ const emit = defineEmits<{
select: [shop: PddShopVO.Info | null];
addForShop: [shopId: number];
}>();
const { width: leftWidth, collapsed: leftCollapsed } =
useColSidebarLayout('pdd-shop');
</script>
<template>
<ColPage
:auto-content-height="autoContentHeight"
:left-width="leftWidth"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div class="flex h-full min-h-0 min-w-0 flex-col overflow-hidden">
<PddShopSidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-shop-id="selectedShopId"
:show-add-action="showAddAction"
@collapse="collapse"
@expand="expand"
@update:selected-shop-id="emit('update:selectedShopId', $event)"
@select="emit('select', $event)"
@add-for-shop="emit('addForShop', $event)"
/>
</div>
</template>
<div class="pdd-shop-col-page h-full min-h-0">
<ColPage
v-model:left-width="leftWidth"
v-model:left-collapsed="leftCollapsed"
:auto-content-height="autoContentHeight"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div
class="flex h-full min-h-0 flex-col"
:class="
isCollapsed
? 'shop-sidebar-collapsed-mark min-w-[56px] overflow-visible'
: 'min-w-0 overflow-hidden'
"
>
<PddShopSidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-shop-id="selectedShopId"
:show-add-action="showAddAction"
@collapse="collapse"
@expand="expand"
@update:selected-shop-id="emit('update:selectedShopId', $event)"
@select="emit('select', $event)"
@add-for-shop="emit('addForShop', $event)"
/>
</div>
</template>
<slot />
</ColPage>
<slot />
</ColPage>
</div>
</template>
<style scoped>
/* 收起态:logo 36 + p-0.5 + ring-2 + offset-1,固定 56px */
.pdd-shop-col-page :deep([data-panel]:has(.shop-sidebar-collapsed-mark)),
.pdd-shop-col-page :deep([data-panel-group-direction] > *:first-child:has(.shop-sidebar-collapsed-mark)) {
flex: 0 0 56px !important;
width: 56px !important;
min-width: 56px !important;
max-width: 56px !important;
overflow: visible;
}
</style>
@@ -140,7 +140,7 @@ onMounted(() => {
</Tooltip>
<div
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1 pb-1 pt-2"
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1.5 pb-1 pt-2"
>
<Tooltip title="全部店铺">
<button
@@ -378,6 +378,7 @@ onMounted(() => {
width: 100%;
flex-direction: column;
align-items: center;
overflow: visible;
}
:deep(.pdd-shop-sidebar-collapsed-spin .ant-spin-container) {
@@ -385,5 +386,6 @@ onMounted(() => {
width: 100%;
flex-direction: column;
align-items: center;
overflow: visible;
}
</style>
@@ -3,15 +3,17 @@ import type { CompanyVO } from '#/api/company/types';
import { ColPage } from '@vben/common-ui';
import { useColSidebarLayout } from '#/store/col-sidebar-layout';
import CompanySidebarList from '#/views/company/components/CompanySidebarList.vue';
defineOptions({ name: 'CompanyColPage' });
/** 公司侧栏:展开/宽度走全局持久化,跨页面共用 */
withDefaults(
defineProps<{
selectedCompanyId?: number;
autoContentHeight?: boolean;
leftWidth?: number;
leftMinWidth?: number;
leftMaxWidth?: number;
leftCollapsedWidth?: number;
@@ -22,10 +24,9 @@ withDefaults(
}>(),
{
autoContentHeight: true,
leftWidth: 22,
leftMinWidth: 16,
leftMaxWidth: 36,
leftCollapsedWidth: 5,
leftCollapsedWidth: 3,
leftCollapsible: true,
resizable: true,
splitHandle: false,
@@ -37,37 +38,62 @@ const emit = defineEmits<{
'update:selectedCompanyId': [id: number | undefined];
select: [company: CompanyVO.CompanyInfoVO];
}>();
const { width: leftWidth, collapsed: leftCollapsed } =
useColSidebarLayout('company');
</script>
<template>
<ColPage
:auto-content-height="autoContentHeight"
:left-width="leftWidth"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div class="flex h-full min-h-0 min-w-0 flex-col overflow-hidden">
<CompanySidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-company-id="selectedCompanyId"
@collapse="collapse"
@expand="expand"
@update:selected-company-id="emit('update:selectedCompanyId', $event)"
@select="emit('select', $event)"
/>
</div>
</template>
<div class="company-col-page h-full min-h-0">
<ColPage
v-model:left-width="leftWidth"
v-model:left-collapsed="leftCollapsed"
:auto-content-height="autoContentHeight"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div
class="flex h-full min-h-0 flex-col"
:class="
isCollapsed
? 'company-sidebar-collapsed-mark min-w-[56px] overflow-visible'
: 'min-w-0 overflow-hidden'
"
>
<CompanySidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-company-id="selectedCompanyId"
@collapse="collapse"
@expand="expand"
@update:selected-company-id="emit('update:selectedCompanyId', $event)"
@select="emit('select', $event)"
/>
</div>
</template>
<slot />
</ColPage>
<slot />
</ColPage>
</div>
</template>
<style scoped>
/* 收起态:logo 36 + p-0.5 + ring-2 + offset-1,固定 56px */
.company-col-page :deep([data-panel]:has(.company-sidebar-collapsed-mark)),
.company-col-page :deep([data-panel-group-direction] > *:first-child:has(.company-sidebar-collapsed-mark)) {
flex: 0 0 56px !important;
width: 56px !important;
min-width: 56px !important;
max-width: 56px !important;
overflow: visible;
}
</style>
@@ -22,6 +22,7 @@ const props = withDefaults(
const BuildingIcon = createIconifyIcon('lucide:building-2');
/** 无 logo 时用名称首字;仍无则显示公司图标 */
const fallbackText = computed(() => {
const text = props.name?.trim();
return text ? text.charAt(0).toUpperCase() : '';
@@ -34,9 +35,14 @@ const fallbackText = computed(() => {
:src="logo"
:alt="name"
shape="square"
class="company-logo-avatar shrink-0 !rounded-md !bg-muted"
class="company-logo-avatar shrink-0 !rounded-md !bg-slate-200 !text-slate-700 dark:!bg-slate-600 dark:!text-slate-100"
>
<span v-if="fallbackText" class="text-xs font-medium">{{ fallbackText }}</span>
<span
v-if="fallbackText"
class="company-logo-avatar__text text-xs font-semibold"
>
{{ fallbackText }}
</span>
<BuildingIcon v-else class="h-4 w-4 text-muted-foreground" />
</Avatar>
</template>
@@ -48,8 +54,9 @@ const fallbackText = computed(() => {
justify-content: center !important;
}
.company-logo-avatar span {
.company-logo-avatar__text {
display: block;
line-height: 1;
color: inherit;
}
</style>
@@ -25,8 +25,11 @@ defineOptions({ name: 'CompanySidebarList' });
const props = withDefaults(
defineProps<{
selectedCompanyId?: number;
/** 填满父容器宽度(ColPage 左栏);默认固定 320px */
fluid?: boolean;
/** 显示标题栏收起按钮(配合 ColPage collapse) */
showCollapseAction?: boolean;
/** 窄栏模式:仅展示 logo 列表(ColPage 收起态) */
collapsed?: boolean;
}>(),
{
@@ -122,7 +125,7 @@ onMounted(() => {
</Tooltip>
<div
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1 pb-1 pt-2"
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1.5 pb-1 pt-2"
>
<Spin
:spinning="companiesLoading"
@@ -319,6 +322,7 @@ onMounted(() => {
width: 100%;
flex-direction: column;
align-items: center;
overflow: visible;
}
:deep(.company-sidebar-collapsed-spin .ant-spin-container) {
@@ -326,5 +330,6 @@ onMounted(() => {
width: 100%;
flex-direction: column;
align-items: center;
overflow: visible;
}
</style>
@@ -3,18 +3,19 @@ import type { ShopVO } from '#/api/ec/shop/types';
import { ColPage } from '@vben/common-ui';
import { useColSidebarLayout } from '#/store/col-sidebar-layout';
import ShopSidebarList from '#/views/ec/components/ShopSidebarList.vue';
defineOptions({ name: 'EcShopColPage' });
/** 内部店铺侧栏:展开/宽度走全局持久化,跨页面共用 */
withDefaults(
defineProps<{
/** undefined = 全部店铺 */
selectedShopId?: number;
showAddAction?: boolean;
autoContentHeight?: boolean;
/** 左栏默认宽度(百分比) */
leftWidth?: number;
leftMinWidth?: number;
leftMaxWidth?: number;
leftCollapsedWidth?: number;
@@ -24,12 +25,11 @@ withDefaults(
splitLine?: boolean;
}>(),
{
showAddAction: true,
showAddAction: false,
autoContentHeight: true,
leftWidth: 22,
leftMinWidth: 16,
leftMaxWidth: 36,
leftCollapsedWidth: 5,
leftCollapsedWidth: 3,
leftCollapsible: true,
resizable: true,
splitHandle: false,
@@ -42,39 +42,64 @@ const emit = defineEmits<{
select: [shop: ShopVO.Info | null];
addForShop: [shopId: number];
}>();
const { width: leftWidth, collapsed: leftCollapsed } =
useColSidebarLayout('ec-shop');
</script>
<template>
<ColPage
:auto-content-height="autoContentHeight"
:left-width="leftWidth"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div class="flex h-full min-h-0 min-w-0 flex-col overflow-hidden">
<ShopSidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-shop-id="selectedShopId"
:show-add-action="showAddAction"
@collapse="collapse"
@expand="expand"
@update:selected-shop-id="emit('update:selectedShopId', $event)"
@select="emit('select', $event)"
@add-for-shop="emit('addForShop', $event)"
/>
</div>
</template>
<div class="ec-shop-col-page h-full min-h-0">
<ColPage
v-model:left-width="leftWidth"
v-model:left-collapsed="leftCollapsed"
:auto-content-height="autoContentHeight"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div
class="flex h-full min-h-0 flex-col"
:class="
isCollapsed
? 'shop-sidebar-collapsed-mark min-w-[56px] overflow-visible'
: 'min-w-0 overflow-hidden'
"
>
<ShopSidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-shop-id="selectedShopId"
:show-add-action="showAddAction"
@collapse="collapse"
@expand="expand"
@update:selected-shop-id="emit('update:selectedShopId', $event)"
@select="emit('select', $event)"
@add-for-shop="emit('addForShop', $event)"
/>
</div>
</template>
<slot />
</ColPage>
<slot />
</ColPage>
</div>
</template>
<style scoped>
/* 收起态:logo 36 + p-0.5 + ring-2 + offset-1,固定 56px */
.ec-shop-col-page :deep([data-panel]:has(.shop-sidebar-collapsed-mark)),
.ec-shop-col-page :deep([data-panel-group-direction] > *:first-child:has(.shop-sidebar-collapsed-mark)) {
flex: 0 0 56px !important;
width: 56px !important;
min-width: 56px !important;
max-width: 56px !important;
overflow: visible;
}
</style>
@@ -35,11 +35,11 @@ const fallbackText = computed(() => {
:src="logo"
:alt="name"
shape="square"
class="shop-logo-avatar shrink-0 !rounded-md !bg-muted"
class="shop-logo-avatar shrink-0 !rounded-md !bg-slate-200 !text-slate-700 dark:!bg-slate-600 dark:!text-slate-100"
>
<span
v-if="fallbackText"
class="shop-logo-avatar__text text-xs font-medium"
class="shop-logo-avatar__text text-xs font-semibold"
>
{{ fallbackText }}
</span>
@@ -57,5 +57,6 @@ const fallbackText = computed(() => {
.shop-logo-avatar__text {
display: block;
line-height: 1;
color: inherit;
}
</style>
@@ -42,7 +42,7 @@ const props = withDefaults(
}>(),
{
selectedShopId: undefined,
showAddAction: true,
showAddAction: false,
fluid: false,
showCollapseAction: false,
collapsed: false,
@@ -59,7 +59,6 @@ const emit = defineEmits<{
}>();
const StoreIcon = createIconifyIcon('lucide:store');
const PlusIcon = createIconifyIcon('lucide:plus');
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
const PanelOpenIcon = createIconifyIcon('lucide:panel-left-open');
const ChevronUpIcon = createIconifyIcon('lucide:chevron-up');
@@ -146,15 +145,6 @@ function selectShop(shop: ShopVO.Info) {
emit('select', shop);
}
function handleAdd(shopId: number) {
const shop = shops.value.find((s) => s.id === shopId) ?? null;
emit('update:selectedShopId', shopId);
if (shop) {
emit('select', shop);
}
emit('addForShop', shopId);
}
onMounted(() => {
void loadPlatformOptions();
void searchShops();
@@ -174,7 +164,7 @@ onMounted(() => {
</Tooltip>
<div
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1 pb-1 pt-2"
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1.5 pb-1 pt-2"
>
<Tooltip title="全部店铺">
<button
@@ -344,39 +334,21 @@ onMounted(() => {
"
@click="selectShop(shop)"
>
<div class="flex items-start gap-2">
<div class="flex items-center gap-2">
<ShopLogoAvatar
:logo="shop.logo"
:name="shop.name"
:size="36"
/>
<div class="flex min-w-0 flex-1 items-start justify-between gap-2">
<div class="min-w-0 flex-1">
<div class="truncate text-sm font-medium">{{ shop.name }}</div>
<div
v-if="shop.platformCode || shop.platformName"
class="mt-1"
>
<Tag
class="m-0"
:color="getPlatformTagColor(shop.platformCode)"
>
{{
getPlatformLabel(shop.platformCode, shop.platformName)
}}
</Tag>
</div>
</div>
<Button
v-if="showAddAction"
type="link"
size="small"
class="!h-7 shrink-0 !px-1 !text-xs opacity-80 group-hover:opacity-100"
@click.stop="handleAdd(shop.id)"
<div class="flex min-w-0 flex-1 items-center justify-between gap-2">
<span class="min-w-0 truncate text-sm font-medium">{{ shop.name }}</span>
<Tag
v-if="shop.platformCode || shop.platformName"
class="m-0 shrink-0"
:color="getPlatformTagColor(shop.platformCode)"
>
<PlusIcon class="mr-0.5 inline h-3.5 w-3.5" />
添加
</Button>
{{ getPlatformLabel(shop.platformCode, shop.platformName) }}
</Tag>
</div>
</div>
</Card>
@@ -422,6 +394,7 @@ onMounted(() => {
width: 100%;
flex-direction: column;
align-items: center;
overflow: visible;
}
:deep(.shop-sidebar-collapsed-spin .ant-spin-container) {
@@ -429,5 +402,6 @@ onMounted(() => {
width: 100%;
flex-direction: column;
align-items: center;
overflow: visible;
}
</style>