refactor: 调整页面组件位置

This commit is contained in:
2026-08-14 14:37:54 +08:00
parent 5f824531ce
commit c51e13f4b4
82 changed files with 1 additions and 1 deletions
@@ -0,0 +1,502 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type {
PromotionFeeDTO,
PromotionFeeVO,
} from '#/api/ecommerce/promotion-fee/types';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
Card,
DatePicker,
Empty,
Flex,
message,
Popconfirm,
Select,
Space,
Spin,
} from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePromotionFeeApi,
getPromotionFeePageApi,
} from '#/api/ecommerce/promotion-fee';
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
import { getAllPromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type/apis';
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
import {
SIDEBAR_LIST_SHELL_CLASS,
sidebarListRowClass,
} from '#/utils/sidebar-list-styles';
defineOptions({ name: 'PromotionFeeManagement' });
const PlusIcon = createIconifyIcon('lucide:plus');
const StoreIcon = createIconifyIcon('lucide:store');
const loading = ref(false);
const shopsLoading = ref(false);
const shops = ref<ShopVO.Info[]>([]);
/** 未选择具体店铺:undefined 表示全部店铺 */
const selectedShopId = ref<number | undefined>(undefined);
const formModalVisible = ref(false);
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
const presetShopIdForModal = ref<number | null>(null);
const feeTypeOptions = ref<{ label: string; value: number }[]>([]);
const feeTypeLoading = ref(false);
const feeTypeFetched = ref(false);
async function fetchFeeTypeOptions() {
if (feeTypeFetched.value || feeTypeLoading.value) return;
feeTypeLoading.value = true;
try {
const data = await getAllPromotionFeeTypeListApi();
feeTypeOptions.value = (data || []).map((type: { id: number; typeName: string }) => ({
label: type.typeName,
value: type.id,
}));
feeTypeFetched.value = true;
} catch {
message.error('获取推广费类型失败');
} finally {
feeTypeLoading.value = false;
}
}
const searchForm = ref({
feeTypeId: undefined as number | undefined,
feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined,
});
async function loadShops() {
shopsLoading.value = true;
try {
const data = await getShopPageApi({ page: 1, pageSize: 500, filters: {} });
shops.value = data.records ?? [];
} catch {
message.error('获取店铺列表失败');
shops.value = [];
} finally {
shopsLoading.value = false;
}
}
const selectedShopLabel = computed(() => {
if (selectedShopId.value == null) {
return '全部店铺';
}
const s = shops.value.find((x) => x.id === selectedShopId.value);
return s?.name ?? `店铺 #${selectedShopId.value}`;
});
function selectShopAll() {
selectedShopId.value = undefined;
}
function selectShop(id: number) {
selectedShopId.value = id;
}
const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
columns: [
{
type: 'seq' as const,
minWidth: 56,
title: '序号',
},
{
field: 'shopName',
title: '店铺',
minWidth: 120,
showOverflow: 'tooltip' as const,
},
{
field: 'categoryName',
title: '类目',
minWidth: 120,
showOverflow: 'tooltip' as const,
slots: { default: 'category' },
},
{
field: 'productName',
title: '商品',
minWidth: 180,
showOverflow: 'tooltip' as const,
slots: { default: 'product' },
},
{
field: 'feeTypeName',
title: '推广费类型',
minWidth: 110,
showOverflow: 'tooltip' as const,
},
{
field: 'campaignName',
title: '推广活动',
minWidth: 120,
showOverflow: 'tooltip' as const,
},
{
title: '推广费金额',
minWidth: 110,
slots: { default: 'feeAmount' },
},
{
field: 'feeDate',
title: '发生日期',
minWidth: 110,
},
{
title: '操作',
minWidth: 140,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: '100%',
border: true,
stripe: true,
rowConfig: { isHover: true },
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: selectedShopId.value,
feeTypeId: searchForm.value.feeTypeId || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined,
},
};
const data = await getPromotionFeePageApi(params);
return { items: data.records, total: data.total };
} catch {
message.error('获取推广费记录列表失败');
return { items: [], total: 0 };
} finally {
loading.value = false;
}
},
},
},
};
function refreshTable() {
gridApi?.reload();
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
showSearchForm: false,
tableTitle: '推广记录',
});
watch(selectedShopId, () => {
gridApi.reload();
});
onMounted(() => {
void loadShops();
void fetchFeeTypeOptions();
});
function resetModalPreset() {
presetShopIdForModal.value = null;
}
const handleAdd = () => {
currentPromotionFeeData.value = null;
resetModalPreset();
formModalVisible.value = true;
};
function handleAddForShop(shopId: number) {
selectShop(shopId);
currentPromotionFeeData.value = null;
presetShopIdForModal.value = shopId;
formModalVisible.value = true;
}
const handleEdit = (record: PromotionFeeVO.Info) => {
resetModalPreset();
currentPromotionFeeData.value = record;
formModalVisible.value = true;
};
async function handleDelete(id: number) {
try {
await deletePromotionFeeApi(id);
message.success('删除成功');
refreshTable();
} catch {
message.error('删除失败');
}
}
const handleFormSuccess = () => {
resetModalPreset();
refreshTable();
};
const handleFormCancel = () => {
resetModalPreset();
formModalVisible.value = false;
};
const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
function shopRowClass(id: number | 'all') {
const active =
id === 'all'
? selectedShopId.value === undefined
: selectedShopId.value === id;
const layout =
id === 'all'
? 'mb-1.5 flex w-full cursor-pointer items-center gap-2 text-left'
: 'group flex w-full cursor-pointer items-center gap-2';
return sidebarListRowClass(active, layout);
}
</script>
<template>
<Page title="推广费管理" :auto-content-height="true">
<template #description>
<div class="text-foreground/80 mt-2">
左侧选择店铺筛选右侧推广记录;未选店铺时展示全部记录。可在店铺行快捷新增该店铺推广费。
</div>
</template>
<template #extra>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="mr-2 h-4 w-4" />
新增推广费
</Button>
</Space>
</template>
<Flex gap="middle" class="h-full min-h-0">
<!-- 左:店铺(与 company-menu-manage 一致:Card + h-full + 内部滚动) -->
<Card
class="flex h-full w-[420px] shrink-0 flex-col"
:body-style="{
height: '100%',
display: 'flex',
flexDirection: 'column',
gap: '8px',
minHeight: 0,
padding: '12px',
}"
>
<template #title>
<span class="flex items-center gap-2 text-base font-semibold">
<StoreIcon class="h-4 w-4" />
店铺
</span>
</template>
<Spin :spinning="shopsLoading" class="flex min-h-0 flex-1 flex-col">
<div :class="SIDEBAR_LIST_SHELL_CLASS">
<button
type="button"
:class="shopRowClass('all')"
@click="selectShopAll"
>
<span class="min-w-0 flex-1 truncate">全部店铺</span>
<span class="shrink-0 text-xs font-normal text-muted-foreground">
全部记录
</span>
</button>
<Empty
v-if="!shopsLoading && shops.length === 0"
class="py-8"
description="暂无店铺"
/>
<div v-else class="space-y-1">
<div
v-for="shop in shops"
:key="shop.id"
:class="shopRowClass(shop.id)"
class="group w-full"
>
<button
type="button"
class="min-w-0 flex-1 truncate text-left"
@click="selectShop(shop.id)"
>
{{ shop.name }}
</button>
<Button
type="link"
size="small"
class="!h-7 shrink-0 !px-1 !text-xs font-semibold opacity-80 group-hover:opacity-100"
@click.stop="handleAddForShop(shop.id)"
>
<PlusIcon class="mr-0.5 inline h-3.5 w-3.5" />
添加
</Button>
</div>
</div>
</div>
</Spin>
</Card>
<!-- 右:推广记录 -->
<Card
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
:body-style="{
height: '100%',
minHeight: 0,
padding: 0,
display: 'flex',
flexDirection: 'column',
}"
>
<template #title>
<span class="text-base font-semibold">推广记录</span>
</template>
<template #extra>
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
<Select
v-model:value="searchForm.feeTypeId"
allow-clear
show-search
:options="feeTypeOptions"
:loading="feeTypeLoading"
placeholder="类型"
class="min-w-[120px]"
option-filter-prop="label"
@dropdown-visible-change="
(open: boolean) => open && fetchFeeTypeOptions()
"
@change="() => refreshTable()"
/>
<DatePicker
v-model:value="searchForm.feeDateStart"
value-format="YYYY-MM-DD"
placeholder="开始"
class="w-[118px]"
allow-clear
@change="() => refreshTable()"
/>
<span class="text-muted-foreground">—</span>
<DatePicker
v-model:value="searchForm.feeDateEnd"
value-format="YYYY-MM-DD"
placeholder="结束"
class="w-[118px]"
allow-clear
@change="() => refreshTable()"
/>
</Space>
</template>
<div
class="shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground"
>
当前:{{ selectedShopLabel }}
</div>
<div class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3">
<Grid :loading="loading" class="h-full min-h-0">
<template #toolbar-tools>
<span class="text-xs text-muted-foreground">
使用上方类型与日期筛选;表格在区域内滚动
</span>
</template>
<template #category="{ row }">
<span>{{ row.categoryName || '—' }}</span>
</template>
<template #feeAmount="{ row }">
<span class="font-semibold text-red-600">
{{ formatAmount(row.feeAmount) }}
</span>
</template>
<template #product="{ row }">
<div>
<div>{{ row.productName || '—' }}</div>
<div
v-if="row.productCode"
class="text-xs text-muted-foreground"
>
{{ row.productCode }}
</div>
</div>
</template>
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">编辑</Button>
<Popconfirm
title="确定要删除这条推广费记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
</Card>
</Flex>
<PromotionFeeFormModal
v-model:open="formModalVisible"
:promotion-fee-data="currentPromotionFeeData"
:preset-shop-id="presetShopIdForModal"
@success="handleFormSuccess"
@cancel="handleFormCancel"
/>
</Page>
</template>