mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:49:19 +08:00
feat: 优化店铺和公司侧边栏
This commit is contained in:
@@ -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';
|
||||
|
||||
+60
-34
@@ -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>
|
||||
|
||||
+3
-1
@@ -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>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ColPageProps } from './types';
|
||||
|
||||
import { computed, ref, useSlots } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, unref, useSlots, watch } from 'vue';
|
||||
|
||||
import {
|
||||
ResizableHandle,
|
||||
@@ -18,12 +18,34 @@ defineOptions({
|
||||
|
||||
const props = withDefaults(defineProps<ColPageProps>(), {
|
||||
leftWidth: 30,
|
||||
leftCollapsed: false,
|
||||
rightWidth: 70,
|
||||
resizable: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:leftWidth': [width: number];
|
||||
'update:leftCollapsed': [collapsed: boolean];
|
||||
}>();
|
||||
|
||||
const delegatedProps = computed(() => {
|
||||
const { leftWidth: _, ...delegated } = props;
|
||||
const {
|
||||
leftWidth: _leftWidth,
|
||||
leftMinWidth: _leftMinWidth,
|
||||
leftMaxWidth: _leftMaxWidth,
|
||||
leftCollapsedWidth: _leftCollapsedWidth,
|
||||
leftCollapsible: _leftCollapsible,
|
||||
leftCollapsed: _leftCollapsed,
|
||||
rightWidth: _rightWidth,
|
||||
rightMinWidth: _rightMinWidth,
|
||||
rightMaxWidth: _rightMaxWidth,
|
||||
rightCollapsedWidth: _rightCollapsedWidth,
|
||||
rightCollapsible: _rightCollapsible,
|
||||
resizable: _resizable,
|
||||
splitLine: _splitLine,
|
||||
splitHandle: _splitHandle,
|
||||
...delegated
|
||||
} = props;
|
||||
return delegated;
|
||||
});
|
||||
|
||||
@@ -41,6 +63,32 @@ const delegatedSlots = computed(() => {
|
||||
});
|
||||
|
||||
const leftPanelRef = ref<InstanceType<typeof ResizablePanel>>();
|
||||
/** 自身操作引起的回写,避免与外部 v-model 互相触发 */
|
||||
const suppressExternalSync = ref(false);
|
||||
|
||||
const leftDefaultSize = computed(() =>
|
||||
props.leftCollapsed
|
||||
? (props.leftCollapsedWidth ?? 0)
|
||||
: props.leftWidth,
|
||||
);
|
||||
|
||||
const rightDefaultSize = computed(() =>
|
||||
props.leftCollapsed
|
||||
? 100 - (props.leftCollapsedWidth ?? 0)
|
||||
: props.rightWidth,
|
||||
);
|
||||
|
||||
function isLeftCollapsed() {
|
||||
return !!unref(leftPanelRef.value?.isCollapsed);
|
||||
}
|
||||
|
||||
function runAsSelfApply(apply: () => void) {
|
||||
suppressExternalSync.value = true;
|
||||
apply();
|
||||
void nextTick(() => {
|
||||
suppressExternalSync.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function expandLeft() {
|
||||
leftPanelRef.value?.expand();
|
||||
@@ -50,6 +98,56 @@ function collapseLeft() {
|
||||
leftPanelRef.value?.collapse();
|
||||
}
|
||||
|
||||
function applyCollapsed(collapsed: boolean) {
|
||||
const panel = leftPanelRef.value;
|
||||
if (!panel) return;
|
||||
if (collapsed) {
|
||||
panel.collapse();
|
||||
return;
|
||||
}
|
||||
panel.expand();
|
||||
void nextTick(() => panel.resize(props.leftWidth));
|
||||
}
|
||||
|
||||
function onLeftCollapse() {
|
||||
runAsSelfApply(() => emit('update:leftCollapsed', true));
|
||||
}
|
||||
|
||||
function onLeftExpand() {
|
||||
runAsSelfApply(() => emit('update:leftCollapsed', false));
|
||||
}
|
||||
|
||||
/** 收起过程中的尺寸不写入展开宽度 */
|
||||
function onLeftResize(size: number) {
|
||||
const collapsedSize = props.leftCollapsedWidth ?? 0;
|
||||
if (isLeftCollapsed() || size <= collapsedSize + 0.51) return;
|
||||
if (Math.abs(size - props.leftWidth) < 0.15) return;
|
||||
runAsSelfApply(() => emit('update:leftWidth', size));
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.leftCollapsed,
|
||||
(collapsed) => {
|
||||
if (suppressExternalSync.value) return;
|
||||
applyCollapsed(collapsed);
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.leftWidth,
|
||||
(width) => {
|
||||
if (suppressExternalSync.value || isLeftCollapsed()) return;
|
||||
const current = leftPanelRef.value?.getSize();
|
||||
if (current == null || Math.abs(current - width) < 0.3) return;
|
||||
leftPanelRef.value?.resize(width);
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
if (!props.leftCollapsed) return;
|
||||
void nextTick(() => applyCollapsed(true));
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
expandLeft,
|
||||
collapseLeft,
|
||||
@@ -68,12 +166,16 @@ defineExpose({
|
||||
|
||||
<ResizablePanelGroup class="w-full" direction="horizontal">
|
||||
<ResizablePanel
|
||||
id="col-page-left"
|
||||
ref="leftPanelRef"
|
||||
:collapsed-size="leftCollapsedWidth"
|
||||
:collapsible="leftCollapsible"
|
||||
:default-size="leftWidth"
|
||||
:default-size="leftDefaultSize"
|
||||
:max-size="leftMaxWidth"
|
||||
:min-size="leftMinWidth"
|
||||
@collapse="onLeftCollapse"
|
||||
@expand="onLeftExpand"
|
||||
@resize="onLeftResize"
|
||||
>
|
||||
<template #default="slotProps">
|
||||
<slot
|
||||
@@ -92,9 +194,10 @@ defineExpose({
|
||||
:with-handle="splitHandle"
|
||||
/>
|
||||
<ResizablePanel
|
||||
id="col-page-right"
|
||||
:collapsed-size="rightCollapsedWidth"
|
||||
:collapsible="rightCollapsible"
|
||||
:default-size="rightWidth"
|
||||
:default-size="rightDefaultSize"
|
||||
:max-size="rightMaxWidth"
|
||||
:min-size="rightMinWidth"
|
||||
>
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { PageProps } from '../page/types';
|
||||
|
||||
export interface ColPageProps extends PageProps {
|
||||
/**
|
||||
* 左侧宽度
|
||||
* 左侧宽度(百分比 1-100)。配合 `update:leftWidth` 可做受控/持久化。
|
||||
* @default 30
|
||||
*/
|
||||
leftWidth?: number;
|
||||
@@ -10,6 +10,10 @@ export interface ColPageProps extends PageProps {
|
||||
leftMaxWidth?: number;
|
||||
leftCollapsedWidth?: number;
|
||||
leftCollapsible?: boolean;
|
||||
/**
|
||||
* 左侧是否收起。配合 `update:leftCollapsed` 可做受控/持久化。
|
||||
*/
|
||||
leftCollapsed?: boolean;
|
||||
/**
|
||||
* 右侧宽度
|
||||
* @default 70
|
||||
|
||||
Reference in New Issue
Block a user