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

145 lines
2.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="card-container" :style="{ borderRadius: borderRadius }">
<!-- 头部区域 -->
<view class="card-header" :style="headerStyle">
<text class="header-title">{{ title }}</text>
<text class="header-value">{{ value }}</text>
</view>
<!-- 信息容器条件渲染 -->
<view v-if="info && info.length" class="info-container">
<view v-for="(item, rowIndex) in info" :key="rowIndex" class="info-item">
<text class="info-label">{{ item.label }}</text>
<text class="info-value">
{{ item.value }}
<text v-if="item.unit" class="unit-text">{{ item.unit }}</text>
</text>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'DeviceInfoCard',
props: {
title: {
type: String,
required: true
},
value: {
type: [String, Number],
required: true
},
info: {
type: Array,
default: () => []
},
// 样式相关props
borderRadius: {
type: String,
default: '10rpx'
},
headerStyle: {
type: Object,
default: () => ({
backgroundColor: '#d9edf6',
border: '1px solid #d9edf6'
})
},
itemWidth: {
type: String,
default: '48%' // 控制信息项宽度
}
}
}
</script>
<style scoped>
/* 简洁信息卡片容器 */
.card-container {
overflow: hidden;
background: #ffffff;
border-radius: 16rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
border: 1rpx solid #e8e8e8;
transition: all 0.2s ease;
&:active {
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}
}
/* 简洁头部样式 */
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 24rpx 30rpx;
background: #1a73e8;
}
.header-title {
font-size: 32rpx;
color: #ffffff;
font-weight: 600;
}
.header-value {
font-size: 36rpx;
color: #ffffff;
font-weight: 700;
}
/* 信息容器 */
.info-container {
padding: 30rpx;
display: flex;
box-sizing: border-box;
flex-wrap: wrap;
gap: 20rpx;
background: #fff;
}
.info-row {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
}
/* 信息项 */
.info-item {
display: flex;
align-items: baseline;
flex: 0 0 calc(50% - 10rpx);
padding: 16rpx 20rpx;
background: #f8f9fa;
border-radius: 10rpx;
border: 1rpx solid #e8e8e8;
transition: all 0.2s ease;
&:active {
background: #f0f2f5;
}
}
.info-label {
color: #666;
font-size: 26rpx;
flex-shrink: 0;
margin-right: 16rpx;
}
.info-value {
color: #333;
font-size: 28rpx;
font-weight: 500;
word-break: break-all;
}
.unit-text {
font-size: 0.8em;
color: #999;
margin-left: 6rpx;
}
</style>