清除“Task”模块
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { apiGet } from "./axios";
|
||||
import type { ApiListResponse, Study, UserInfo } from "../types/api";
|
||||
import type { ApiListResponse } from "../types/api";
|
||||
|
||||
export const fetchProgress = (studyId: string) =>
|
||||
apiGet(`/api/v1/studies/${studyId}/dashboard/progress`);
|
||||
@@ -12,8 +12,3 @@ export const fetchOverdueAesCount = (studyId: string) =>
|
||||
|
||||
export const fetchOverdueQueriesCount = (studyId: string) =>
|
||||
apiGet<ApiListResponse<any>>(`/api/v1/studies/${studyId}/data-queries/`, { params: { overdue: true, limit: 1 } });
|
||||
|
||||
export const fetchMyTodoTasks = (studyId: string, assigneeId: string) =>
|
||||
apiGet<ApiListResponse<any>>(`/api/v1/studies/${studyId}/tasks/`, {
|
||||
params: { assignee_id: assigneeId, status: "TODO" },
|
||||
});
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { apiGet, apiPost, apiPatch } from "./axios";
|
||||
import type { ApiListResponse } from "../types/api";
|
||||
|
||||
export const fetchTasks = (studyId: string, params?: Record<string, any>) =>
|
||||
apiGet<ApiListResponse<any>>(`/api/v1/studies/${studyId}/tasks/`, { params });
|
||||
|
||||
export const createTask = (studyId: string, payload: Record<string, any>) =>
|
||||
apiPost(`/api/v1/studies/${studyId}/tasks/`, payload);
|
||||
|
||||
export const updateTask = (studyId: string, taskId: string, payload: Record<string, any>) =>
|
||||
apiPatch(`/api/v1/studies/${studyId}/tasks/${taskId}`, payload);
|
||||
@@ -22,11 +22,6 @@ export const auditDict: Record<
|
||||
actionText: "重置了用户密码",
|
||||
targetLabel: "用户账号",
|
||||
},
|
||||
TASK_STATUS_CHANGED: {
|
||||
label: "任务状态变更",
|
||||
actionText: "更新了任务状态",
|
||||
targetLabel: "任务",
|
||||
},
|
||||
ISSUE_STATUS_CHANGED: {
|
||||
label: "风险/问题状态变更",
|
||||
actionText: "更新了风险/问题状态",
|
||||
@@ -67,11 +62,6 @@ export const auditDict: Record<
|
||||
actionText: "导出了项目审计日志",
|
||||
targetLabel: "审计日志",
|
||||
},
|
||||
TASK_COMPLETE: {
|
||||
label: "任务完成",
|
||||
actionText: "完成了任务",
|
||||
targetLabel: "任务",
|
||||
},
|
||||
FINANCE_APPROVED: {
|
||||
label: "费用审批",
|
||||
actionText: "审批通过费用",
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
<template v-if="study.currentStudy">
|
||||
<el-menu-item index="/study/home">项目概览</el-menu-item>
|
||||
<el-menu-item index="/study/milestones">伦理与启动管理</el-menu-item>
|
||||
<el-menu-item index="/study/tasks">任务</el-menu-item>
|
||||
<el-menu-item index="/study/subjects">受试者</el-menu-item>
|
||||
<el-menu-item index="/study/aes">不良事件</el-menu-item>
|
||||
<el-menu-item index="/study/issues">风险与问题</el-menu-item>
|
||||
|
||||
@@ -14,7 +14,7 @@ import { useRouter } from "vue-router";
|
||||
const router = useRouter();
|
||||
|
||||
const actions = [
|
||||
{ label: "任务", path: "/study/tasks" },
|
||||
{ label: "伦理与启动", path: "/study/milestones" },
|
||||
{ label: "受试者", path: "/study/subjects" },
|
||||
{ label: "AE", path: "/study/aes" },
|
||||
{ label: "数据问题", path: "/study/data-queries" },
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
<template>
|
||||
<el-dialog :title="isEdit ? '编辑任务' : '新增任务'" v-model="visible" width="600px" @close="onClose">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="标题" prop="title">
|
||||
<el-input v-model="form.title" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="里程碑" prop="milestone_id">
|
||||
<el-select v-model="form.milestone_id" placeholder="请选择">
|
||||
<el-option v-for="m in milestones" :key="m.id" :label="m.name" :value="m.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="负责人" prop="assignee_id">
|
||||
<el-select v-model="form.assignee_id" placeholder="选择负责人" filterable clearable>
|
||||
<el-option v-for="m in assigneeOptions" :key="m.value" :label="m.label" :value="m.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="优先级" prop="priority">
|
||||
<el-select v-model="form.priority" placeholder="请选择">
|
||||
<el-option v-for="p in priorities" :key="p" :label="priorityLabel(p)" :value="p" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="截止日期" prop="due_date">
|
||||
<el-date-picker v-model="form.due_date" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" placeholder="请选择">
|
||||
<el-option v-for="s in statuses" :key="s" :label="statusLabel(s)" :value="s" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="onClose">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="onSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from "vue";
|
||||
import type { FormInstance, FormRules } from "element-plus";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { createTask, updateTask } from "../api/tasks";
|
||||
import { useStudyStore } from "../store/study";
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean;
|
||||
task?: Record<string, any>;
|
||||
milestones: any[];
|
||||
members?: any[];
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits(["update:modelValue", "success"]);
|
||||
|
||||
const formRef = ref<FormInstance>();
|
||||
const study = useStudyStore();
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v: boolean) => emit("update:modelValue", v),
|
||||
});
|
||||
|
||||
const priorities = ["LOW", "MEDIUM", "HIGH"];
|
||||
const statuses = ["TODO", "DOING", "DONE", "BLOCKED"];
|
||||
const priorityLabel = (v: string) => ({ LOW: "低", MEDIUM: "中", HIGH: "高" }[v] || v);
|
||||
const statusLabel = (v: string) =>
|
||||
({
|
||||
TODO: "待处理",
|
||||
DOING: "进行中",
|
||||
DONE: "已完成",
|
||||
BLOCKED: "阻塞",
|
||||
}[v] || v);
|
||||
|
||||
const form = reactive({
|
||||
title: "",
|
||||
description: "",
|
||||
milestone_id: "",
|
||||
assignee_id: "",
|
||||
priority: "MEDIUM",
|
||||
due_date: "",
|
||||
status: "TODO",
|
||||
});
|
||||
|
||||
const rules: FormRules = {
|
||||
title: [{ required: true, message: "请输入标题", trigger: "blur" }],
|
||||
priority: [{ required: true, message: "请选择优先级", trigger: "change" }],
|
||||
status: [{ required: true, message: "请选择状态", trigger: "change" }],
|
||||
};
|
||||
|
||||
const submitting = ref(false);
|
||||
const isEdit = computed(() => !!props.task);
|
||||
const assigneeOptions = computed(() => {
|
||||
const seen = new Set<string>();
|
||||
return (props.members || [])
|
||||
.filter((m: any) => m.is_active !== false)
|
||||
.map((m: any) => {
|
||||
const user = m.user || {};
|
||||
return { value: m.user_id, label: user.display_name || user.username || m.username || "—" };
|
||||
})
|
||||
.filter((opt) => {
|
||||
if (seen.has(opt.value)) return false;
|
||||
seen.add(opt.value);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.task,
|
||||
(val) => {
|
||||
if (val) {
|
||||
form.title = val.title || "";
|
||||
form.description = val.description || "";
|
||||
form.milestone_id = val.milestone_id || "";
|
||||
form.assignee_id = val.assignee_id || "";
|
||||
form.priority = val.priority || "MEDIUM";
|
||||
form.due_date = val.due_date || "";
|
||||
form.status = val.status || "TODO";
|
||||
} else {
|
||||
form.title = "";
|
||||
form.description = "";
|
||||
form.milestone_id = "";
|
||||
form.assignee_id = "";
|
||||
form.priority = "MEDIUM";
|
||||
form.due_date = "";
|
||||
form.status = "TODO";
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const onClose = () => {
|
||||
visible.value = false;
|
||||
};
|
||||
|
||||
const onSubmit = async () => {
|
||||
if (!formRef.value) return;
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return;
|
||||
if (!study.currentStudy) {
|
||||
ElMessage.error("未选择项目");
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
const payload: Record<string, any> = {};
|
||||
Object.entries(form).forEach(([k, v]) => {
|
||||
if (v !== "" && v !== null && v !== undefined) {
|
||||
payload[k] = v;
|
||||
}
|
||||
});
|
||||
if (isEdit.value && props.task) {
|
||||
await updateTask(study.currentStudy.id, props.task.id, payload);
|
||||
} else {
|
||||
await createTask(study.currentStudy.id, payload);
|
||||
}
|
||||
ElMessage.success("提交成功");
|
||||
emit("success");
|
||||
onClose();
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "提交失败");
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
@@ -5,7 +5,6 @@ import Layout from "../components/Layout.vue";
|
||||
import Login from "../views/Login.vue";
|
||||
import StudyList from "../views/StudyList.vue";
|
||||
import StudyHome from "../views/StudyHome.vue";
|
||||
import Tasks from "../views/Tasks.vue";
|
||||
import Milestones from "../views/Milestones.vue";
|
||||
import MilestoneDetail from "../views/MilestoneDetail.vue";
|
||||
import Subjects from "../views/Subjects.vue";
|
||||
@@ -58,12 +57,6 @@ const routes: RouteRecordRaw[] = [
|
||||
component: StudyHome,
|
||||
meta: { title: "项目首页", requiresStudy: true },
|
||||
},
|
||||
{
|
||||
path: "study/tasks",
|
||||
name: "StudyTasks",
|
||||
component: Tasks,
|
||||
meta: { title: "任务", requiresStudy: true },
|
||||
},
|
||||
{
|
||||
path: "study/milestones",
|
||||
name: "StudyMilestones",
|
||||
|
||||
@@ -23,7 +23,6 @@ export const canDoAction = (machine: StateMachine, actionKey: string, currentSta
|
||||
};
|
||||
|
||||
export * from "./types";
|
||||
export * from "./task.machine";
|
||||
export * from "./subject.machine";
|
||||
export * from "./ae.machine";
|
||||
export * from "./finance.machine";
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import type { StateMachine } from "./types";
|
||||
|
||||
export const taskMachine: StateMachine = {
|
||||
states: {
|
||||
TODO: { value: "TODO", label: "待处理", color: "info" },
|
||||
DONE: { value: "DONE", label: "已完成", color: "success", isTerminal: true },
|
||||
},
|
||||
actions: {
|
||||
complete: {
|
||||
key: "complete",
|
||||
label: "完成",
|
||||
from: ["TODO"],
|
||||
to: "DONE",
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -3,8 +3,6 @@ import { useAuthStore } from "../store/auth";
|
||||
import { useStudyStore } from "../store/study";
|
||||
|
||||
const PERMISSIONS: Record<string, string[]> = {
|
||||
"task.create": ["ADMIN", "PM"],
|
||||
"task.edit": ["ADMIN", "PM"],
|
||||
"milestone.create": ["ADMIN", "PM"],
|
||||
"subject.create": ["ADMIN", "PM", "CRA"],
|
||||
"subject.enroll": ["ADMIN", "PM", "CRA"],
|
||||
@@ -26,8 +24,6 @@ const PERMISSIONS: Record<string, string[]> = {
|
||||
};
|
||||
|
||||
const REASONS: Record<string, string> = {
|
||||
"task.create": "仅项目负责人可以创建任务",
|
||||
"task.edit": "仅项目负责人可以编辑任务",
|
||||
"milestone.create": "仅项目负责人可以维护里程碑",
|
||||
"subject.enroll": "仅 PM/CRA 可更新受试者状态",
|
||||
"subject.complete": "仅 PM/CRA 可更新受试者状态",
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
|
||||
<el-row :gutter="16" class="kpi-row">
|
||||
<el-col :span="6">
|
||||
<KpiCard title="任务完成率" :value="formatPercent(progress?.completion_rate)" :loading="loading.progress" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<KpiCard title="逾期任务" :value="progress?.tasks_overdue ?? 0" :loading="loading.progress" />
|
||||
<KpiCard
|
||||
title="节点完成率"
|
||||
:value="milestoneCompletionRate"
|
||||
:subtext="milestoneCompletionText"
|
||||
:loading="loading.progress"
|
||||
/>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<KpiCard title="逾期 AE" :value="overdueAes" :loading="loading.overdueAes" />
|
||||
@@ -32,15 +34,12 @@
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-card class="section-card" header="我的待办任务">
|
||||
<el-alert v-if="errors.tasks" type="warning" :title="errors.tasks" show-icon class="mb-8" />
|
||||
<el-table v-else :data="todoTasks" style="width: 100%" v-loading="loading.tasks" @row-click="goTasks">
|
||||
<el-table-column prop="title" label="标题" />
|
||||
<el-table-column prop="priority" label="优先级" width="100" />
|
||||
<el-table-column prop="status" label="状态" width="120" />
|
||||
<el-table-column prop="due_date" label="截止日期" width="140" />
|
||||
</el-table>
|
||||
</el-card>
|
||||
<el-alert
|
||||
type="info"
|
||||
title="任务模块已并入伦理与启动管理,请在节点下处理相关事项"
|
||||
show-icon
|
||||
class="section-card"
|
||||
/>
|
||||
|
||||
<QuickActions class="mt-16" />
|
||||
</div>
|
||||
@@ -50,39 +49,38 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { ElAlert } from "element-plus";
|
||||
import { useRouter } from "vue-router";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { fetchFinanceSummary, fetchMyTodoTasks, fetchOverdueAesCount, fetchOverdueQueriesCount, fetchProgress } from "../api/dashboard";
|
||||
import { fetchFinanceSummary, fetchOverdueAesCount, fetchOverdueQueriesCount, fetchProgress } from "../api/dashboard";
|
||||
import KpiCard from "../components/KpiCard.vue";
|
||||
import QuickActions from "../components/QuickActions.vue";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const study = useStudyStore();
|
||||
const router = useRouter();
|
||||
|
||||
const progress = ref<any>(null);
|
||||
const financeSummary = ref<any>(null);
|
||||
const todoTasks = ref<any[]>([]);
|
||||
const overdueAes = ref<number>(0);
|
||||
const overdueQueries = ref<number>(0);
|
||||
|
||||
const loading = ref({
|
||||
progress: false,
|
||||
finance: false,
|
||||
tasks: false,
|
||||
overdueAes: false,
|
||||
overdueQueries: false,
|
||||
});
|
||||
|
||||
const errors = ref({
|
||||
progress: "",
|
||||
finance: "",
|
||||
tasks: "",
|
||||
overdueAes: "",
|
||||
overdueQueries: "",
|
||||
const milestoneCompletionRate = computed(() => {
|
||||
const total = progress.value?.milestones_total ?? 0;
|
||||
if (!total) return "-";
|
||||
return formatPercent((progress.value?.milestones_done ?? 0) / total);
|
||||
});
|
||||
|
||||
const milestoneCompletionText = computed(() => {
|
||||
const total = progress.value?.milestones_total ?? 0;
|
||||
const done = progress.value?.milestones_done ?? 0;
|
||||
return total ? `已完成 ${done}/${total}` : "暂无节点数据";
|
||||
});
|
||||
|
||||
const formatPercent = (v?: number | null) => {
|
||||
@@ -90,61 +88,38 @@ const formatPercent = (v?: number | null) => {
|
||||
return `${(v * 100).toFixed(0)}%`;
|
||||
};
|
||||
|
||||
const goTasks = () => {
|
||||
if (study.currentStudy) {
|
||||
router.push("/study/tasks");
|
||||
}
|
||||
};
|
||||
|
||||
const loadData = async () => {
|
||||
const studyId = study.currentStudy?.id;
|
||||
const userId = auth.user?.id;
|
||||
if (!studyId || !userId) return;
|
||||
if (!studyId) return;
|
||||
|
||||
loading.value.progress = true;
|
||||
loading.value.finance = true;
|
||||
loading.value.tasks = true;
|
||||
loading.value.overdueAes = true;
|
||||
loading.value.overdueQueries = true;
|
||||
|
||||
try {
|
||||
const [pRes, fRes, aesRes, dqRes, tasksRes] = await Promise.allSettled([
|
||||
const [pRes, fRes, aesRes, dqRes] = await Promise.allSettled([
|
||||
fetchProgress(studyId),
|
||||
fetchFinanceSummary(studyId),
|
||||
fetchOverdueAesCount(studyId),
|
||||
fetchOverdueQueriesCount(studyId),
|
||||
fetchMyTodoTasks(studyId, userId),
|
||||
]);
|
||||
|
||||
if (pRes.status === "fulfilled") {
|
||||
progress.value = pRes.value.data;
|
||||
} else {
|
||||
errors.value.progress = "进度数据加载失败";
|
||||
}
|
||||
if (fRes.status === "fulfilled") {
|
||||
financeSummary.value = fRes.value.data;
|
||||
} else {
|
||||
errors.value.finance = "费用汇总加载失败";
|
||||
}
|
||||
if (aesRes.status === "fulfilled") {
|
||||
overdueAes.value = aesRes.value.data?.total ?? 0;
|
||||
} else {
|
||||
errors.value.overdueAes = "逾期 AE 加载失败";
|
||||
}
|
||||
if (dqRes.status === "fulfilled") {
|
||||
overdueQueries.value = dqRes.value.data?.total ?? 0;
|
||||
} else {
|
||||
errors.value.overdueQueries = "逾期数据问题加载失败";
|
||||
}
|
||||
if (tasksRes.status === "fulfilled") {
|
||||
todoTasks.value = tasksRes.value.data?.items ?? [];
|
||||
} else {
|
||||
errors.value.tasks = "待办任务加载失败";
|
||||
}
|
||||
} finally {
|
||||
loading.value.progress = false;
|
||||
loading.value.finance = false;
|
||||
loading.value.tasks = false;
|
||||
loading.value.overdueAes = false;
|
||||
loading.value.overdueQueries = false;
|
||||
}
|
||||
|
||||
@@ -1,351 +0,0 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<el-card class="mb-12">
|
||||
<div class="filters">
|
||||
<el-select v-model="filters.status" placeholder="状态" clearable @change="loadTasks">
|
||||
<el-option v-for="opt in statusOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
<el-select v-model="filters.milestone_id" placeholder="里程碑" clearable @change="loadTasks">
|
||||
<el-option v-for="m in milestones" :key="m.id" :label="m.name" :value="m.id" />
|
||||
</el-select>
|
||||
<el-select
|
||||
v-model="filters.assignee_id"
|
||||
placeholder="负责人"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 200px"
|
||||
@change="loadTasks"
|
||||
>
|
||||
<el-option v-for="opt in assigneeOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
<div class="spacer" />
|
||||
<PermissionAction action="task.create">
|
||||
<el-button type="primary" @click="openCreate">新建任务</el-button>
|
||||
</PermissionAction>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card>
|
||||
<el-table :data="tasks" v-loading="loading" style="width: 100%">
|
||||
<el-table-column prop="title" label="标题" />
|
||||
<el-table-column prop="milestone_id" label="节点/里程碑">
|
||||
<template #default="scope">
|
||||
{{ milestoneName(scope.row.milestone_id) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="assignee_id" label="负责人" width="160">
|
||||
<template #default="scope">
|
||||
{{ assigneeName(scope.row.assignee_id) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="priority" label="优先级" width="100">
|
||||
<template #default="scope">
|
||||
<el-tag :type="priorityColor(scope.row.priority)">{{ priorityLabel(scope.row.priority) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="120">
|
||||
<template #default="scope">
|
||||
<el-tag :type="statusColor(scope.row.status)">{{ statusLabel(scope.row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="due_date" label="截止日期" width="140" />
|
||||
<el-table-column label="操作" width="200">
|
||||
<template #default="scope">
|
||||
<PermissionAction action="task.edit">
|
||||
<el-button type="primary" link size="small" @click="openEdit(scope.row)">编辑</el-button>
|
||||
</PermissionAction>
|
||||
<el-button
|
||||
v-if="showComplete(scope.row)"
|
||||
type="success"
|
||||
size="small"
|
||||
@click.stop="onComplete(scope.row)"
|
||||
>
|
||||
完成
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="pagination"
|
||||
layout="prev, pager, next"
|
||||
:page-size="pageSize"
|
||||
:current-page="page"
|
||||
:total="total"
|
||||
@current-change="onPageChange"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<TaskForm
|
||||
v-model="showForm"
|
||||
:task="editingTask"
|
||||
:milestones="milestones"
|
||||
:members="members"
|
||||
@success="loadTasks"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { fetchTasks, updateTask } from "../api/tasks";
|
||||
import { fetchMilestones } from "../api/milestones";
|
||||
import { listMembers } from "../api/members";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import PermissionAction from "../components/PermissionAction.vue";
|
||||
import { usePermission } from "../utils/permission";
|
||||
import TaskForm from "../components/TaskForm.vue";
|
||||
import { getDictColor, getDictLabel, getDictOptions, statusDict, priorityDict } from "../dictionaries";
|
||||
import { getAvailableActions, taskMachine } from "../state-machine";
|
||||
import { evaluateAction } from "../guards/actionGuard";
|
||||
import { logAudit } from "../audit";
|
||||
|
||||
const study = useStudyStore();
|
||||
const auth = useAuthStore();
|
||||
|
||||
const tasks = ref<any[]>([]);
|
||||
const milestones = ref<any[]>([]);
|
||||
const members = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
const pageSize = 10;
|
||||
|
||||
const statusOptions = getDictOptions(statusDict).filter((opt) => ["TODO", "DOING", "DONE", "BLOCKED"].includes(opt.value));
|
||||
|
||||
const filters = ref({
|
||||
status: "",
|
||||
milestone_id: "",
|
||||
assignee_id: "",
|
||||
});
|
||||
|
||||
const showForm = ref(false);
|
||||
const editingTask = ref<any | null>(null);
|
||||
|
||||
const { can } = usePermission();
|
||||
const milestoneMap = computed(() =>
|
||||
milestones.value.reduce<Record<string, string>>((acc, cur) => {
|
||||
acc[cur.id] = cur.name || cur.id;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
const memberMap = computed(() =>
|
||||
members.value.reduce<Record<string, string>>((acc, cur) => {
|
||||
const username = cur?.user?.display_name || cur?.user?.username || cur?.username;
|
||||
if (cur?.user_id) acc[cur.user_id] = username || cur.user_id;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
const assigneeOptions = computed(() => {
|
||||
const seen = new Set<string>();
|
||||
return members.value
|
||||
.filter((m) => m.is_active !== false)
|
||||
.map((m) => {
|
||||
const user = m.user || {};
|
||||
return { value: m.user_id, label: user.display_name || user.username || m.username || "—" };
|
||||
})
|
||||
.filter((opt) => {
|
||||
if (seen.has(opt.value)) return false;
|
||||
seen.add(opt.value);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
const loadMilestones = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
try {
|
||||
const { data } = await fetchMilestones(study.currentStudy.id);
|
||||
milestones.value = data.items || data; // 兼容
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "里程碑加载失败");
|
||||
}
|
||||
};
|
||||
|
||||
const loadMembers = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
try {
|
||||
const { data } = await listMembers(study.currentStudy.id, { limit: 500 });
|
||||
members.value = Array.isArray(data) ? data : data.items || [];
|
||||
} catch {
|
||||
members.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadTasks = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: Record<string, any> = {
|
||||
skip: (page.value - 1) * pageSize,
|
||||
limit: pageSize,
|
||||
};
|
||||
if (filters.value.status) params.status = filters.value.status;
|
||||
if (filters.value.milestone_id) params.milestone_id = filters.value.milestone_id;
|
||||
if (filters.value.assignee_id) params.assignee_id = filters.value.assignee_id;
|
||||
|
||||
const { data } = await fetchTasks(study.currentStudy.id, params);
|
||||
if (Array.isArray(data)) {
|
||||
tasks.value = data;
|
||||
total.value = data.length;
|
||||
} else {
|
||||
tasks.value = data.items || [];
|
||||
total.value = data.total || tasks.value.length;
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "任务加载失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onPageChange = (p: number) => {
|
||||
page.value = p;
|
||||
loadTasks();
|
||||
};
|
||||
|
||||
const openCreate = () => {
|
||||
editingTask.value = null;
|
||||
showForm.value = true;
|
||||
};
|
||||
|
||||
const openEdit = (row: any) => {
|
||||
editingTask.value = row;
|
||||
showForm.value = true;
|
||||
};
|
||||
|
||||
const ensureUser = async () => {
|
||||
if (!auth.user && auth.token) {
|
||||
try {
|
||||
await auth.fetchMe();
|
||||
} catch {
|
||||
// ignore, canEdit 将保持 false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const filterKey = computed(() => (study.currentStudy ? `tasks_filter_${study.currentStudy.id}` : null));
|
||||
const saveFilters = () => {
|
||||
if (!filterKey.value) return;
|
||||
localStorage.setItem(filterKey.value, JSON.stringify({ ...filters.value, page: page.value }));
|
||||
};
|
||||
const loadSavedFilters = () => {
|
||||
if (!filterKey.value) return;
|
||||
const raw = localStorage.getItem(filterKey.value);
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
filters.value.status = parsed.status || "";
|
||||
filters.value.milestone_id = parsed.milestone_id || "";
|
||||
filters.value.assignee_id = parsed.assignee_id || "";
|
||||
page.value = parsed.page || 1;
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const statusLabel = (v: string) => getDictLabel(statusDict, v);
|
||||
const statusColor = (v: string) => getDictColor(statusDict, v) || "info";
|
||||
const priorityLabel = (v: string) => getDictLabel(priorityDict, v);
|
||||
const priorityColor = (v: string) => getDictColor(priorityDict, v) || "info";
|
||||
|
||||
const milestoneName = (id: string) => milestoneMap.value[id] || id || "-";
|
||||
const assigneeName = (id: string) => {
|
||||
const fromPayload = tasks.value.find((t) => t.assignee_id === id)?.assignee;
|
||||
return (
|
||||
fromPayload?.display_name ||
|
||||
fromPayload?.username ||
|
||||
memberMap.value[id] ||
|
||||
id ||
|
||||
"-"
|
||||
);
|
||||
};
|
||||
|
||||
const showComplete = (row: any) => {
|
||||
const actions = getAvailableActions(taskMachine, row.status);
|
||||
const hasComplete = actions.some((a) => a.key === "complete");
|
||||
if (!hasComplete) return false;
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "task.edit",
|
||||
stateMachine: taskMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "complete",
|
||||
});
|
||||
return decision.allowed;
|
||||
};
|
||||
|
||||
const onComplete = async (row: any) => {
|
||||
if (!study.currentStudy) return;
|
||||
const action = getAvailableActions(taskMachine, row.status).find((a) => a.key === "complete");
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "task.edit",
|
||||
stateMachine: taskMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "complete",
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
ElMessage.warning(decision.reason || "当前不可执行该操作");
|
||||
logAudit(decision.auditType, {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
reason: decision.reason,
|
||||
severity: decision.severity,
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await updateTask(study.currentStudy.id, row.id, { status: action?.to || "DONE" });
|
||||
ElMessage.success("已完成");
|
||||
logAudit("TASK_COMPLETE", {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "DONE" },
|
||||
severity: "normal",
|
||||
});
|
||||
loadTasks();
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "操作失败");
|
||||
logAudit("TASK_COMPLETE", {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "DONE" },
|
||||
severity: "warning",
|
||||
reason: e?.response?.data?.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await ensureUser();
|
||||
loadSavedFilters();
|
||||
loadMilestones();
|
||||
loadMembers();
|
||||
loadTasks();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
padding: 16px;
|
||||
}
|
||||
.filters {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.spacer {
|
||||
flex: 1;
|
||||
}
|
||||
.pagination {
|
||||
margin-top: 12px;
|
||||
text-align: right;
|
||||
}
|
||||
.mb-12 {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -76,7 +76,6 @@ import { useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useAuthStore } from "../../store/auth";
|
||||
import { useStudyStore } from "../../store/study";
|
||||
import { fetchTasks } from "../../api/tasks";
|
||||
import { fetchAes } from "../../api/aes";
|
||||
import { fetchFinanceItems } from "../../api/finance";
|
||||
import { fetchImpTransactions } from "../../api/impTransactions";
|
||||
@@ -113,25 +112,24 @@ const quickActions = computed(() => {
|
||||
if (!currentStudyId.value) return [];
|
||||
if (role.value === "CRA")
|
||||
return [
|
||||
{ label: "新建 AE", path: "/study/aes" },
|
||||
{ label: "我的任务", path: "/study/tasks" },
|
||||
{ label: "伦理与启动", path: "/study/milestones" },
|
||||
{ label: "AE 列表", path: "/study/aes" },
|
||||
];
|
||||
if (role.value === "PM")
|
||||
return [
|
||||
{ label: "派发任务", path: "/study/tasks" },
|
||||
{ label: "发公告", path: "/study/faq" },
|
||||
{ label: "查看 CRA 列表", path: "/study/tasks" },
|
||||
{ label: "伦理与启动", path: "/study/milestones" },
|
||||
{ label: "费用审核", path: "/study/finance" },
|
||||
{ label: "公告维护", path: "/study/faq" },
|
||||
];
|
||||
if (role.value === "PV") return [{ label: "AE 列表", path: "/study/aes" }];
|
||||
if (role.value === "IMP") return [{ label: "药品台账", path: "/study/imp/transactions" }];
|
||||
return [];
|
||||
return [{ label: "伦理与启动", path: "/study/milestones" }];
|
||||
});
|
||||
|
||||
const todayMorePath = computed(() => (role.value === "CRA" ? "/study/tasks" : "/study/tasks"));
|
||||
const overdueMorePath = computed(() => (role.value === "CRA" ? "/study/tasks" : "/study/tasks"));
|
||||
const todayMorePath = computed(() => (role.value === "IMP" ? "/study/imp/transactions" : "/study/aes"));
|
||||
const overdueMorePath = computed(() => (role.value === "IMP" ? "/study/imp/transactions" : "/study/aes"));
|
||||
const actionMorePath = computed(() => {
|
||||
if (role.value === "IMP") return "/study/imp/transactions";
|
||||
if (role.value === "PV") return "/study/aes";
|
||||
if (role.value === "PM" || role.value === "ADMIN") return "/study/finance";
|
||||
return "/study/aes";
|
||||
});
|
||||
@@ -141,19 +139,11 @@ const isOverdue = (d?: string | null) => {
|
||||
return new Date(d) < new Date(todayStr.value);
|
||||
};
|
||||
|
||||
const toTaskItem = (task: any): WorkItem => ({
|
||||
title: task.title || "任务",
|
||||
subtitle: study.currentStudy?.name || "",
|
||||
status: task.due_date || task.status,
|
||||
overdue: isOverdue(task.due_date),
|
||||
path: "/study/tasks",
|
||||
});
|
||||
|
||||
const toAeItem = (ae: any): WorkItem => ({
|
||||
title: ae.term || "不良事件",
|
||||
subtitle: study.currentStudy?.name || "",
|
||||
status: ae.status,
|
||||
overdue: false,
|
||||
overdue: isOverdue(ae.expected_resolution_date || ae.updated_at),
|
||||
path: `/study/aes/${ae.id}`,
|
||||
});
|
||||
|
||||
@@ -178,19 +168,17 @@ const loadData = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const studyId = currentStudyId.value;
|
||||
const tasksReq = fetchTasks(studyId, { limit: 200, assignee_id: auth.user?.id });
|
||||
const aesReq = fetchAes(studyId, { status: "NEW", limit: 50 });
|
||||
const financeReq = fetchFinanceItems(studyId, { status: "SUBMITTED", limit: 50 });
|
||||
const impReq = fetchImpTransactions ? fetchImpTransactions(studyId, { limit: 50 }) : Promise.resolve({ data: [] });
|
||||
|
||||
const [tasksRes, aesRes, financeRes, impRes] = await Promise.allSettled([tasksReq, aesReq, financeReq, impReq]);
|
||||
const tasks = tasksRes.status === "fulfilled" ? (tasksRes.value.data.items || tasksRes.value.data || []) : [];
|
||||
const [aesRes, financeRes, impRes] = await Promise.allSettled([aesReq, financeReq, impReq]);
|
||||
const aes = aesRes.status === "fulfilled" ? (aesRes.value.data.items || aesRes.value.data || []) : [];
|
||||
const finances =
|
||||
financeRes.status === "fulfilled" ? (financeRes.value.data.items || financeRes.value.data || []) : [];
|
||||
const impTx = impRes.status === "fulfilled" ? (impRes.value.data.items || impRes.value.data || []) : [];
|
||||
|
||||
buildSections(tasks, aes, finances, impTx);
|
||||
buildSections(aes, finances, impTx);
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "工作台数据加载失败");
|
||||
} finally {
|
||||
@@ -198,21 +186,25 @@ const loadData = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const buildSections = (tasks: any[], aes: any[], finances: any[], impTx: any[]) => {
|
||||
const buildSections = (aes: any[], finances: any[], impTx: any[]) => {
|
||||
todayList.value = [];
|
||||
overdueList.value = [];
|
||||
actionList.value = [];
|
||||
|
||||
const openAes = aes.filter((a) => a.status !== "CLOSED");
|
||||
const financePending = finances.filter((f) => f.status !== "PAID");
|
||||
|
||||
const overdueAes = openAes.filter((a) => isOverdue(a.expected_resolution_date || a.updated_at));
|
||||
|
||||
if (role.value === "CRA") {
|
||||
todayList.value = tasks.filter((t) => t.due_date === todayStr.value).slice(0, 5).map(toTaskItem);
|
||||
overdueList.value = tasks.filter((t) => isOverdue(t.due_date)).slice(0, 5).map(toTaskItem);
|
||||
actionList.value = aes.slice(0, 5).map(toAeItem);
|
||||
} else if (role.value === "PM") {
|
||||
todayList.value = tasks.filter((t) => t.due_date === todayStr.value).slice(0, 5).map(toTaskItem);
|
||||
overdueList.value = tasks.filter((t) => isOverdue(t.due_date)).slice(0, 5).map(toTaskItem);
|
||||
const financePending = finances.slice(0, 3).map(toFinanceItem);
|
||||
const aePending = aes.slice(0, 2).map(toAeItem);
|
||||
actionList.value = [...financePending, ...aePending].slice(0, 5);
|
||||
todayList.value = openAes.slice(0, 5).map(toAeItem);
|
||||
overdueList.value = overdueAes.slice(0, 5).map(toAeItem);
|
||||
actionList.value = openAes.slice(0, 5).map(toAeItem);
|
||||
} else if (role.value === "PM" || role.value === "ADMIN") {
|
||||
todayList.value = openAes.slice(0, 5).map(toAeItem);
|
||||
overdueList.value = overdueAes.slice(0, 5).map(toAeItem);
|
||||
const financeTodo = financePending.slice(0, 3).map(toFinanceItem);
|
||||
actionList.value = [...financeTodo, ...openAes.slice(0, 2).map(toAeItem)].slice(0, 5);
|
||||
} else if (role.value === "PV") {
|
||||
const aeOpen = aes.filter((a) => a.status !== "CLOSED");
|
||||
todayList.value = aeOpen.slice(0, 5).map(toAeItem);
|
||||
|
||||
Reference in New Issue
Block a user