cczg-lottery-activity/uni_modules/uview-ui/components/u-dropdown-item/u-dropdown-item.vue

128 lines
3.3 KiB
Vue
Raw Permalink Normal View History

2024-05-30 11:04:54 +08:00
<template>
<view class="u-drawdown">
<view
class="u-dropdown__menu"
:style="{
height: $u.addUnit(height)
}"
ref="u-dropdown__menu"
>
<view
class="u-dropdown__menu__item"
v-for="(item, index) in menuList"
:key="index"
@tap.stop="clickHandler(item, index)"
>
<view class="u-dropdown__menu__item__content">
<text
class="u-dropdown__menu__item__content__text"
:style="[index === current ? activeStyle : inactiveStyle]"
>{{item.title}}</text>
<view
class="u-dropdown__menu__item__content__arrow"
:class="[index === current && 'u-dropdown__menu__item__content__arrow--rotate']"
>
<u-icon
:name="menuIcon"
:size="$u.addUnit(menuIconSize)"
></u-icon>
</view>
</view>
</view>
</view>
<view class="u-dropdown__content">
<slot />
</view>
</view>
</template>
<script>
import props from './props.js';
/**
* Dropdown
* @description
* @tutorial url
* @property {String}
* @event {Function}
* @example
*/
export default {
name: 'u-dropdown',
mixins: [uni.$u.mixin, props],
data() {
return {
// <20>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>
menuList: [],
current: 0
}
},
computed: {
},
created() {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(u-dropdown-item)<29><>this<69><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>data<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>΢<EFBFBD><CEA2>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>
this.children = [];
},
methods: {
clickHandler(item, index) {
this.children.map(child => {
if(child.title === item.title) {
// this.queryRect('u-dropdown__menu').then(size => {
child.$emit('click')
child.setContentAnimate(child.show ? 0 : 300)
child.show = !child.show
// })
} else {
child.show = false
child.setContentAnimate(0)
}
})
},
// <20><>ȡ<EFBFBD><C8A1>ǩ<EFBFBD>ijߴ<C4B3>λ<EFBFBD><CEBB>
queryRect(el) {
// #ifndef APP-NVUE
// $uGetRectΪuView<65>Դ<EFBFBD><D4B4>Ľڵ<C4BD><DAB5>ѯ<EFBFBD>򻯷<EFBFBD><F2BBAFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ܣ<EFBFBD>https://www.uviewui.com/js/getRect.html
// <20><><EFBFBD><EFBFBD>ڲ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>this.$uGetRect<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊthis.$u.getRect<63><74><EFBFBD><EFBFBD><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD>Ʋ<EFBFBD>ͬ
return new Promise(resolve => {
this.$uGetRect(`.${el}`).then(size => {
resolve(size)
})
})
// #endif
// #ifdef APP-NVUE
// nvue<75>£<EFBFBD>ʹ<EFBFBD><CAB9>domģ<6D><C4A3><EFBFBD>ѯԪ<D1AF>ظ߶<D8B8>
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>promise<73><65><EFBFBD>õ<EFBFBD><C3B5>ô˷<C3B4><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>then<65>ص<EFBFBD>
return new Promise(resolve => {
dom.getComponentRect(this.$refs[el], res => {
resolve(res.size)
})
})
// #endif
},
},
}
</script>
<style lang="scss">
@import '../../libs/css/components.scss';
.u-dropdown {
&__menu {
@include flex;
&__item {
flex: 1;
@include flex;
justify-content: center;
&__content {
@include flex;
align-items: center;
}
}
}
}
</style>