feat: markdown编辑器

This commit is contained in:
wangdan-fit2cloud 2024-03-14 17:28:47 +08:00
parent 31ee6a4ae8
commit 2e016372f6
2 changed files with 28 additions and 5 deletions

View File

@ -333,7 +333,7 @@ const {
const defaultPrompt = `已知信息:
{data}
回答要求
- 简洁和专业的来回答用户的问题
- 使用简洁且专业的语言来回答用户的问题
- 如果你不知道答案请回答没有在知识库中查找到相关信息建议咨询相关技术支持或参考官方文档进行操作
- 避免提及你是从已知信息中获得的知识
- 请保证答案与已知信息中描述的一致

View File

@ -31,13 +31,19 @@
:toolbars="toolbars"
style="height: 300px"
/>
<MdPreview v-else ref="editorRef" editorId="preview-only" :modelValue="form.content" />
<MdPreview
v-else
ref="editorRef"
editorId="preview-only"
:modelValue="form.content"
class="maxkb-md"
/>
<!-- <span v-else class="break-all lighter">{{ form.content }}</span> -->
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
import { ref, reactive, onUnmounted, watch } from 'vue'
import { ref, reactive, onUnmounted, watch, nextTick } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
import { MdEditor, MdPreview } from 'md-editor-v3'
const props = defineProps({
@ -76,8 +82,10 @@ const toolbars = [
'pageFullscreen',
'preview',
'htmlPreview',
'catalog',
]
'catalog'
] as any[]
const editorRef = ref()
const form = ref<any>({
title: '',
@ -127,6 +135,21 @@ function validate() {
})
}
const onHtmlChanged = () => {
appendTarget()
}
const appendTarget = () => {
nextTick(() => {
var item = document.getElementsByClassName('maxkb-md')
for (var j = 0; j < item.length; j++) {
var aTags = item[j].getElementsByTagName('a')
for (var i = 0; i < aTags.length; i++) {
aTags[i].setAttribute('target', '_blank')
}
}
})
}
onUnmounted(() => {
form.value = {
title: '',