index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script setup>
  2. import { ref, computed } from 'vue';
  3. import { NEllipsis } from "naive-ui";
  4. import { BaseButton, SvgIcon } from '@/components';
  5. import { truncateDecimals } from '@/utils/format';
  6. const props = defineProps({
  7. item: {
  8. type: Object,
  9. default: () => ({})
  10. }
  11. });
  12. const emit = defineEmits(['on-click']);
  13. const warningType = computed(() => {
  14. const item = props.item;
  15. const waterEnum = {
  16. '0': {
  17. label: '报警中',
  18. cls: 'tips_warning'
  19. },
  20. '1': {
  21. label: '用户关闭',
  22. cls: 'tips_success'
  23. },
  24. '2': {
  25. label: '系统关闭',
  26. cls: 'tips_close'
  27. },
  28. '3': {
  29. label: '应急处理中',
  30. cls: 'tips_warning'
  31. }
  32. }
  33. const earlyEnum = {
  34. '0': {
  35. label: '预警中',
  36. cls: 'tips_warning'
  37. },
  38. '2': {
  39. label: '已完成',
  40. cls: 'tips_success'
  41. },
  42. }
  43. switch(item.type) {
  44. case 0:
  45. return waterEnum[item.status + ''];
  46. case 1:
  47. return waterEnum[item.status + ''];
  48. case 2:
  49. return earlyEnum[item.status + ''];
  50. default:
  51. return {
  52. label: '未知',
  53. cls: 'tips_close'
  54. }
  55. }
  56. })
  57. const dataSources = computed(() => {
  58. const item = props.item;
  59. if (item.type == 0) {
  60. return [
  61. { label: '报警时间', value: item.time },
  62. { label: '报警值', value: truncateDecimals(item.warningVal), type: 'wraning', unit: 'mg/L' },
  63. { label: '报警级别', value: item.level },
  64. { label: '报警次数', value: item.counts },
  65. ]
  66. }
  67. if (item.type == 1) {
  68. return [
  69. { label: '报警时间', value: item.time },
  70. { label: '报警值', value: Number(item?.warningVal?.toFixed(2)), type: 'wraning', unit: 'mg/L' },
  71. { label: '报警次数', value: item.counts },
  72. ]
  73. }
  74. if (item.type == 2) {
  75. return [
  76. { label: '预警时间', value: item.createTime },
  77. { label: '超标时间', value: item.time },
  78. { label: '现在值', value: Number(item?.warningVal?.toFixed(2)) ?? '', unit: 'mg/L' },
  79. { label: '预测值', value: Number(item?.forecastVal?.toFixed(2)) ?? '', type: 'wraning', unit: 'mg/L' },
  80. { label: '设计值', value: item.designVal, unit: 'mg/L' }
  81. ]
  82. }
  83. });
  84. const handleEmitParent = () => {
  85. emit('on-click', props.item)
  86. };
  87. </script>
  88. <template>
  89. <div class="warning-item-inner">
  90. <div :class="['tips', warningType?.cls]">
  91. <span>{{ warningType?.label }}</span>
  92. </div>
  93. <dl class="warning-info">
  94. <dt>
  95. <NEllipsis class="font-bold text-[#1A2029] leading-[20px]">{{ item.reason }}</NEllipsis>
  96. </dt>
  97. <dd class="flex items-center" v-for="(item, index) in dataSources" :key="index">
  98. <span>{{ item.label }}: {{ item.value }} {{ item.unit }}</span>
  99. <SvgIcon name="tool-up" class="ml-[4px]" v-if="item.type"></SvgIcon>
  100. </dd>
  101. </dl>
  102. <BaseButton type="gray" class="mt-[8px]" @click="handleEmitParent">操作</BaseButton>
  103. </div>
  104. </template>