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',
},
{
@@ -36,10 +42,11 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'InputNumber',
componentProps: {
min: 0,
controlsPosition: 'right',
placeholder: '请输入品牌排序',
controlsPosition: 'right',
class: '!w-full',
},
rules: z.number().min(0).default(1),
rules: 'required',
},
{
fieldName: 'status',
@@ -56,6 +63,9 @@ export function useFormSchema(): VbenFormSchema[] {
fieldName: 'description',
label: '品牌描述',
component: 'Textarea',
componentProps: {
placeholder: '请输入品牌描述',
},
},
];
}
@@ -67,6 +77,10 @@ export function useGridFormSchema(): VbenFormSchema[] {
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
placeholder: '请输入品牌名称',
allowClear: true,
},
},
{
fieldName: 'status',
@@ -74,6 +88,8 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
placeholder: '请选择品牌状态',
allowClear: true,
},
},
{
@@ -82,37 +98,37 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
clearable: true,
allowClear: true,
},
},
];
}
/** 表格列配置 */
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',
props: {
class: 'w-10 h-10',
},
},
},
{
field: 'sort',
title: '品牌排序',
minWidth: 100,
},
{
field: 'status',
title: '开启状态',
title: '品牌状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@@ -121,6 +137,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();
}
@@ -39,9 +39,9 @@ async function handleDelete(row: MallBrandApi.Brand) {
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteBrand(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
await deleteBrand(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
loadingInstance.close();
}
@@ -68,6 +68,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@@ -79,7 +80,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>