列表内高频操作直达-初稿(ID问题未解决)
This commit is contained in:
@@ -34,6 +34,18 @@
|
||||
<el-tag :type="scope.row.is_overdue ? 'danger' : 'info'">{{ statusLabel(scope.row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="showClose(scope.row)"
|
||||
type="danger"
|
||||
size="small"
|
||||
@click.stop="onClose(scope.row)"
|
||||
>
|
||||
关闭 AE
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="pagination"
|
||||
@@ -52,12 +64,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { fetchAes } from "../api/aes";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { fetchAes, updateAe } from "../api/aes";
|
||||
import { fetchSubjects } from "../api/subjects";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import AeForm from "../components/AeForm.vue";
|
||||
import { aeMachine, getAvailableActions } from "../state-machine";
|
||||
import { evaluateAction } from "../guards/actionGuard";
|
||||
import { logAudit } from "../audit";
|
||||
|
||||
const study = useStudyStore();
|
||||
const auth = useAuthStore();
|
||||
@@ -155,6 +170,70 @@ const seriousnessLabel = (v: string) =>
|
||||
NON_SERIOUS: "非严重",
|
||||
}[v] || v);
|
||||
|
||||
const showClose = (row: any) => {
|
||||
const actions = getAvailableActions(aeMachine, row.status);
|
||||
const has = actions.some((a) => a.key === "close");
|
||||
if (!has) return false;
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "ae.close",
|
||||
stateMachine: aeMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "close",
|
||||
});
|
||||
return decision.allowed;
|
||||
};
|
||||
|
||||
const onClose = async (row: any) => {
|
||||
if (!study.currentStudy) return;
|
||||
const action = getAvailableActions(aeMachine, row.status).find((a) => a.key === "close");
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "ae.close",
|
||||
stateMachine: aeMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "close",
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
ElMessage.warning(decision.reason || "当前不可执行该操作");
|
||||
logAudit(decision.auditType, {
|
||||
targetId: row.id,
|
||||
targetName: row.term,
|
||||
reason: decision.reason,
|
||||
severity: decision.severity,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action?.confirm) {
|
||||
const ok = await ElMessageBox.confirm(action.confirmText || "确认关闭?", "提示", {
|
||||
type: action.danger ? "warning" : "info",
|
||||
}).catch(() => null);
|
||||
if (!ok) return;
|
||||
}
|
||||
try {
|
||||
await updateAe(study.currentStudy.id, row.id, { status: action?.to || "CLOSED" });
|
||||
ElMessage.success("已关闭");
|
||||
logAudit("AE_CLOSED", {
|
||||
targetId: row.id,
|
||||
targetName: row.term,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "CLOSED" },
|
||||
severity: "normal",
|
||||
});
|
||||
loadAes();
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "操作失败");
|
||||
logAudit("AE_CLOSED", {
|
||||
targetId: row.id,
|
||||
targetName: row.term,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "CLOSED" },
|
||||
severity: "warning",
|
||||
reason: e?.response?.data?.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
if (!auth.user && auth.token) {
|
||||
await auth.fetchMe().catch(() => {});
|
||||
|
||||
@@ -36,6 +36,18 @@
|
||||
<el-tag :type="scope.row.is_overdue ? 'danger' : 'info'">{{ statusLabel(scope.row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="showResolve(scope.row)"
|
||||
type="primary"
|
||||
size="small"
|
||||
@click.stop="onResolve(scope.row)"
|
||||
>
|
||||
标记已解决
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="pagination"
|
||||
@@ -54,12 +66,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { fetchDataQueries } from "../api/dataQueries";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { fetchDataQueries, updateDataQuery } from "../api/dataQueries";
|
||||
import { fetchSubjects } from "../api/subjects";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import DataQueryForm from "../components/DataQueryForm.vue";
|
||||
import { evaluateAction } from "../guards/actionGuard";
|
||||
import { logAudit } from "../audit";
|
||||
import { getAvailableActions, type StateMachine } from "../state-machine";
|
||||
|
||||
const study = useStudyStore();
|
||||
const auth = useAuthStore();
|
||||
@@ -81,6 +96,24 @@ const subjectMap = computed(() =>
|
||||
const statuses = ["OPEN", "IN_PROGRESS", "ANSWERED", "CLOSED"];
|
||||
const categories = ["MISSING", "INCONSISTENT", "OUT_OF_RANGE", "OTHER"];
|
||||
const priorities = ["LOW", "MEDIUM", "HIGH"];
|
||||
const dataQueryMachine: StateMachine = {
|
||||
states: {
|
||||
OPEN: { value: "OPEN", label: "待处理" },
|
||||
IN_PROGRESS: { value: "IN_PROGRESS", label: "处理中" },
|
||||
ANSWERED: { value: "ANSWERED", label: "已回复" },
|
||||
CLOSED: { value: "CLOSED", label: "已关闭", isTerminal: true },
|
||||
},
|
||||
actions: {
|
||||
resolve: {
|
||||
key: "resolve",
|
||||
label: "标记已解决",
|
||||
from: ["OPEN", "IN_PROGRESS", "ANSWERED"],
|
||||
to: "CLOSED",
|
||||
confirm: true,
|
||||
confirmText: "确认标记为已解决?",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const filters = ref({
|
||||
status: "",
|
||||
@@ -157,6 +190,67 @@ const priorityLabel = (v: string) =>
|
||||
HIGH: "高",
|
||||
}[v] || v);
|
||||
|
||||
const showResolve = (row: any) => {
|
||||
const actions = getAvailableActions(dataQueryMachine, row.status).filter((a) => a.key === "resolve");
|
||||
if (!actions.length) return false;
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "dataquery.edit",
|
||||
stateMachine: dataQueryMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "resolve",
|
||||
});
|
||||
return decision.allowed;
|
||||
};
|
||||
|
||||
const onResolve = async (row: any) => {
|
||||
if (!study.currentStudy) return;
|
||||
const action = getAvailableActions(dataQueryMachine, row.status).find((a) => a.key === "resolve");
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "dataquery.edit",
|
||||
stateMachine: dataQueryMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "resolve",
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
ElMessage.warning(decision.reason || "当前不可执行该操作");
|
||||
logAudit(decision.auditType, {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
reason: decision.reason,
|
||||
severity: decision.severity,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action?.confirm) {
|
||||
const ok = await ElMessageBox.confirm(action.confirmText || "确认操作?", "提示").catch(() => null);
|
||||
if (!ok) return;
|
||||
}
|
||||
try {
|
||||
await updateDataQuery(study.currentStudy.id, row.id, { status: action?.to || "CLOSED" });
|
||||
ElMessage.success("已标记");
|
||||
logAudit("QUERY_RESOLVED", {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "CLOSED" },
|
||||
severity: "normal",
|
||||
});
|
||||
loadQueries();
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "操作失败");
|
||||
logAudit("QUERY_RESOLVED", {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "CLOSED" },
|
||||
severity: "warning",
|
||||
reason: e?.response?.data?.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
if (!auth.user && auth.token) {
|
||||
await auth.fetchMe().catch(() => {});
|
||||
|
||||
@@ -53,6 +53,26 @@
|
||||
<el-table-column prop="submitted_at" label="提交时间" width="160" />
|
||||
<el-table-column prop="approved_at" label="审批时间" width="160" />
|
||||
<el-table-column prop="paid_at" label="支付时间" width="160" />
|
||||
<el-table-column label="操作" width="220">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="showAction(scope.row, 'approve')"
|
||||
type="primary"
|
||||
size="small"
|
||||
@click.stop="onApprove(scope.row)"
|
||||
>
|
||||
审批
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="showAction(scope.row, 'reject')"
|
||||
type="danger"
|
||||
size="small"
|
||||
@click.stop="onReject(scope.row)"
|
||||
>
|
||||
驳回
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="pagination"
|
||||
@@ -71,14 +91,17 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import FinanceSummary from "../components/FinanceSummary.vue";
|
||||
import FinanceForm from "../components/FinanceForm.vue";
|
||||
import { fetchFinanceItems, fetchFinanceSummary } from "../api/finance";
|
||||
import { fetchFinanceItems, fetchFinanceSummary, changeFinanceStatus } from "../api/finance";
|
||||
import { useStudyStore } from "../store/study";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import PermissionAction from "../components/PermissionAction.vue";
|
||||
import { usePermission } from "../utils/permission";
|
||||
import { financeMachine, getAvailableActions } from "../state-machine";
|
||||
import { evaluateAction } from "../guards/actionGuard";
|
||||
import { logAudit } from "../audit";
|
||||
|
||||
const study = useStudyStore();
|
||||
const auth = useAuthStore();
|
||||
@@ -105,6 +128,10 @@ const showForm = ref(false);
|
||||
|
||||
const { can } = usePermission();
|
||||
const canCreate = computed(() => can("finance.create"));
|
||||
const permissionMap: Record<string, string> = {
|
||||
approve: "finance.approve",
|
||||
reject: "finance.approve",
|
||||
};
|
||||
|
||||
const formatAmount = (num?: number | string) => {
|
||||
const n = Number(num);
|
||||
@@ -144,6 +171,112 @@ const categoryLabel = (c?: string) =>
|
||||
OTHER: "其他",
|
||||
}[c || ""] || c || "");
|
||||
|
||||
const showAction = (row: any, key: string) => {
|
||||
const actions = getAvailableActions(financeMachine, row.status).filter((a) => a.key === key);
|
||||
if (!actions.length) return false;
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: permissionMap[key],
|
||||
stateMachine: financeMachine,
|
||||
currentState: row.status,
|
||||
actionKey: key,
|
||||
});
|
||||
return decision.allowed;
|
||||
};
|
||||
|
||||
const doChange = async (row: any, status: string, reason?: string) => {
|
||||
if (!study.currentStudy) return false;
|
||||
try {
|
||||
await changeFinanceStatus(study.currentStudy.id, row.id, { status, reject_reason: reason });
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || "操作失败");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const onApprove = async (row: any) => {
|
||||
const action = getAvailableActions(financeMachine, row.status).find((a) => a.key === "approve");
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: permissionMap.approve,
|
||||
stateMachine: financeMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "approve",
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
ElMessage.warning(decision.reason || "当前不可执行该操作");
|
||||
logAudit(decision.auditType, {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
reason: decision.reason,
|
||||
severity: decision.severity,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action?.confirm) {
|
||||
const ok = await ElMessageBox.confirm(action.confirmText || "确认审批通过?", "提示").catch(() => null);
|
||||
if (!ok) return;
|
||||
}
|
||||
const ok = await doChange(row, action?.to || "APPROVED");
|
||||
logAudit("FINANCE_APPROVED", {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "APPROVED" },
|
||||
severity: ok ? "normal" : "warning",
|
||||
});
|
||||
if (ok) {
|
||||
ElMessage.success("已审批");
|
||||
loadList();
|
||||
}
|
||||
};
|
||||
|
||||
const onReject = async (row: any) => {
|
||||
const action = getAvailableActions(financeMachine, row.status).find((a) => a.key === "reject");
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: permissionMap.reject,
|
||||
stateMachine: financeMachine,
|
||||
currentState: row.status,
|
||||
actionKey: "reject",
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
ElMessage.warning(decision.reason || "当前不可执行该操作");
|
||||
logAudit(decision.auditType, {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
reason: decision.reason,
|
||||
severity: decision.severity,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action?.confirm) {
|
||||
const ok = await ElMessageBox.confirm(action.confirmText || "确认驳回?", "提示", {
|
||||
type: action.danger ? "warning" : "info",
|
||||
}).catch(() => null);
|
||||
if (!ok) return;
|
||||
}
|
||||
const reason = await ElMessageBox.prompt("请输入驳回原因", "驳回", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
}).catch(() => null);
|
||||
if (!reason || !reason.value) return;
|
||||
const ok = await doChange(row, action?.to || "REJECTED", reason.value);
|
||||
logAudit("FINANCE_REJECTED", {
|
||||
targetId: row.id,
|
||||
targetName: row.title,
|
||||
before: { status: row.status },
|
||||
after: { status: action?.to || "REJECTED" },
|
||||
severity: ok ? "normal" : "warning",
|
||||
reason: reason.value,
|
||||
});
|
||||
if (ok) {
|
||||
ElMessage.success("已驳回");
|
||||
loadList();
|
||||
}
|
||||
};
|
||||
|
||||
const loadSummary = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
try {
|
||||
|
||||
@@ -40,6 +40,18 @@
|
||||
<el-table-column prop="subject_id" label="受试者" width="180" />
|
||||
<el-table-column prop="quantity" label="数量" width="100" align="right" />
|
||||
<el-table-column prop="reference" label="单号/备注" />
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="canEdit"
|
||||
type="primary"
|
||||
size="small"
|
||||
@click.stop="confirmTx(scope.row)"
|
||||
>
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="pagination"
|
||||
@@ -56,7 +68,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { fetchImpTransactions } from "../api/impTransactions";
|
||||
import { fetchImpBatches } from "../api/impBatches";
|
||||
import { useStudyStore } from "../store/study";
|
||||
@@ -64,6 +76,8 @@ import { useAuthStore } from "../store/auth";
|
||||
import PermissionAction from "../components/PermissionAction.vue";
|
||||
import { usePermission } from "../utils/permission";
|
||||
import ImpTransactionForm from "../components/ImpTransactionForm.vue";
|
||||
import { evaluateAction } from "../guards/actionGuard";
|
||||
import { logAudit } from "../audit";
|
||||
|
||||
const study = useStudyStore();
|
||||
const auth = useAuthStore();
|
||||
@@ -129,6 +143,34 @@ const txTypeLabel = (t: string) =>
|
||||
TRANSFER_OUT: "调出",
|
||||
}[t] || t);
|
||||
|
||||
const confirmTx = async (row: any) => {
|
||||
const decision = evaluateAction({
|
||||
actorRole: auth.user?.role || null,
|
||||
requiredPermission: "imp.transaction",
|
||||
actionKey: "confirm",
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
ElMessage.warning(decision.reason || "当前不可执行该操作");
|
||||
logAudit(decision.auditType, {
|
||||
targetId: row.id,
|
||||
targetName: row.reference,
|
||||
reason: decision.reason,
|
||||
severity: decision.severity,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const ok = await ElMessageBox.confirm("确认该出入库记录?", "提示", { type: "info" }).catch(() => null);
|
||||
if (!ok) return;
|
||||
// 无需调用后端变更(无状态字段),仅记录审计并提示
|
||||
logAudit("IMP_CONFIRMED", {
|
||||
targetId: row.id,
|
||||
targetName: row.reference,
|
||||
severity: "normal",
|
||||
});
|
||||
ElMessage.success("已确认");
|
||||
load();
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
if (!auth.user && auth.token) {
|
||||
await auth.fetchMe().catch(() => {});
|
||||
|
||||
@@ -23,7 +23,11 @@
|
||||
<el-card>
|
||||
<el-table :data="subjects" v-loading="loading" style="width: 100%" @row-click="goDetail">
|
||||
<el-table-column prop="subject_no" label="受试者编号" />
|
||||
<el-table-column prop="site_id" label="中心ID" />
|
||||
<el-table-column prop="site_id" label="中心">
|
||||
<template #default="scope">
|
||||
{{ siteName(scope.row.site_id) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="120">
|
||||
<template #default="scope">
|
||||
<el-tag>{{ statusLabel(scope.row.status) }}</el-tag>
|
||||
@@ -66,6 +70,12 @@ const loading = ref(false);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
const pageSize = 10;
|
||||
const siteMap = computed(() =>
|
||||
sites.value.reduce<Record<string, string>>((acc, cur) => {
|
||||
acc[cur.id] = cur.name || cur.id;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
const statuses = ["SCREENING", "ENROLLED", "COMPLETED", "DROPPED"];
|
||||
|
||||
@@ -140,6 +150,8 @@ const statusLabel = (v: string) =>
|
||||
COMPLETED: "已完成",
|
||||
DROPPED: "已脱落",
|
||||
}[v] || v);
|
||||
|
||||
const siteName = (id: string) => siteMap.value[id] || id || "-";
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -24,7 +24,11 @@
|
||||
{{ milestoneName(scope.row.milestone_id) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="assignee_id" label="负责人" width="160" />
|
||||
<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>
|
||||
@@ -36,11 +40,19 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="due_date" label="截止日期" width="140" />
|
||||
<el-table-column label="操作" width="120">
|
||||
<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>
|
||||
@@ -61,20 +73,27 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { fetchTasks } from "../api/tasks";
|
||||
import { fetchTasks, updateTask } from "../api/tasks";
|
||||
import { fetchMilestones } from "../api/milestones";
|
||||
import { listMembers } from "../api/members";
|
||||
import { fetchUsers } from "../api/users";
|
||||
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 users = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
@@ -98,6 +117,18 @@ const milestoneMap = computed(() =>
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
const memberMap = computed(() =>
|
||||
members.value.reduce<Record<string, string>>((acc, cur) => {
|
||||
acc[cur.user_id] = cur.username || cur.user_id;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
const userMap = computed(() =>
|
||||
users.value.reduce<Record<string, string>>((acc, cur) => {
|
||||
acc[cur.id] = cur.username || cur.id;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
const loadMilestones = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
@@ -109,6 +140,25 @@ const loadMilestones = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadMembers = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
try {
|
||||
const { data } = await listMembers(study.currentStudy.id);
|
||||
members.value = Array.isArray(data) ? data : data.items || [];
|
||||
} catch {
|
||||
members.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
const { data } = await fetchUsers({ limit: 500 });
|
||||
users.value = (data as any).items || data || [];
|
||||
} catch {
|
||||
users.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadTasks = async () => {
|
||||
if (!study.currentStudy) return;
|
||||
loading.value = true;
|
||||
@@ -188,11 +238,72 @@ 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) => userMap.value[id] || 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();
|
||||
loadUsers();
|
||||
loadTasks();
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user