文本编辑器添加文件目录

This commit is contained in:
jmal 2020-06-01 22:24:24 +08:00
parent daf1f0884d
commit 28f26d764d

View File

@ -22,38 +22,45 @@
</div> </div>
</div> </div>
<div class="content" @keydown="onKeyDown"> <div class="content" @keydown="onKeyDown">
<div class="editor_main_storey"></div> <div class="file-contents">
<MonacoEditor <file-tree :directoryTreeData="directoryTreeData" :localFileMode="true" @treeNodeClick="treeNodeClick"></file-tree>
v-if="textPreviewVisible" </div>
ref="monacoEditor" <div class="editor">
:width="editorWidth" <div class="editor_main_storey"></div>
:height="editorHieght" <MonacoEditor
:theme="lightTheme?'vs':'vs-dark'" v-if="textPreviewVisible"
:language="language" ref="monacoEditor"
:diffEditor="diffEditor" :width="editorWidth"
original="..." :height="editorHieght"
:value="content" :theme="lightTheme?'vs':'vs-dark'"
:options="options" :language="language"
@change="change" :diffEditor="diffEditor"
></MonacoEditor> original="..."
:value="content"
:options="options"
@change="change"
></MonacoEditor>
</div>
</div> </div>
</el-dialog> </el-dialog>
</template> </template>
<script> <script>
import '@/utils/directives.js' import '@/utils/directives.js'
import api from '@/api/file-api.js' import api from '@/api/file-api'
import markdownApi from '@/api/markdown-api' import markdownApi from '@/api/markdown-api'
import { lineWrapping } from '@/utils/file-type' import { lineWrapping } from '@/utils/file-type'
import MonacoEditor from '../MonacoEditorVue' import MonacoEditor from '../MonacoEditorVue'
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
import FileTree from"@/components/FileTree"
export default { export default {
name: "SimTextPreview", name: "SimTextPreview",
components: { components: {
MonacoEditor MonacoEditor,FileTree
}, },
props: { props: {
file: { file: {
@ -108,7 +115,8 @@
background: '#565656!important', background: '#565656!important',
border: '1px solid #565656!important', border: '1px solid #565656!important',
color: '#ffffff!important' color: '#ffffff!important'
} },
directoryTreeData: []
} }
}, },
mounted() { mounted() {
@ -135,7 +143,7 @@
}, },
watch: { //监听file的变化,进行相应的操作即可 watch: { //监听file的变化,进行相应的操作即可
file: function (file) { file: function (file) {
this.editorWidth = document.body.clientWidth * this.dialogWidth this.editorWidth = document.body.clientWidth * this.dialogWidth - 250
this.editorHieght = document.body.clientHeight * this.dialogWidth - 50 this.editorHieght = document.body.clientHeight * this.dialogWidth - 50
this.loading = this.$message({ this.loading = this.$message({
@ -163,6 +171,7 @@
let request = 'previewText' let request = 'previewText'
if(this.shareId){ if(this.shareId){
request = 'sharePreviewText' request = 'sharePreviewText'
this.options.readOnly = true
} }
if(this.filepath){ if(this.filepath){
request = 'previewTextByPath' request = 'previewTextByPath'
@ -176,6 +185,7 @@
username: this.$store.state.user.name username: this.$store.state.user.name
}).then((res)=>{ }).then((res)=>{
this.loading.close() this.loading.close()
this.directoryTreeData = [{name: res.data.name, isFolder: true, isLeaf: false, path: res.data.path}]
this.textPreviewVisible = true this.textPreviewVisible = true
this.content = res.data.contentText this.content = res.data.contentText
}).catch(() => { }).catch(() => {
@ -189,8 +199,44 @@
} }
}, },
methods:{ methods:{
treeNodeClick(row) {
this.loading = this.$message({
iconClass: 'el-icon-loading',
type: 'info',
duration: 0,
dangerouslyUseHTMLString: true,
message: '<span>&nbsp;&nbsp;正在加载数据...</span>'
})
let suffix = row.suffix
let languages = monaco.languages.getLanguages();
const languagesIndex = languages.findIndex(item => item.extensions && item.extensions.includes('.'+suffix))
if(languagesIndex > -1){
this.language = languages[languagesIndex].id
}else{
this.language = this.defalutLanguage
}
if(lineWrapping.includes(suffix)) {
this.options.wordWrap = 'wordWrapColumn'
this.lineWrapping = true
}else{
this.options.wordWrap = ''
}
console.log(row)
api.previewTextByPath({
path: row.path,
username: this.$store.state.user.name
}).then((res)=>{
this.loading.close()
// this.directoryTreeData = [{name: res.data.name, isFolder: true, isLeaf: false, path: res.data.path}]
// this.textPreviewVisible = true
this.content = res.data.contentText
}).catch(() => {
this.loading.close()
})
},
containerResize() { containerResize() {
this.editorWidth = document.body.clientWidth * this.dialogWidth this.editorWidth = document.body.clientWidth * this.dialogWidth - 250
this.editorHieght = document.body.clientHeight * this.dialogWidth - 50 this.editorHieght = document.body.clientHeight * this.dialogWidth - 50
}, },
handleClose(done) { handleClose(done) {
@ -397,6 +443,11 @@
} }
.content { .content {
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
display: flex;
.file-contents{
width: 250px;
}
} }
} }