1、html
<el-select
v-model="searchForm.hour"
:class="searchForm.hour?.length>1?'edit-tag-hour':'keep-tag-hour'"
filterable
multiple
clearable
:multiple-limit="2"
@remove-tag="removeChange"
@change="hourChange"
>
<el-option v-for="item in hourList" :key="item.value" class="ad-hour-bg" :label="item.label" :value="item.value" @mouseover.native="handleMouseOver(index)" />
</el-select>
2、js
handleMouseOver(index) {
if (this.searchForm.hour?.length === 1) {
const arrIndex = [this.searchForm.hour[0], index].sort((x, y) => x - y)
const elements = document.querySelectorAll('.ad-hour-bg')
elements.forEach((element, index) => {
if (index > arrIndex[0] && index < arrIndex[1]) {
element.style.backgroundColor = '#F2F6FC'
element.style.color = '#C0C4CC'
} else if (index === arrIndex[1]) {
element.style.backgroundColor = '#1177ff'
element.style.color = '#FFF'
} else if (index !== arrIndex[0]) {
element.style.backgroundColor = ''
element.style.color = '#606266'
}
})
}
},
removeChange(value) {
if (this.searchForm.hour?.length > 0) {
const elements = document.querySelectorAll('.ad-hour-bg')
elements.forEach((element, index) => {
if (index === this.searchForm.hour[0]) {
element.style.backgroundColor = '#FFF'
element.style.color = '#606266'
}
})
this.searchForm.hour = null
}
},
hourChange(value) {
const elements = document.querySelectorAll('.ad-hour-bg')
if (value?.length > 1) {
value.sort((x, y) => x - y)
this.$nextTick(() => {
const parentElement = document.querySelector('.edit-tag-hour')
if (parentElement) {
const bbElements = parentElement.querySelectorAll('.el-select__tags-text')
if (bbElements.length > 0) {
const firstBbElement = bbElements[0]
firstBbElement.textContent = `${firstBbElement.textContent} - `
}
}
})
elements.forEach((element, index) => {
if (index > value[0] && index < value[1]) {
element.style.backgroundColor = '#F2F6FC'
} else if (index === value[0] || index === value[1]) {
element.style.backgroundColor = '#1177ff'
element.style.color = '#FFF'
} else {
element.style.color = '#C0C4CC'
}
})
} else {
elements.forEach((element, index) => {
if (index === value[0]) {
element.style.backgroundColor = '#1177ff'
element.style.color = '#FFF'
} else {
element.style.backgroundColor = ''
element.style.color = '#606266'
}
})
this.$nextTick(() => {
const parentElement = document.querySelector('.keep-tag-hour')
if (parentElement) {
const bbElements = parentElement.querySelectorAll('.el-select__tags-text')
const firstBbElement = bbElements[0]
firstBbElement.textContent = firstBbElement.textContent.replace('-', '')
}
})
}
},
3、 css
.edit-tag-hour {
.el-tag:nth-child(1) {
border-right: 0;
border-radius: 4px 0 0 4px;
padding-right: 0;
.el-tag__close {
display: none;
}
}
.el-tag:nth-child(2) {
margin-left: 0;
border-left: 0;
border-radius: 0 4px 4px 0;
}
}
效果图
文章来源:https://www.toymoban.com/news/detail-681808.html
仅供参考,具体的实现可能根据自己的需要修改 ,仅供参考!仅供参考!仅供参考!文章来源地址https://www.toymoban.com/news/detail-681808.html
到了这里,关于el-select范围选择框的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!