优化:文本预览,适配移动端
This commit is contained in:
parent
e637ee2366
commit
e7fc2666c3
@ -26,7 +26,6 @@
|
|||||||
<el-input placeholder="请输入内容" size="small">
|
<el-input placeholder="请输入内容" size="small">
|
||||||
<el-button slot="append" size="small" icon="el-icon-search"></el-button>
|
<el-button slot="append" size="small" icon="el-icon-search"></el-button>
|
||||||
</el-input>
|
</el-input>
|
||||||
<el-button slot="reference" :class="lightTheme?'light-button':'dark-button'" size="small" icon="el-icon-search">搜索</el-button>
|
|
||||||
</el-popover>
|
</el-popover>
|
||||||
|
|
||||||
</el-button-group>
|
</el-button-group>
|
||||||
@ -135,7 +134,7 @@
|
|||||||
let input = data.node.span.querySelector('.fancytree-title .fancytree-edit-input')
|
let input = data.node.span.querySelector('.fancytree-title .fancytree-edit-input')
|
||||||
let width = input.style.width.substring(0,input.style.width.length-2)
|
let width = input.style.width.substring(0,input.style.width.length-2)
|
||||||
input.style.width = parseInt(width)+50+'px'
|
input.style.width = parseInt(width)+50+'px'
|
||||||
if(input.value.length -1 > data.node.data.suffix.length){
|
if(input.value && input.value.length -1 > data.node.data.suffix.length){
|
||||||
input.selectionStart = 0
|
input.selectionStart = 0
|
||||||
input.selectionEnd = input.value.length - 1 - data.node.data.suffix.length
|
input.selectionEnd = input.value.length - 1 - data.node.data.suffix.length
|
||||||
}
|
}
|
||||||
@ -246,6 +245,7 @@
|
|||||||
username: this.$store.state.user.name,
|
username: this.$store.state.user.name,
|
||||||
path: data.path
|
path: data.path
|
||||||
}).then(()=>{
|
}).then(()=>{
|
||||||
|
this.$emit('removeFile', data.path)
|
||||||
let node = this.tree.getActiveNode()
|
let node = this.tree.getActiveNode()
|
||||||
node.remove()
|
node.remove()
|
||||||
this.$message.success("删除成功!")
|
this.$message.success("删除成功!")
|
||||||
|
|||||||
@ -76,6 +76,7 @@
|
|||||||
@treeNodeClick="treeNodeClick"
|
@treeNodeClick="treeNodeClick"
|
||||||
@onLoadTreePath="onLoadTreePath"
|
@onLoadTreePath="onLoadTreePath"
|
||||||
@onRename="onRename"
|
@onRename="onRename"
|
||||||
|
@removeFile="removeFile"
|
||||||
>
|
>
|
||||||
</fancy-tree>
|
</fancy-tree>
|
||||||
</div>
|
</div>
|
||||||
@ -85,7 +86,7 @@
|
|||||||
<i v-show="!options.readOnly && !moblie " class="editor-resize-conter" icon="el-icon-arrow-right" title="影藏文件目录" @click="hideContents"/>
|
<i v-show="!options.readOnly && !moblie " class="editor-resize-conter" icon="el-icon-arrow-right" title="影藏文件目录" @click="hideContents"/>
|
||||||
</div>
|
</div>
|
||||||
<div :style="{width: editorWidth-2+'px'}">
|
<div :style="{width: editorWidth-2+'px'}">
|
||||||
<el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab">
|
<el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab" @tab-click="clickTab">
|
||||||
<el-tab-pane
|
<el-tab-pane
|
||||||
v-for="(item,index) in editableTabs"
|
v-for="(item,index) in editableTabs"
|
||||||
:key="item.name"
|
:key="item.name"
|
||||||
@ -95,21 +96,20 @@
|
|||||||
<span slot="label"><svg-icon class="tabs-icon-svg" :icon-class="findSvgClass(item.name)"></svg-icon> {{item.title}}</span>
|
<span slot="label"><svg-icon class="tabs-icon-svg" :icon-class="findSvgClass(item.name)"></svg-icon> {{item.title}}</span>
|
||||||
<div v-if="textPreviewVisible" class="editor">
|
<div v-if="textPreviewVisible" class="editor">
|
||||||
<vditor-preview
|
<vditor-preview
|
||||||
|
:ref="'vditor'+index"
|
||||||
class="content-body"
|
class="content-body"
|
||||||
v-show="editableTabsValue.endsWith('.md') && previewMode"
|
v-show="editableTabsValue.endsWith('.md') && previewMode"
|
||||||
:content="item.content"
|
|
||||||
:style="{height: editorHieght+'px'}"
|
:style="{height: editorHieght+'px'}"
|
||||||
/>
|
/>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
v-show="editableTabsValue.endsWith('.md') ? !previewMode: true"
|
v-show="editableTabsValue.endsWith('.md') ? !previewMode: true"
|
||||||
ref="monacoEditor"
|
:ref="'monacoEditor'+index"
|
||||||
:width="editorWidth"
|
:width="editorWidth"
|
||||||
:height="editorHieght"
|
:height="editorHieght"
|
||||||
:theme="lightTheme?'vs':'vs-dark'"
|
:theme="lightTheme?'vs':'vs-dark'"
|
||||||
:language="item.language"
|
:language="item.language"
|
||||||
:diffEditor="diffEditor"
|
:diffEditor="diffEditor"
|
||||||
original="..."
|
original="..."
|
||||||
:value="item.content"
|
|
||||||
:options="options"
|
:options="options"
|
||||||
@change="change($event,index)"
|
@change="change($event,index)"
|
||||||
@save="save($event,index)"
|
@save="save($event,index)"
|
||||||
@ -182,6 +182,7 @@
|
|||||||
contextmenu: true,
|
contextmenu: true,
|
||||||
codeLens: true,
|
codeLens: true,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
|
lineNumbers: this.$pc,
|
||||||
minimap: {
|
minimap: {
|
||||||
enabled: this.$pc
|
enabled: this.$pc
|
||||||
},
|
},
|
||||||
@ -217,7 +218,9 @@
|
|||||||
},
|
},
|
||||||
directoryTreeData: {},
|
directoryTreeData: {},
|
||||||
editableTabsValue: '1',
|
editableTabsValue: '1',
|
||||||
|
nextActiveName: '',
|
||||||
editableTabs: [],
|
editableTabs: [],
|
||||||
|
editableValueMap: new Map(),
|
||||||
filePathNav: '',
|
filePathNav: '',
|
||||||
toolbars: {
|
toolbars: {
|
||||||
readmodel: true, // 沉浸式阅读
|
readmodel: true, // 沉浸式阅读
|
||||||
@ -306,9 +309,9 @@
|
|||||||
copyTitle: res.data.name,
|
copyTitle: res.data.name,
|
||||||
language: this.getEditorLanguage(res.data.suffix),
|
language: this.getEditorLanguage(res.data.suffix),
|
||||||
status: undefined,//标签状态
|
status: undefined,//标签状态
|
||||||
name: pathname,
|
name: pathname
|
||||||
content: res.data.contentText
|
|
||||||
})
|
})
|
||||||
|
this.setEditMap(0, res.data.contentText)
|
||||||
this.editableTabsValue = pathname
|
this.editableTabsValue = pathname
|
||||||
// 界面的渲染后的初始化工作
|
// 界面的渲染后的初始化工作
|
||||||
this.$nextTick(()=>{
|
this.$nextTick(()=>{
|
||||||
@ -479,6 +482,12 @@
|
|||||||
onLoadTreePath(path){
|
onLoadTreePath(path){
|
||||||
this.filePathNav = path
|
this.filePathNav = path
|
||||||
},
|
},
|
||||||
|
removeFile(filepath) {
|
||||||
|
let findIndex = this.editableTabs.findIndex(editable => editable.name === filepath)
|
||||||
|
if(findIndex > -1){
|
||||||
|
this.editableTabs.splice(findIndex, 1)
|
||||||
|
}
|
||||||
|
},
|
||||||
treeNodeClick(row) {
|
treeNodeClick(row) {
|
||||||
if(row.isFolder){
|
if(row.isFolder){
|
||||||
return
|
return
|
||||||
@ -519,17 +528,19 @@
|
|||||||
copyTitle:row.name,
|
copyTitle:row.name,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
language: this.getEditorLanguage(row.suffix),
|
language: this.getEditorLanguage(row.suffix),
|
||||||
name:row.path,
|
name:row.path
|
||||||
content:res.data.contentText
|
|
||||||
}
|
}
|
||||||
if(row.isAddTab){
|
if(row.isAddTab){
|
||||||
this.editableTabs.push(tab)
|
this.editableTabs.push(tab)
|
||||||
|
this.setEditMap(this.editableTabs.length -1, res.data.contentText)
|
||||||
}else{
|
}else{
|
||||||
let thisTabIndex = this.editableTabs.findIndex(tab=> tab.status===undefined)
|
let thisTabIndex = this.editableTabs.findIndex(tab=> tab.status===undefined)
|
||||||
if(thisTabIndex > -1){
|
if(thisTabIndex > -1){
|
||||||
this.editableTabs[thisTabIndex] = tab
|
this.editableTabs[thisTabIndex] = tab
|
||||||
|
this.setEditMap(thisTabIndex, res.data.contentText)
|
||||||
}else{
|
}else{
|
||||||
this.editableTabs.push(tab)
|
this.editableTabs.push(tab)
|
||||||
|
this.setEditMap(this.editableTabs.length - 1, res.data.contentText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.editableTabsValue = row.path
|
this.editableTabsValue = row.path
|
||||||
@ -538,8 +549,19 @@
|
|||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
this.editableTabsValue = row.path
|
this.editableTabsValue = row.path
|
||||||
|
this.clickTab()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setEditMap(index, text) {
|
||||||
|
this.editableValueMap.set(index, text)
|
||||||
|
this.$nextTick(()=> {
|
||||||
|
let ref = 'monacoEditor' + index
|
||||||
|
this.$refs[ref][0]._setValue(text)
|
||||||
|
if (!this.$pc && this.dialogWidthPercent < 1) {
|
||||||
|
this.fullScreen()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
containerResize() {
|
containerResize() {
|
||||||
this.loadEditorSize()
|
this.loadEditorSize()
|
||||||
},
|
},
|
||||||
@ -554,7 +576,9 @@
|
|||||||
if(this.$store.state.user.token && this.$store.state.user.userId === fileUserId){
|
if(this.$store.state.user.token && this.$store.state.user.userId === fileUserId){
|
||||||
this.options.readOnly = false
|
this.options.readOnly = false
|
||||||
}
|
}
|
||||||
console.log(this.options.readOnly, this.moblie)
|
if (!this.$pc) {
|
||||||
|
this.options.readOnly = true
|
||||||
|
}
|
||||||
if(this.options.readOnly || this.moblie){
|
if(this.options.readOnly || this.moblie){
|
||||||
this.$nextTick(()=> {
|
this.$nextTick(()=> {
|
||||||
this.editorWidth += this.contentsWidth
|
this.editorWidth += this.contentsWidth
|
||||||
@ -598,9 +622,15 @@
|
|||||||
this.isSaveDialogVisible = false
|
this.isSaveDialogVisible = false
|
||||||
this.isShowUpdateBtn = false
|
this.isShowUpdateBtn = false
|
||||||
},
|
},
|
||||||
|
// 放弃修改
|
||||||
closeTabDialog(){
|
closeTabDialog(){
|
||||||
this.isTabSaveDialogVisible = false
|
this.isTabSaveDialogVisible = false
|
||||||
|
this.editableTabsValue = this.nextActiveName
|
||||||
this.editableTabs.splice(this.removeIndex,1)
|
this.editableTabs.splice(this.removeIndex,1)
|
||||||
|
let modifyingIndex = this.editableTabs.findIndex(editable => editable.status === 'Modifying')
|
||||||
|
if (modifyingIndex < 0){
|
||||||
|
this.isShowUpdateBtn = false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
closeDialog() {
|
closeDialog() {
|
||||||
this.textPreviewVisible = false
|
this.textPreviewVisible = false
|
||||||
@ -610,7 +640,7 @@
|
|||||||
this.closeAllTabs()
|
this.closeAllTabs()
|
||||||
},
|
},
|
||||||
change(value,index) {
|
change(value,index) {
|
||||||
if(value === this.editableTabs[index].content){
|
if(value === this.editableValueMap.get(index)){
|
||||||
if(this.editableTabs[index].copyTitle !== this.editableTabs[index].title){
|
if(this.editableTabs[index].copyTitle !== this.editableTabs[index].title){
|
||||||
this.editableTabs[index].title = this.editableTabs[index].copyTitle
|
this.editableTabs[index].title = this.editableTabs[index].copyTitle
|
||||||
this.editableTabs[index].status = 'Modified'
|
this.editableTabs[index].status = 'Modified'
|
||||||
@ -759,7 +789,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
changePreviewMode() {
|
changePreviewMode() {
|
||||||
|
let currentIndex = this.editableTabs.findIndex(editable => editable.name === this.editableTabsValue)
|
||||||
|
if (currentIndex > -1){
|
||||||
|
let ref = 'vditor' + currentIndex
|
||||||
|
this.$refs[ref][0].setContent(this.editableValueMap.get(currentIndex))
|
||||||
|
}
|
||||||
this.previewMode = !this.previewMode
|
this.previewMode = !this.previewMode
|
||||||
|
this.clickTab()
|
||||||
|
},
|
||||||
|
clickTab() {
|
||||||
|
this.editorWidth += 0.001
|
||||||
|
this.editorHieght += 0.001
|
||||||
},
|
},
|
||||||
removeTab(targetName) {
|
removeTab(targetName) {
|
||||||
let tabs = this.editableTabs;
|
let tabs = this.editableTabs;
|
||||||
@ -776,6 +816,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.nextActiveName = activeName
|
||||||
if(this.editableTabs[removeIndex].status !== 'Modifying'){
|
if(this.editableTabs[removeIndex].status !== 'Modifying'){
|
||||||
this.editableTabsValue = activeName;
|
this.editableTabsValue = activeName;
|
||||||
this.editableTabs = tabs.filter(tab => tab.name !== targetName);
|
this.editableTabs = tabs.filter(tab => tab.name !== targetName);
|
||||||
|
|||||||
@ -30,10 +30,7 @@ import "vditor/src/assets/scss/index.scss"
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
content(val){
|
content(val){
|
||||||
if(!this.vditorPreviewShow){
|
this.setContent(val)
|
||||||
this.vditorPreviewInit(val)
|
|
||||||
this.vditorPreviewShow = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -43,6 +40,12 @@ import "vditor/src/assets/scss/index.scss"
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
|
setContent(val) {
|
||||||
|
if(!this.vditorPreviewShow){
|
||||||
|
this.vditorPreviewInit(val)
|
||||||
|
this.vditorPreviewShow = true
|
||||||
|
}
|
||||||
|
},
|
||||||
vditorPreviewInit(content){
|
vditorPreviewInit(content){
|
||||||
const that = this
|
const that = this
|
||||||
vditor.preview(document.getElementById('vditor'),
|
vditor.preview(document.getElementById('vditor'),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user