feat: 配置了插件动态导入,新增了一个完成度不高的代码编辑插件
This commit is contained in:
1 parent
803fd69850
commit
86b3a02237
9 files changed
+414
-35
No files matched your search
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div class="codemirror-container">
|
||||
<NScrollbar>
|
||||
<codemirror v-model="codeData" :extensions="extensions" />
|
||||
</NScrollbar>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { VirtualFile } from '@/class/VirtualDirectory'
|
||||
import useMiaoFetchApi from '@/hooks/useMiaoFetchApi'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { Codemirror } from 'vue-codemirror'
|
||||
import { NScrollbar } from 'naive-ui'
|
||||
|
||||
const miaoFetchApi = useMiaoFetchApi()
|
||||
|
||||
const currentFiles = defineModel<VirtualFile[]>('currentFiles', {
|
||||
required: true
|
||||
})
|
||||
|
||||
const codeData = ref<string>()
|
||||
const extensions = ref<any[]>([])
|
||||
|
||||
const setExtensions = async (fileName: string) => {
|
||||
const ext = fileName.split('.').pop()
|
||||
switch (ext) {
|
||||
case 'js':
|
||||
case 'ts':
|
||||
const { javascript } = await import('@codemirror/lang-javascript')
|
||||
extensions.value = [javascript()]
|
||||
break
|
||||
case 'css':
|
||||
case 'scss':
|
||||
const { css } = await import('@codemirror/lang-css')
|
||||
extensions.value = [css()]
|
||||
break
|
||||
case 'html':
|
||||
const { html } = await import('@codemirror/lang-html')
|
||||
extensions.value = [html()]
|
||||
break
|
||||
case 'py':
|
||||
const { python } = await import('@codemirror/lang-python')
|
||||
extensions.value = [python()]
|
||||
break
|
||||
default:
|
||||
extensions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const fileName = currentFiles.value[0].name
|
||||
codeData.value = (await miaoFetchApi.getFile(currentFiles.value[0])).toString()
|
||||
await setExtensions(fileName)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.codemirror-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -13,7 +13,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</NScrollbar>
|
||||
<div class="miao-container-loading" v-if="isLoading">{{ loadingPercent === -1 ? '缓存中' :
|
||||
<div class="miao-container-loading" v-if="isLoading">{{ loadingPercent === -1 ? '加载插件中' :
|
||||
`渲染进度:${canvasList.length}/${pdfPageCount}` }}</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -103,7 +103,7 @@ onMounted(async () => {
|
||||
.miao-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgb(53, 53, 53);
|
||||
background-color: rgb(201, 201, 201);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in new issue
Block a user