feat: 完善流程表达式管理功能
							parent
							
								
									211c403940
								
							
						
					
					
						commit
						abe1c32b3e
					
				|  | @ -0,0 +1,53 @@ | ||||||
|  | import type { PageParam, PageResult } from '@vben/request'; | ||||||
|  | 
 | ||||||
|  | import { requestClient } from '#/api/request'; | ||||||
|  | 
 | ||||||
|  | export namespace BpmProcessExpressionApi { | ||||||
|  |   /** BPM 流程表达式 VO */ | ||||||
|  |   export interface ProcessExpressionVO { | ||||||
|  |     id: number; // 编号
 | ||||||
|  |     name: string; // 表达式名字
 | ||||||
|  |     status: number; // 表达式状态
 | ||||||
|  |     expression: string; // 表达式
 | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 查询流程表达式分页 */ | ||||||
|  | export async function getProcessExpressionPage(params: PageParam) { | ||||||
|  |   return requestClient.get< | ||||||
|  |     PageResult<BpmProcessExpressionApi.ProcessExpressionVO> | ||||||
|  |   >('/bpm/process-expression/page', { params }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 查询流程表达式详情 */ | ||||||
|  | export async function getProcessExpression(id: number) { | ||||||
|  |   return requestClient.get<BpmProcessExpressionApi.ProcessExpressionVO>( | ||||||
|  |     `/bpm/process-expression/get?id=${id}`, | ||||||
|  |   ); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 新增流程表达式 */ | ||||||
|  | export async function createProcessExpression( | ||||||
|  |   data: BpmProcessExpressionApi.ProcessExpressionVO, | ||||||
|  | ) { | ||||||
|  |   return requestClient.post<number>('/bpm/process-expression/create', data); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 修改流程表达式 */ | ||||||
|  | export async function updateProcessExpression( | ||||||
|  |   data: BpmProcessExpressionApi.ProcessExpressionVO, | ||||||
|  | ) { | ||||||
|  |   return requestClient.put<boolean>('/bpm/process-expression/update', data); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 删除流程表达式 */ | ||||||
|  | export async function deleteProcessExpression(id: number) { | ||||||
|  |   return requestClient.delete<boolean>( | ||||||
|  |     `/bpm/process-expression/delete?id=${id}`, | ||||||
|  |   ); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 导出流程表达式 */ | ||||||
|  | export async function exportProcessExpression(params: any) { | ||||||
|  |   return requestClient.download('/bpm/process-expression/export-excel', params); | ||||||
|  | } | ||||||
|  | @ -0,0 +1,151 @@ | ||||||
|  | import type { VbenFormSchema } from '#/adapter/form'; | ||||||
|  | import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; | ||||||
|  | import type { BpmProcessExpressionApi } from '#/api/bpm/processExpression'; | ||||||
|  | 
 | ||||||
|  | import { useAccess } from '@vben/access'; | ||||||
|  | 
 | ||||||
|  | import { z } from '#/adapter/form'; | ||||||
|  | import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils'; | ||||||
|  | 
 | ||||||
|  | const { hasAccessByCodes } = useAccess(); | ||||||
|  | /** 新增/修改的表单 */ | ||||||
|  | export function useFormSchema(): VbenFormSchema[] { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       fieldName: 'id', | ||||||
|  |       component: 'Input', | ||||||
|  |       dependencies: { | ||||||
|  |         triggerFields: [''], | ||||||
|  |         show: () => false, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'name', | ||||||
|  |       label: '名字', | ||||||
|  |       component: 'Input', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请输入名字', | ||||||
|  |       }, | ||||||
|  |       rules: 'required', | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'status', | ||||||
|  |       label: '状态', | ||||||
|  |       component: 'RadioGroup', | ||||||
|  |       componentProps: { | ||||||
|  |         options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), | ||||||
|  |         buttonStyle: 'solid', | ||||||
|  |         optionType: 'button', | ||||||
|  |       }, | ||||||
|  |       rules: z.number().default(CommonStatusEnum.ENABLE), | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'expression', | ||||||
|  |       label: '表达式', | ||||||
|  |       component: 'Textarea', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请输入表达式', | ||||||
|  |       }, | ||||||
|  |       rules: 'required', | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 列表的搜索表单 */ | ||||||
|  | export function useGridFormSchema(): VbenFormSchema[] { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       fieldName: 'name', | ||||||
|  |       label: '名字', | ||||||
|  |       component: 'Input', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: '请输入名字', | ||||||
|  |         allowClear: true, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'status', | ||||||
|  |       label: '状态', | ||||||
|  |       component: 'Select', | ||||||
|  |       componentProps: { | ||||||
|  |         options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), | ||||||
|  |         placeholder: '请选择状态', | ||||||
|  |         allowClear: true, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       fieldName: 'createTime', | ||||||
|  |       label: '创建时间', | ||||||
|  |       component: 'RangePicker', | ||||||
|  |       componentProps: { | ||||||
|  |         placeholder: ['开始时间', '结束时间'], | ||||||
|  |         valueFormat: 'YYYY-MM-DD HH:mm:ss', | ||||||
|  |         allowClear: true, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 列表的字段 */ | ||||||
|  | export function useGridColumns<T = BpmProcessExpressionApi.ProcessExpressionVO>( | ||||||
|  |   onActionClick: OnActionClickFn<T>, | ||||||
|  | ): VxeTableGridOptions['columns'] { | ||||||
|  |   return [ | ||||||
|  |     { | ||||||
|  |       field: 'id', | ||||||
|  |       title: '编号', | ||||||
|  |       minWidth: 100, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'name', | ||||||
|  |       title: '名字', | ||||||
|  |       minWidth: 200, | ||||||
|  |     }, | ||||||
|  | 
 | ||||||
|  |     { | ||||||
|  |       field: 'status', | ||||||
|  |       title: '状态', | ||||||
|  |       minWidth: 100, | ||||||
|  |       cellRender: { | ||||||
|  |         name: 'CellDict', | ||||||
|  |         props: { type: DICT_TYPE.COMMON_STATUS }, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       field: 'expression', | ||||||
|  |       title: '表达式', | ||||||
|  |       minWidth: 200, | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       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:process-expression:update']), | ||||||
|  |           }, | ||||||
|  |           { | ||||||
|  |             code: 'delete', | ||||||
|  |             show: hasAccessByCodes(['bpm:process-expression:delete']), | ||||||
|  |           }, | ||||||
|  |         ], | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | @ -1,31 +1,125 @@ | ||||||
| <script lang="ts" setup> | <script lang="ts" setup> | ||||||
| import { Page } from '@vben/common-ui'; | import type { | ||||||
|  |   OnActionClickParams, | ||||||
|  |   VxeTableGridOptions, | ||||||
|  | } from '#/adapter/vxe-table'; | ||||||
|  | import type { BpmProcessExpressionApi } from '#/api/bpm/processExpression'; | ||||||
| 
 | 
 | ||||||
| import { Button } from 'ant-design-vue'; | 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 { | ||||||
|  |   deleteProcessExpression, | ||||||
|  |   getProcessExpressionPage, | ||||||
|  | } from '#/api/bpm/processExpression'; | ||||||
| import { DocAlert } from '#/components/doc-alert'; | import { DocAlert } from '#/components/doc-alert'; | ||||||
|  | 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 getProcessExpressionPage({ | ||||||
|  |             pageNo: page.currentPage, | ||||||
|  |             pageSize: page.pageSize, | ||||||
|  |             ...formValues, | ||||||
|  |           }); | ||||||
|  |         }, | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |     rowConfig: { | ||||||
|  |       keyField: 'id', | ||||||
|  |     }, | ||||||
|  |     toolbarConfig: { | ||||||
|  |       refresh: { code: 'query' }, | ||||||
|  |       search: true, | ||||||
|  |     }, | ||||||
|  |   } as VxeTableGridOptions<BpmProcessExpressionApi.ProcessExpressionVO>, | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | /** 表格操作按钮的回调函数 */ | ||||||
|  | function onActionClick({ | ||||||
|  |   code, | ||||||
|  |   row, | ||||||
|  | }: OnActionClickParams<BpmProcessExpressionApi.ProcessExpressionVO>) { | ||||||
|  |   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: BpmProcessExpressionApi.ProcessExpressionVO) { | ||||||
|  |   formModalApi.setData(row).open(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** 删除流程表达式 */ | ||||||
|  | async function onDelete(row: BpmProcessExpressionApi.ProcessExpressionVO) { | ||||||
|  |   const hideLoading = message.loading({ | ||||||
|  |     content: $t('ui.actionMessage.deleting', [row.name]), | ||||||
|  |     duration: 0, | ||||||
|  |     key: 'action_process_msg', | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   try { | ||||||
|  |     await deleteProcessExpression(row.id as number); | ||||||
|  |     message.success($t('ui.actionMessage.deleteSuccess', [row.name])); | ||||||
|  |     onRefresh(); | ||||||
|  |   } finally { | ||||||
|  |     hideLoading(); | ||||||
|  |   } | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|   <Page> |   <Page auto-content-height> | ||||||
|     <DocAlert title="流程表达式" url="https://doc.iocoder.cn/bpm/expression/" /> |     <DocAlert title="流程表达式" url="https://doc.iocoder.cn/bpm/expression/" /> | ||||||
|     <Button | 
 | ||||||
|       danger |     <FormModal @success="onRefresh" /> | ||||||
|       type="link" |     <Grid table-title="流程表达式"> | ||||||
|       target="_blank" |       <template #toolbar-tools> | ||||||
|       href="https://github.com/yudaocode/yudao-ui-admin-vue3" |         <Button | ||||||
|     > |           type="primary" | ||||||
|       该功能支持 Vue3 + element-plus 版本! |           @click="onCreate" | ||||||
|     </Button> |           v-access:code="['bpm:process-expression:create']" | ||||||
|     <br /> |         > | ||||||
|     <Button |           <Plus class="size-5" /> | ||||||
|       type="link" |           {{ $t('ui.actionTitle.create', ['流程表达式']) }} | ||||||
|       target="_blank" |         </Button> | ||||||
|       href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/bpm/processExpression/index" |       </template> | ||||||
|     > |     </Grid> | ||||||
|       可参考 |  | ||||||
|       https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/bpm/processExpression/index |  | ||||||
|       代码,pull request 贡献给我们! |  | ||||||
|     </Button> |  | ||||||
|   </Page> |   </Page> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
|  | @ -0,0 +1,83 @@ | ||||||
|  | <script lang="ts" setup> | ||||||
|  | import type { BpmProcessExpressionApi } from '#/api/bpm/processExpression'; | ||||||
|  | 
 | ||||||
|  | import { computed, ref } from 'vue'; | ||||||
|  | 
 | ||||||
|  | import { useVbenModal } from '@vben/common-ui'; | ||||||
|  | 
 | ||||||
|  | import { message } from 'ant-design-vue'; | ||||||
|  | 
 | ||||||
|  | import { useVbenForm } from '#/adapter/form'; | ||||||
|  | import { | ||||||
|  |   createProcessExpression, | ||||||
|  |   getProcessExpression, | ||||||
|  |   updateProcessExpression, | ||||||
|  | } from '#/api/bpm/processExpression'; | ||||||
|  | import { $t } from '#/locales'; | ||||||
|  | 
 | ||||||
|  | import { useFormSchema } from '../data'; | ||||||
|  | 
 | ||||||
|  | const emit = defineEmits(['success']); | ||||||
|  | const formData = ref<BpmProcessExpressionApi.ProcessExpressionVO>(); | ||||||
|  | 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 BpmProcessExpressionApi.ProcessExpressionVO; | ||||||
|  |     try { | ||||||
|  |       await (formData.value?.id | ||||||
|  |         ? updateProcessExpression(data) | ||||||
|  |         : createProcessExpression(data)); | ||||||
|  |       // 关闭并提示 | ||||||
|  |       await modalApi.close(); | ||||||
|  |       emit('success'); | ||||||
|  |       message.success($t('ui.actionMessage.operationSuccess')); | ||||||
|  |     } finally { | ||||||
|  |       modalApi.unlock(); | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   async onOpenChange(isOpen: boolean) { | ||||||
|  |     if (!isOpen) { | ||||||
|  |       formData.value = undefined; | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     // 加载数据 | ||||||
|  |     const data = | ||||||
|  |       modalApi.getData<BpmProcessExpressionApi.ProcessExpressionVO>(); | ||||||
|  |     if (!data || !data.id) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |     modalApi.lock(); | ||||||
|  |     try { | ||||||
|  |       formData.value = await getProcessExpression(data.id as number); | ||||||
|  |       // 设置到 values | ||||||
|  |       await formApi.setValues(formData.value); | ||||||
|  |     } finally { | ||||||
|  |       modalApi.unlock(); | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  | }); | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <Modal :title="getTitle" class="w-[600px]"> | ||||||
|  |     <Form class="mx-4" /> | ||||||
|  |   </Modal> | ||||||
|  | </template> | ||||||
		Loading…
	
		Reference in New Issue
	
	 子夜
						子夜