|
|
|
|
@ -1,146 +1,127 @@
|
|
|
|
|
<template>
|
|
|
|
|
<view class="u-drawdown-item">
|
|
|
|
|
<u-overlay
|
|
|
|
|
customStyle="top: 126px"
|
|
|
|
|
:show="show"
|
|
|
|
|
:closeOnClickOverlay="closeOnClickOverlay"
|
|
|
|
|
@click="overlayClick"
|
|
|
|
|
></u-overlay>
|
|
|
|
|
<view
|
|
|
|
|
class="u-drawdown-item__content"
|
|
|
|
|
:style="[style]"
|
|
|
|
|
:animation="animationData"
|
|
|
|
|
ref="animation"
|
|
|
|
|
>
|
|
|
|
|
<slot />
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<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>
|
|
|
|
|
// #ifdef APP-NVUE
|
|
|
|
|
const animation = uni.requireNativePlugin('animation')
|
|
|
|
|
const dom = uni.requireNativePlugin('dom')
|
|
|
|
|
// #endif
|
|
|
|
|
import props from './props.js';
|
|
|
|
|
/**
|
|
|
|
|
* Drawdownitem
|
|
|
|
|
* @description
|
|
|
|
|
* @tutorial url
|
|
|
|
|
* @property {String}
|
|
|
|
|
* @event {Function}
|
|
|
|
|
* @example
|
|
|
|
|
*/
|
|
|
|
|
export default {
|
|
|
|
|
name: 'u-drawdown-item',
|
|
|
|
|
mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
show: false,
|
|
|
|
|
top: '126px',
|
|
|
|
|
// uni.createAnimation的导出数据
|
|
|
|
|
animationData: {},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.init()
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
// 发生变化时,需要去更新父组件对应的值
|
|
|
|
|
dataChange(newValue, oldValue) {
|
|
|
|
|
this.updateParentData()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
// 监听对应变量的变化
|
|
|
|
|
dataChange() {
|
|
|
|
|
return [this.title, this.disabled]
|
|
|
|
|
},
|
|
|
|
|
style() {
|
|
|
|
|
const style = {
|
|
|
|
|
zIndex: 10071,
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0
|
|
|
|
|
}
|
|
|
|
|
style.top = uni.$u.addUnit(this.top)
|
|
|
|
|
return style
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
init() {
|
|
|
|
|
this.updateParentData()
|
|
|
|
|
},
|
|
|
|
|
// 更新父组件所需的数据
|
|
|
|
|
updateParentData() {
|
|
|
|
|
// 获取父组件u-dropdown
|
|
|
|
|
this.getParentData('u-dropdown')
|
|
|
|
|
if (!this.parent) uni.$u.error('u-dropdown-item必须配合u-dropdown使用')
|
|
|
|
|
// 查找父组件menuList数组中对应的标题数据
|
|
|
|
|
const menuIndex = this.parent.menuList.findIndex(item => item.title === this.title)
|
|
|
|
|
const menuContent = {
|
|
|
|
|
title: this.title,
|
|
|
|
|
disabled: this.disabled
|
|
|
|
|
}
|
|
|
|
|
if (menuIndex >= 0) {
|
|
|
|
|
// 如果能找到,则直接修改
|
|
|
|
|
this.parent.menuList[menuIndex] = menuContent;
|
|
|
|
|
} else {
|
|
|
|
|
// 如果无法找到,则为第一次添加,直接push即可
|
|
|
|
|
this.parent.menuList.push(menuContent);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async setContentAnimate(height) {
|
|
|
|
|
this.animating = true
|
|
|
|
|
// #ifdef APP-NVUE
|
|
|
|
|
const ref = this.$refs['animation'].ref
|
|
|
|
|
animation.transition(ref, {
|
|
|
|
|
styles: {
|
|
|
|
|
height: uni.$u.addUnit(height)
|
|
|
|
|
},
|
|
|
|
|
duration: this.duration,
|
|
|
|
|
timingFunction: 'ease-in-out',
|
|
|
|
|
}, () => {
|
|
|
|
|
this.animating = false
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// #ifndef APP-NVUE
|
|
|
|
|
const animation = uni.createAnimation({
|
|
|
|
|
timingFunction: 'ease-in-out',
|
|
|
|
|
});
|
|
|
|
|
animation
|
|
|
|
|
.height(height)
|
|
|
|
|
.step({
|
|
|
|
|
duration: this.duration,
|
|
|
|
|
})
|
|
|
|
|
.step()
|
|
|
|
|
// 导出动画数据给面板的animationData值
|
|
|
|
|
this.animationData = animation.export()
|
|
|
|
|
// 标识动画结束
|
|
|
|
|
uni.$u.sleep(this.duration).then(() => {
|
|
|
|
|
this.animating = false
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
|
|
|
|
overlayClick() {
|
|
|
|
|
this.show = false
|
|
|
|
|
this.setContentAnimate(0)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
|
// <EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
menuList: [],
|
|
|
|
|
current: 0
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(u-dropdown-item)<EFBFBD><EFBFBD>this<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>data<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD><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)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǩ<EFBFBD>ijߴ<EFBFBD>λ<EFBFBD><EFBFBD>
|
|
|
|
|
queryRect(el) {
|
|
|
|
|
// #ifndef APP-NVUE
|
|
|
|
|
// $uGetRectΪuView<EFBFBD>Դ<EFBFBD><EFBFBD>Ľڵ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>https://www.uviewui.com/js/getRect.html
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>this.$uGetRect<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊthis.$u.getRect<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߹<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>ͬ
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
this.$uGetRect(`.${el}`).then(size => {
|
|
|
|
|
resolve(size)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// #ifdef APP-NVUE
|
|
|
|
|
// nvue<EFBFBD>£<EFBFBD>ʹ<EFBFBD><EFBFBD>domģ<EFBFBD><EFBFBD><EFBFBD>ѯԪ<EFBFBD>ظ߶<EFBFBD>
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>promise<EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ô˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>then<EFBFBD>ص<EFBFBD>
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
dom.getComponentRect(this.$refs[el], res => {
|
|
|
|
|
resolve(res.size)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
@import '../../libs/css/components.scss';
|
|
|
|
|
|
|
|
|
|
.u-drawdown-item {
|
|
|
|
|
|
|
|
|
|
&__content {
|
|
|
|
|
background-color: #FFFFFF;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
height: 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<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>
|
|
|
|
|
|