go-view-fetch/src/packages/components/Charts/MyComponents/TopAlarms/index.vue

239 lines
5.5 KiB
Vue
Raw Normal View History

2025-08-20 12:09:24 +08:00
<template>
2025-08-21 16:06:26 +08:00
<SmallBorder class="SmallBorder">
<div class="go-top-alarms">
<div class="header">
<div class="title">
<div class="title-text">
<span :style="{
color: option.titleColor,
fontSize: option.titleSize + 'px',
marginTop: option.paddingY + 'px',
marginLeft: option.paddingX + 'px',
letterSpacing: option.letterSpacing + 'px'
}">{{ option.title }}</span>
2025-08-20 12:09:24 +08:00
</div>
2025-08-21 16:06:26 +08:00
</div>
<n-dropdown v-if='option.isShowButton' trigger="hover" :options="dropdownOptions" @select="handleSelect">
<div class="dropdown-button">
{{ selectedOption }}
<svg-icon icon-class="arrow-down" class="arrow-down-icon" />
2025-08-20 12:09:24 +08:00
</div>
2025-08-21 16:06:26 +08:00
</n-dropdown>
</div>
<div class="content">
<ul>
<li v-for="(item, index) in option.dataset" :key="index" class="alarm-item">
<div class="item-info">
<span class="rank" :style="{ color: option.rankColor }">
<span class="rank-icon"></span>
{{ item.rank }}
</span>
<span class="name" :style="{ color: option.nameColor }">{{ item.name }}</span>
</div>
<div class="item-value">
<span class="value" :style="{ color: option.valueColor }">{{ item.value }}</span>
</div>
<div class="progress-bar-wrapper">
<div class="progress-bar">
<div class="progress" :style="{
2025-08-20 18:36:43 +08:00
width: calculateWidth(item.value),
background: `linear-gradient(to right, ${option.barColorStart}, ${option.barColorEnd})`
2025-08-21 16:06:26 +08:00
}"></div>
</div>
2025-08-20 18:36:43 +08:00
</div>
2025-08-21 16:06:26 +08:00
</li>
</ul>
</div>
2025-08-20 12:09:24 +08:00
</div>
2025-08-21 16:06:26 +08:00
</SmallBorder>
2025-08-20 12:09:24 +08:00
</template>
<script setup lang="ts">
import { ref, computed, PropType } from 'vue'
import { option as configOption } from './config'
2025-08-21 16:06:26 +08:00
import SmallBorder from '../SmallBorder/index.vue'
2025-08-20 12:09:24 +08:00
const props = defineProps({
chartConfig: {
type: Object as PropType<{ option: typeof configOption }>,
required: true
}
})
const option = computed(() => props.chartConfig.option)
const selectedOption = ref(props.chartConfig.option.dropdownDefault)
const dropdownOptions = computed(() => {
return props.chartConfig.option.dropdownOptions.map(opt => ({
label: opt,
key: opt
}))
})
const maxValue = computed(() => {
2025-08-20 18:36:43 +08:00
const values = props.chartConfig.option.dataset.map(item => item.value)
return Math.max(...values, 1) // Avoid division by zero
2025-08-20 12:09:24 +08:00
})
const calculateWidth = (value: number) => {
if (maxValue.value === 0) return '0%'
2025-08-20 18:36:43 +08:00
return `${(value / maxValue.value) * 80}%` // Max width 80% to leave space for value
2025-08-20 12:09:24 +08:00
}
const handleSelect = (key: string) => {
selectedOption.value = key
}
</script>
<style lang="scss" scoped>
2025-08-21 16:06:26 +08:00
.SmallBorder {
position: relative;
}
2025-08-20 12:09:24 +08:00
.go-top-alarms {
2025-08-21 16:06:26 +08:00
position: absolute;
top: 0;
right: 0;
2025-08-20 12:09:24 +08:00
width: 100%;
height: 100%;
2025-08-21 16:06:26 +08:00
margin-top: -10px;
// background-color: #0a162b;
2025-08-20 12:09:24 +08:00
padding: 15px;
box-sizing: border-box;
display: flex;
flex-direction: column;
2025-08-20 18:36:43 +08:00
color: #fff;
2025-08-20 12:09:24 +08:00
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
.title {
display: flex;
align-items: center;
2025-08-21 16:06:26 +08:00
2025-08-20 18:36:43 +08:00
.title-text {
height: 35px;
display: flex;
align-items: center;
padding: 0 20px 0 20px;
2025-08-21 16:06:26 +08:00
margin-left: 0px;
2025-08-20 18:36:43 +08:00
clip-path: polygon(10% 0, 100% 0, 100% 100%, 0% 100%);
}
}
.dropdown-button {
height: 30px;
padding: 0 15px;
background-color: #034a4b;
border: 1px solid #00e5ff;
border-radius: 15px;
display: flex;
align-items: center;
cursor: pointer;
color: #fff;
2025-08-21 16:06:26 +08:00
2025-08-20 18:36:43 +08:00
.arrow-down-icon {
margin-left: 8px;
font-size: 14px;
2025-08-20 12:09:24 +08:00
}
}
}
.content {
flex: 1;
2025-08-21 16:06:26 +08:00
margin-top: -15px;
padding-right: 10px;
font-size: 12.5px;
2025-08-20 12:09:24 +08:00
ul {
list-style: none;
padding: 0;
margin: 0;
2025-08-20 18:36:43 +08:00
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-around;
2025-08-20 12:09:24 +08:00
}
}
.alarm-item {
display: grid;
grid-template-columns: 1fr auto;
grid-template-rows: auto auto;
grid-template-areas:
2025-08-20 18:36:43 +08:00
'info value'
'bar bar';
align-items: center;
2025-08-21 16:06:26 +08:00
padding: 0 10px;
gap: 6px 15px;
2025-08-20 12:09:24 +08:00
.item-info {
grid-area: info;
display: flex;
align-items: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
.rank {
2025-08-21 16:06:26 +08:00
font-weight: normal;
2025-08-20 12:09:24 +08:00
margin-right: 10px;
2025-08-20 18:36:43 +08:00
display: flex;
align-items: center;
2025-08-21 16:06:26 +08:00
2025-08-20 12:09:24 +08:00
.rank-icon {
2025-08-20 18:36:43 +08:00
display: inline-block;
2025-08-21 16:06:26 +08:00
width: 4px;
height: 4px;
2025-08-20 18:36:43 +08:00
border-radius: 50%;
background-color: #00e5ff;
margin-right: 8px;
2025-08-21 16:06:26 +08:00
margin-left: 6px;
box-shadow: 0 0 6px #00e5ff;
2025-08-20 12:09:24 +08:00
}
}
2025-08-21 16:06:26 +08:00
2025-08-20 18:36:43 +08:00
.name {
overflow: hidden;
text-overflow: ellipsis;
2025-08-21 16:06:26 +08:00
flex-grow: 1;
2025-08-20 18:36:43 +08:00
}
2025-08-20 12:09:24 +08:00
}
.item-value {
grid-area: value;
text-align: right;
2025-08-21 16:06:26 +08:00
// font-size: 16px;
font-weight: normal;
2025-08-20 12:09:24 +08:00
}
2025-08-20 18:36:43 +08:00
.progress-bar-wrapper {
2025-08-20 12:09:24 +08:00
grid-area: bar;
2025-08-21 16:06:26 +08:00
width: calc(100% - 60px);
2025-08-20 18:36:43 +08:00
position: relative;
2025-08-21 16:06:26 +08:00
left: 20px;
2025-08-20 18:36:43 +08:00
}
.progress-bar {
2025-08-20 12:09:24 +08:00
width: 100%;
2025-08-20 18:36:43 +08:00
height: 5px;
2025-08-21 16:06:26 +08:00
border-radius: 1px;
2025-08-20 12:09:24 +08:00
overflow: hidden;
.progress {
height: 100%;
2025-08-21 16:06:26 +08:00
border-radius: 1px;
2025-08-20 12:09:24 +08:00
}
}
}
}
2025-08-20 18:36:43 +08:00
</style>