提交 5b1b43d9 作者: 方治民

feat: fui-collapse 支持嵌套

上级 d816b05c
...@@ -104,6 +104,21 @@ ...@@ -104,6 +104,21 @@
watch: { watch: {
open(val) { open(val) {
this.isOpen = val this.isOpen = val
},
isOpen(val) {
this.$nextTick(async () => {
let parent = this.$parent;
let parentName = parent.$options.name;
while (parentName !== 'PageBody') {
if (parentName === 'fui-collapse-item') {
await parent.init()
}
parent = parent.$parent;
if (!parent) return false;
parentName = parent.$options.name;
}
})
} }
}, },
updated(e) { updated(e) {
...@@ -136,12 +151,14 @@ ...@@ -136,12 +151,14 @@
}, },
methods: { methods: {
init() { init() {
const promise = []
// #ifndef APP-NVUE // #ifndef APP-NVUE
this.getCollapseHeight() promise.push(this.getCollapseHeight())
// #endif // #endif
// #ifdef APP-NVUE // #ifdef APP-NVUE
this.getNvueHeight() promise.push(this.getNvueHeight())
// #endif // #endif
return Promise.all(promise)
}, },
uninstall() { uninstall() {
if (this.collapse) { if (this.collapse) {
...@@ -165,41 +182,49 @@ ...@@ -165,41 +182,49 @@
} }
}, },
getCollapseHeight(index = 0) { getCollapseHeight(index = 0) {
uni.createSelectorQuery() return new Promise((resolve) => {
// #ifndef MP-ALIPAY uni.createSelectorQuery()
.in(this) // #ifndef MP-ALIPAY
// #endif .in(this)
.select(`#${this.elId}`)
.fields({
size: true
}, data => {
if (index >= 10) return
if (!data) {
index++
this.getCollapseHeight(index)
return
}
// #ifdef APP-NVUE
this.height = data.height + 1
// #endif
// #ifndef APP-NVUE
this.height = data.height
// #endif // #endif
this.isHeight = true .select(`#${this.elId}`)
}) .fields({
.exec() size: true
}, data => {
if (index >= 10) return
if (!data) {
index++
this.getCollapseHeight(index)
return
}
// #ifdef APP-NVUE
this.height = data.height + 1
// #endif
// #ifndef APP-NVUE
this.height = data.height
// #endif
this.isHeight = true
resolve(this.height)
})
.exec()
})
}, },
getNvueHeight() { getNvueHeight() {
const result = dom.getComponentRect(this.$refs['fui_collapse__el'], option => { return new Promise((resolve) => {
if (option && option.result && option.size) { const result = dom.getComponentRect(this.$refs['fui_collapse__el'], option => {
// #ifdef APP-NVUE if (option && option.result && option.size) {
this.height = option.size.height + 1 // #ifdef APP-NVUE
// #endif this.height = option.size.height + 1
// #ifndef APP-NVUE // #endif
this.height = option.size.height // #ifndef APP-NVUE
// #endif this.height = option.size.height
this.isHeight = true // #endif
} this.isHeight = true
resolve(this.height)
}
})
}) })
}, },
getCollapse(name = 'fui-collapse') { getCollapse(name = 'fui-collapse') {
......
...@@ -8,13 +8,33 @@ ...@@ -8,13 +8,33 @@
<view class="fui-page__bd"> <view class="fui-page__bd">
<view class="fui-section__title">基础使用</view> <view class="fui-section__title">基础使用</view>
<!--fui-collapse-item可单独使用 @change事件仅无父组件fui-collapse时生效--> <!--fui-collapse-item可单独使用 @change事件仅无父组件fui-collapse时生效-->
<fui-collapse-item @change="change"> <fui-collapse-item @change="change" :animation="false">
<view class="fui-item__box"> <view class="fui-item__box">
<image src="/static/images/common/logo.png" class="fui-logo"></image> <image src="/static/images/common/logo.png" class="fui-logo"></image>
<text>First UI</text> <text>First UI</text>
</view> </view>
<template v-slot:content> <template v-slot:content>
<view class="fui-descr">First UI 是一套基于uni-app开发的组件化、可复用、易扩展、低耦合的跨平台移动端UI 组件库。</view> <view class="fui-descr">First UI 是一套基于uni-app开发的组件化、可复用、易扩展、低耦合的跨平台移动端UI 组件库。</view>
<fui-collapse-item @change="change" :animation="false">
<view class="fui-item__box">
<image src="/static/images/common/logo.png" class="fui-logo"></image>
<text>First UI2</text>
</view>
<template v-slot:content>
<view class="fui-descr">First UI2 是一套基于uni-app开发的组件化、可复用、易扩展、低耦合的跨平台移动端UI 组件库。</view>
<fui-collapse-item @change="change" :animation="false">
<view class="fui-item__box">
<image src="/static/images/common/logo.png" class="fui-logo"></image>
<text>First UI3</text>
</view>
<template v-slot:content>
<view class="fui-descr">First UI3 是一套基于uni-app开发的组件化、可复用、易扩展、低耦合的跨平台移动端UI 组件库。</view>
</template>
</fui-collapse-item>
</template>
</fui-collapse-item>
</template> </template>
</fui-collapse-item> </fui-collapse-item>
<view class="fui-section__title">默认展开</view> <view class="fui-section__title">默认展开</view>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论