修改
This commit is contained in:
267
src/views/home/components/top-item.vue
Normal file
267
src/views/home/components/top-item.vue
Normal file
@@ -0,0 +1,267 @@
|
||||
<template>
|
||||
<div class="coreItem">
|
||||
<div class="item" v-for="(item, index) in itemList" :key="index" @click="handleRouter(item)">
|
||||
<div class="unit">{{ item.unit }}</div>
|
||||
<div class="item-content">
|
||||
<div class="content-wrapper">
|
||||
<div class="left">
|
||||
<div class="number">{{ item.targetValue }}</div>
|
||||
<div class="title">目标值</div>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<!-- 实际值:根据与目标值的比较动态变色 -->
|
||||
<div class="right">
|
||||
<div class="number" :class="{
|
||||
'exceed-target': item.currentValue > item.targetValue,
|
||||
'below-target': item.currentValue < item.targetValue,
|
||||
'equal-target': item.currentValue === item.targetValue
|
||||
}">
|
||||
{{ item.currentValue }}
|
||||
</div>
|
||||
<div class="title">实际值</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 进度条和百分比:同步变色逻辑 -->
|
||||
<div class="progress-group">
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar" :style="{ width: item.progress + '%' }" :class="{
|
||||
'exceed-pro-target': item.currentValue > item.targetValue,
|
||||
'below-pro-target': item.currentValue < item.targetValue,
|
||||
'equal-pro-target': item.currentValue === item.targetValue
|
||||
}"></div>
|
||||
</div>
|
||||
<div class="progress-percent" :class="{
|
||||
'exceed-target': item.currentValue > item.targetValue,
|
||||
'below-target': item.currentValue < item.targetValue,
|
||||
'equal-target': item.currentValue === item.targetValue
|
||||
}">
|
||||
{{ item.progress }}%
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "Container",
|
||||
components: {},
|
||||
props: ["name", "size", "icon"],
|
||||
data() {
|
||||
return {
|
||||
itemList: [
|
||||
{
|
||||
unit: "单价·元/㎡",
|
||||
targetValue: 16,
|
||||
currentValue: 14.5, // 小于目标值(黄色)
|
||||
progress: 90,
|
||||
path: "/cost/cost"
|
||||
},
|
||||
{
|
||||
unit: "净价·元/㎡",
|
||||
targetValue: 16,
|
||||
currentValue: 16, // 等于目标值(默认灰色)
|
||||
progress: 100,
|
||||
path: "/cost/cost"
|
||||
},
|
||||
{
|
||||
unit: "销量·万㎡",
|
||||
targetValue: 20,
|
||||
currentValue: 22, // 大于目标值(绿色)
|
||||
progress: 110,
|
||||
path: "PSIAnal"
|
||||
},
|
||||
{
|
||||
unit: "双镀面板·万㎡",
|
||||
targetValue: 15,
|
||||
currentValue: 13.8, // 小于目标值(黄色)
|
||||
progress: 92,
|
||||
path: "PSIAnal"
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
// 处理路由跳转
|
||||
handleRouter(obj) {
|
||||
if (obj.path) {
|
||||
this.$router.push({ path: obj.path });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.coreItem {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-rows: 1fr 1fr;
|
||||
gap: 8px;
|
||||
// padding: 8px; // 避免边缘item hover时阴影被截断
|
||||
}
|
||||
|
||||
.item {
|
||||
width: 252px;
|
||||
height: 110px;
|
||||
background: #f9fcff;
|
||||
padding: 12px;
|
||||
box-sizing: border-box;
|
||||
cursor: pointer; // 提示可点击
|
||||
transition: all 0.3s ease; // 动画过渡
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0px 4px 12px 2px #B5CDE5;
|
||||
transform: translateY(-2px); // 轻微上浮增强交互感
|
||||
}
|
||||
|
||||
.unit {
|
||||
height: 18px;
|
||||
font-family: PingFangSC, PingFang SC;
|
||||
font-weight: 400;
|
||||
font-size: 18px;
|
||||
color: #000000;
|
||||
line-height: 18px;
|
||||
letter-spacing: 1px;
|
||||
text-align: left;
|
||||
font-style: normal;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.item-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
height: calc(100% - 26px);
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.line {
|
||||
width: 1px;
|
||||
height: 46px;
|
||||
background: linear-gradient(to bottom, rgba(255, 0, 0, 0), rgba(40, 203, 151, 1));
|
||||
}
|
||||
|
||||
.left,
|
||||
.right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.number {
|
||||
height: 22px;
|
||||
font-family: PingFangSC, PingFang SC;
|
||||
font-weight: 600;
|
||||
font-size: 24px;
|
||||
color: rgba(103, 103, 103, 0.79);
|
||||
/* 默认颜色(等于目标值时) */
|
||||
line-height: 22px;
|
||||
text-align: center;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.title {
|
||||
height: 14px;
|
||||
font-family: PingFangSC, PingFang SC;
|
||||
font-weight: 400;
|
||||
font-size: 12px;
|
||||
color: #868687;
|
||||
line-height: 14px;
|
||||
text-align: center;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.progress-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
width: 190px;
|
||||
height: 10px;
|
||||
background: #ECEFF7;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
background: rgba(98, 213, 180, 1);
|
||||
/* 默认进度条颜色(等于目标值时) */
|
||||
border-radius: 8px;
|
||||
opacity: 0.7;
|
||||
transition: width 0.5s ease; // 进度条动画
|
||||
}
|
||||
|
||||
.progress-percent {
|
||||
font-family: PingFangSC, PingFang SC;
|
||||
font-weight: 400;
|
||||
font-size: 12px;
|
||||
color: #868687;
|
||||
/* 默认百分比颜色(等于目标值时) */
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* 实际值 > 目标值:绿色样式 */
|
||||
.exceed-target {
|
||||
color: rgba(98, 213, 180, 1) !important;
|
||||
/* 文字绿色 */
|
||||
// background: rgba(98, 213, 180, 1) !important;
|
||||
/* 进度条绿色 */
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
/* 实际值 < 目标值:黄色样式 */
|
||||
.below-target {
|
||||
color: rgba(249, 164, 74, 1) !important;
|
||||
/* 文字黄色 */
|
||||
// background: rgba(249, 164, 74, 1) !important;
|
||||
/* 进度条黄色 */
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.exceed-pro-target {
|
||||
// color: rgba(98, 213, 180, 1) !important;
|
||||
/* 文字绿色 */
|
||||
background: rgba(98, 213, 180, 1) !important;
|
||||
/* 进度条绿色 */
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
/* 实际值 < 目标值:黄色样式 */
|
||||
.below-pro-target {
|
||||
// color: rgba(249, 164, 74, 1) !important;
|
||||
/* 文字黄色 */
|
||||
background: rgba(249, 164, 74, 1) !important;
|
||||
/* 进度条黄色 */
|
||||
opacity: 1 !important;
|
||||
}
|
||||
/* 实际值 = 目标值:默认灰色(可自定义) */
|
||||
.equal-target{
|
||||
color: rgba(98, 213, 180, 1) !important;
|
||||
/* 文字绿色 */
|
||||
// background: rgba(98, 213, 180, 1) !important;
|
||||
/* 进度条绿色 */
|
||||
opacity: 1 !important;
|
||||
}
|
||||
.equal-pro-target {
|
||||
// color: rgba(98, 213, 180, 1) !important;
|
||||
/* 文字绿色 */
|
||||
background: rgba(98, 213, 180, 1) !important;
|
||||
/* 进度条绿色 */
|
||||
opacity: 1 !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user