列表内高频操作直达-初稿(ID问题未解决)
This commit is contained in:
@@ -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(() => {});
|
||||
|
||||
Reference in New Issue
Block a user