fix(我的事项、产品/项目、工作台我的待办): 修复已知的一些问题。

This commit is contained in:
dk
2026-06-30 11:55:43 +08:00
parent 4f357a35a9
commit a650f6e96d
11 changed files with 373 additions and 109 deletions

View File

@@ -1,6 +1,10 @@
<script setup lang="ts">
import { computed, reactive, ref, watch } from 'vue';
import { fetchGetPersonalItemExecutionOptions } from '@/service/api';
import {
fetchGetMyOwnedProjectPage,
fetchGetMyParticipatedProjectPage,
fetchGetProjectExecutionPage
} from '@/service/api';
import { useForm, useFormRules } from '@/hooks/common/form';
import BusinessFormDialog from '@/components/custom/business-form-dialog.vue';
@@ -28,44 +32,113 @@ const visible = defineModel<boolean>('visible', {
const { formRef, validate } = useForm();
const { createRequiredRule } = useFormRules();
const loading = ref(false);
const executionOptions = ref<Api.PersonalItem.PersonalItemExecutionOption[]>([]);
interface ProjectOption {
label: string;
value: string;
}
interface ExecutionOption {
label: string;
value: string;
}
const projectLoading = ref(false);
const executionLoading = ref(false);
const projectOptions = ref<ProjectOption[]>([]);
const executionOptions = ref<ExecutionOption[]>([]);
const loading = computed(() => projectLoading.value || executionLoading.value);
const model = reactive({
projectId: '',
executionId: ''
});
const rules = computed(
() =>
({
projectId: [createRequiredRule('请选择项目')],
executionId: [createRequiredRule('请选择执行')]
}) satisfies Record<string, App.Global.FormRule[]>
);
function getExecutionOptionLabel(option: Api.PersonalItem.PersonalItemExecutionOption) {
if (option.projectName?.trim()) {
return `${option.projectName} / ${option.executionName}`;
}
function createProjectOptions(
participated: Api.Project.MyParticipatedProjectItem[],
owned: Api.Project.MyOwnedProjectItem[]
): ProjectOption[] {
const optionMap = new Map<string, ProjectOption>();
return option.executionName;
owned.forEach(item => {
if (!item.id || !item.name?.trim()) return;
optionMap.set(item.id, {
label: item.name.trim(),
value: item.id
});
});
participated.forEach(item => {
if (!item.id || !item.name?.trim()) return;
if (item.statusCode === 'completed' || item.statusCode === 'cancelled' || item.statusCode === 'archived') {
return;
}
if (!optionMap.has(item.id)) {
optionMap.set(item.id, {
label: item.name.trim(),
value: item.id
});
}
});
return Array.from(optionMap.values());
}
async function loadExecutionOptions() {
loading.value = true;
const { error, data } = await fetchGetPersonalItemExecutionOptions();
loading.value = false;
async function loadProjectOptions() {
projectLoading.value = true;
const [participatedResult, ownedResult] = await Promise.all([
fetchGetMyParticipatedProjectPage({ pageNo: 1, pageSize: -1 }),
fetchGetMyOwnedProjectPage({ pageNo: 1, pageSize: -1 })
]);
projectLoading.value = false;
if (participatedResult.error || ownedResult.error || !participatedResult.data || !ownedResult.data) {
projectOptions.value = [];
executionOptions.value = [];
return;
}
projectOptions.value = createProjectOptions(participatedResult.data.list, ownedResult.data.list);
}
async function loadExecutionOptions(projectId: string) {
if (!projectId) {
executionOptions.value = [];
return;
}
executionLoading.value = true;
const { error, data } = await fetchGetProjectExecutionPage(projectId, {
pageNo: 1,
pageSize: -1
});
executionLoading.value = false;
if (error || !data) {
executionOptions.value = [];
return;
}
executionOptions.value = data.map(item => ({ ...item }));
executionOptions.value = data.list
.filter(item => !item.terminal && item.statusCode !== 'completed' && item.statusCode !== 'cancelled')
.map(item => ({
label: item.executionName,
value: item.id
}));
}
async function initDialog() {
model.projectId = '';
model.executionId = '';
await loadExecutionOptions();
executionOptions.value = [];
await loadProjectOptions();
formRef.value?.clearValidate();
}
@@ -85,42 +158,84 @@ watch(
}
}
);
watch(
() => model.projectId,
async (projectId, previousProjectId) => {
if (projectId === previousProjectId) return;
model.executionId = '';
if (!projectId) {
executionOptions.value = [];
formRef.value?.clearValidate('executionId');
return;
}
await loadExecutionOptions(projectId);
formRef.value?.clearValidate('executionId');
}
);
</script>
<template>
<BusinessFormDialog
v-model="visible"
title="批量关联执行"
preset="sm"
preset="md"
:loading="loading"
:confirm-loading="props.submitLoading"
@confirm="handleConfirm"
>
<ElAlert
:title="`已选中 ${props.selectedCount} 条个人事项,关联成功后这些事项会从当前列表移除。`"
:title="`已选中 ${props.selectedCount} 条我的事项,关联成功后这些事项会从当前列表移除。`"
type="info"
:closable="false"
class="mb-16px"
/>
<ElForm ref="formRef" :model="model" :rules="rules" label-position="top" :validate-on-rule-change="false">
<ElFormItem label="执行" prop="executionId">
<ElSelect
v-model="model.executionId"
clearable
filterable
placeholder="请选择执行"
class="w-full"
:loading="loading"
>
<ElOption
v-for="option in executionOptions"
:key="option.executionId"
:label="getExecutionOptionLabel(option)"
:value="option.executionId"
/>
</ElSelect>
</ElFormItem>
<ElRow :gutter="16">
<ElCol :span="12">
<ElFormItem label="项目" prop="projectId">
<ElSelect
v-model="model.projectId"
clearable
filterable
placeholder="请选择项目"
class="w-full"
:loading="projectLoading"
>
<ElOption
v-for="option in projectOptions"
:key="option.value"
:label="option.label"
:value="option.value"
/>
</ElSelect>
</ElFormItem>
</ElCol>
<ElCol :span="12">
<ElFormItem label="执行" prop="executionId">
<ElSelect
v-model="model.executionId"
clearable
filterable
placeholder="请选择执行"
class="w-full"
:loading="executionLoading"
:disabled="!model.projectId"
>
<ElOption
v-for="option in executionOptions"
:key="option.value"
:label="option.label"
:value="option.value"
/>
</ElSelect>
</ElFormItem>
</ElCol>
</ElRow>
</ElForm>
</BusinessFormDialog>
</template>