feat:【mall 商城】商品分类的迁移

This commit is contained in:
YunaiV
2025-10-08 10:22:27 +08:00
parent 1e9bfb419e
commit e84cd6147c
6 changed files with 69 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
@@ -22,12 +22,18 @@ export function useFormSchema(): VbenFormSchema[] {
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
placeholder: '请输入品牌名称',
},
rules: 'required',
},
{
fieldName: 'picUrl',
label: '品牌图片',
component: 'ImageUpload',
componentProps: {
placeholder: '请上传品牌图片',
},
rules: 'required',
},
{
@@ -38,7 +44,7 @@ export function useFormSchema(): VbenFormSchema[] {
min: 0,
placeholder: '请输入品牌排序',
},
rules: z.number().min(0).default(1),
rules: 'required',
},
{
fieldName: 'status',
@@ -55,6 +61,9 @@ export function useFormSchema(): VbenFormSchema[] {
fieldName: 'description',
label: '品牌描述',
component: 'Textarea',
componentProps: {
placeholder: '请输入品牌描述',
},
},
];
}
@@ -66,6 +75,10 @@ export function useGridFormSchema(): VbenFormSchema[] {
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
placeholder: '请输入品牌名称',
allowClear: true,
},
},
{
fieldName: 'status',
@@ -73,6 +86,8 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
placeholder: '请选择品牌状态',
allowClear: true,
},
},
{
@@ -88,16 +103,17 @@ export function useGridFormSchema(): VbenFormSchema[] {
}
/** 表格列配置 */
export function useGridColumns(): VxeGridPropTypes.Columns {
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'name',
title: '分类名称',
fixed: 'left',
title: '品牌名称',
minWidth: 180,
},
{
field: 'picUrl',
title: '品牌图片',
minWidth: 120,
cellRender: {
name: 'CellImage',
},
@@ -105,10 +121,12 @@ export function useGridColumns(): VxeGridPropTypes.Columns {
{
field: 'sort',
title: '品牌排序',
minWidth: 100,
},
{
field: 'status',
title: '开启状态',
title: '品牌状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@@ -117,6 +135,7 @@ export function useGridColumns(): VxeGridPropTypes.Columns {
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{

View File

@@ -19,7 +19,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -40,11 +40,9 @@ async function handleDelete(row: MallBrandApi.Brand) {
duration: 0,
});
try {
await deleteBrand(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
await deleteBrand(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
@@ -71,6 +69,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@@ -82,7 +81,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="品牌列表">
<template #toolbar-tools>
<TableAction

View File

@@ -28,7 +28,7 @@ const [Form, formApi] = useVbenForm({
class: 'w-full',
},
formItemClass: 'col-span-2',
labelWidth: 120,
labelWidth: 80,
},
layout: 'horizontal',
schema: useFormSchema(),
@@ -77,7 +77,7 @@ const [Modal, modalApi] = useVbenModal({
</script>
<template>
<Modal class="w-2/5" :title="getTitle">
<Modal :title="getTitle" class="w-1/4">
<Form class="mx-4" />
</Modal>
</template>