data-row.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div
  3. style="border-radius: 5px"
  4. :class="[
  5. 'flex text-[#00d9df] items-center justify-between border-b border-cyan-500/20 hover:bg-cyan-500/10 transition-colors px-2 -mx-2 rounded gap-5',
  6. compact ? 'py-1' : 'py-2'
  7. ]"
  8. >
  9. <span class="text-cyan-200">{{ label }}</span>
  10. <div class="flex items-center gap-2">
  11. <!-- 对于运行状态类的字段,显示状态指示器 -->
  12. <template v-if="isStatusField(label)">
  13. <span class="flex items-center">
  14. <!-- 使用图片作为状态指示器 -->
  15. <img :src="getStatusImage(value)" :alt="getStatusText(value)" class="w-5 h-5 mr-1" />
  16. </span>
  17. </template>
  18. <span v-else class="font-mono text-white font-bold">{{ formattedValue }}</span>
  19. <button
  20. v-if="button"
  21. style="border-radius: 5px"
  22. :class="[
  23. 'px-3 py-1 rounded text-white text-sm transition-all',
  24. buttonColor === 'green'
  25. ? 'bg-green-600 hover:bg-green-500 shadow-[0_0_10px_rgba(22,163,74,0.5)]'
  26. : 'bg-red-600 hover:bg-red-500 shadow-[0_0_10px_rgba(220,38,38,0.5)]'
  27. ]"
  28. >
  29. {{ button }}
  30. </button>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup lang="ts">
  35. import green from '@/assets/imgs/green.png'
  36. import red from '@/assets/imgs/red.png'
  37. interface Props {
  38. label: string
  39. value: string
  40. button?: string
  41. buttonColor?: 'green' | 'red'
  42. compact?: boolean
  43. }
  44. const props = withDefaults(defineProps<Props>(), {
  45. compact: false
  46. })
  47. // 判断是否为状态字段
  48. const isStatusField = (label: string) => {
  49. return (
  50. label.includes('运行状态') ||
  51. label.includes('加载状态') ||
  52. label.includes('PSA运行状态') ||
  53. label.toLowerCase().includes('status')
  54. )
  55. }
  56. // 获取状态文本
  57. const getStatusText = (statusValue: string | number) => {
  58. return statusValue === '1' || statusValue === 1 || statusValue === 'true' ? '运行中' : '停止'
  59. }
  60. // 获取状态图片路径
  61. const getStatusImage = (statusValue: string | number) => {
  62. return statusValue === '1' || statusValue === 1 || statusValue === 'true'
  63. ? green // 绿色状态使用green.png
  64. : red // 红色状态使用red.png
  65. }
  66. // 格式化非状态字段的值
  67. const formattedValue = computed(() => {
  68. // 如果是状态字段,则不显示原始值
  69. if (isStatusField(props.label)) {
  70. return ''
  71. }
  72. return props.value
  73. })
  74. </script>
  75. <style scoped>
  76. .status-active {
  77. background: rgb(34, 197, 94); /* 绿色 */
  78. box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
  79. }
  80. .status-inactive {
  81. background: rgb(239, 68, 68); /* 红色 */
  82. box-shadow: 0 0 8px rgba(239, 68, 68, 0.8);
  83. }
  84. </style>