将知识库笔记迁移为注意事项
This commit is contained in:
+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