blob: 8572957adf5722656fe1dd9738b9f92635616c6a [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<template>
2 <view class="u-collapse">
3 <slot />
4 </view>
5</template>
6
7<script>
8 /**
9 * collapse 手风琴
10 * @description 通过折叠面板收纳内容区域
11 * @tutorial https://www.uviewui.com/components/collapse.html
12 * @property {Boolean} accordion 是否手风琴模式(默认true)
13 * @property {Boolean} arrow 是否显示标题右侧的箭头(默认true)
14 * @property {String} arrow-color 标题右侧箭头的颜色(默认#909399)
15 * @property {Object} head-style 标题自定义样式,对象形式
16 * @property {Object} body-style 主体自定义样式,对象形式
17 * @property {String} hover-class 样式类名,按下时有效(默认u-hover-class)
18 * @event {Function} change 当前激活面板展开时触发(如果是手风琴模式,参数activeNames类型为String,否则为Array)
19 * @example <u-collapse></u-collapse>
20 */
21 export default {
22 name:"u-collapse",
23 props: {
24 // 是否手风琴模式
25 accordion: {
26 type: Boolean,
27 default: true
28 },
29 // 头部的样式
30 headStyle: {
31 type: Object,
32 default () {
33 return {}
34 }
35 },
36 // 主体的样式
37 bodyStyle: {
38 type: Object,
39 default () {
40 return {}
41 }
42 },
43 // 每一个item的样式
44 itemStyle: {
45 type: Object,
46 default () {
47 return {}
48 }
49 },
50 // 是否显示右侧的箭头
51 arrow: {
52 type: Boolean,
53 default: true
54 },
55 // 箭头的颜色
56 arrowColor: {
57 type: String,
58 default: '#909399'
59 },
60 // 标题部分按压时的样式类,"none"为无效果
61 hoverClass: {
62 type: String,
63 default: 'u-hover-class'
64 }
65 },
66 created() {
67 this.childrens = []
68 },
69 data() {
70 return {
71
72 }
73 },
74 methods: {
75 // 重新初始化一次内部的所有子元素的高度计算,用于异步获取数据渲染的情况
76 init() {
77 this.childrens.forEach((vm, index) => {
78 vm.init();
79 })
80 },
81 // collapse item被点击,由collapse item调用父组件方法
82 onChange() {
83 let activeItem = [];
84 this.childrens.forEach((vm, index) => {
85 if (vm.isShow) {
86 activeItem.push(vm.nameSync);
87 }
88 })
89 // 如果是手风琴模式,只有一个匹配结果,也即activeItem长度为1,将其转为字符串
90 if (this.accordion) activeItem = activeItem.join('');
91 this.$emit('change', activeItem);
92 }
93 }
94 }
95</script>
96
97<style lang="scss" scoped>
98 @import "../../libs/css/style.components.scss";
99</style>