mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
feat(shop): 新增店铺卡片式管理页面
This commit is contained in:
@@ -0,0 +1,234 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Empty,
|
||||
Input,
|
||||
message,
|
||||
Pagination,
|
||||
Popconfirm,
|
||||
Spin,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform/apis';
|
||||
import type { PlatformVO } from '#/api/ecommerce/platform/types';
|
||||
|
||||
import ShopFormModal from '../list/components/ShopFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopManagement' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const StoreIcon = createIconifyIcon('lucide:store');
|
||||
const SearchIcon = createIconifyIcon('lucide:search');
|
||||
|
||||
const loading = ref(false);
|
||||
const shops = ref<ShopVO.Info[]>([]);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
|
||||
const searchName = ref('');
|
||||
const platformOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
const shopFormModalRef = ref();
|
||||
|
||||
async function fetchShops() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<ShopDTO.Filters> = {
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: searchName.value || undefined,
|
||||
},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shops.value = data.records ?? [];
|
||||
total.value = data.total ?? 0;
|
||||
} catch {
|
||||
message.error('获取店铺列表失败');
|
||||
shops.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
shopFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
function handleEdit(record: ShopVO.Info) {
|
||||
shopFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
async function handleDelete(record: ShopVO.Info) {
|
||||
try {
|
||||
await deleteShopApi(record.id);
|
||||
message.success('删除成功');
|
||||
void fetchShops();
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
function handleModalSuccess() {
|
||||
void fetchShops();
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
page.value = 1;
|
||||
void fetchShops();
|
||||
}
|
||||
|
||||
function handlePageChange(p: number) {
|
||||
page.value = p;
|
||||
void fetchShops();
|
||||
}
|
||||
|
||||
function handlePageSizeChange(ps: number) {
|
||||
pageSize.value = ps;
|
||||
page.value = 1;
|
||||
void fetchShops();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const platforms = await getActivePlatformsApi();
|
||||
platformOptions.value = (platforms ?? []).map((p: PlatformVO.Info) => ({
|
||||
label: p.platformName,
|
||||
value: p.id,
|
||||
}));
|
||||
} catch {
|
||||
platformOptions.value = [];
|
||||
}
|
||||
void fetchShops();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="店铺管理" :auto-content-height="true">
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="mr-1 h-4 w-4" />
|
||||
添加店铺
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<!-- 搜索栏 -->
|
||||
<Card :body-style="{ padding: '16px' }">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input
|
||||
v-model:value="searchName"
|
||||
placeholder="搜索店铺名称"
|
||||
class="!w-[260px]"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
<Button type="primary" ghost @click="handleSearch">
|
||||
<SearchIcon class="mr-1 h-4 w-4" />
|
||||
搜索
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<!-- 卡片网格 -->
|
||||
<Spin :spinning="loading">
|
||||
<Empty v-if="!loading && shops.length === 0" description="暂无店铺" class="py-16" />
|
||||
<div
|
||||
v-else
|
||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
|
||||
>
|
||||
<Card
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:body-style="{ padding: 0 }"
|
||||
class="group overflow-hidden transition-shadow hover:shadow-md"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<!-- 顶部标识区 -->
|
||||
<div class="flex items-center gap-3 bg-gradient-to-r from-blue-50 to-white px-4 py-4 dark:from-blue-950/30 dark:to-transparent">
|
||||
<div
|
||||
class="flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-white shadow-sm"
|
||||
>
|
||||
<img
|
||||
v-if="shop.logo"
|
||||
:src="shop.logo"
|
||||
:alt="shop.name"
|
||||
class="h-full w-full object-cover"
|
||||
/>
|
||||
<StoreIcon v-else class="h-6 w-6 text-blue-500" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate text-base font-bold text-slate-800 dark:text-slate-100">
|
||||
{{ shop.name }}
|
||||
</div>
|
||||
<div class="mt-0.5 text-xs text-slate-500 dark:text-slate-400">
|
||||
<Tag v-if="shop.platformName" color="blue" class="!mr-0 !text-xs">
|
||||
{{ shop.platformName }}
|
||||
</Tag>
|
||||
<span v-else class="italic">未关联平台</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 信息行 -->
|
||||
<div class="space-y-2 px-4 py-3">
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-500 dark:text-slate-400">店铺ID</span>
|
||||
<span class="font-mono text-slate-700 dark:text-slate-300">#{{ shop.id }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-500 dark:text-slate-400">创建时间</span>
|
||||
<span class="text-slate-700 dark:text-slate-300">{{ shop.createTime }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作区 -->
|
||||
<div class="flex items-center justify-end gap-2 border-t border-slate-100 px-4 py-2.5 dark:border-slate-700">
|
||||
<Button size="small" type="link" @click="handleEdit(shop)">
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定删除这个店铺?"
|
||||
@confirm="handleDelete(shop)"
|
||||
>
|
||||
<Button size="small" type="link" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div v-if="total > 0" class="mt-4 flex justify-center">
|
||||
<Pagination
|
||||
:current="page"
|
||||
:page-size="pageSize"
|
||||
:total="total"
|
||||
show-size-changer
|
||||
:page-size-options="['12', '20', '36', '60']"
|
||||
@change="handlePageChange"
|
||||
@show-size-change="
|
||||
(_current: number, size: number) => {
|
||||
handlePageSizeChange(size);
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
|
||||
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user