mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
feat: 新增电商平台管理模块(ec_platform),店铺表platform改为外键
后端: - 新增 ec_platform 表 + 10条初始平台数据(淘宝/京东/拼多多/抖音等) - ec_shop 表 platform varchar → platform_id bigint 外键 - 新增 Platform 模块:PO/VO/DTO/Mapper/Service/Controller - 修复 ShopServiceImpl/CompanyOverviewServiceImpl/ExportServiceImpl 中 platform 字段引用 前端: - 新增平台管理页面(列表 + 表单弹窗) - 路由注册 /data/platform - 店铺管理:平台选择改为下拉,字段 platform 字符串 → platformId 外键 - 同步更新 ShopVO/ShopDTO 类型定义 数据库: - V20260422__add_ec_platform.sql 迁移文件
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import type { PlatformDTO, PlatformVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 平台管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 分页获取平台列表
|
||||
*/
|
||||
export async function getPlatformPageApi(
|
||||
params: PageQueryDTO<PlatformDTO.Filters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<PlatformVO.Info>>(
|
||||
'/ec/platform/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建平台
|
||||
*/
|
||||
export async function createPlatformApi(data: PlatformDTO.Create) {
|
||||
return requestClient.post<PlatformVO.Info>('/ec/platform/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新平台
|
||||
*/
|
||||
export async function updatePlatformApi(id: number, data: PlatformDTO.Update) {
|
||||
return requestClient.put<PlatformVO.Info>(`/ec/platform/update/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除平台
|
||||
*/
|
||||
export async function deletePlatformApi(id: number) {
|
||||
return requestClient.delete(`/ec/platform/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用的平台列表
|
||||
*/
|
||||
export async function getActivePlatformsApi() {
|
||||
return requestClient.get<PlatformVO.Info[]>('/ec/platform/active');
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,32 @@
|
||||
export namespace PlatformDTO {
|
||||
/**
|
||||
* 创建平台
|
||||
*/
|
||||
export interface Create {
|
||||
platformName: string;
|
||||
platformCode: string;
|
||||
logoUrl?: string;
|
||||
sortOrder?: number;
|
||||
isActive?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新平台
|
||||
*/
|
||||
export interface Update {
|
||||
platformName: string;
|
||||
platformCode: string;
|
||||
logoUrl?: string;
|
||||
sortOrder: number;
|
||||
isActive: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤条件
|
||||
*/
|
||||
export interface Filters {
|
||||
platformName?: string;
|
||||
platformCode?: string;
|
||||
isActive?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export namespace PlatformVO {
|
||||
/**
|
||||
* 平台信息
|
||||
*/
|
||||
export interface Info {
|
||||
id: number;
|
||||
platformName: string;
|
||||
platformCode: string;
|
||||
logoUrl?: string;
|
||||
sortOrder: number;
|
||||
isActive: number;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ export namespace ShopDTO {
|
||||
name: string;
|
||||
/** logo图片ID */
|
||||
logoImageId?: number;
|
||||
/** 平台(如淘宝、京东、拼多多) */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
}
|
||||
|
||||
/** 更新店铺参数 */
|
||||
@@ -19,16 +19,16 @@ export namespace ShopDTO {
|
||||
name: string;
|
||||
/** logo图片ID */
|
||||
logoImageId?: number;
|
||||
/** 平台(如淘宝、京东、拼多多) */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
}
|
||||
|
||||
/** 店铺过滤条件 */
|
||||
export interface Filters {
|
||||
/** 店铺名称(模糊查询) */
|
||||
name?: string;
|
||||
/** 平台 */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
}
|
||||
|
||||
/** 店铺统计查询参数 */
|
||||
|
||||
@@ -15,8 +15,10 @@ export namespace ShopVO {
|
||||
logo?: string;
|
||||
/** logo图片ID */
|
||||
logoImageId?: number;
|
||||
/** 平台(如淘宝、京东、拼多多) */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
/** 平台名称 */
|
||||
platformName?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
|
||||
@@ -19,6 +19,15 @@ const routes: RouteRecordRaw[] = [
|
||||
title: '数据导入',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'PlatformManagement',
|
||||
path: '/data/platform',
|
||||
component: () => import('#/views/ecommerce/platform/list/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:app-store',
|
||||
title: '平台管理',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -181,7 +181,8 @@ const goImportTask = () => {
|
||||
--border-color: #e2e8f0;
|
||||
--badge-bg: #eff6ff;
|
||||
--badge-border: #dbeafe;
|
||||
height: 100vh;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
@@ -513,7 +514,6 @@ html.dark .welcome-page {
|
||||
--border-color: hsl(240deg 3.7% 22%);
|
||||
--badge-bg: hsl(217deg 91% 60% / 14%);
|
||||
--badge-border: hsl(217deg 91% 60% / 28%);
|
||||
height: 100vh;
|
||||
background: linear-gradient(
|
||||
145deg,
|
||||
hsl(222.34deg 10.43% 12.27%) 0%,
|
||||
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PlatformDTO, PlatformVO } from '#/api/ecommerce/platform/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message, Select, Switch } from 'ant-design-vue';
|
||||
|
||||
import { createPlatformApi, updatePlatformApi } from '#/api/ecommerce/platform';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 内部状态
|
||||
const isEdit = ref(false);
|
||||
const currentPlatformData = ref<PlatformVO.Info | null>(null);
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
platformName: '',
|
||||
platformCode: '',
|
||||
logoUrl: '',
|
||||
sortOrder: 0,
|
||||
isActive: true,
|
||||
});
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑平台' : '添加平台'));
|
||||
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentPlatformData.value) {
|
||||
formData.value = {
|
||||
platformName: currentPlatformData.value.platformName || '',
|
||||
platformCode: currentPlatformData.value.platformCode || '',
|
||||
logoUrl: currentPlatformData.value.logoUrl || '',
|
||||
sortOrder: currentPlatformData.value.sortOrder || 0,
|
||||
isActive: currentPlatformData.value.isActive === 1,
|
||||
};
|
||||
} else {
|
||||
formData.value = {
|
||||
platformName: '',
|
||||
platformCode: '',
|
||||
logoUrl: '',
|
||||
sortOrder: 0,
|
||||
isActive: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function handleCancel() {
|
||||
formRef.value?.resetFields();
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
const submitData: PlatformDTO.Create | PlatformDTO.Update = {
|
||||
platformName: formData.value.platformName,
|
||||
platformCode: formData.value.platformCode,
|
||||
logoUrl: formData.value.logoUrl || undefined,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isActive: formData.value.isActive ? 1 : 0,
|
||||
};
|
||||
|
||||
if (isEdit.value && currentPlatformData.value?.id) {
|
||||
await updatePlatformApi(
|
||||
currentPlatformData.value.id,
|
||||
submitData as PlatformDTO.Update,
|
||||
);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPlatformApi(submitData as PlatformDTO.Create);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
handleCancel();
|
||||
} catch (error: any) {
|
||||
if (error?.errorFields) {
|
||||
return;
|
||||
}
|
||||
message.error(error?.message || '操作失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
editMode: boolean = false,
|
||||
platformData?: PlatformVO.Info,
|
||||
) {
|
||||
isEdit.value = editMode;
|
||||
currentPlatformData.value = platformData || null;
|
||||
initFormData();
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
layout="vertical"
|
||||
class="mx-4 my-4"
|
||||
>
|
||||
<Form.Item
|
||||
label="平台名称"
|
||||
name="platformName"
|
||||
:rules="[{ required: true, message: '请输入平台名称' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.platformName"
|
||||
placeholder="如:淘宝、京东"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="平台代码"
|
||||
name="platformCode"
|
||||
:rules="[{ required: true, message: '请输入平台代码' }]"
|
||||
>
|
||||
<Input
|
||||
v-model:value="formData.platformCode"
|
||||
placeholder="如:taobao、jd"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="Logo URL" name="logoUrl">
|
||||
<Input
|
||||
v-model:value="formData.logoUrl"
|
||||
placeholder="平台Logo图片地址(可选)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="排序" name="sortOrder">
|
||||
<Input
|
||||
v-model:value="formData.sortOrder"
|
||||
type="number"
|
||||
placeholder="数值越小越靠前"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="启用状态" name="isActive">
|
||||
<Switch v-model:checked="formData.isActive" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,294 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PlatformVO } from '#/api/ecommerce/platform/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Avatar, Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
createPlatformApi,
|
||||
deletePlatformApi,
|
||||
getPlatformPageApi,
|
||||
updatePlatformApi,
|
||||
} from '#/api/ecommerce/platform';
|
||||
|
||||
import PlatformFormModal from './components/PlatformFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'PlatformManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const platformFormModalRef = ref<InstanceType<typeof PlatformFormModal>>();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
platformName: '',
|
||||
platformCode: '',
|
||||
isActive: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 当前排序状态
|
||||
const currentSort = ref<null | { field: string; order: 'asc' | 'desc' }>(null);
|
||||
|
||||
// VxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
width: 80,
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'platformName',
|
||||
title: '平台名称',
|
||||
minWidth: 140,
|
||||
showOverflow: true,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'platformCode',
|
||||
title: '平台代码',
|
||||
minWidth: 120,
|
||||
showOverflow: true,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'logoUrl',
|
||||
title: 'Logo',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
slots: { default: 'logo' },
|
||||
},
|
||||
{
|
||||
field: 'sortOrder',
|
||||
title: '排序',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'isActive',
|
||||
title: '状态',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
slots: { default: 'isActive' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 160,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSize: 20,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page, form }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const filters = {
|
||||
platformName:
|
||||
form?.platformName || searchForm.value.platformName || undefined,
|
||||
platformCode:
|
||||
form?.platformCode || searchForm.value.platformCode || undefined,
|
||||
isActive: form?.isActive ?? searchForm.value.isActive,
|
||||
};
|
||||
const params: any = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters,
|
||||
};
|
||||
if (currentSort.value) {
|
||||
params.sorts = [currentSort.value];
|
||||
}
|
||||
const data = await getPlatformPageApi(params);
|
||||
return {
|
||||
items: data.records || [],
|
||||
total: data.total || 0,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取平台列表失败:', error);
|
||||
message.error('获取平台列表失败');
|
||||
return { items: [], total: 0 };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置(FormSearch 组件)
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入平台名称(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'platformName',
|
||||
label: '平台名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入平台代码(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'platformCode',
|
||||
label: '平台代码',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.isActive = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'isActive',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '平台管理',
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
// 刷新表格
|
||||
function refreshTable() {
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
// 打开新增模态框
|
||||
function handleAdd() {
|
||||
platformFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 打开编辑模态框
|
||||
function handleEdit(row: PlatformVO.Info) {
|
||||
platformFormModalRef.value?.open(true, row);
|
||||
}
|
||||
|
||||
// 删除平台
|
||||
async function handleDelete(id: number) {
|
||||
try {
|
||||
await deletePlatformApi(id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 排序变化
|
||||
function handleSortChange({
|
||||
field,
|
||||
order,
|
||||
}: {
|
||||
field?: string;
|
||||
order?: 'asc' | 'desc' | null;
|
||||
}) {
|
||||
currentSort.value = field
|
||||
? { field, order: order || 'desc' }
|
||||
: null;
|
||||
gridReloadRef.value?.();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<!-- VxeGrid 表格 -->
|
||||
<Grid :loading="loading" @sort-change="handleSortChange">
|
||||
<!-- 工具栏 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加平台
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- Logo 列 -->
|
||||
<template #logo="{ row }">
|
||||
<Avatar
|
||||
v-if="row.logoUrl"
|
||||
:src="row.logoUrl"
|
||||
:size="36"
|
||||
shape="square"
|
||||
/>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #isActive="{ row }">
|
||||
<Tag :color="row.isActive === 1 ? 'success' : 'default'" type="outline">
|
||||
{{ row.isActive === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<Button type="link" size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm title="确定删除该平台?" @confirm="handleDelete(row.id)">
|
||||
<Button type="link" danger size="small">删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 表单模态框 -->
|
||||
<PlatformFormModal ref="platformFormModalRef" @success="refreshTable" />
|
||||
</Page>
|
||||
</template>
|
||||
+24
-12
@@ -9,6 +9,7 @@ import { createIconifyIcon } from '@vben/icons';
|
||||
import { Button, Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import { createShopApi, updateShopApi } from '#/api/ecommerce/shop';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
|
||||
import { uploadFileToOss } from '#/utils/oss-upload';
|
||||
|
||||
interface Emits {
|
||||
@@ -46,17 +47,26 @@ const imageLoadError = ref(false); // 图片加载错误状态
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
name: '',
|
||||
platform: '',
|
||||
platformId: undefined as number | undefined,
|
||||
logoImageId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
];
|
||||
// 平台选项(动态加载)
|
||||
const platformOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
|
||||
// 加载平台列表
|
||||
async function fetchPlatformOptions() {
|
||||
try {
|
||||
const data = await getActivePlatformsApi();
|
||||
platformOptions.value = data.map((p: any) => ({
|
||||
label: p.platformName,
|
||||
value: p.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取平台列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑店铺' : '添加店铺'));
|
||||
@@ -75,7 +85,7 @@ function initFormData() {
|
||||
// 编辑模式
|
||||
formData.value = {
|
||||
name: currentShopData.value.name || '',
|
||||
platform: currentShopData.value.platform || '',
|
||||
platformId: currentShopData.value.platformId,
|
||||
logoImageId: undefined,
|
||||
};
|
||||
|
||||
@@ -85,7 +95,7 @@ function initFormData() {
|
||||
// 创建模式 - 如果有传入的shopData,则使用它来初始化表单
|
||||
formData.value = {
|
||||
name: currentShopData.value?.name || '',
|
||||
platform: currentShopData.value?.platform || '',
|
||||
platformId: currentShopData.value?.platformId,
|
||||
logoImageId: undefined,
|
||||
};
|
||||
originalLogoUrl.value = currentShopData.value?.logo || '';
|
||||
@@ -102,6 +112,8 @@ function resetForm() {
|
||||
newLogoFile.value = null;
|
||||
originalLogoUrl.value = '';
|
||||
imageLoadError.value = false;
|
||||
// 加载平台选项
|
||||
fetchPlatformOptions();
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
@@ -366,9 +378,9 @@ onUnmounted(() => {
|
||||
<Input v-model:value="formData.name" placeholder="请输入店铺名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Form.Item label="平台" name="platformId">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
v-model:value="formData.platformId"
|
||||
placeholder="请选择平台"
|
||||
:options="platformOptions"
|
||||
allow-clear
|
||||
|
||||
@@ -30,18 +30,13 @@ const shopFormModalRef = ref();
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
platform: undefined as string | undefined,
|
||||
platformId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表单数据(已移至ShopFormModal组件)
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
];
|
||||
// 平台选项(动态加载)
|
||||
const platformOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
@@ -65,10 +60,10 @@ const gridOptions: VxeGridProps<any> = {
|
||||
slots: { default: 'name' },
|
||||
},
|
||||
{
|
||||
field: 'platform',
|
||||
field: 'platformName',
|
||||
title: '平台',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
minWidth: 120,
|
||||
showOverflow: true,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
@@ -133,7 +128,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
platform: searchForm.value.platform,
|
||||
platformId: searchForm.value.platformId,
|
||||
},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
@@ -175,9 +170,12 @@ const formOptions = computed(() => ({
|
||||
placeholder: '请选择平台',
|
||||
options: platformOptions,
|
||||
allowClear: true,
|
||||
onChange: () => gridReloadRef.value?.(),
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.platformId = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'platform',
|
||||
fieldName: 'platformId',
|
||||
label: '平台',
|
||||
},
|
||||
],
|
||||
@@ -195,6 +193,20 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
|
||||
// 加载平台选项
|
||||
async function fetchPlatformOptions() {
|
||||
try {
|
||||
const data = await getActivePlatformsApi();
|
||||
platformOptions.value = data.map((p: any) => ({
|
||||
label: p.platformName,
|
||||
value: p.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取平台列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
|
||||
Reference in New Issue
Block a user