diff --git a/Yi.Bbs.Vue3/src/apis/articleApi.js b/Yi.Bbs.Vue3/src/apis/articleApi.js index a7febf61..ae4ae28e 100644 --- a/Yi.Bbs.Vue3/src/apis/articleApi.js +++ b/Yi.Bbs.Vue3/src/apis/articleApi.js @@ -38,3 +38,16 @@ export function all(discussId) { method: "get", }); } + +/** + * 导入文章 + */ +export function importArticle(params, data) { + return request({ + url: `/article/import`, + headers: { "Content-Type": "multipart/form-data" }, + params: params, + data, + method: "post", + }); +} diff --git a/Yi.Bbs.Vue3/src/components/TreeArticleInfo.vue b/Yi.Bbs.Vue3/src/components/TreeArticleInfo.vue index c46fda5e..d14a14a7 100644 --- a/Yi.Bbs.Vue3/src/components/TreeArticleInfo.vue +++ b/Yi.Bbs.Vue3/src/components/TreeArticleInfo.vue @@ -11,7 +11,15 @@ > @@ -89,6 +116,7 @@ import MavonEdit from "@/components/MavonEdit.vue"; import UserSelectInfo from "@/components/UserSelectInfo.vue"; import { ref, reactive, onMounted } from "vue"; import { useRoute, useRouter } from "vue-router"; +import { Plus, Download } from "@element-plus/icons-vue"; import { add as discussAdd, @@ -100,6 +128,7 @@ import { add as articleAdd, update as articleUpdate, get as articleGet, + importArticle, } from "@/apis/articleApi.js"; //数据定义 @@ -158,7 +187,7 @@ const submit = async (formEl) => { await formEl.validate(async (valid, fields) => { if (valid) { //dicuss主题处理 - if (route.query.artType == "discuss") { + if (radio.value == "discuss") { discuss.title = editForm.title; discuss.types = editForm.types; discuss.introduction = editForm.introduction; @@ -193,7 +222,7 @@ const submit = async (formEl) => { } //artcle文章处理 - else if (route.query.artType == "article") { + else if (radio.value == "article") { //组装文章内容:需要添加的文章信息 article.content = editForm.content; article.name = editForm.name; @@ -237,11 +266,11 @@ onMounted(async () => { //如果是更新操作,需要先查询 if (route.query.operType == "update") { //更新主题 - if (route.query.artType == "discuss") { + if (radio.value == "discuss") { await loadDiscuss(); //更新文章 - } else if (route.query.artType == "article") { + } else if (radio.value == "article") { await loadArticle(); } } @@ -267,6 +296,49 @@ const loadArticle = async () => { editForm.name = res.name; editForm.discussId = res.discussId; }; + +// 导入 +let importLoading = ref(false); +const fileRef = ref(null); +const handleImport = async () => { + fileRef.value.click(); +}; +const currentType = ref("Defalut"); +const typeOptions = [ + { + value: "Defalut", + label: "默认", + }, + { + value: "Vuepress", + label: "Vuepress", + }, +]; +const getFile = async (e) => { + importLoading.value = true; + try { + let formDate = new FormData(); + formDate.append("file", e.target.files[0]); + await importArticle( + { + discussId: route.query.discussId, + articleParentId: route.query.parentArticleId, + importType: currentType.value, + }, + formDate + ); + ElMessage({ + message: `导入成功!`, + type: "success", + }); + importLoading.value = false; + } catch (error) { + console.log(error, "error"); + const { data } = error.response.data; + ElMessage.error(data.message); + importLoading.value = false; + } +};