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,12 +136,14 @@ export default {
// //
let id = this.beInsertNodeUid let id = this.beInsertNodeUid
if (id && this.$refs.tree) { if (id && this.$refs.tree) {
try {
this.isAfterCreateNewNode = true
// //
this.$refs.tree.setCurrentKey(id) this.$refs.tree.setCurrentKey(id)
let node = this.$refs.tree.getNode(id) let node = this.$refs.tree.getNode(id)
this.onCurrentChange(node.data) this.onCurrentChange(node.data)
// //
this.onClick(null, node.data) this.onClick(node.data)
// //
const el = document.querySelector( const el = document.querySelector(
`.customNode[data-id="${id}"] .nodeEdit` `.customNode[data-id="${id}"] .nodeEdit`
@ -144,7 +157,11 @@ export default {
let offsetTop = el.offsetTop let offsetTop = el.offsetTop
this.$emit('scrollTo', 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,10 +7,12 @@
<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="outlineEditBox" ref="outlineEditBox">
<div class="outlineEdit"> <div class="outlineEdit">
<Outline :mindMap="mindMap" @scrollTo="onScrollTo"></Outline> <Outline :mindMap="mindMap" @scrollTo="onScrollTo"></Outline>
</div> </div>
</div> </div>
</div>
</template> </template>
<script> <script>
@ -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,11 +84,17 @@ export default {
} }
} }
.outlineEditBox {
width: 100%;
height: 100%;
overflow-y: auto;
padding: 50px 0;
.outlineEdit { .outlineEdit {
width: 1000px; width: 1000px;
height: 100%;
height: max-content; height: max-content;
overflow: hidden; margin: 0 auto;
padding: 50px 0;
/deep/ .customNode { /deep/ .customNode {
.nodeEdit { .nodeEdit {
@ -97,4 +103,5 @@ export default {
} }
} }
} }
}
</style> </style>