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

View File

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