2025-04-21 19:05:00 +08:00
|
|
|
|
<script lang="ts" setup>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
import type { BpmProcessDefinitionApi } from '#/api/bpm/definition';
|
2025-05-09 20:23:19 +08:00
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
import { computed, nextTick, onMounted, ref } from 'vue';
|
2025-05-09 20:23:19 +08:00
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
|
|
2025-04-21 19:05:00 +08:00
|
|
|
|
import { Page } from '@vben/common-ui';
|
2025-04-23 12:56:35 +08:00
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Card,
|
|
|
|
|
|
Col,
|
|
|
|
|
|
InputSearch,
|
|
|
|
|
|
message,
|
|
|
|
|
|
Row,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Tabs,
|
|
|
|
|
|
Tooltip,
|
|
|
|
|
|
} from 'ant-design-vue';
|
2025-05-09 20:23:19 +08:00
|
|
|
|
|
|
|
|
|
|
import { getCategorySimpleList } from '#/api/bpm/category';
|
|
|
|
|
|
import { getProcessDefinitionList } from '#/api/bpm/definition';
|
|
|
|
|
|
import { getProcessInstance } from '#/api/bpm/processInstance';
|
|
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
import ProcessDefinitionDetail from './modules/form.vue';
|
|
|
|
|
|
|
2025-05-09 20:23:19 +08:00
|
|
|
|
defineOptions({ name: 'BpmProcessInstanceCreate' });
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute(); // 路由
|
|
|
|
|
|
|
|
|
|
|
|
const searchName = ref(''); // 当前搜索关键字
|
2025-05-12 00:53:48 +08:00
|
|
|
|
const isSearching = ref(false); // 是否处于搜索状态
|
2025-05-09 20:23:19 +08:00
|
|
|
|
const processInstanceId: any = route.query.processInstanceId; // 流程实例编号。场景:重新发起时
|
|
|
|
|
|
const loading = ref(true); // 加载中
|
|
|
|
|
|
const categoryList: any = ref([]); // 分类的列表
|
2025-05-12 00:53:48 +08:00
|
|
|
|
const activeCategory = ref(''); // 当前选中的分类
|
2025-05-09 20:23:19 +08:00
|
|
|
|
const processDefinitionList = ref([]); // 流程定义的列表
|
|
|
|
|
|
|
|
|
|
|
|
// 实现 groupBy 功能
|
|
|
|
|
|
const groupBy = (array: any[], key: string) => {
|
|
|
|
|
|
const result: Record<string, any[]> = {};
|
|
|
|
|
|
for (const item of array) {
|
|
|
|
|
|
const groupKey = item[key];
|
|
|
|
|
|
if (!result[groupKey]) {
|
|
|
|
|
|
result[groupKey] = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
result[groupKey].push(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 查询列表 */
|
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 所有流程分类数据
|
|
|
|
|
|
await getCategoryList();
|
|
|
|
|
|
// 所有流程定义数据
|
|
|
|
|
|
await handleGetProcessDefinitionList();
|
|
|
|
|
|
|
|
|
|
|
|
// 如果 processInstanceId 非空,说明是重新发起
|
|
|
|
|
|
if (processInstanceId?.length > 0) {
|
|
|
|
|
|
const processInstance = await getProcessInstance(processInstanceId);
|
|
|
|
|
|
if (!processInstance) {
|
|
|
|
|
|
message.error('重新发起流程失败,原因:流程实例不存在');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const processDefinition = processDefinitionList.value.find(
|
|
|
|
|
|
(item: any) => item.key === processInstance.processDefinition?.key,
|
|
|
|
|
|
);
|
|
|
|
|
|
if (!processDefinition) {
|
|
|
|
|
|
message.error('重新发起流程失败,原因:流程定义不存在');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
await handleSelect(processDefinition, processInstance.formVariables);
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 获取所有流程分类数据 */
|
|
|
|
|
|
const getCategoryList = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 流程分类
|
|
|
|
|
|
categoryList.value = await getCategorySimpleList();
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// 错误处理
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 获取所有流程定义数据 */
|
|
|
|
|
|
const handleGetProcessDefinitionList = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 流程定义
|
|
|
|
|
|
processDefinitionList.value = await getProcessDefinitionList({
|
|
|
|
|
|
suspensionState: 1,
|
|
|
|
|
|
});
|
|
|
|
|
|
// 初始化过滤列表为全部流程定义
|
|
|
|
|
|
filteredProcessDefinitionList.value = processDefinitionList.value;
|
|
|
|
|
|
|
|
|
|
|
|
// 在获取完所有数据后,设置第一个有效分类为激活状态
|
2025-05-12 00:53:48 +08:00
|
|
|
|
if (availableCategories.value.length > 0 && !activeCategory.value) {
|
|
|
|
|
|
activeCategory.value = availableCategories.value[0].code;
|
2025-05-09 20:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// 错误处理
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 搜索流程 */
|
|
|
|
|
|
const filteredProcessDefinitionList = ref([]); // 用于存储搜索过滤后的流程定义
|
|
|
|
|
|
const handleQuery = () => {
|
2025-05-12 00:53:48 +08:00
|
|
|
|
if (searchName.value.trim()) {
|
|
|
|
|
|
// 如果有搜索关键字,进行过滤
|
|
|
|
|
|
isSearching.value = true;
|
|
|
|
|
|
filteredProcessDefinitionList.value = processDefinitionList.value.filter(
|
|
|
|
|
|
(definition: any) =>
|
|
|
|
|
|
definition.name.toLowerCase().includes(searchName.value.toLowerCase()),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取搜索结果中的分类
|
|
|
|
|
|
const searchResultGroups = groupBy(
|
|
|
|
|
|
filteredProcessDefinitionList.value,
|
|
|
|
|
|
'category',
|
|
|
|
|
|
);
|
|
|
|
|
|
const availableCategoryCodes = Object.keys(searchResultGroups);
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有匹配的分类,切换到第一个包含匹配结果的分类
|
|
|
|
|
|
if (availableCategoryCodes.length > 0 && availableCategoryCodes[0]) {
|
|
|
|
|
|
activeCategory.value = availableCategoryCodes[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果没有搜索关键字,恢复所有数据
|
|
|
|
|
|
isSearching.value = false;
|
|
|
|
|
|
filteredProcessDefinitionList.value = processDefinitionList.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 判断流程定义是否匹配搜索 */
|
|
|
|
|
|
const isDefinitionMatchSearch = (definition: any) => {
|
|
|
|
|
|
if (!isSearching.value) return false;
|
|
|
|
|
|
return definition.name.toLowerCase().includes(searchName.value.toLowerCase());
|
2025-05-09 20:23:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 流程定义的分组 */
|
|
|
|
|
|
const processDefinitionGroup: any = computed(() => {
|
|
|
|
|
|
if (!processDefinitionList.value?.length) {
|
|
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const grouped = groupBy(filteredProcessDefinitionList.value, 'category');
|
|
|
|
|
|
// 按照 categoryList 的顺序重新组织数据
|
|
|
|
|
|
const orderedGroup = {};
|
|
|
|
|
|
categoryList.value.forEach((category: any) => {
|
|
|
|
|
|
if (grouped[category.code]) {
|
|
|
|
|
|
orderedGroup[category.code] = grouped[category.code];
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return orderedGroup;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** 通过分类 code 获取对应的名称 */
|
|
|
|
|
|
const getCategoryName = (categoryCode: string) => {
|
|
|
|
|
|
return categoryList.value?.find((ctg: any) => ctg.code === categoryCode)
|
|
|
|
|
|
?.name;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 表单相关 ==========
|
|
|
|
|
|
const selectProcessDefinition = ref(); // 选择的流程定义
|
|
|
|
|
|
const processDefinitionDetailRef = ref();
|
|
|
|
|
|
|
|
|
|
|
|
/** 处理选择流程的按钮操作 */
|
|
|
|
|
|
const handleSelect = async (
|
2025-05-12 00:53:48 +08:00
|
|
|
|
row: BpmProcessDefinitionApi.ProcessDefinitionVO,
|
2025-05-09 20:23:19 +08:00
|
|
|
|
formVariables?: any,
|
|
|
|
|
|
) => {
|
|
|
|
|
|
// 设置选择的流程
|
|
|
|
|
|
selectProcessDefinition.value = row;
|
|
|
|
|
|
// 初始化流程定义详情
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
processDefinitionDetailRef.value?.initProcessInfo(row, formVariables);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** 过滤出有流程的分类列表。目的:只展示有流程的分类 */
|
|
|
|
|
|
const availableCategories = computed(() => {
|
|
|
|
|
|
if (!categoryList.value?.length || !processDefinitionGroup.value) {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取所有有流程的分类代码
|
|
|
|
|
|
const availableCategoryCodes = Object.keys(processDefinitionGroup.value);
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤出有流程的分类
|
|
|
|
|
|
return categoryList.value.filter((category: CategoryVO) =>
|
|
|
|
|
|
availableCategoryCodes.includes(category.code),
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
/** 获取 tab 的位置 */
|
|
|
|
|
|
|
|
|
|
|
|
const tabPosition = computed(() => {
|
|
|
|
|
|
return window.innerWidth < 768 ? 'top' : 'left';
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-05-09 20:23:19 +08:00
|
|
|
|
/** 初始化 */
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
getList();
|
|
|
|
|
|
});
|
2025-04-21 19:05:00 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
<Page auto-content-height>
|
|
|
|
|
|
<!-- 第一步,通过流程定义的列表,选择对应的流程 -->
|
|
|
|
|
|
<template v-if="!selectProcessDefinition">
|
|
|
|
|
|
<Card
|
2025-05-12 00:53:48 +08:00
|
|
|
|
class="h-full"
|
|
|
|
|
|
title="全部流程"
|
2025-05-09 20:23:19 +08:00
|
|
|
|
:class="{
|
|
|
|
|
|
'process-definition-container': filteredProcessDefinitionList?.length,
|
|
|
|
|
|
}"
|
|
|
|
|
|
:loading="loading"
|
|
|
|
|
|
>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
<template #extra>
|
|
|
|
|
|
<div class="flex items-end">
|
|
|
|
|
|
<InputSearch
|
|
|
|
|
|
v-model:value="searchName"
|
|
|
|
|
|
class="!w-50% mb-15px"
|
|
|
|
|
|
placeholder="请输入流程名称检索"
|
|
|
|
|
|
allow-clear
|
|
|
|
|
|
@input="handleQuery"
|
|
|
|
|
|
@clear="handleQuery"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #prefix>
|
|
|
|
|
|
<IconifyIcon icon="mdi:search-web" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</InputSearch>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
</div>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="filteredProcessDefinitionList?.length">
|
|
|
|
|
|
<Tabs v-model:active-key="activeCategory" :tab-position="tabPosition">
|
|
|
|
|
|
<Tabs.TabPane
|
|
|
|
|
|
v-for="category in availableCategories"
|
|
|
|
|
|
:key="category.code"
|
|
|
|
|
|
:tab="category.name"
|
2025-05-09 20:23:19 +08:00
|
|
|
|
>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
<Row :gutter="[16, 16]">
|
|
|
|
|
|
<Col
|
|
|
|
|
|
v-for="definition in processDefinitionGroup[category.code]"
|
|
|
|
|
|
:key="definition.id"
|
|
|
|
|
|
:xs="24"
|
|
|
|
|
|
:sm="12"
|
|
|
|
|
|
:md="8"
|
|
|
|
|
|
:lg="6"
|
|
|
|
|
|
:xl="4"
|
|
|
|
|
|
@click="handleSelect(definition)"
|
|
|
|
|
|
>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
<Card
|
|
|
|
|
|
hoverable
|
2025-05-12 00:53:48 +08:00
|
|
|
|
class="definition-item-card w-full cursor-pointer"
|
|
|
|
|
|
:class="{
|
|
|
|
|
|
'search-match': isDefinitionMatchSearch(definition),
|
|
|
|
|
|
}"
|
|
|
|
|
|
:body-style="{
|
|
|
|
|
|
width: '100%',
|
|
|
|
|
|
}"
|
2025-05-09 20:23:19 +08:00
|
|
|
|
>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
<div class="flex items-center">
|
2025-05-09 20:23:19 +08:00
|
|
|
|
<img
|
|
|
|
|
|
v-if="definition.icon"
|
|
|
|
|
|
:src="definition.icon"
|
2025-05-13 01:04:32 +08:00
|
|
|
|
class="flow-icon-img object-contain"
|
2025-05-12 00:53:48 +08:00
|
|
|
|
alt="流程图标"
|
2025-05-09 20:23:19 +08:00
|
|
|
|
/>
|
2025-05-13 01:04:32 +08:00
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
<div v-else class="flow-icon flex-shrink-0">
|
|
|
|
|
|
<Tooltip :title="definition.name">
|
|
|
|
|
|
<span class="text-xs text-white">
|
2025-05-13 01:04:32 +08:00
|
|
|
|
{{ definition.name?.slice(0, 2) }}
|
2025-05-12 00:53:48 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</Tooltip>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
</div>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
<span class="ml-3 flex-1 truncate text-base">
|
|
|
|
|
|
<Tooltip
|
|
|
|
|
|
placement="topLeft"
|
|
|
|
|
|
:title="`${definition.name}`"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ definition.name }}
|
|
|
|
|
|
</Tooltip>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- TODO: 发起流程按钮 -->
|
|
|
|
|
|
<!-- <template #actions>
|
|
|
|
|
|
<div class="flex justify-end px-4">
|
|
|
|
|
|
<Button type="link" @click="handleSelect(definition)">
|
|
|
|
|
|
发起流程
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template> -->
|
2025-05-09 20:23:19 +08:00
|
|
|
|
</Card>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
</Tabs.TabPane>
|
|
|
|
|
|
</Tabs>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div v-else class="!py-200px text-center">
|
|
|
|
|
|
<Space direction="vertical" size="large">
|
|
|
|
|
|
<span class="text-gray-500">没有找到搜索结果</span>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 第二步,填写表单,进行流程的提交 -->
|
2025-05-12 00:53:48 +08:00
|
|
|
|
<ProcessDefinitionDetail
|
|
|
|
|
|
v-else
|
|
|
|
|
|
ref="processDefinitionDetailRef"
|
|
|
|
|
|
:select-process-definition="selectProcessDefinition"
|
|
|
|
|
|
@cancel="selectProcessDefinition = undefined"
|
|
|
|
|
|
/>
|
2025-04-21 19:05:00 +08:00
|
|
|
|
</Page>
|
2025-04-23 12:56:35 +08:00
|
|
|
|
</template>
|
2025-05-09 20:23:19 +08:00
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2025-05-12 00:53:48 +08:00
|
|
|
|
.process-definition-container {
|
|
|
|
|
|
.definition-item-card {
|
2025-05-13 01:04:32 +08:00
|
|
|
|
.flow-icon-img {
|
|
|
|
|
|
width: 48px;
|
|
|
|
|
|
height: 48px;
|
|
|
|
|
|
border-radius: 0.25rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
.flow-icon {
|
2025-05-13 01:04:32 +08:00
|
|
|
|
@apply bg-primary;
|
|
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2025-05-13 01:04:32 +08:00
|
|
|
|
width: 48px;
|
|
|
|
|
|
height: 48px;
|
|
|
|
|
|
border-radius: 0.25rem;
|
2025-05-12 00:53:48 +08:00
|
|
|
|
}
|
2025-05-09 20:23:19 +08:00
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
&.search-match {
|
|
|
|
|
|
background-color: rgb(63 115 247 / 10%);
|
2025-05-13 01:04:32 +08:00
|
|
|
|
border: 1px solid var(--primary);
|
2025-05-12 00:53:48 +08:00
|
|
|
|
animation: bounce 0.5s ease;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-09 20:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 00:53:48 +08:00
|
|
|
|
@keyframes bounce {
|
|
|
|
|
|
0%,
|
|
|
|
|
|
100% {
|
|
|
|
|
|
transform: translateY(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
50% {
|
|
|
|
|
|
transform: translateY(-5px);
|
2025-05-09 20:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|