feat: 【BPM 工作流】完善流程表单模块

pull/103/head
ziye 2025-05-14 01:20:11 +08:00
parent 3ac5f784e7
commit 18c4e92418
8 changed files with 678 additions and 20 deletions

View File

@ -0,0 +1,48 @@
import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request';
export namespace BpmFormApi {
export interface FormVO {
id?: number | undefined;
name: string;
conf: string;
fields: string[];
status: number;
remark: string;
createTime: string;
}
}
/** 获取表单分页列表 */
export async function getFormPage(params: PageParam) {
return requestClient.get<PageResult<BpmFormApi.FormVO>>('/bpm/form/page', {
params,
});
}
/** 获取表单详情 */
export async function getFormDetail(id: number) {
return requestClient.get<BpmFormApi.FormVO>(`/bpm/form/get?id=${id}`);
}
/** 创建表单 */
export async function createForm(data: BpmFormApi.FormVO) {
return requestClient.post('/bpm/form/create', data);
}
/** 更新表单 */
export async function updateForm(data: BpmFormApi.FormVO) {
return requestClient.put('/bpm/form/update', data);
}
/** 删除表单 */
export async function deleteForm(id: number) {
return requestClient.delete(`/bpm/form/delete?id=${id}`);
}
/** 获取表单简单列表 */
export async function getFormSimpleList() {
return requestClient.get<BpmFormApi.FormVO[]>('/bpm/form/simple-list');
}

View File

@ -47,6 +47,24 @@ const routes: RouteRecordRaw[] = [
};
},
},
/** 编辑流程表单 */
{
path: '/bpm/manager/form/edit',
name: 'BpmFormEditor',
component: () => import('#/views/bpm/form/editor.vue'),
meta: {
title: '编辑流程表单',
activePath: '/bpm/manager/form',
},
props: (route) => {
return {
id: route.query.id,
type: route.query.type,
copyId: route.query.copyId,
};
},
},
],
},
];

View File

@ -0,0 +1,146 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BpmFormApi } from '#/api/bpm/form';
import { useAccess } from '@vben/access';
import { $t } from '@vben/locales';
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: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '表单名称',
component: 'Input',
componentProps: {
placeholder: '请输入表单名称',
allowClear: true,
},
},
];
}
/** 列表的字段 */
export function useGridColumns<T = BpmFormApi.FormVO>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '编号',
minWidth: 100,
},
{
field: 'name',
title: '表单名称',
minWidth: 200,
},
{
field: 'status',
title: '状态',
minWidth: 200,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
},
},
{
field: 'remark',
title: '备注',
minWidth: 200,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'operation',
title: '操作',
minWidth: 150,
align: 'center',
fixed: 'right',
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '流程名称',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'copy',
text: $t('ui.actionTitle.copy'),
show: hasAccessByCodes(['bpm:form:update']),
},
{
code: 'edit',
text: $t('ui.actionTitle.edit'),
show: hasAccessByCodes(['bpm:form:update']),
},
{
code: 'detail',
text: $t('ui.actionTitle.detail'),
show: hasAccessByCodes(['bpm:form:query']),
},
{
code: 'delete',
text: $t('ui.actionTitle.delete'),
show: hasAccessByCodes(['bpm:form:delete']),
},
],
},
},
];
}

View File

