预览功能

This commit is contained in:
ivamp 2023-12-07 21:24:42 +08:00
parent 2feb51adf7
commit 1f6726af57
4 changed files with 102 additions and 54 deletions

View File

@ -34,6 +34,11 @@ const routes = [
path: "/library/:LibraryId/documents/create", path: "/library/:LibraryId/documents/create",
name: "library.documents.create", name: "library.documents.create",
component: () => import("@/views/documents/Create.vue"), component: () => import("@/views/documents/Create.vue"),
},
{
path: "/library/:LibraryId/documents/:DocumentId",
name: "library.documents.view",
component: () => import("@/views/documents/View.vue"),
} }
]; ];

View File

@ -1,4 +1,6 @@
<template> <template>
<v-btn class="mb-3" @click="router.back()">返回</v-btn>
<h2>新建文档</h2> <h2>新建文档</h2>
<div class="form-floating mb-3"> <div class="form-floating mb-3">
@ -10,7 +12,10 @@
></v-text-field> ></v-text-field>
</div> </div>
<MdEditor :theme="theme == 'dark' ? 'dark' : 'light'" v-model="createData.Content" /> <MdEditor
:theme="theme == 'dark' ? 'dark' : 'light'"
v-model="createData.Content"
/>
<v-btn class="mt-3" color="primary" @click="createDocument">新建文档</v-btn> <v-btn class="mt-3" color="primary" @click="createDocument">新建文档</v-btn>
@ -22,83 +27,76 @@
text="您成功创建了一篇文档,稍后我们将开始索引您的文档。在完成后您就可以使用 AI 工具了。" text="您成功创建了一篇文档,稍后我们将开始索引您的文档。在完成后您就可以使用 AI 工具了。"
></v-alert> ></v-alert>
<v-snackbar <v-snackbar v-model="show_created_failed" vertical>
v-model="show_created_failed" <div class="text-subtitle-1 pb-2">创建失败</div>
vertical
>
<div class="text-subtitle-1 pb-2">创建失败</div>
<p>可能出现了一些问题比如您没有完整填写或者某一个内容超出了长度</p> <p>可能出现了一些问题比如您没有完整填写或者某一个内容超出了长度</p>
<template v-slot:actions> <template v-slot:actions>
<v-btn <v-btn color="pink" variant="text" @click="show_created_failed = false">
color="pink" 关闭
variant="text" </v-btn>
@click="show_created_failed = false" </template>
> </v-snackbar>
关闭
</v-btn>
</template>
</v-snackbar>
<v-snackbar <v-snackbar v-model="show_title_is_not_filled">
v-model="show_title_is_not_filled" <p>您还没有填写标题</p>
>
<p>您还没有填写标题</p>
<template v-slot:actions> <template v-slot:actions>
<v-btn <v-btn
color="pink" color="pink"
variant="text" variant="text"
@click="show_title_is_not_filled = false" @click="show_title_is_not_filled = false"
> >
关闭 关闭
</v-btn> </v-btn>
</template> </template>
</v-snackbar> </v-snackbar>
</template> </template>
<script setup> <script setup>
import { ref } from "vue"; import { ref } from "vue";
import { MdEditor } from "md-editor-v3"; import { MdEditor } from "md-editor-v3";
import "md-editor-v3/lib/style.css"; import "md-editor-v3/lib/style.css";
import router from "@/router/index" import router from "@/router/index";
import { document } from "@/plugins/api"; import { document } from "@/plugins/api";
import { useTheme } from "vuetify/lib/framework.mjs"; import { useTheme } from "vuetify/lib/framework.mjs";
import { toRef } from "vue";
// get current theme // get current theme
const theme = useTheme().name const theme = useTheme().name;
const created = ref(false);
const created = ref(false) const libraryIdInt = parseInt(router.currentRoute.value.params.LibraryId);
const libraryIdInt = parseInt(router.currentRoute.value.params.LibraryId)
const createData = ref({ const createData = ref({
Title: "", Title: "",
Content: "# Markdown 支持", Content: "# Markdown 支持",
}) });
const show_created_failed = ref(false)
const show_title_is_not_filled = ref(false)
const show_created_failed = ref(false);
const show_title_is_not_filled = ref(false);
function createDocument() { function createDocument() {
if (createData.value.Title == "") {
if (createData.value.Title == "") { show_title_is_not_filled.value = true;
show_title_is_not_filled.value = true return;
return
} }
document.libraryLibraryIdDocumentsPost(libraryIdInt, createData.value.Title, null, createData.value.Content).then((r) => { document
console.log(r) .libraryLibraryIdDocumentsPost(
libraryIdInt,
createData.value.Title,
null,
createData.value.Content
)
.then((r) => {
console.log(r);
created.value = true created.value = true;
}).catch(() => { })
show_created_failed.value = true .catch(() => {
}) show_created_failed.value = true;
});
} }
</script> </script>

View File

@ -33,7 +33,7 @@
</v-card-subtitle> </v-card-subtitle>
<v-card-text>{{ document.content }}</v-card-text> <v-card-text>{{ document.content }}</v-card-text>
<v-card-actions> <v-card-actions>
<v-btn text color="primary">详情</v-btn> <v-btn text color="primary" @click="goto_document(document.ID)">预览</v-btn>
<v-btn text color="secondary">编辑</v-btn> <v-btn text color="secondary">编辑</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
@ -97,4 +97,14 @@ function goto_create_document() {
}, },
}); });
} }
function goto_document(documentId) {
router.push({
name: "library.documents.view",
params: {
DocumentId: documentId,
}
})
}
</script> </script>

View File

@ -0,0 +1,35 @@
<script setup>
import router from '@/router';
import { ref } from 'vue'
import { document } from '@/plugins/api';
import { MdPreview, MdCatalog } from 'md-editor-v3';
const libraryId = parseInt(router.currentRoute.value.params.LibraryId)
const documentId = parseInt(router.currentRoute.value.params.DocumentId)
const docu = ref({
Title: "",
Content: ""
})
document.libraryLibraryIdDocumentDocumentIdGet(libraryId, documentId).then((r) => {
docu.value = r.data
console.log(r.data)
})
</script>
<template>
<v-btn @click="router.back(0)">返回</v-btn>
<h2>{{ docu.Title }}</h2>
<MdPreview :modelValue="docu.Content" />
</template>