yj_ventWarn.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div class="vent_warn">
  3. <div v-for="(item, index) in ventData" :key="index" class="vent_warn_item">
  4. <div class="risk-label">{{ item.name }}</div>
  5. <div class="risk_progress_container">
  6. <div class="risk_progress" :style="getProgressStyle(item)"></div>
  7. </div>
  8. <div class="risk-value">{{ item.value }}</div>
  9. </div>
  10. </div>
  11. </template>
  12. <script setup lang="ts">
  13. import { ref, reactive, watch, onMounted, nextTick } from 'vue';
  14. let props = defineProps({
  15. ventData: {
  16. type: Array,
  17. default: () => {
  18. return [];
  19. },
  20. },
  21. });
  22. const colorMap = {
  23. 报警: ['#62465d', '#f50405'],
  24. 重大风险: ['#60685e', '#f37606'],
  25. 较大风险: ['#53777d', '#dfae6a'],
  26. 一般风险: ['#588063', '#efce09'],
  27. 低风险: ['#2a7296', '#47a0cc'],
  28. };
  29. const getProgressStyle = (item) => {
  30. const maxValue = 10;
  31. const [startColor, endColor] = colorMap[item.name];
  32. return {
  33. width: `${item.value > 0 ? (item.value / maxValue) * 100 : 0}%`,
  34. background: `linear-gradient(90deg, ${startColor} 0%, ${endColor} 100%)`,
  35. };
  36. };
  37. watch(
  38. () => props.ventData,
  39. (newV, oldV) => {
  40. console.log(props.ventData, '99900');
  41. },
  42. { immediate: true }
  43. );
  44. </script>
  45. <style lang="less" scoped>
  46. .vent_warn {
  47. position: relative;
  48. padding-top: 10px;
  49. height: 100%;
  50. .vent_warn_item {
  51. margin-left: 5px;
  52. margin-top: 10px;
  53. padding: 10px 0 10px 20px;
  54. width: 94%;
  55. height: 39px;
  56. background: url('@/assets/images/home-warn/3-2.png') no-repeat;
  57. background-size: 100% 100%;
  58. display: flex;
  59. justify-content: space-between;
  60. align-items: center;
  61. .risk-label {
  62. flex: 1;
  63. font-size: 14px;
  64. color: #ffffff;
  65. }
  66. .risk-value {
  67. flex: 1;
  68. margin-right: 10px;
  69. color: #ffffff;
  70. }
  71. .risk_progress_container {
  72. margin-left: 20px;
  73. flex: 3;
  74. height: 8px;
  75. margin: 0 10px;
  76. background: rgba(255, 255, 255, 0.1);
  77. border-radius: 4px;
  78. overflow: hidden;
  79. min-width: 0; /* 关键:允许容器收缩 */
  80. }
  81. .risk_progress {
  82. height: 100%;
  83. border-radius: 4px;
  84. transition: width 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
  85. }
  86. }
  87. }
  88. </style>