Skip to content

Commit 667d07e

Browse files
committed
知识库后台管理
1 parent 1c702c9 commit 667d07e

File tree

7 files changed

+863
-0
lines changed

7 files changed

+863
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<template>
2+
<div class="guide-editor">
3+
<mavon-editor
4+
v-if="showEditor"
5+
style="height: 100%; z-index: 1"
6+
:externalLink="externalLink"
7+
v-model="source"
8+
ref="md"
9+
@save="saveContent"
10+
@imgAdd="onImgAdd"
11+
></mavon-editor>
12+
</div>
13+
</template>
14+
15+
<script>
16+
import axios from "axios";
17+
import { GetContent, UpdateGuideContent } from "@/common/service/apiGuide";
18+
import { mavonEditor } from "mavon-editor";
19+
import "mavon-editor/dist/css/index.css";
20+
import "mavon-editor/dist/markdown/github-markdown.min.css";
21+
export default {
22+
name: "guide",
23+
components: {
24+
mavonEditor,
25+
},
26+
data() {
27+
return {
28+
externalLink: false, // 禁用自动加载highlight.js,github-markdown-css,katex
29+
source: "",
30+
};
31+
},
32+
computed: {
33+
showEditor() {
34+
return !!this.$route.query.id;
35+
},
36+
},
37+
watch: {
38+
"$route.query.id": {
39+
handler: function (value) {
40+
if (value) {
41+
this.getChapter();
42+
}
43+
},
44+
deep: true,
45+
immediate: true,
46+
},
47+
},
48+
methods: {
49+
getChapter() {
50+
GetContent(this.$route.query.id).then((data) => {
51+
this.source = data.result.content || "";
52+
});
53+
},
54+
saveContent(value, render) {
55+
UpdateGuideContent({
56+
id: this.$route.query.id,
57+
content: value,
58+
contentHtml: render,
59+
}).then((res) => {
60+
this.$Message.success("保存成功");
61+
});
62+
},
63+
// 绑定@imgAdd event
64+
onImgAdd(pos, $file) {
65+
var formdata = new FormData();
66+
formdata.append("file", $file);
67+
axios({
68+
url: `http://${window.location.host}/api/rest_j/v1/dss/guide/admin/guidecontent/uploadImage`,
69+
method: "post",
70+
data: formdata,
71+
headers: { "Content-Type": "multipart/form-data" },
72+
}).then((response) => {
73+
if (response.status === 200) {
74+
if (response.data.data && response.data.data.result) {
75+
// 成功返回的response.data
76+
// {
77+
// data: {result: "8b50cbf5-e754-4883-97ba-a035f13008a7.jpg"}
78+
// result: "8b50cbf5-e754-4883-97ba-a035f13008a7.jpg"
79+
// message: "OK"
80+
// method: null
81+
// status: 0
82+
// }
83+
// 将返回的url替换到文本原位置![...](0) -> ![...](url)
84+
const imgName = response.data.data.result;
85+
this.$refs.md.$img2Url(pos, `/guideAssets/${imgName}`);
86+
} else {
87+
// 失败返回的response.data
88+
// {
89+
// data: {}
90+
// message: "没有上传文件"
91+
// method: null
92+
// status: 1
93+
// }
94+
this.$Message.error(response.data.message || "上传失败");
95+
}
96+
} else {
97+
this.$Message.error(response.data.message || "上传失败");
98+
}
99+
});
100+
},
101+
},
102+
};
103+
</script>
104+
105+
<style lang="scss" scoped>
106+
@import "@/common/style/variables.scss";
107+
.guide-editor {
108+
height: calc(100vh - 54px);
109+
}
110+
</style>

0 commit comments

Comments
 (0)