Files
klp-mono/apps/hand-factory/components/klp-ui/k-collapse-panel/k-collapse-panel.vue
2025-10-29 15:38:20 +08:00

151 lines
2.7 KiB
Vue

<template>
<view class="collapse-panel">
<view
class="collapse-header"
@click="toggleCollapse"
>
<view class="title">
<uni-icons type="gear-filled" size="18" color="white" />
<text>{{ title }}</text>
</view>
<view class="header-right">
<view class="extra" @click.stop>
<slot name="extra"></slot>
</view>
<view
class="arrow"
:class="{ 'arrow-open': isOpen }"
>
<uni-icons type="arrowright" size="18" color="white" />
</view>
</view>
</view>
<view
class="collapse-content"
:style="contentStyle"
>
<slot />
</view>
</view>
</template>
<script>
export default {
// 定义组件接收的属性
props: {
title: {
type: String,
required: true
},
duration: {
type: Number,
default: 300
},
isBorder: {
type: Boolean,
default: true
}
},
// 响应式数据
data() {
return {
isOpen: false,
contentHeight: 0
};
},
// 计算属性
computed: {
contentStyle() {
return {
'max-height': this.isOpen ? '1000px' : '0',
'transition': `all ${this.duration}ms ease`,
'opacity': this.isOpen ? 1 : 0
};
}
},
// 方法定义
methods: {
toggleCollapse() {
this.isOpen = !this.isOpen;
}
}
};
</script>
<style lang="scss" scoped>
/* 简洁折叠面板 */
.collapse-panel {
margin: 16rpx 0;
border-radius: 16rpx;
overflow: hidden;
background: #ffffff;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
border: 1rpx solid #e8e8e8;
transition: all 0.3s ease;
.collapse-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 24rpx 30rpx;
background: #1a73e8;
color: white;
transition: all 0.2s ease;
&:active {
opacity: 0.9;
}
.title {
font-size: 32rpx;
font-weight: 600;
color: #ffffff;
display: flex;
align-items: center;
gap: 12rpx;
}
.header-right {
display: flex;
align-items: center;
gap: 16rpx;
}
.extra {
display: flex;
align-items: center;
}
.arrow {
transition: transform 0.3s ease;
color: white;
display: flex;
align-items: center;
justify-content: center;
&-open {
transform: rotate(90deg);
}
}
}
.collapse-content {
overflow: hidden;
padding: 0;
background: #fff;
&-enter-active,
&-leave-active {
transition: all 0.3s ease;
}
&-enter-from,
&-leave-to {
opacity: 0;
max-height: 0;
}
}
}
</style>