将知识库笔记迁移为注意事项
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import { apiDelete, apiGet, apiPatch, apiPost } from "./axios";
|
||||
|
||||
export const listKnowledgeNotes = (studyId: string, params?: Record<string, any>) =>
|
||||
apiGet(`/api/v1/studies/${studyId}/knowledge/notes`, { params });
|
||||
|
||||
export const getKnowledgeNote = (studyId: string, noteId: string) =>
|
||||
apiGet(`/api/v1/studies/${studyId}/knowledge/notes/${noteId}`);
|
||||
|
||||
export const createKnowledgeNote = (studyId: string, payload: Record<string, any>) =>
|
||||
apiPost(`/api/v1/studies/${studyId}/knowledge/notes`, payload);
|
||||
|
||||
export const updateKnowledgeNote = (studyId: string, noteId: string, payload: Record<string, any>) =>
|
||||
apiPatch(`/api/v1/studies/${studyId}/knowledge/notes/${noteId}`, payload);
|
||||
|
||||
export const deleteKnowledgeNote = (studyId: string, noteId: string) =>
|
||||
apiDelete(`/api/v1/studies/${studyId}/knowledge/notes/${noteId}`);
|
||||
@@ -0,0 +1,18 @@
|
||||
import { apiDelete, apiGet, apiPatch, apiPost } from "./axios";
|
||||
|
||||
const baseUrl = (studyId: string) => `/api/v1/studies/${studyId}/shared-library/precautions`;
|
||||
|
||||
export const listPrecautions = (studyId: string, params?: Record<string, any>) =>
|
||||
apiGet(baseUrl(studyId), { params });
|
||||
|
||||
export const getPrecaution = (studyId: string, precautionId: string) =>
|
||||
apiGet(`${baseUrl(studyId)}/${precautionId}`);
|
||||
|
||||
export const createPrecaution = (studyId: string, payload: Record<string, any>) =>
|
||||
apiPost(baseUrl(studyId), payload);
|
||||
|
||||
export const updatePrecaution = (studyId: string, precautionId: string, payload: Record<string, any>) =>
|
||||
apiPatch(`${baseUrl(studyId)}/${precautionId}`, payload);
|
||||
|
||||
export const deletePrecaution = (studyId: string, precautionId: string) =>
|
||||
apiDelete(`${baseUrl(studyId)}/${precautionId}`);
|
||||
@@ -24,7 +24,7 @@
|
||||
<el-button @click="resetFilters">{{ TEXT.common.actions.reset }}</el-button>
|
||||
</div>
|
||||
<div class="filter-spacer"></div>
|
||||
<el-button v-if="canWriteSharedLibrary" type="primary" @click="goNew">
|
||||
<el-button v-if="canWritePrecautions" type="primary" @click="goNew">
|
||||
{{ TEXT.modules.knowledgeNotes.newTitle }}
|
||||
</el-button>
|
||||
</el-form>
|
||||
@@ -36,7 +36,7 @@
|
||||
style="width: 100%"
|
||||
class="ctms-table"
|
||||
@row-click="onRowClick"
|
||||
:row-class-name="noteRowClass"
|
||||
:row-class-name="precautionRowClass"
|
||||
table-layout="fixed"
|
||||
>
|
||||
<el-table-column prop="site_name" :label="TEXT.common.fields.site" show-overflow-tooltip />
|
||||
@@ -48,7 +48,7 @@
|
||||
<el-table-column :label="TEXT.common.labels.actions" width="120">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="canWriteSharedLibrary"
|
||||
v-if="canWritePrecautions"
|
||||
link
|
||||
type="danger"
|
||||
size="small"
|
||||
@@ -73,7 +73,7 @@ import { computed, onMounted, reactive, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { useStudyStore } from "../../store/study";
|
||||
import { listKnowledgeNotes, deleteKnowledgeNote } from "../../api/knowledgeNotes";
|
||||
import { listPrecautions, deletePrecaution } from "../../api/precautions";
|
||||
import { fetchSites } from "../../api/sites";
|
||||
import { displayDateTime } from "../../utils/display";
|
||||
import { usePermission } from "../../utils/permission";
|
||||
@@ -98,7 +98,7 @@ const siteActiveMap = computed(() => {
|
||||
return map;
|
||||
});
|
||||
const isInactiveSite = (siteName?: string) => !!siteName && siteActiveMap.value[siteName] === false;
|
||||
const noteRowClass = ({ row }: { row: any }) =>
|
||||
const precautionRowClass = ({ row }: { row: any }) =>
|
||||
`${row?.id ? "clickable-row" : ""}${isInactiveSite(row?.site_name) ? " row-inactive" : ""}`.trim();
|
||||
const filteredItems = computed(() => {
|
||||
const siteKeyword = filters.site_name.trim().toLowerCase();
|
||||
@@ -112,7 +112,7 @@ const filteredItems = computed(() => {
|
||||
const sortedItems = computed(() =>
|
||||
[...filteredItems.value].sort((a, b) => Number(isInactiveSite(a?.site_name)) - Number(isInactiveSite(b?.site_name)))
|
||||
);
|
||||
const canWriteSharedLibrary = computed(() => can("shared.library.write"));
|
||||
const canWritePrecautions = computed(() => can("precautions.write"));
|
||||
|
||||
const loadSites = async () => {
|
||||
const studyId = study.currentStudy?.id;
|
||||
@@ -130,7 +130,7 @@ const load = async () => {
|
||||
if (!studyId) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await listKnowledgeNotes(studyId, {}) as any;
|
||||
const { data } = await listPrecautions(studyId, {}) as any;
|
||||
items.value = Array.isArray(data) ? data : data.items || [];
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || TEXT.common.messages.loadFailed);
|
||||
@@ -144,8 +144,8 @@ const resetFilters = () => {
|
||||
filters.keyword = "";
|
||||
};
|
||||
|
||||
const goNew = () => router.push("/knowledge/notes/new");
|
||||
const goDetail = (id: string) => router.push(`/knowledge/notes/${id}`);
|
||||
const goNew = () => router.push("/knowledge/precautions/new");
|
||||
const goDetail = (id: string) => router.push(`/knowledge/precautions/${id}`);
|
||||
const onRowClick = (row: any) => {
|
||||
if (!row?.id) return;
|
||||
goDetail(row.id);
|
||||
@@ -161,7 +161,7 @@ const remove = async (row: any) => {
|
||||
const ok = await ElMessageBox.confirm(TEXT.common.confirm.delete, TEXT.common.labels.tips).catch(() => null);
|
||||
if (!ok) return;
|
||||
try {
|
||||
await deleteKnowledgeNote(studyId, row.id);
|
||||
await deletePrecaution(studyId, row.id);
|
||||
ElMessage.success(TEXT.common.messages.deleteSuccess);
|
||||
load();
|
||||
} catch (e: any) {
|
||||
+12
-12
@@ -21,10 +21,10 @@
|
||||
</el-card>
|
||||
|
||||
<AttachmentList
|
||||
v-if="noteId"
|
||||
v-if="precautionId"
|
||||
:study-id="studyId"
|
||||
entity-type="knowledge_note"
|
||||
:entity-id="noteId"
|
||||
entity-type="precaution"
|
||||
:entity-id="precautionId"
|
||||
:readonly="isReadOnly"
|
||||
/>
|
||||
</div>
|
||||
@@ -35,7 +35,7 @@ import { computed, onMounted, reactive, ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useStudyStore } from "../../store/study";
|
||||
import { getKnowledgeNote } from "../../api/knowledgeNotes";
|
||||
import { getPrecaution } from "../../api/precautions";
|
||||
import { fetchSites } from "../../api/sites";
|
||||
import AttachmentList from "../../components/attachments/AttachmentList.vue";
|
||||
import { usePermission } from "../../utils/permission";
|
||||
@@ -46,7 +46,7 @@ const router = useRouter();
|
||||
const study = useStudyStore();
|
||||
const { can } = usePermission();
|
||||
const loading = ref(false);
|
||||
const noteId = route.params.noteId as string;
|
||||
const precautionId = route.params.id as string;
|
||||
const studyId = study.currentStudy?.id || "";
|
||||
const sites = ref<any[]>([]);
|
||||
|
||||
@@ -64,8 +64,8 @@ const siteActiveMap = computed(() => {
|
||||
});
|
||||
return map;
|
||||
});
|
||||
const canWriteSharedLibrary = computed(() => can("shared.library.write"));
|
||||
const isReadOnly = computed(() => !canWriteSharedLibrary.value || (!!detail.site_name && siteActiveMap.value[detail.site_name] === false));
|
||||
const canWritePrecautions = computed(() => can("precautions.write"));
|
||||
const isReadOnly = computed(() => !canWritePrecautions.value || (!!detail.site_name && siteActiveMap.value[detail.site_name] === false));
|
||||
|
||||
const loadSites = async () => {
|
||||
if (!studyId) return;
|
||||
@@ -78,10 +78,10 @@ const loadSites = async () => {
|
||||
};
|
||||
|
||||
const load = async () => {
|
||||
if (!studyId || !noteId) return;
|
||||
if (!studyId || !precautionId) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await getKnowledgeNote(studyId, noteId);
|
||||
const { data } = await getPrecaution(studyId, precautionId);
|
||||
Object.assign(detail, data);
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || TEXT.common.messages.loadFailed);
|
||||
@@ -92,12 +92,12 @@ const load = async () => {
|
||||
|
||||
const goEdit = () => {
|
||||
if (isReadOnly.value) {
|
||||
ElMessage.warning(canWriteSharedLibrary.value ? "中心已停用" : "权限不足");
|
||||
ElMessage.warning(canWritePrecautions.value ? "中心已停用" : "权限不足");
|
||||
return;
|
||||
}
|
||||
router.push(`/knowledge/notes/${noteId}/edit`);
|
||||
router.push(`/knowledge/precautions/${precautionId}/edit`);
|
||||
};
|
||||
const goBack = () => router.push("/knowledge/notes");
|
||||
const goBack = () => router.push("/knowledge/precautions");
|
||||
|
||||
onMounted(async () => {
|
||||
await loadSites();
|
||||
+17
-17
@@ -30,10 +30,10 @@
|
||||
</el-card>
|
||||
|
||||
<AttachmentList
|
||||
v-if="isEdit && noteId"
|
||||
v-if="isEdit && precautionId"
|
||||
:study-id="studyId"
|
||||
entity-type="knowledge_note"
|
||||
:entity-id="noteId"
|
||||
entity-type="precaution"
|
||||
:entity-id="precautionId"
|
||||
:readonly="isReadOnly"
|
||||
/>
|
||||
<el-card v-else class="hint-card unified-shell">
|
||||
@@ -47,7 +47,7 @@ import { computed, onMounted, reactive, ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useStudyStore } from "../../store/study";
|
||||
import { createKnowledgeNote, getKnowledgeNote, updateKnowledgeNote } from "../../api/knowledgeNotes";
|
||||
import { createPrecaution, getPrecaution, updatePrecaution } from "../../api/precautions";
|
||||
import { fetchSites } from "../../api/sites";
|
||||
import AttachmentList from "../../components/attachments/AttachmentList.vue";
|
||||
import StateEmpty from "../../components/StateEmpty.vue";
|
||||
@@ -61,8 +61,8 @@ const { can } = usePermission();
|
||||
const saving = ref(false);
|
||||
const sites = ref<any[]>([]);
|
||||
|
||||
const noteId = computed(() => route.params.noteId as string | undefined);
|
||||
const isEdit = computed(() => !!noteId.value);
|
||||
const precautionId = computed(() => route.params.id as string | undefined);
|
||||
const isEdit = computed(() => !!precautionId.value);
|
||||
const studyId = computed(() => study.currentStudy?.id || "");
|
||||
|
||||
const form = reactive({
|
||||
@@ -79,8 +79,8 @@ const siteActiveMap = computed(() => {
|
||||
});
|
||||
return map;
|
||||
});
|
||||
const canWriteSharedLibrary = computed(() => can("shared.library.write"));
|
||||
const isReadOnly = computed(() => !canWriteSharedLibrary.value || (isEdit.value && !!form.site_name && siteActiveMap.value[form.site_name] === false));
|
||||
const canWritePrecautions = computed(() => can("precautions.write"));
|
||||
const isReadOnly = computed(() => !canWritePrecautions.value || (isEdit.value && !!form.site_name && siteActiveMap.value[form.site_name] === false));
|
||||
|
||||
const loadSites = async () => {
|
||||
if (!studyId.value) return;
|
||||
@@ -93,9 +93,9 @@ const loadSites = async () => {
|
||||
};
|
||||
|
||||
const load = async () => {
|
||||
if (!isEdit.value || !studyId.value || !noteId.value) return;
|
||||
if (!isEdit.value || !studyId.value || !precautionId.value) return;
|
||||
try {
|
||||
const { data } = await getKnowledgeNote(studyId.value, noteId.value);
|
||||
const { data } = await getPrecaution(studyId.value, precautionId.value);
|
||||
Object.assign(form, {
|
||||
site_name: data.site_name || "",
|
||||
title: data.title || "",
|
||||
@@ -110,7 +110,7 @@ const load = async () => {
|
||||
const submit = async () => {
|
||||
if (!studyId.value) return;
|
||||
if (isReadOnly.value) {
|
||||
ElMessage.warning(canWriteSharedLibrary.value ? "中心已停用" : "权限不足");
|
||||
ElMessage.warning(canWritePrecautions.value ? "中心已停用" : "权限不足");
|
||||
return;
|
||||
}
|
||||
if (!form.site_name) {
|
||||
@@ -129,14 +129,14 @@ const submit = async () => {
|
||||
level: form.level || null,
|
||||
content: form.content,
|
||||
};
|
||||
if (isEdit.value && noteId.value) {
|
||||
await updateKnowledgeNote(studyId.value, noteId.value, payload);
|
||||
if (isEdit.value && precautionId.value) {
|
||||
await updatePrecaution(studyId.value, precautionId.value, payload);
|
||||
ElMessage.success(TEXT.common.messages.saveSuccess);
|
||||
router.push(`/knowledge/notes/${noteId.value}`);
|
||||
router.push(`/knowledge/precautions/${precautionId.value}`);
|
||||
} else {
|
||||
const { data } = await createKnowledgeNote(studyId.value, payload);
|
||||
const { data } = await createPrecaution(studyId.value, payload);
|
||||
ElMessage.success(TEXT.common.messages.createSuccess);
|
||||
router.push(`/knowledge/notes/${data.id}`);
|
||||
router.push(`/knowledge/precautions/${data.id}`);
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.message || TEXT.common.messages.saveFailed);
|
||||
@@ -145,7 +145,7 @@ const submit = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const goBack = () => router.push("/knowledge/notes");
|
||||
const goBack = () => router.push("/knowledge/precautions");
|
||||
|
||||
onMounted(async () => {
|
||||
await loadSites();
|
||||
Reference in New Issue
Block a user