feat: 流程分类功能

pull/71/head
jason 2025-04-11 10:47:08 +08:00
parent 446cb6cbbf
commit ce431e28be
4 changed files with 405 additions and 0 deletions

View File

@ -0,0 +1,44 @@
import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request';
export namespace CategoryApi {
/** BPM 流程分类 VO */
export interface CategoryVO {
id: number;
name: string;
code: string;
status: number;
sort: number; // 分类排序
}
}
/** 查询流程分类分页 */
export async function getCategoryPage(params: PageParam) {
return requestClient.get<PageResult<CategoryApi.CategoryVO>>(
'/bpm/category/page',
{ params },
);
}
/** 查询流程分类详情 */
export async function getCategory(id: number) {
return requestClient.get<CategoryApi.CategoryVO>(
`/bpm/category/get?id=${id}`,
);
}
/** 新增流程分类 */
export async function createCategory(data: CategoryApi.CategoryVO) {
return requestClient.post('/bpm/category/create', data);
}
/** 修改流程分类 */
export async function updateCategory(data: CategoryApi.CategoryVO) {
return requestClient.put('/bpm/category/update', data);
}
/** 删除流程分类 */
export async function deleteCategory(id: number) {
return requestClient.delete(`/bpm/category/delete?id=${id}`);
}

View File

@ -0,0 +1,163 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CategoryApi } from '#/api/bpm/category/index';
import { z } from '#/adapter/form';
import { CommonStatusEnum } from '#/utils/constants';
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'name',
label: '分类名',
component: 'Input',
componentProps: {
placeholder: '请输入分类名',
},
rules: 'required',
},
{
label: '分类标志',
fieldName: 'code',
component: 'Input',
componentProps: {
placeholder: '请输入分类标志',
},
rules: 'required',
},
{
fieldName: 'description',
label: '分类描述',
component: 'Textarea',
componentProps: {
placeholder: '请输入分类描述',
},
},
{
fieldName: 'status',
label: '分类状态',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
buttonStyle: 'solid',
optionType: 'button',
},
rules: z.number().default(CommonStatusEnum.ENABLE),
},
{
fieldName: 'sort',
label: '分类排序',
component: 'InputNumber',
componentProps: {
min: 0,
class: 'w-full',
controlsPosition: 'right',
placeholder: '请输入分类排序',
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '分类名',
component: 'Input',
componentProps: {
placeholder: '请输入分类名',
allowClear: true,
},
},
// TODO 分类标志
{
fieldName: 'status',
label: '分类状态',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
placeholder: '请选择分类状态',
allowClear: true,
},
},
];
}
/** 列表的字段 */
export function useGridColumns<T = CategoryApi.CategoryVO>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '分类编号',
minWidth: 100,
},
{
field: 'name',
title: '分类名',
minWidth: 200,
},
{
field: 'code',
title: '分类标志',
minWidth: 200,
},
{
field: 'description',
title: '分类描述',
minWidth: 200,
},
{
field: 'status',
title: '分类状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
},
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'operation',
title: '操作',
minWidth: 180,
align: 'center',
fixed: 'right',
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '流程分类',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
// show: hasAccessByCodes(['bpm:category:update']), TODO 权限
},
{
code: 'delete',
// show: hasAccessByCodes(['bpm:category:delete']),
},
],
},
},
];
}

View File

@ -0,0 +1,117 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { CategoryApi } from '#/api/bpm/category/index';
import { Page, useVbenModal } from '@vben/common-ui';
import { Plus } from '@vben/icons';
import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteCategory, getCategoryPage } from '#/api/bpm/category/index';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(onActionClick),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getCategoryPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<CategoryApi.CategoryVO>,
});
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<CategoryApi.CategoryVO>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
}
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 创建流程分类 */
function onCreate() {
formModalApi.setData(null).open();
}
/** 编辑流程分类 */
function onEdit(row: CategoryApi.CategoryVO) {
formModalApi.setData(row).open();
}
/** 删除流程分类 */
async function onDelete(row: CategoryApi.CategoryVO) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.code]),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteCategory(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.code]),
key: 'action_process_msg',
});
onRefresh();
} catch {
hideLoading();
}
}
</script>
<template>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<Button type="primary" @click="onCreate">
<Plus class="size-5" />
{{ $t('ui.actionTitle.create', ['流程分类']) }}
</Button>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,81 @@
<script lang="ts" setup>
import type { CategoryApi } from '#/api/bpm/category/index';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
createCategory,
getCategory,
updateCategory,
} from '#/api/bpm/category/index';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<CategoryApi.CategoryVO>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['流程分类'])
: $t('ui.actionTitle.create', ['流程分类']);
});
const [Form, formApi] = useVbenForm({
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data = (await formApi.getValues()) as CategoryApi.CategoryVO;
try {
await (formData.value?.id ? updateCategory(data) : createCategory(data));
//
await modalApi.close();
emit('success');
message.success({
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
});
} finally {
modalApi.lock(false);
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
return;
}
//
const data = modalApi.getData<CategoryApi.CategoryVO>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getCategory(data.id as number);
// values
await formApi.setValues(formData.value);
} finally {
modalApi.lock(false);
}
},
});
</script>
<template>
<Modal :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>