Demo:优化大纲编辑

This commit is contained in:
wanglin2 2023-08-07 10:09:05 +08:00
parent ff56fe3e68
commit d17191c890
2 changed files with 79 additions and 45 deletions

View File

@ -20,7 +20,7 @@
class="customNode"
slot-scope="{ node, data }"
:data-id="data.uid"
@click="onClick($event, data)"
@click="onClick(data)"
>
<span
class="nodeEdit"
@ -63,7 +63,9 @@ export default {
notHandleDataChange: false,
handleNodeTreeRenderEnd: false,
beInsertNodeUid: '',
isInTreArea: false
insertType: '',
isInTreArea: false,
isAfterCreateNewNode: false
}
},
computed: {
@ -72,18 +74,27 @@ export default {
created() {
window.addEventListener('keydown', this.onKeyDown)
this.$bus.$on('data_change', () => {
//
//
if (this.notHandleDataChange) {
this.notHandleDataChange = false
return
}
if (this.isAfterCreateNewNode) {
this.isAfterCreateNewNode = false
return
}
this.refresh()
})
this.$bus.$on('node_tree_render_end', () => {
//
//
if (this.insertType) {
this[this.insertType]()
this.insertType = ''
return
}
//
if (this.handleNodeTreeRenderEnd) {
this.handleNodeTreeRenderEnd = false
this.notHandleDataChange = false
this.refresh()
this.$nextTick(() => {
this.afterCreateNewNode()
@ -125,26 +136,32 @@ export default {
//
let id = this.beInsertNodeUid
if (id && this.$refs.tree) {
//
this.$refs.tree.setCurrentKey(id)
let node = this.$refs.tree.getNode(id)
this.onCurrentChange(node.data)
//
this.onClick(null, node.data)
//
const el = document.querySelector(
`.customNode[data-id="${id}"] .nodeEdit`
)
if (el) {
let selection = window.getSelection()
let range = document.createRange()
range.selectNodeContents(el)
selection.removeAllRanges()
selection.addRange(range)
let offsetTop = el.offsetTop
this.$emit('scrollTo', offsetTop)
try {
this.isAfterCreateNewNode = true
//
this.$refs.tree.setCurrentKey(id)
let node = this.$refs.tree.getNode(id)
this.onCurrentChange(node.data)
//
this.onClick(node.data)
//
const el = document.querySelector(
`.customNode[data-id="${id}"] .nodeEdit`
)
if (el) {
let selection = window.getSelection()
let range = document.createRange()
range.selectNodeContents(el)
selection.removeAllRanges()
selection.addRange(range)
let offsetTop = el.offsetTop
this.$emit('scrollTo', offsetTop)
}
} catch (error) {
console.log(error)
}
}
this.beInsertNodeUid = ''
},
//
@ -154,9 +171,16 @@ export default {
//
onBlur(e, node) {
//
if (node.data.textCache === e.target.innerHTML) {
//
if (this.insertType) {
this[this.insertType]()
this.insertType = ''
}
return
}
//
const richText = node.data.data.richText
const text = richText ? e.target.innerHTML : e.target.innerText
const targetNode = this.mindMap.renderer.findNodeByUid(node.data.uid)
@ -193,11 +217,13 @@ export default {
onNodeInputKeydown(e) {
if (e.keyCode === 13 && !e.shiftKey) {
e.preventDefault()
this.insertNode()
this.insertType = 'insertNode'
e.target.blur()
}
if (e.keyCode === 9) {
e.preventDefault()
this.insertChildNode()
this.insertType = 'insertChildNode'
e.target.blur()
}
},
@ -222,13 +248,14 @@ export default {
},
//
onClick(e, data) {
onClick(data) {
this.notHandleDataChange = true
const targetNode = this.mindMap.renderer.findNodeByUid(data.uid)
if (targetNode && targetNode.nodeData.data.isActive) return
this.mindMap.renderer.textEdit.stopFocusOnNodeActive()
this.mindMap.execCommand('GO_TARGET_NODE', data.uid, () => {
this.mindMap.renderer.textEdit.openFocusOnNodeActive()
this.notHandleDataChange = false
})
},

View File

@ -7,8 +7,10 @@
<div class="closeBtn" @click="onClose">
<span class="icon iconfont iconguanbi"></span>
</div>
<div class="outlineEdit">
<Outline :mindMap="mindMap" @scrollTo="onScrollTo"></Outline>
<div class="outlineEditBox" ref="outlineEditBox">
<div class="outlineEdit">
<Outline :mindMap="mindMap" @scrollTo="onScrollTo"></Outline>
</div>
</div>
</div>
</template>
@ -33,11 +35,11 @@ export default {
},
watch: {
isOutlineEdit(val) {
if (val) {
this.$nextTick(() => {
document.body.appendChild(this.$refs.outlineEditContainer)
})
}
if (val) {
this.$nextTick(() => {
document.body.appendChild(this.$refs.outlineEditContainer)
})
}
}
},
methods: {
@ -48,7 +50,7 @@ export default {
},
onScrollTo(y) {
let container = this.$refs.outlineEditContainer
let container = this.$refs.outlineEditBox
let height = container.offsetHeight
let top = container.scrollTop
y += 50
@ -68,14 +70,12 @@ export default {
width: 100%;
height: 100%;
z-index: 9999;
display: flex;
justify-content: center;
background-color: #fff;
overflow-y: auto;
overflow: hidden;
.closeBtn {
position: absolute;
right: 20px;
right: 40px;
top: 20px;
cursor: pointer;
@ -84,15 +84,22 @@ export default {
}
}
.outlineEdit {
width: 1000px;
height: max-content;
overflow: hidden;
.outlineEditBox {
width: 100%;
height: 100%;
overflow-y: auto;
padding: 50px 0;
/deep/ .customNode {
.nodeEdit {
max-width: 800px;
.outlineEdit {
width: 1000px;
height: 100%;
height: max-content;
margin: 0 auto;
/deep/ .customNode {
.nodeEdit {
max-width: 800px;
}
}
}
}