feat:【mall 商城】文章分类(100% antd)

This commit is contained in:
YunaiV
2025-10-15 23:53:10 +08:00
parent 6c6e1d4720
commit b28a35cd79
3 changed files with 45 additions and 30 deletions

View File

@@ -1,9 +1,10 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridPropTypes } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { DICT_TYPE } from '@vben/constants'; import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { z } from '#/adapter/form';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
/** 新增/修改的表单 */ /** 新增/修改的表单 */
@@ -21,20 +22,26 @@ export function useFormSchema(): VbenFormSchema[] {
fieldName: 'name', fieldName: 'name',
label: '分类名称', label: '分类名称',
component: 'Input', component: 'Input',
componentProps: {
placeholder: '请输入分类名称',
},
rules: 'required', rules: 'required',
}, },
{ {
fieldName: 'picUrl', fieldName: 'picUrl',
label: '图标地址', label: '分类图片',
component: 'ImageUpload', component: 'ImageUpload',
componentProps: {
placeholder: '请上传分类图片',
},
}, },
{ {
fieldName: 'sort', fieldName: 'sort',
label: '序', label: '显示顺序',
component: 'InputNumber', component: 'InputNumber',
componentProps: { componentProps: {
min: 0, min: 0,
placeholder: '请输入序', placeholder: '请输入显示顺序',
}, },
rules: 'required', rules: 'required',
}, },
@@ -47,7 +54,7 @@ export function useFormSchema(): VbenFormSchema[] {
buttonStyle: 'solid', buttonStyle: 'solid',
optionType: 'button', optionType: 'button',
}, },
rules: 'required', rules: z.number().default(CommonStatusEnum.ENABLE),
}, },
]; ];
} }
@@ -61,6 +68,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Input', component: 'Input',
componentProps: { componentProps: {
placeholder: '请输入分类名称', placeholder: '请输入分类名称',
allowClear: true,
}, },
}, },
{ {
@@ -69,6 +77,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Select', component: 'Select',
componentProps: { componentProps: {
placeholder: '请选择状态', placeholder: '请选择状态',
allowClear: true,
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
}, },
}, },
@@ -85,51 +94,51 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 表格列配置 */ /** 表格列配置 */
export function useGridColumns(): VxeGridPropTypes.Columns { export function useGridColumns(): VxeTableGridOptions['columns'] {
return [ return [
{ {
title: '编号',
field: 'id', field: 'id',
width: 100, title: '编号',
minWidth: 100,
}, },
{ {
title: '分类名称',
field: 'name', field: 'name',
title: '分类名称',
minWidth: 240, minWidth: 240,
align: 'left',
fixed: 'left',
}, },
{ {
title: '分类图片',
field: 'picUrl', field: 'picUrl',
width: 80, title: '分类图片',
minWidth: 80,
cellRender: { cellRender: {
name: 'CellImage', name: 'CellImage',
}, },
}, },
{ {
title: '状态',
field: 'status', field: 'status',
width: 150, title: '状态',
minWidth: 150,
cellRender: { cellRender: {
name: 'CellDictTag', name: 'CellDict',
props: { props: { type: DICT_TYPE.COMMON_STATUS },
dictType: DICT_TYPE.COMMON_STATUS,
},
}, },
}, },
{ {
title: '排序',
field: 'sort', field: 'sort',
width: 150, title: '显示顺序',
minWidth: 150,
}, },
{ {
title: '创建时间',
field: 'createTime', field: 'createTime',
width: 180, title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
title: '操作', title: '操作',
width: 180, minWidth: 220,
fixed: 'right', fixed: 'right',
slots: { default: 'actions' }, slots: { default: 'actions' },
}, },

View File

@@ -2,7 +2,7 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallArticleCategoryApi } from '#/api/mall/promotion/articleCategory'; import type { MallArticleCategoryApi } from '#/api/mall/promotion/articleCategory';
import { Page, useVbenModal } from '@vben/common-ui'; import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
@@ -43,10 +43,8 @@ async function handleDelete(row: MallArticleCategoryApi.ArticleCategory) {
duration: 0, duration: 0,
}); });
try { try {
await deleteArticleCategory(row.id as number); await deleteArticleCategory(row.id!);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
handleRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();
@@ -74,6 +72,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@@ -85,6 +84,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<template #doc>
<DocAlert
title="【营销】内容管理"
url="https://doc.iocoder.cn/mall/promotion-content/"
/>
</template>
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="文章分类列表"> <Grid table-title="文章分类列表">
<template #toolbar-tools> <template #toolbar-tools>

View File

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