管理后台前后端逻辑、UI美化
This commit is contained in:
@@ -1,79 +1,320 @@
|
||||
<template>
|
||||
<div class="ctms-page">
|
||||
<div class="ctms-page-header">
|
||||
<div>
|
||||
<h1 class="ctms-page-title">{{ TEXT.modules.adminProjects.detailTitle }}</h1>
|
||||
<div class="page-header-section">
|
||||
<div class="header-top">
|
||||
<h1 class="page-title">{{ TEXT.modules.adminProjects.detailTitle }}</h1>
|
||||
<el-tag v-if="project?.is_locked" type="warning" size="large" effect="dark">
|
||||
<el-icon><Lock /></el-icon>
|
||||
已锁定
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="ctms-page-actions">
|
||||
<el-button type="primary" @click="enterProject" :disabled="!project">{{ TEXT.modules.adminProjects.enter }}</el-button>
|
||||
<el-button @click="goMembers" :disabled="!project">{{ TEXT.modules.adminProjects.members }}</el-button>
|
||||
<el-button @click="goSites" :disabled="!project">{{ TEXT.modules.adminProjects.sites }}</el-button>
|
||||
<div class="quick-actions">
|
||||
<div class="action-card" @click="enterProject" :class="{ disabled: !project }">
|
||||
<el-icon class="action-icon"><Promotion /></el-icon>
|
||||
<span class="action-text">{{ TEXT.modules.adminProjects.enter }}</span>
|
||||
</div>
|
||||
<div class="action-card" @click="goMembers" :class="{ disabled: !project }">
|
||||
<el-icon class="action-icon"><User /></el-icon>
|
||||
<span class="action-text">{{ TEXT.modules.adminProjects.members }}</span>
|
||||
</div>
|
||||
<div class="action-card" @click="goSites" :class="{ disabled: !project }">
|
||||
<el-icon class="action-icon"><OfficeBuilding /></el-icon>
|
||||
<span class="action-text">{{ TEXT.modules.adminProjects.sites }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-card class="ctms-section-card">
|
||||
<template #header>
|
||||
<div>
|
||||
<div class="ctms-section-header">
|
||||
<div class="ctms-section-title">{{ TEXT.modules.adminProjects.basicInfo }}</div>
|
||||
<div class="ctms-section-actions">
|
||||
<template v-if="!isEditing">
|
||||
<el-button type="primary" @click="startEdit" :disabled="!project || project.is_locked">
|
||||
{{ TEXT.common.actions.edit }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="!project?.is_locked"
|
||||
type="info"
|
||||
@click="handleLock"
|
||||
:disabled="!project"
|
||||
>
|
||||
<el-icon><Lock /></el-icon>
|
||||
锁定项目
|
||||
</el-button>
|
||||
<el-button @click="goBack">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
{{ TEXT.common.actions.back }}
|
||||
</el-button>
|
||||
<el-button type="danger" @click="handleDelete" :disabled="!project">
|
||||
<el-icon><Delete /></el-icon>
|
||||
{{ TEXT.common.actions.delete }}
|
||||
</el-button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-button @click="cancelEdit">{{ TEXT.common.actions.cancel }}</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="saveEdit">
|
||||
{{ TEXT.common.actions.save }}
|
||||
</el-button>
|
||||
<el-button @click="goBack">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
{{ TEXT.common.actions.back }}
|
||||
</el-button>
|
||||
<el-button type="danger" @click="handleDelete" :disabled="!project">
|
||||
<el-icon><Delete /></el-icon>
|
||||
{{ TEXT.common.actions.delete }}
|
||||
</el-button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-descriptions v-if="project" :column="2" border class="detail-descriptions">
|
||||
<el-descriptions-item :label="TEXT.common.fields.projectCode">{{ project.code }}</el-descriptions-item>
|
||||
<el-descriptions-item :label="TEXT.common.fields.projectName">{{ project.name }}</el-descriptions-item>
|
||||
<el-descriptions-item :label="TEXT.common.fields.sponsor">{{ project.sponsor || TEXT.common.fallback }}</el-descriptions-item>
|
||||
<el-descriptions-item :label="TEXT.common.fields.status">{{ statusLabel(project.status) }}</el-descriptions-item>
|
||||
<el-descriptions-item :label="TEXT.modules.adminProjects.createdAt">{{ displayDateTime(project.created_at) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<StateLoading v-else :rows="4" />
|
||||
</el-card>
|
||||
<el-form v-if="project" ref="formRef" :model="form" :rules="rules" label-width="120px" class="detail-form" label-position="top">
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="16">
|
||||
<el-form-item :label="TEXT.common.fields.projectName" prop="name">
|
||||
<el-input v-model="form.name" :disabled="!isEditing" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item :label="TEXT.common.fields.projectCode" prop="code">
|
||||
<el-input v-model="form.code" :disabled="!isEditing" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-card class="ctms-section-card">
|
||||
<template #header>
|
||||
<div>
|
||||
<div class="ctms-section-title">{{ TEXT.modules.adminProjects.filesTitle }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<AttachmentList
|
||||
v-if="project"
|
||||
:study-id="project.id"
|
||||
entity-type="project"
|
||||
:entity-id="project.id"
|
||||
:show-uploader="true"
|
||||
/>
|
||||
<StateLoading v-else :rows="3" />
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="8">
|
||||
<el-form-item :label="TEXT.common.fields.status" prop="status">
|
||||
<el-select v-model="form.status" :placeholder="TEXT.common.placeholders.select" :disabled="!isEditing" class="w-full">
|
||||
<el-option :label="TEXT.enums.projectStatus.DRAFT" value="DRAFT" />
|
||||
<el-option :label="TEXT.enums.projectStatus.ACTIVE" value="ACTIVE" />
|
||||
<el-option :label="TEXT.enums.projectStatus.CLOSED" value="CLOSED" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item :label="TEXT.common.fields.protocolNo" prop="protocol_no">
|
||||
<el-input v-model="form.protocol_no" :placeholder="TEXT.modules.adminProjects.protocolPlaceholder" :disabled="!isEditing" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item :label="TEXT.common.fields.phase" prop="phase">
|
||||
<el-input v-model="form.phase" :placeholder="TEXT.modules.adminProjects.phasePlaceholder" :disabled="!isEditing" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-divider content-position="left" class="form-divider">{{ TEXT.modules.adminProjects.visitTemplate }}</el-divider>
|
||||
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="TEXT.common.fields.visitTotal">
|
||||
<el-input-number v-model="form.visit_total" :min="1" :max="50" :step="1" :disabled="!isEditing" class="w-full" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="TEXT.common.fields.visitIntervalDays">
|
||||
<el-input-number v-model="form.visit_interval_days" :min="1" :max="365" :step="1" :disabled="!isEditing" class="w-full" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="TEXT.common.fields.visitWindowStartOffset">
|
||||
<el-input-number v-model="form.visit_window_start_offset" :min="-365" :max="365" :step="1" :disabled="!isEditing" class="w-full" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="TEXT.common.fields.visitWindowEndOffset">
|
||||
<el-input-number v-model="form.visit_window_end_offset" :min="-365" :max="365" :step="1" :disabled="!isEditing" class="w-full" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="24" class="mt-4">
|
||||
<el-col :span="24">
|
||||
<el-form-item :label="TEXT.modules.adminProjects.createdAt">
|
||||
<span class="info-text">{{ displayDateTime(project.created_at) }}</span>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<StateLoading v-else :rows="4" />
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { fetchStudyDetail } from "../../api/studies";
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from "element-plus";
|
||||
import { ArrowLeft, Promotion, User, OfficeBuilding, Delete, Lock } from "@element-plus/icons-vue";
|
||||
import { fetchStudyDetail, updateStudy, deleteStudy, lockStudy } from "../../api/studies";
|
||||
import type { Study } from "../../types/api";
|
||||
import AttachmentList from "../../components/attachments/AttachmentList.vue";
|
||||
import StateLoading from "../../components/StateLoading.vue";
|
||||
import { useStudyStore } from "../../store/study";
|
||||
import { displayDateTime } from "../../utils/display";
|
||||
import { TEXT } from "../../locales";
|
||||
import { TEXT, requiredMessage } from "../../locales";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const studyStore = useStudyStore();
|
||||
|
||||
const project = ref<Study | null>(null);
|
||||
const isEditing = ref(false);
|
||||
const submitting = ref(false);
|
||||
const formRef = ref<FormInstance>();
|
||||
const form = ref({
|
||||
code: "",
|
||||
name: "",
|
||||
protocol_no: "",
|
||||
phase: "",
|
||||
status: "DRAFT",
|
||||
visit_interval_days: null as number | null,
|
||||
visit_total: null as number | null,
|
||||
visit_window_start_offset: null as number | null,
|
||||
visit_window_end_offset: null as number | null,
|
||||
});
|
||||
|
||||
const rules = ref<FormRules>({
|
||||
code: [{ required: true, message: requiredMessage(TEXT.common.fields.projectCode), trigger: "blur" }],
|
||||
name: [{ required: true, message: requiredMessage(TEXT.common.fields.projectName), trigger: "blur" }],
|
||||
status: [{ required: true, message: requiredMessage(TEXT.common.fields.status), trigger: "change" }],
|
||||
});
|
||||
|
||||
const syncForm = (data: Study | null) => {
|
||||
form.value.code = data?.code || "";
|
||||
form.value.name = data?.name || "";
|
||||
form.value.protocol_no = data?.protocol_no || "";
|
||||
form.value.phase = data?.phase || "";
|
||||
form.value.status = data?.status || "DRAFT";
|
||||
form.value.visit_interval_days = data?.visit_interval_days ?? null;
|
||||
form.value.visit_total = data?.visit_total ?? null;
|
||||
form.value.visit_window_start_offset = data?.visit_window_start_offset ?? null;
|
||||
form.value.visit_window_end_offset = data?.visit_window_end_offset ?? null;
|
||||
};
|
||||
|
||||
const loadProject = async () => {
|
||||
try {
|
||||
const { data } = await fetchStudyDetail(route.params.projectId as string);
|
||||
project.value = data as Study;
|
||||
syncForm(project.value);
|
||||
isEditing.value = false;
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || TEXT.modules.adminProjects.loadFailed);
|
||||
}
|
||||
};
|
||||
|
||||
const statusLabel = (status: string) =>
|
||||
TEXT.enums.projectStatus[status as keyof typeof TEXT.enums.projectStatus] || status;
|
||||
const startEdit = () => {
|
||||
if (!project.value) return;
|
||||
if (project.value.is_locked) {
|
||||
ElMessage.warning("项目已锁定,无法编辑。请先解锁项目。");
|
||||
return;
|
||||
}
|
||||
isEditing.value = true;
|
||||
};
|
||||
|
||||
const cancelEdit = () => {
|
||||
syncForm(project.value);
|
||||
isEditing.value = false;
|
||||
};
|
||||
|
||||
const saveEdit = async () => {
|
||||
if (!project.value || !formRef.value) return;
|
||||
await formRef.value.validate();
|
||||
submitting.value = true;
|
||||
try {
|
||||
const { data } = await updateStudy(project.value.id, {
|
||||
code: form.value.code,
|
||||
name: form.value.name,
|
||||
protocol_no: form.value.protocol_no,
|
||||
phase: form.value.phase,
|
||||
status: form.value.status,
|
||||
visit_interval_days: form.value.visit_interval_days,
|
||||
visit_total: form.value.visit_total,
|
||||
visit_window_start_offset: form.value.visit_window_start_offset,
|
||||
visit_window_end_offset: form.value.visit_window_end_offset,
|
||||
});
|
||||
project.value = data as Study;
|
||||
syncForm(project.value);
|
||||
isEditing.value = false;
|
||||
ElMessage.success(TEXT.modules.adminProjects.updateSuccess);
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || TEXT.common.messages.saveFailed);
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!project.value) return;
|
||||
try {
|
||||
// 第一次确认
|
||||
await ElMessageBox.confirm(
|
||||
`确定要删除项目"${project.value.name}"吗?该操作将永久删除项目及其所有关联数据(成员、站点等),且不可恢复!`,
|
||||
TEXT.common.actions.delete,
|
||||
{
|
||||
confirmButtonText: "继续",
|
||||
cancelButtonText: TEXT.common.actions.cancel,
|
||||
type: "error",
|
||||
}
|
||||
);
|
||||
|
||||
// 第二次确认:要求输入项目名称
|
||||
const { value } = await ElMessageBox.prompt(
|
||||
`请输入项目名称 "${project.value.name}" 以确认删除`,
|
||||
"删除确认",
|
||||
{
|
||||
confirmButtonText: TEXT.common.actions.confirm,
|
||||
cancelButtonText: TEXT.common.actions.cancel,
|
||||
inputPattern: new RegExp(`^${project.value.name.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\$&')}$`),
|
||||
inputErrorMessage: "项目名称不匹配",
|
||||
inputPlaceholder: "请输入项目名称",
|
||||
type: "error",
|
||||
}
|
||||
);
|
||||
|
||||
if (value !== project.value.name) {
|
||||
ElMessage.warning("项目名称不匹配,已取消删除");
|
||||
return;
|
||||
}
|
||||
|
||||
await deleteStudy(project.value.id);
|
||||
ElMessage.success("项目已删除");
|
||||
router.push("/admin/projects");
|
||||
} catch (err) {
|
||||
if (err !== "cancel") {
|
||||
ElMessage.error("删除项目失败");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleLock = async () => {
|
||||
if (!project.value) return;
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要锁定项目"${project.value.name}"吗?锁定后项目内数据将无法编辑,且不可解锁!`,
|
||||
"锁定项目",
|
||||
{
|
||||
confirmButtonText: TEXT.common.actions.confirm,
|
||||
cancelButtonText: TEXT.common.actions.cancel,
|
||||
type: "warning",
|
||||
}
|
||||
);
|
||||
|
||||
const { data } = await lockStudy(project.value.id);
|
||||
project.value = data as Study;
|
||||
syncForm(project.value);
|
||||
ElMessage.success("项目已锁定");
|
||||
} catch (err) {
|
||||
if (err !== "cancel") {
|
||||
ElMessage.error("锁定项目失败");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const goBack = () => {
|
||||
router.back();
|
||||
};
|
||||
|
||||
const enterProject = () => {
|
||||
if (!project.value) return;
|
||||
@@ -97,7 +338,169 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.detail-descriptions :deep(.el-descriptions__label) {
|
||||
color: var(--ctms-text-secondary);
|
||||
.page-header-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 32px 40px;
|
||||
border-radius: 16px;
|
||||
margin-bottom: 24px;
|
||||
box-shadow: 0 4px 20px rgba(102, 126, 234, 0.25);
|
||||
}
|
||||
|
||||
.page-title {
|
||||
color: white;
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.action-card {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 12px;
|
||||
padding: 20px 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
border: 2px solid transparent;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.action-card:hover:not(.disabled) {
|
||||
transform: translateY(-4px) scale(1.02);
|
||||
box-shadow: 0 8px 24px rgba(247, 107, 28, 0.4);
|
||||
border-color: #f76b1c;
|
||||
}
|
||||
|
||||
.action-card:hover:not(.disabled)::before {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.action-card.primary {
|
||||
background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
|
||||
box-shadow: 0 2px 8px rgba(252, 182, 159, 0.3);
|
||||
}
|
||||
|
||||
.action-card.primary::before {
|
||||
background: linear-gradient(135deg, rgba(255, 107, 28, 0.15) 0%, rgba(252, 107, 79, 0.15) 100%);
|
||||
}
|
||||
|
||||
.action-card.primary:hover:not(.disabled) {
|
||||
transform: translateY(-4px) scale(1.02);
|
||||
box-shadow: 0 8px 24px rgba(247, 107, 28, 0.4);
|
||||
border-color: #f76b1c;
|
||||
background: linear-gradient(135deg, #fff0e0 0%, #ffd0b8 100%);
|
||||
}
|
||||
|
||||
.action-card.disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 28px;
|
||||
color: #667eea;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.action-card:hover:not(.disabled) .action-icon {
|
||||
transform: scale(1.15);
|
||||
color: #f76b1c;
|
||||
}
|
||||
|
||||
.action-card.primary .action-icon {
|
||||
color: #f76b1c;
|
||||
}
|
||||
|
||||
.action-card.primary:hover:not(.disabled) .action-icon {
|
||||
color: #e05a0a;
|
||||
transform: scale(1.15) rotate(5deg);
|
||||
}
|
||||
|
||||
.action-text {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: #2d3748;
|
||||
transition: color 0.3s ease;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.action-card:hover:not(.disabled) .action-text {
|
||||
color: #1a202c;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ctms-section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.ctms-section-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
|
||||
.detail-form :deep(.el-form-item) {
|
||||
margin-bottom: 0; /* Let rows handle internal spacing if needed, or keep minimal */
|
||||
}
|
||||
.w-full {
|
||||
width: 100%;
|
||||
}
|
||||
.form-divider {
|
||||
margin: 32px 0 24px;
|
||||
}
|
||||
.mt-4 {
|
||||
margin-top: 16px;
|
||||
}
|
||||
.info-text {
|
||||
color: #6b7280;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Ensure inputs are full width in grid */
|
||||
.detail-form :deep(.el-input),
|
||||
.detail-form :deep(.el-select),
|
||||
.detail-form :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user