diff --git a/apps/web-antd/src/api/bpm/definition/index.ts b/apps/web-antd/src/api/bpm/definition/index.ts index 502d5e366..146fc38a3 100644 --- a/apps/web-antd/src/api/bpm/definition/index.ts +++ b/apps/web-antd/src/api/bpm/definition/index.ts @@ -9,6 +9,7 @@ export namespace BpmProcessDefinitionApi { key?: string; version: number; name: string; + category: string; description: string; deploymentTime: number; suspensionState: number; diff --git a/apps/web-antd/src/views/bpm/processInstance/create/index.vue b/apps/web-antd/src/views/bpm/processInstance/create/index.vue index 95c1e45f4..c4cefbbfc 100644 --- a/apps/web-antd/src/views/bpm/processInstance/create/index.vue +++ b/apps/web-antd/src/views/bpm/processInstance/create/index.vue @@ -6,6 +6,7 @@ import { computed, nextTick, onMounted, ref, watch } from 'vue'; import { useRoute } from 'vue-router'; import { Page } from '@vben/common-ui'; +import { groupBy } from '@vben/utils'; import { Card, @@ -28,45 +29,33 @@ defineOptions({ name: 'BpmProcessInstanceCreate' }); const route = useRoute(); -// 当前搜索关键字 -const searchName = ref(''); -const isSearching = ref(false); -// 流程实例编号。场景:重新发起时 -const processInstanceId: any = route.query.processInstanceId; -// 加载中 -const loading = ref(true); -// 分类的列表 -const categoryList: any = ref([]); -// 当前选中的分类 -const activeCategory = ref(''); -// 流程定义的列表 +const loading = ref(true); // 加载中 +const processInstanceId: any = route.query.processInstanceId; // 流程实例编号。场景:重新发起时 + +const categoryList: any = ref([]); // 分类的列表 +const activeCategory = ref(''); // 当前选中的分类 + +const searchName = ref(''); // 当前搜索关键字 const processDefinitionList = ref( [], -); +); // 流程定义的列表 +const filteredProcessDefinitionList = ref< + BpmProcessDefinitionApi.ProcessDefinition[] +>([]); // 用于存储搜索过滤后的流程定义 -// 实现 groupBy 功能 -function groupBy(array: any[], key: string) { - const result: Record = {}; - for (const item of array) { - const groupKey = item[key]; - if (!result[groupKey]) { - result[groupKey] = []; - } - result[groupKey].push(item); - } - return result; -} +const selectProcessDefinition = ref(); // 选择的流程定义 +const processDefinitionDetailRef = ref(); /** 查询列表 */ async function getList() { loading.value = true; try { - // 所有流程分类数据 - await getCategoryList(); - // 所有流程定义数据 - await handleGetProcessDefinitionList(); + // 1.1 所有流程分类数据 + await loadCategoryList(); + // 1.2 所有流程定义数据 + await loadProcessDefinitionList(); - // 如果 processInstanceId 非空,说明是重新发起 + // 2. 如果 processInstanceId 非空,说明是重新发起 if (processInstanceId?.length > 0) { const processInstance = await getProcessInstance(processInstanceId); if (!processInstance) { @@ -88,65 +77,34 @@ async function getList() { } /** 获取所有流程分类数据 */ -async function getCategoryList() { - try { - // 流程分类 - categoryList.value = await getCategorySimpleList(); - } catch { - // 错误处理 - } +async function loadCategoryList() { + categoryList.value = await getCategorySimpleList(); } /** 获取所有流程定义数据 */ -async function handleGetProcessDefinitionList() { - try { - // 流程定义 - processDefinitionList.value = await getProcessDefinitionList({ - suspensionState: 1, - }); - // 初始化过滤列表为全部流程定义 - filteredProcessDefinitionList.value = processDefinitionList.value; +async function loadProcessDefinitionList() { + // 流程定义 + processDefinitionList.value = await getProcessDefinitionList({ + suspensionState: 1, + }); - // 在获取完所有数据后,设置第一个有效分类为激活状态 - if (availableCategories.value.length > 0 && !activeCategory.value) { - activeCategory.value = availableCategories.value[0].code; - } - } catch { - // 错误处理 - } + // 空搜索,初始化相关数据 + handleQuery(); } -/** 用于存储搜索过滤后的流程定义 */ -const filteredProcessDefinitionList = ref< - BpmProcessDefinitionApi.ProcessDefinition[] ->([]); - /** 搜索流程 */ function handleQuery() { 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]; - } + // 如果有匹配,切换到第一个包含匹配结果的分类 + activeCategory.value = availableCategories.value[0]?.name; } else { // 如果没有搜索关键字,恢复所有数据 - isSearching.value = false; filteredProcessDefinitionList.value = processDefinitionList.value; - // 恢复到第一个可用分类 if (availableCategories.value.length > 0) { activeCategory.value = availableCategories.value[0].code; @@ -154,20 +112,13 @@ function handleQuery() { } } -/** 判断流程定义是否匹配搜索 */ -function isDefinitionMatchSearch(definition: any) { - if (!isSearching.value) return false; - return definition.name.toLowerCase().includes(searchName.value.toLowerCase()); -} - /** 流程定义的分组 */ const processDefinitionGroup = computed(() => { if (!processDefinitionList.value?.length) { return {}; } - - const grouped = groupBy(filteredProcessDefinitionList.value, 'category'); // 按照 categoryList 的顺序重新组织数据 + const grouped = groupBy(filteredProcessDefinitionList.value, 'category'); const orderedGroup: Record< string, BpmProcessDefinitionApi.ProcessDefinition[] @@ -182,17 +133,6 @@ const processDefinitionGroup = computed(() => { return orderedGroup; }); -/** 通过分类 code 获取对应的名称 */ -// eslint-disable-next-line no-unused-vars -function _getCategoryName(categoryCode: string) { - return categoryList.value?.find((ctg: any) => ctg.code === categoryCode) - ?.name; -} - -// ========== 表单相关 ========== -const selectProcessDefinition = ref(); // 选择的流程定义 -const processDefinitionDetailRef = ref(); - /** 处理选择流程的按钮操作 */ async function handleSelect( row: BpmProcessDefinitionApi.ProcessDefinition, @@ -210,21 +150,14 @@ const availableCategories = computed(() => { if (!categoryList.value?.length || !processDefinitionGroup.value) { return []; } - // 获取所有有流程的分类代码 const availableCategoryCodes = Object.keys(processDefinitionGroup.value); - // 过滤出有流程的分类 return categoryList.value.filter((category: BpmCategoryApi.Category) => availableCategoryCodes.includes(category.code), ); }); -/** 获取 tab 的位置 */ -const tabPosition = computed(() => { - return window.innerWidth < 768 ? 'top' : 'left'; -}); - /** 监听可用分类变化,自动设置正确的活动分类 */ watch( availableCategories, @@ -251,7 +184,7 @@ onMounted(() => {