feat: [bpm][antd] bpm设计器 用户任务自定义配置优化

This commit is contained in:
jason
2025-12-08 00:01:44 +08:00
parent 2cf7e70b70
commit 1c17746864
4 changed files with 261 additions and 186 deletions

View File

@@ -8,17 +8,20 @@
7. 是否需要签名 7. 是否需要签名
--> -->
<script lang="ts" setup> <script lang="ts" setup>
import type { ComponentPublicInstance } from 'vue';
import type { SystemUserApi } from '#/api/system/user'; import type { SystemUserApi } from '#/api/system/user';
import type { ButtonSetting } from '#/views/bpm/components/simple-process-design/consts';
import { inject, nextTick, onMounted, ref, toRaw, watch } from 'vue'; import { inject, nextTick, onMounted, ref, toRaw, watch } from 'vue';
import { BpmModelFormType } from '@vben/constants'; import { BpmModelFormType } from '@vben/constants';
import { IconifyIcon } from '@vben/icons';
import { import {
Button, Button,
Divider, Divider,
Form, Form,
Input,
Radio, Radio,
RadioGroup, RadioGroup,
Select, Select,
@@ -74,15 +77,67 @@ const assignEmptyUserIdsEl = ref<any>();
const assignEmptyUserIds = ref<any>(); const assignEmptyUserIds = ref<any>();
// 操作按钮 // 操作按钮
const buttonsSettingEl = ref<any>(); // const buttonsSettingEl = ref<any>();
const { btnDisplayNameEdit, changeBtnDisplayName } = useButtonsSetting(); // const { btnDisplayNameEdit, changeBtnDisplayName } = useButtonsSetting();
const btnDisplayNameBlurEvent = (index: number) => { // const btnDisplayNameBlurEvent = (index: number) => {
btnDisplayNameEdit.value[index] = false; // btnDisplayNameEdit.value[index] = false;
const buttonItem = buttonsSettingEl.value[index]; // const buttonItem = buttonsSettingEl.value[index];
buttonItem.displayName = // buttonItem.displayName =
buttonItem.displayName || OPERATION_BUTTON_NAME.get(buttonItem.id)!; // buttonItem.displayName || OPERATION_BUTTON_NAME.get(buttonItem.id)!;
updateElementExtensions(); // updateElementExtensions();
}; // };
// 操作按钮设置
const {
buttonsSetting,
btnDisplayNameEdit,
changeBtnDisplayName,
btnDisplayNameBlurEvent,
setInputRef,
} = useButtonsSetting();
/** 操作按钮设置 */
function useButtonsSetting() {
const buttonsSetting = ref<any[]>([]);
// 操作按钮显示名称可编辑
const btnDisplayNameEdit = ref<boolean[]>([]);
// 输入框的引用数组 - 内部使用,不暴露出去
const _btnDisplayNameInputRefs = ref<Array<HTMLInputElement | null>>([]);
const changeBtnDisplayName = (index: number) => {
btnDisplayNameEdit.value[index] = true;
// 输入框自动聚集
nextTick(() => {
if (_btnDisplayNameInputRefs.value[index]) {
_btnDisplayNameInputRefs.value[index]?.focus();
}
});
};
const btnDisplayNameBlurEvent = (index: number) => {
btnDisplayNameEdit.value[index] = false;
const buttonItem = buttonsSetting.value![index];
if (buttonItem)
buttonItem.displayName =
buttonItem.displayName || OPERATION_BUTTON_NAME.get(buttonItem.id)!;
};
// 设置 ref 引用的方法
const setInputRef = (
el: ComponentPublicInstance | Element | null,
index: number,
) => {
_btnDisplayNameInputRefs.value[index] = el as HTMLInputElement;
};
return {
buttonsSetting,
btnDisplayNameEdit,
changeBtnDisplayName,
btnDisplayNameBlurEvent,
setInputRef,
};
}
// 字段权限 // 字段权限
const fieldsPermissionEl = ref<any[]>([]); const fieldsPermissionEl = ref<any[]>([]);
@@ -178,12 +233,12 @@ const resetCustomConfigList = () => {
}); });
// 操作按钮 // 操作按钮
buttonsSettingEl.value = elExtensionElements.value.values?.filter( buttonsSetting.value = elExtensionElements.value.values?.filter(
(ex: any) => ex.$type === `${prefix}:ButtonsSetting`, (ex: any) => ex.$type === `${prefix}:ButtonsSetting`,
); );
if (buttonsSettingEl.value.length === 0) { if (buttonsSetting.value.length === 0) {
DEFAULT_BUTTON_SETTING.forEach((item) => { DEFAULT_BUTTON_SETTING.forEach((item) => {
buttonsSettingEl.value.push( buttonsSetting.value.push(
bpmnInstances().moddle.create(`${prefix}:ButtonsSetting`, { bpmnInstances().moddle.create(`${prefix}:ButtonsSetting`, {
'flowable:id': item.id, 'flowable:id': item.id,
'flowable:displayName': item.displayName, 'flowable:displayName': item.displayName,
@@ -226,7 +281,7 @@ const resetCustomConfigList = () => {
// 保留剩余扩展元素,便于后面更新该元素对应属性 // 保留剩余扩展元素,便于后面更新该元素对应属性
otherExtensions.value = otherExtensions.value =
elExtensionElements.value.values?.find( elExtensionElements.value.values?.filter(
(ex: any) => (ex: any) =>
ex.$type !== `${prefix}:AssignStartUserHandlerType` && ex.$type !== `${prefix}:AssignStartUserHandlerType` &&
ex.$type !== `${prefix}:RejectHandlerType` && ex.$type !== `${prefix}:RejectHandlerType` &&
@@ -287,7 +342,7 @@ const updateElementExtensions = () => {
assignEmptyHandlerTypeEl.value, assignEmptyHandlerTypeEl.value,
assignEmptyUserIdsEl.value, assignEmptyUserIdsEl.value,
approveType.value, approveType.value,
...buttonsSettingEl.value, ...buttonsSetting.value,
...fieldsPermissionEl.value, ...fieldsPermissionEl.value,
signEnable.value, signEnable.value,
reasonRequire.value, reasonRequire.value,
@@ -357,19 +412,19 @@ function findAllPredecessorsExcludingStart(elementId: string, modeler: any) {
return [...predecessors]; // 返回前置节点数组 return [...predecessors]; // 返回前置节点数组
} }
function useButtonsSetting() { // function useButtonsSetting() {
const buttonsSetting = ref<ButtonSetting[]>(); // const buttonsSetting = ref<ButtonSetting[]>();
// 操作按钮显示名称可编辑 // // 操作按钮显示名称可编辑
const btnDisplayNameEdit = ref<boolean[]>([]); // const btnDisplayNameEdit = ref<boolean[]>([]);
const changeBtnDisplayName = (index: number) => { // const changeBtnDisplayName = (index: number) => {
btnDisplayNameEdit.value[index] = true; // btnDisplayNameEdit.value[index] = true;
}; // };
return { // return {
buttonsSetting, // buttonsSetting,
btnDisplayNameEdit, // btnDisplayNameEdit,
changeBtnDisplayName, // changeBtnDisplayName,
}; // };
} // }
/** 批量更新权限 */ /** 批量更新权限 */
const updatePermission = (type: string) => { const updatePermission = (type: string) => {
@@ -413,13 +468,13 @@ onMounted(async () => {
:disabled="returnTaskList.length === 0" :disabled="returnTaskList.length === 0"
@change="updateRejectHandlerType" @change="updateRejectHandlerType"
> >
<div class="flex-col"> <Radio
<div v-for="(item, index) in REJECT_HANDLER_TYPES" :key="index"> v-for="(item, index) in REJECT_HANDLER_TYPES"
<Radio :key="item.value" :value="item.value"> :key="index"
{{ item.label }} :value="item.value"
</Radio> >
</div> {{ item.label }}
</div> </Radio>
</RadioGroup> </RadioGroup>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
@@ -450,7 +505,7 @@ onMounted(async () => {
v-model:value="assignEmptyHandlerType" v-model:value="assignEmptyHandlerType"
@change="updateAssignEmptyHandlerType" @change="updateAssignEmptyHandlerType"
> >
<div class="flex-col"> <div class="flex flex-col gap-2">
<div v-for="(item, index) in ASSIGN_EMPTY_HANDLER_TYPES" :key="index"> <div v-for="(item, index) in ASSIGN_EMPTY_HANDLER_TYPES" :key="index">
<Radio :key="item.value" :value="item.value"> <Radio :key="item.value" :value="item.value">
{{ item.label }} {{ item.label }}
@@ -486,7 +541,7 @@ onMounted(async () => {
v-model:value="assignStartUserHandlerType" v-model:value="assignStartUserHandlerType"
@change="updateAssignStartUserHandlerType" @change="updateAssignStartUserHandlerType"
> >
<div class="flex-col"> <div class="flex flex-col gap-2">
<div <div
v-for="(item, index) in ASSIGN_START_USER_HANDLER_TYPES" v-for="(item, index) in ASSIGN_START_USER_HANDLER_TYPES"
:key="index" :key="index"
@@ -499,35 +554,44 @@ onMounted(async () => {
</RadioGroup> </RadioGroup>
<Divider orientation="left">操作按钮</Divider> <Divider orientation="left">操作按钮</Divider>
<div class="button-setting-pane"> <div class="mt-2 text-sm">
<div class="button-setting-title"> <!-- 头部标题行 -->
<div class="button-title-label">操作按钮</div>
<div class="button-title-label pl-4">显示名称</div>
<div class="button-title-label">启用</div>
</div>
<div <div
class="button-setting-item" class="flex items-center justify-between border border-slate-200 bg-slate-50 px-3 py-2 text-xs font-semibold text-slate-900"
v-for="(item, index) in buttonsSettingEl"
:key="index"
> >
<div class="button-setting-item-label"> <div class="w-28 text-left">操作按钮</div>
<div class="w-40 pl-2 text-left">显示名称</div>
<div class="w-20 text-center">启用</div>
</div>
<!-- 按钮配置行 -->
<div
v-for="(item, index) in buttonsSetting"
:key="index"
class="flex items-center justify-between border border-t-0 border-slate-200 px-3 py-2 text-sm"
>
<div class="w-28 truncate text-left">
{{ OPERATION_BUTTON_NAME.get(item.id) }} {{ OPERATION_BUTTON_NAME.get(item.id) }}
</div> </div>
<div class="button-setting-item-label"> <div class="flex w-40 items-center truncate text-left">
<input <Input
type="text"
class="editable-title-input"
@blur="btnDisplayNameBlurEvent(index)"
v-mounted-focus
v-model="item.displayName"
:placeholder="item.displayName"
v-if="btnDisplayNameEdit[index]" v-if="btnDisplayNameEdit[index]"
:ref="(el) => setInputRef(el, index)"
@blur="btnDisplayNameBlurEvent(index)"
@press-enter="btnDisplayNameBlurEvent(index)"
type="text"
v-model:value="item.displayName"
:placeholder="item.displayName"
class="max-w-32 focus:border-blue-500 focus:shadow-[0_0_0_2px_rgba(24,144,255,0.2)] focus:outline-none"
/> />
<Button v-else type="text" @click="changeBtnDisplayName(index)"> <Button v-else @click="changeBtnDisplayName(index)">
{{ item.displayName }} <div class="flex items-center">
{{ item.displayName }}
<IconifyIcon icon="lucide:edit" class="ml-2" />
</div>
</Button> </Button>
</div> </div>
<div class="button-setting-item-label"> <div class="flex w-20 items-center justify-center">
<Switch <Switch
v-model:checked="item.enable" v-model:checked="item.enable"
@change="updateElementExtensions" @change="updateElementExtensions"
@@ -537,40 +601,50 @@ onMounted(async () => {
</div> </div>
<Divider orientation="left">字段权限</Divider> <Divider orientation="left">字段权限</Divider>
<div class="field-setting-pane" v-if="formType === BpmModelFormType.NORMAL"> <div v-if="formType === BpmModelFormType.NORMAL" class="mt-2 text-sm">
<div class="field-permit-title"> <!-- 头部标题行 -->
<div class="setting-title-label first-title">字段名称</div> <div
<div class="other-titles"> class="flex items-center justify-between border border-slate-200 bg-slate-50 px-3 py-2 text-xs font-semibold text-slate-900"
>
<div class="w-28 text-left">字段名称</div>
<div class="flex flex-1 justify-between">
<span <span
class="setting-title-label cursor-pointer" class="inline-block w-24 cursor-pointer text-center hover:text-blue-500"
@click="updatePermission('READ')" @click="updatePermission('READ')"
>只读 >
只读
</span> </span>
<span <span
class="setting-title-label cursor-pointer" class="inline-block w-24 cursor-pointer text-center hover:text-blue-500"
@click="updatePermission('WRITE')" @click="updatePermission('WRITE')"
> >
可编辑 可编辑
</span> </span>
<span <span
class="setting-title-label cursor-pointer" class="inline-block w-24 cursor-pointer text-center hover:text-blue-500"
@click="updatePermission('NONE')" @click="updatePermission('NONE')"
>隐藏 >
隐藏
</span> </span>
</div> </div>
</div> </div>
<!-- 字段权限行 -->
<div <div
class="field-setting-item"
v-for="(item, index) in fieldsPermissionEl" v-for="(item, index) in fieldsPermissionEl"
:key="index" :key="index"
class="flex items-center justify-between border border-t-0 border-slate-200 px-3 py-2 text-sm"
> >
<div class="field-setting-item-label">{{ item.title }}</div> <div class="w-28 truncate text-left" :title="item.title">
{{ item.title }}
</div>
<RadioGroup <RadioGroup
class="field-setting-item-group"
v-model:value="item.permission" v-model:value="item.permission"
class="flex flex-1 justify-between"
> >
<div class="item-radio-wrap"> <div class="flex w-24 items-center justify-center">
<Radio <Radio
class="ml-5"
:value="FieldPermissionType.READ" :value="FieldPermissionType.READ"
size="large" size="large"
@change="updateElementExtensions" @change="updateElementExtensions"
@@ -578,8 +652,9 @@ onMounted(async () => {
<span></span> <span></span>
</Radio> </Radio>
</div> </div>
<div class="item-radio-wrap"> <div class="flex w-24 items-center justify-center">
<Radio <Radio
class="ml-5"
:value="FieldPermissionType.WRITE" :value="FieldPermissionType.WRITE"
size="large" size="large"
@change="updateElementExtensions" @change="updateElementExtensions"
@@ -587,8 +662,9 @@ onMounted(async () => {
<span></span> <span></span>
</Radio> </Radio>
</div> </div>
<div class="item-radio-wrap"> <div class="flex w-24 items-center justify-center">
<Radio <Radio
class="ml-5"
:value="FieldPermissionType.NONE" :value="FieldPermissionType.NONE"
size="large" size="large"
@change="updateElementExtensions" @change="updateElementExtensions"

View File

@@ -1,96 +0,0 @@
<!-- 表达式选择 -->
<script setup lang="ts">
import type { BpmProcessExpressionApi } from '#/api/bpm/processExpression';
import { reactive, ref } from 'vue';
import { ContentWrap } from '@vben/common-ui';
import { CommonStatusEnum } from '@vben/constants';
import { Button, Modal, Pagination, Table, TableColumn } from 'ant-design-vue';
import { getProcessExpressionPage } from '#/api/bpm/processExpression';
/** BPM 流程 表单 */
defineOptions({ name: 'ProcessExpressionDialog' });
/** 提交表单 */
const emit = defineEmits(['select']);
const dialogVisible = ref(false); // 弹窗的是否展示
const loading = ref(true); // 列表的加载中
const list = ref<BpmProcessExpressionApi.ProcessExpression[]>([]); // 列表的数据
const total = ref(0); // 列表的总页数
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
type: '',
status: CommonStatusEnum.ENABLE,
});
/** 打开弹窗 */
const open = (type: string) => {
queryParams.pageNo = 1;
queryParams.type = type;
getList();
dialogVisible.value = true;
};
defineExpose({ open }); // 提供 open 方法,用于打开弹窗
/** 查询列表 */
const getList = async () => {
loading.value = true;
try {
const data = await getProcessExpressionPage(queryParams);
list.value = data.list;
total.value = data.total;
} finally {
loading.value = false;
}
};
// 定义 select 事件,用于操作成功后的回调
const select = async (row: BpmProcessExpressionApi.ProcessExpression) => {
dialogVisible.value = false;
// 发送操作成功的事件
emit('select', row);
};
// const handleCancel = () => {
// dialogVisible.value = false;
// };
</script>
<template>
<Modal
title="请选择表达式"
v-model:open="dialogVisible"
width="1024px"
:footer="null"
>
<ContentWrap>
<Table
:loading="loading"
:data-source="list"
:pagination="false"
:scroll="{ x: 'max-content' }"
>
<TableColumn title="名字" align="center" data-index="name" />
<TableColumn title="表达式" align="center" data-index="expression" />
<TableColumn title="操作" align="center">
<template #default="{ record }">
<Button type="primary" @click="select(record)"> 选择 </Button>
</template>
</TableColumn>
</Table>
<!-- 分页 -->
<div class="mt-4 flex justify-end">
<Pagination
:total="total"
v-model:current="queryParams.pageNo"
v-model:page-size="queryParams.pageSize"
show-size-changer
@change="getList"
/>
</div>
</ContentWrap>
</Modal>
</template>

View File

@@ -17,6 +17,7 @@ import {
watch, watch,
} from 'vue'; } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { SelectOutlined } from '@vben/icons'; import { SelectOutlined } from '@vben/icons';
import { handleTree } from '@vben/utils'; import { handleTree } from '@vben/utils';
@@ -42,8 +43,7 @@ import {
MULTI_LEVEL_DEPT, MULTI_LEVEL_DEPT,
} from '#/views/bpm/components/simple-process-design/consts'; } from '#/views/bpm/components/simple-process-design/consts';
import { useFormFieldsPermission } from '#/views/bpm/components/simple-process-design/helpers'; import { useFormFieldsPermission } from '#/views/bpm/components/simple-process-design/helpers';
import ProcessExpressionSelectModal from '#/views/bpm/processExpression/components/process-expression-select-modal.vue';
import ProcessExpressionDialog from './ProcessExpressionDialog.vue';
defineOptions({ name: 'UserTask' }); defineOptions({ name: 'UserTask' });
const props = defineProps({ const props = defineProps({
@@ -292,9 +292,13 @@ const updateSkipExpression = () => {
}; };
// 打开监听器弹窗 // 打开监听器弹窗
const processExpressionDialogRef = ref<any>(); const [ProcessExpressionSelectModalComp, ProcessExpressionSelectModalApi] =
useVbenModal({
connectedComponent: ProcessExpressionSelectModal,
destroyOnClose: true,
});
const openProcessExpressionDialog = async () => { const openProcessExpressionDialog = async () => {
processExpressionDialogRef.value.open(); ProcessExpressionSelectModalApi.open();
}; };
const selectProcessExpression = ( const selectProcessExpression = (
expression: BpmProcessExpressionApi.ProcessExpression, expression: BpmProcessExpressionApi.ProcessExpression,
@@ -344,7 +348,7 @@ onBeforeUnmount(() => {
</script> </script>
<template> <template>
<Form> <Form :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
<FormItem label="规则类型" name="candidateStrategy"> <FormItem label="规则类型" name="candidateStrategy">
<Select <Select
v-model:value="userTaskForm.candidateStrategy" v-model:value="userTaskForm.candidateStrategy"
@@ -544,19 +548,19 @@ onBeforeUnmount(() => {
style="width: 100%" style="width: 100%"
@change="updateElementTask" @change="updateElementTask"
/> />
<Button <div class="mt-2 flex w-full items-center justify-center">
class="!w-1/1 mt-5px" <Button
type="primary" class="flex flex-1 items-center justify-center"
:icon="h(SelectOutlined)" type="primary"
@click="openProcessExpressionDialog" size="small"
> :icon="h(SelectOutlined)"
选择表达式 @click="openProcessExpressionDialog"
</Button> >
选择表达式
</Button>
</div>
<!-- 选择弹窗 --> <!-- 选择弹窗 -->
<ProcessExpressionDialog <ProcessExpressionSelectModalComp @select="selectProcessExpression" />
ref="processExpressionDialogRef"
@select="selectProcessExpression"
/>
</FormItem> </FormItem>
<FormItem label="跳过表达式" name="skipExpression"> <FormItem label="跳过表达式" name="skipExpression">

View File

@@ -0,0 +1,91 @@
<script lang="ts" setup>
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
import type { BpmProcessExpressionApi } from '#/api/bpm/processExpression';
import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { CommonStatusEnum } from '@vben/constants';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getProcessExpressionPage } from '#/api/bpm/processExpression';
defineOptions({ name: 'ProcessExpressionSelectModal' });
const emit = defineEmits<{
select: [expression: BpmProcessExpressionApi.ProcessExpression];
}>();
// 查询参数
const queryParams = ref({
status: CommonStatusEnum.ENABLE,
});
// 配置 VxeGrid
const [Grid] = useVbenVxeGrid({
gridOptions: {
columns: [
{ field: 'name', title: '名字', minWidth: 160 },
{ field: 'expression', title: '表达式', minWidth: 260 },
{
field: 'action',
title: '操作',
width: 120,
slots: { default: 'action' },
},
],
showOverflow: true,
minHeight: 300,
proxyConfig: {
ajax: {
// 查询表达式列表
query: async ({ page }) => {
return await getProcessExpressionPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
status: queryParams.value.status,
});
},
},
} as VxeGridPropTypes.ProxyConfig,
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
enabled: false,
},
},
});
// 配置 Modal
const [Modal, modalApi] = useVbenModal({
showConfirmButton: false,
destroyOnClose: true,
});
// 选择表达式
function handleSelect(row: BpmProcessExpressionApi.ProcessExpression) {
emit('select', row);
modalApi.close();
}
</script>
<template>
<Modal class="w-4/5" title="请选择表达式">
<Grid>
<template #action="{ row }">
<TableAction
:actions="[
{
label: '选择',
type: 'link',
icon: 'lucide:pointer',
onClick: handleSelect.bind(null, row),
},
]"
/>
</template>
</Grid>
</Modal>
</template>