@ -0,0 +1,156 @@
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons';
import FcDesigner from '@form-create/antd-designer';
import { Button, message } from 'ant-design-vue';
import { getFormDetail } from '#/api/bpm/form';
import { useFormCreateDesigner } from '#/components/form-create';
import { router } from '#/router';
import { setConfAndFields } from '#/utils';
import Form from './modules/form.vue';
defineOptions({ name: 'BpmFormEditor' });
const props = defineProps<Props>();
interface Props {
copyId?: number;
id?: number;
type: 'copy' | 'create' | 'edit';
}
//
const flowFormConfig = ref();
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const designerRef = ref<InstanceType<typeof FcDesigner>>();
//
const designerConfig = ref({
switchType: [], // ,
autoActive: true, //
useTemplate: false, // vue2
formOptions: {
form: {
labelWidth: '100px', // label 100px
},
}, //
fieldReadonly: false, // field
hiddenDragMenu: false, //
hiddenDragBtn: false, //
hiddenMenu: [], //
hiddenItem: [], //
hiddenItemConfig: {}, //
disabledItemConfig: {}, //
showSaveBtn: false, //
showConfig: true, //
showBaseForm: true, //
showControl: true, //
showPropsForm: true, //
showEventForm: true, //
showValidateForm: true, //
showFormConfig: true, //
showInputData: true, //
showDevice: true, //
appendConfigData: [], // formData
});
useFormCreateDesigner(designerRef); //
// ID
const currentFormId = computed(() => {
switch (props.type) {
case 'copy': {
return props.copyId;
}
case 'create':
case 'edit': {
return props.id;
}
default: {
return undefined;
}
}
});
//
async function loadFormConfig(id: number) {
try {
const formDetail = await getFormDetail(id);
flowFormConfig.value = formDetail;
if (designerRef.value) {
setConfAndFields(designerRef, formDetail.conf, formDetail.fields);
}
} catch {
message.error('加载表单配置失败');
}
}
//
async function initializeDesigner() {
const id = currentFormId.value;
if (props.type === 'copy' && !id) {
message.error('复制ID不能为空');
return;
}
if (id) {
await loadFormConfig(id);
}
}
function handleSave() {
formModalApi
.setData({
designer: designerRef.value,
formConfig: flowFormConfig.value,
action: props.type,
})
.open();
}
function onBack() {
router.push({
path: '/bpm/manager/form',
query: {
refresh: '1',
},
});
}
onMounted(() => {
initializeDesigner();
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="onBack" />
<FcDesigner class="my-designer" ref="designerRef" :config="designerConfig">
<template #handle>
<Button size="small" type="primary" @click="handleSave">
<IconifyIcon icon="mdi:content-save" />
保存
</Button>
</template>
</FcDesigner>
</Page>
</template>
<style scoped>
.my-designer {
height: 100%;
min-height: 500px;
}
</style>

View File

@ -1,34 +1,215 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { BpmFormApi } from '#/api/bpm/form';
import { Button } from 'ant-design-vue';
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui';
import { Plus } from '@vben/icons';
import { $t } from '@vben/locales';
import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteForm, getFormDetail, getFormPage } from '#/api/bpm/form';
import { DocAlert } from '#/components/doc-alert';
import { router } from '#/router';
import { setConfAndFields2 } from '#/utils';
import { useGridColumns, useGridFormSchema } from './data';
defineOptions({ name: 'BpmForm' });
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(onActionClick),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getFormPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
cellConfig: {
height: 64,
},
} as VxeTableGridOptions<BpmFormApi.FormVO>,
});
/** 表格操作按钮的回调函数 */
function onActionClick({ code, row }: OnActionClickParams<BpmFormApi.FormVO>) {
switch (code) {
case 'copy': {
onCopy(row);
break;
}
case 'delete': {
onDelete(row);
break;
}
case 'detail': {
onDetail(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
}
/** 复制 */
function onCopy(row: BpmFormApi.FormVO) {
router.push({
name: 'BpmFormEditor',
query: {
copyId: row.id,
type: 'copy',
},
});
}
/** 删除 */
async function onDelete(row: BpmFormApi.FormVO) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.id]),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteForm(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
} finally {
hideLoading();
}
}
/** 详情 */
const formConfig = ref<any>({});
async function onDetail(row: BpmFormApi.FormVO) {
formConfig.value = await getFormDetail(row.id as number);
setConfAndFields2(
formConfig.value,
formConfig.value.conf,
formConfig.value.fields,
);
detailModalApi.open();
}
/** 编辑 */
function onEdit(row: BpmFormApi.FormVO) {
console.warn(row);
router.push({
name: 'BpmFormEditor',
query: {
id: row.id,
type: 'edit',
},
});
}
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 新增 */
function onCreate() {
router.push({
name: 'BpmFormEditor',
query: {
type: 'create',
},
});
}
/** 详情弹窗 */
const [DetailModal, detailModalApi] = useVbenModal({
destroyOnClose: true,
footer: false,
});
/** 检测路由参数 */
const route = useRoute();
watch(
() => route.query.refresh,
(val) => {
if (val === '1') {
onRefresh();
}
},
{ immediate: true },
);
</script>
<template>
<Page>
<Page auto-content-height>
<DocAlert
title="审批接入(流程表单)"
url="https://doc.iocoder.cn/bpm/use-bpm-form/"
/>
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
<FormModal @success="onRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<Button type="primary" @click="onCreate">
<Plus class="size-5" />
{{ $t('ui.actionTitle.create', ['流程表单']) }}
</Button>
</template>
<!-- 摘要 -->
<template #slot-summary="{ row }">
<div
class="flex flex-col py-2"
v-if="
row.processInstance.summary &&
row.processInstance.summary.length > 0
"
>
<div
v-for="(item, index) in row.processInstance.summary"
:key="index"
>
<span class="text-gray-500">
{{ item.key }} : {{ item.value }}
</span>
</div>
</div>
<div v-else>-</div>
</template>
</Grid>
<DetailModal
title="流程表单详情"
class="w-[800px]"
:body-style="{
maxHeight: '100px',
}"
>
该功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/bpm/form/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/bpm/form/index
代码pull request 贡献给我们
</Button>
<div class="mx-4">
<form-create :option="formConfig.option" :rule="formConfig.rule" />
</div>
</DetailModal>
</Page>
</template>

