2022-08-31 11:03:20 +08:00
< template >
< div class = "dropdown-menu" : class = "{'toggle_disabled': disabled === true}" ref = "elemId" >
< div v-if = "inputed === false" class="fxrow dropdown-menu__item" @click="toggleItem" >
< span class = "dropdown-menu__title" : class = "{'dropdown-menu__title_up': up === true,'dropdown-menu__title--active': open === true,'dropdown-menu__title--active_up': up === true && open === true}" > < div class = "ellipsis chose_T" > { { active === '' ? '请选择' : option [ active ] . label } } < / div > < / span >
< / div >
< div v-if = "inputed === true" class="fxrow dropdown-menu__item dropdown-menu__item_2" >
< input
type = "text"
placeholder = "请输入"
class = "fxcol drop_input"
: value = "value"
@ input = "handleChange($event)" >
< span class = "fxcol dropdown-menu__title dropdown-menu__title_2" : class = "{'dropdown-menu__title_up': up === true,'dropdown-menu__title--active': open === true,'dropdown-menu__title--active_up': up === true && open === true}" @click ="toggleItem" > < div class = "ellipsis" > & nbsp ; < / div > < / span >
< / div >
< div v-show = "open" class="dropdown-item" :style="up === false ? 'top: .9rem' : 'bottom: .9rem'" >
< div ref = "dropdown" class = "dropdown-item__content" >
< div v-show = "option.length > 0" v-for="(e, i) in option" :key="e.value" @click="$emit('dropdownMenu', i)" class="fxrow dropdown-item__option dropdown-item__option--active" >
< div class = "cell__title" : class = "{'cell__title--active': i + '' === active}" > < span > { { e . label } } < / span > < / div >
< div class = "iconfont check_icon" : class = "{'check_icon--checked': i + '' === active}" > < / div >
< / div >
< div v-show = "option.length === 0" class="fxrow dropdown-item__option dropdown-item__option--active" @click="handleBlur" >
< div class = "cell__title" > < span > 无匹配数据 < / span > < / div >
< / div >
< / div >
< / div >
< / div >
< / template >
< script >
export default {
name : 'DropdownMenu' ,
model : {
prop : 'value' ,
event : 'input'
} ,
props : {
value : String ,
option : Array ,
active : String ,
open : Boolean ,
up : {
type : Boolean ,
default : false
} ,
disabled : {
type : Boolean ,
default : false
} ,
inputed : {
type : Boolean ,
default : false
}
} ,
methods : {
toggleItem ( ) {
let cheight = document . body . clientHeight
let bottom = this . $refs . elemId . getBoundingClientRect ( ) . bottom
this . $refs . dropdown . style . maxHeight = ( cheight - bottom - 20 ) + 'px'
this . $emit ( 'toggleItem' )
} ,
handleChange ( $event ) {
let cheight = document . body . clientHeight
let bottom = this . $refs . elemId . getBoundingClientRect ( ) . bottom
this . $refs . dropdown . style . maxHeight = ( cheight - bottom - 20 ) + 'px'
this . $emit ( 'input' , $event . target . value )
this . $emit ( 'handleChange' , $event . target . value )
} ,
handleBlur ( ) {
this . $emit ( 'handleBlur' )
}
}
}
< / script >
< style lang = "stylus" scoped >
@ import '~@style/mixin'
. dropdown - menu
position relative
height .9 rem
border .02 rem solid # dcdfe6
border - radius 4 px
background - color # fff
user - select none
width 100 %
// padding 0 .15rem
. selectopt
// _font(.3rem, .9rem, #606266)
. selectbtn
position relative
flex 0 0 1 rem
_wh ( .8 rem , .8 rem )
vertical - align top
background - color # cccccc
& : : before
content ''
width 0
height 0
border - left .5 rem solid transparent
border - right .5 rem solid transparent
border - top .5 rem solid white
position absolute
right .15 rem
top .15 rem
pointer - events none
z - index 3
. options
position absolute
z - index 100000
top .9 rem
width 100 %
li
width 100 %
_font ( .12 rem , .35 rem , # 000000 )
background - color # cccccc
border - top 1 px solid # ffffff
padding 0 .3 rem 0 .1 rem
user - select none
& : hover
background : # 999
. dropdown - menu _ _item
justify - content center
height inherit
width 100 %
. dropdown - menu _ _item _2
align - items flex - start
. drop _input
height .86 rem
width calc ( 100 % - 3 rem )
padding 0 .15 rem
color # 606266
font - size .3 rem
line - height .86 rem
. dropdown - menu _ _title
position relative
width 100 %
padding 0 .15 rem
color # 606266
font - size .3 rem
line - height .44 rem
width 100 %
display block
& : : after
position absolute
top 50 %
right .16 rem
margin - top - .1 rem
border .06 rem solid
border - color transparent transparent # 606266 # 606266
transform rotate ( - 45 deg )
opacity 0.8
content ''
. dropdown - menu _ _title _2
line - height .9 rem
max - width 1.4 rem
2022-11-28 18:25:59 +08:00
background - color # e5e5e5
2022-08-31 11:03:20 +08:00
& : : after
right .16 rem
. dropdown - menu _ _title _up
& : : after
transform rotate ( 135 deg )
top calc ( 50 % + .06 rem )
. dropdown - menu _ _title -- active , . dropdown - menu _ _title -- active div
color $red ! important
& : : after
border - color transparent transparent currentColor currentColor
margin - top - .02 rem
transform rotate ( 135 deg )
. dropdown - menu _ _title -- active _up , . dropdown - menu _ _title -- active _up div
& : : after
transform rotate ( - 45 deg )
top calc ( 50 % - .06 rem )
. dropdown - item
position absolute
left 0
width 100 %
z - index 10
border - radius 4 px
overflow hidden
box - shadow 0 0 .08 rem 0.02 rem rgba ( 160 , 160 , 160 , 0.9 )
. dropdown - item _ _content
position relative
width 100 %
height auto
z - index 2047
overflow - y auto
background - color # fff
transition transform 0.3 s
. dropdown - item _ _option
width 100 %
height .9 rem
padding 0 .15 rem
overflow hidden
. cell _ _title
height .9 rem
overflow hidden
span
_font ( .3 rem , .9 rem , # 606266 )
. cell _ _title -- active span
color $red
. toggle _disabled
background - color # f5f7fa
border 0.02 rem solid # e4e7ed
cursor not - allowed
. dropdown - menu _ _title
div
color # 929292
& : : after
border - color transparent transparent # 929292 # 929292
. chose _T
width 100 %
overflow hidden
< / style >