uni-collapse.vue 982 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<template>
	<!-- 父组件暂时无用,后续子组件联动需要使用到父组件 -->
	<view>
		<slot></slot>
	</view>
</template>

<script lang="uts">
	export default {
		name: "UniCollapse",
		props: {
			// 是否开启手风琴效果
			accordion: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
20
				child_nodes: [] as Array<ComponentPublicInstance>
fxy060608's avatar
fxy060608 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
			};
		},

		methods: {
			init(child: ComponentPublicInstance) {
				this.child_nodes.push(child)
			},
			// 关闭所有
			cloceAll() {
				// 开启手风琴效果才回关闭其他
				if (this.accordion && this.child_nodes.length > 0) {
					this.child_nodes.forEach((item) => {
						const is_open = item.$data['is_open'] as boolean
						// TODO 暂时无法获取子组件上的属性和方法,暂时使用绕过方案
						if (is_open) {
							item.$data['is_open'] = false
M
mehaotian 已提交
37
							item.$callMethod('openOrClose', false)
fxy060608's avatar
fxy060608 已提交
38 39 40 41 42 43 44 45 46 47 48
						}
					})
				}
			}
		}
	}
</script>

<style>

</style>