Skip to content

Commit

Permalink
feature: 文本框支持联想
Browse files Browse the repository at this point in the history
  • Loading branch information
ywywZhou authored and luofann committed Aug 23, 2023
1 parent e537233 commit 043a143
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<transition>
<div
class="rf-select-list"
:style="`right: ${varListPositionRight}px`"
:style="varListPosition"
v-show="showVarList && isListOpen">
<ul class="rf-select-content">
<li
Expand Down Expand Up @@ -111,7 +111,7 @@
focus: false
},
varList: [],
varListPositionRight: 0,
varListPosition: '',
hoverKey: '',
selection: {}
}
Expand Down Expand Up @@ -171,6 +171,7 @@
const divInputDom = this.$el.querySelector('.div-input')
if (divInputDom) {
divInputDom.innerHTML = this.value
this.handleInputBlur()
}
},
beforeDestroy () {
Expand Down Expand Up @@ -262,6 +263,8 @@
return false
})
selection.collapse(textNode, startToVarTextLength + varTextOffset)
} else if (this.input.value) {
this.handleInputChange(e)
}
},
// 文本框获取焦点
Expand All @@ -278,7 +281,7 @@
const { nodeName, lastChild } = selection.focusNode
if (nodeName === 'DIV') {
focusSelection = {
anchorOffset: lastChild.data.length,
anchorOffset: lastChild.textContent.length,
focusNode: lastChild
}
} else if (nodeName === '#text') {
Expand Down Expand Up @@ -320,7 +323,7 @@
// 计算变量下拉列表的left
this.isListOpen = false
if (this.varList.length) {
const { width: inputWidth } = this.$el.querySelector('.rf-form-wrap').getBoundingClientRect()
const { width: inputWidth, top: inputTop } = this.$el.querySelector('.rf-form-wrap').getBoundingClientRect()
let previousDomWidth = 0
let previousDomLeft = 0
const { previousElementSibling } = focusNode
Expand All @@ -341,6 +344,11 @@
let right = inputWidth - 238 - previousDomLeft - previousDomWidth - focusValueWidth
right = right > 0 ? right : 0
this.varListPositionRight = right
this.$nextTick(() => {
const { height: varListHeight } = document.querySelector('.rf-select-list').getBoundingClientRect()
const top = window.innerHeight < inputTop + 30 + varListHeight + 50 ? -95 : 30
this.varListPosition = `right: ${right}px; top: ${top}px`
})
}
} else {
this.varList = []
Expand Down Expand Up @@ -430,7 +438,7 @@
position: relative;
.rf-select-list {
position: absolute;
top: 40px;
top: 30px;
right: 0;
width: 238px;
background: #ffffff;
Expand Down
Loading

0 comments on commit 043a143

Please sign in to comment.