Log.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div class="flex flex-col">
  3. <div
  4. class="
  5. bg-primary
  6. border-b border-dividerLight
  7. flex flex-1
  8. pl-4
  9. top-0
  10. z-10
  11. sticky
  12. items-center
  13. justify-between
  14. "
  15. >
  16. <label for="log" class="font-semibold text-secondaryLight py-2">
  17. {{ title }}
  18. </label>
  19. </div>
  20. <div ref="logsRef" name="log" class="realtime-log">
  21. <span v-if="log" class="space-y-2">
  22. <span
  23. v-for="(entry, index) in log"
  24. :key="`entry-${index}`"
  25. :style="{ color: entry.color }"
  26. >{{ entry.ts }}{{ source(entry.source) }}{{ entry.payload }}</span
  27. >
  28. </span>
  29. <span v-else>{{ $t("response.waiting_for_connection") }}</span>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import { nextTick, ref, watch } from "@nuxtjs/composition-api"
  35. import { getSourcePrefix as source } from "~/helpers/utils/string"
  36. const props = defineProps({
  37. log: { type: Array, default: () => [] },
  38. title: {
  39. type: String,
  40. default: "",
  41. },
  42. })
  43. const logsRef = ref<any | null>(null)
  44. const BOTTOM_SCROLL_DIST_INNACURACY = 5
  45. watch(
  46. () => props.log,
  47. () => {
  48. if (!logsRef.value) return
  49. const distToBottom =
  50. logsRef.value.scrollHeight -
  51. logsRef.value.scrollTop -
  52. logsRef.value.clientHeight
  53. if (distToBottom < BOTTOM_SCROLL_DIST_INNACURACY) {
  54. nextTick(() => (logsRef.value.scrollTop = logsRef.value.scrollHeight))
  55. }
  56. }
  57. )
  58. </script>
  59. <style scoped lang="scss">
  60. .realtime-log {
  61. @apply p-4;
  62. @apply bg-transparent;
  63. @apply text-secondary;
  64. @apply overflow-auto;
  65. height: 256px;
  66. &,
  67. span {
  68. @apply select-text;
  69. }
  70. span {
  71. @apply block;
  72. @apply break-words break-all;
  73. }
  74. }
  75. </style>