View File

@ -0,0 +1,107 @@
<script lang="ts" setup>
import type { FcDesigner } from '@form-create/antd-designer';
import type { BpmFormApi } from '#/api/bpm/form';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { createForm, updateForm } from '#/api/bpm/form';
import { $t } from '#/locales';
import { encodeConf, encodeFields } from '#/utils';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const designerComponent = ref<InstanceType<typeof FcDesigner>>();
const formData = ref<BpmFormApi.FormVO>();
const editorAction = ref<string>();
const getTitle = computed(() => {
if (!formData.value?.id) {
return $t('ui.actionTitle.create', ['流程表单']);
}
return editorAction.value === 'copy'
? $t('ui.actionTitle.copy', ['流程表单'])
: $t('ui.actionTitle.edit', ['流程表单']);
});
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();
try {
const data = (await formApi.getValues()) as BpmFormApi.FormVO;
data.conf = encodeConf(designerComponent);
data.fields = encodeFields(designerComponent);
const saveForm = async () => {
if (!formData.value?.id) {
return createForm(data);
}
return editorAction.value === 'copy'
? createForm(data)
: updateForm(data);
};
await saveForm();
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
designerComponent.value = undefined;
return;
}
const data = modalApi.getData<any>();
if (!data) return;
designerComponent.value = data.designer;
formData.value = data.formConfig;
editorAction.value = data.action;
if (editorAction.value === 'copy' && formData.value) {
formData.value = {
...formData.value,
name: `${formData.value.name}_copy`,
id: undefined,
};
}
try {
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-[600px]">
<Form class="mx-4" />
</Modal>
</template>

View File

@ -11,6 +11,7 @@
"mobile": "Please input a valid {0}"
},
"actionTitle": {
"copy": "Copy {0}",
"cancel": "Cancel {0}",
"edit": "Modify {0}",
"create": "Create {0}",

View File

@ -11,6 +11,7 @@
"mobile": "请输入正确的{0}"
},
"actionTitle": {
"copy": "复制{0}",
"cancel": "取消{0}",
"edit": "修改{0}",
"create": "新增{0}",