index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup>
  2. import { ref, computed } from 'vue';
  3. import { NEllipsis } from "naive-ui";
  4. import { BaseButton, SvgIcon } from '@/components';
  5. import { truncateToTwoDecimalPlaces } 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 waterWhite = {
  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 earlyWaring = {
  34. '0': {
  35. label: '预警中',
  36. cls: 'tips_warning'
  37. },
  38. '0': {
  39. label: '已完成',
  40. cls: 'tips_success'
  41. },
  42. }
  43. if ( item.type == 0 ) {
  44. return waterWhite[item.status + '']
  45. }
  46. if ( item.type === 1 ) {
  47. return waterWhite[item.status + '']
  48. }
  49. if ( item.type === 2 ) {
  50. return earlyWaring[item.status + '']
  51. }
  52. })
  53. const dataSources = computed(() => {
  54. const item = props.item;
  55. if (item.type == 0) {
  56. return [
  57. { label: '报警时间', value: item.time },
  58. { label: '报警值', value: truncateToTwoDecimalPlaces(item.warningVal), type: 'wraning' },
  59. { label: '报警级别', value: item.level },
  60. { label: '报警次数', value: item.counts },
  61. ]
  62. }
  63. if (item.type == 1) {
  64. return [
  65. { label: '报警时间', value: item.time },
  66. { label: '报警值', value: item.warningVal, type: 'wraning' },
  67. { label: '报警次数', value: item.counts },
  68. ]
  69. }
  70. });
  71. const handleEmitParent = () => {
  72. emit('on-click', props.item)
  73. }
  74. </script>
  75. <template>
  76. <div class="warning-item-inner">
  77. <div :class="['tips', warningType.cls]">
  78. <span>{{ warningType.label }}</span>
  79. </div>
  80. <dl class="warning-info">
  81. <dt>
  82. <NEllipsis class="font-bold text-[#1A2029] leading-[20px]">{{ item.reason }}</NEllipsis>
  83. </dt>
  84. <dd class="flex items-center" v-for="(item, index) in dataSources" :key="index">
  85. <span>{{ item.label }}: {{ item.value }}</span>
  86. <SvgIcon name="tool-up" class="ml-[4px]" v-if="item.type"></SvgIcon>
  87. </dd>
  88. </dl>
  89. <BaseButton type="gray" class="mt-[8px]" @click="handleEmitParent">操作</BaseButton>
  90. </div>
  91. </template>