项目详情页--初步更新

This commit is contained in:
Cheng Zhou
2025-12-18 19:36:47 +08:00
parent eed83cec5a
commit fb4950f8f7
17 changed files with 205 additions and 9 deletions
@@ -14,7 +14,11 @@
<el-table-column label="大小" width="120">
<template #default="scope">{{ formatFileSize(scope.row.file_size) }}</template>
</el-table-column>
<el-table-column prop="uploaded_by" label="上传人" width="160" />
<el-table-column label="上传人" width="180">
<template #default="scope">
{{ uploaderLabel(scope.row) }}
</template>
</el-table-column>
<el-table-column prop="uploaded_at" label="上传时间" width="180" />
<el-table-column label="操作" width="180">
<template #default="scope">
@@ -42,6 +46,8 @@ import AttachmentUploader from "./AttachmentUploader.vue";
import { formatFileSize } from "./attachmentUtils";
import { useAuthStore } from "../../store/auth";
import { useStudyStore } from "../../store/study";
import { fetchUsers } from "../../api/users";
import { listMembers } from "../../api/members";
const props = defineProps<{
studyId: string;
@@ -53,6 +59,8 @@ const attachments = ref<any[]>([]);
const loading = ref(false);
const auth = useAuthStore();
const study = useStudyStore();
const users = ref<any[]>([]);
const members = ref<any[]>([]);
const load = async () => {
if (!props.studyId || !props.entityId) return;
@@ -67,6 +75,37 @@ const load = async () => {
}
};
const loadUsers = async () => {
try {
const { data } = await fetchUsers({ limit: 500 });
users.value = (data as any).items || data || [];
} catch {
users.value = [];
}
};
const loadMembers = async () => {
if (!props.studyId) return;
try {
const { data } = await listMembers(props.studyId, { limit: 500 });
members.value = Array.isArray(data) ? data : data.items || [];
} catch {
members.value = [];
}
};
const uploaderLabel = (row: any) => {
const userMap = users.value.reduce<Record<string, string>>((acc, cur) => {
if (cur?.id) acc[cur.id] = cur.username || cur.id;
return acc;
}, {});
const memberMap = members.value.reduce<Record<string, string>>((acc, cur) => {
if (cur?.user_id) acc[cur.user_id] = cur.username || cur.user_id;
return acc;
}, {});
return userMap[row.uploaded_by] || memberMap[row.uploaded_by] || row.uploaded_by || "-";
};
const download = (row: any) => {
const token = localStorage.getItem("ctms_token");
const url = token ? `/api/v1/attachments/${row.id}/download?token=${token}` : `/api/v1/attachments/${row.id}/download`;
@@ -92,7 +131,10 @@ const remove = async (row: any) => {
}
};
onMounted(load);
onMounted(async () => {
await Promise.all([loadUsers(), loadMembers()]);
load();
});
</script>
<style scoped>