Log.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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="log" 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 }}{{ getSourcePrefix(entry.source)
  27. }}{{ entry.payload }}</span
  28. >
  29. </span>
  30. <span v-else>{{ $t("response.waiting_for_connection") }}</span>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { defineComponent } from "@nuxtjs/composition-api"
  36. import { getSourcePrefix } from "~/helpers/utils/string"
  37. export default defineComponent({
  38. props: {
  39. log: { type: Array, default: () => [] },
  40. title: {
  41. type: String,
  42. default: "",
  43. },
  44. },
  45. updated() {
  46. this.$nextTick(function () {
  47. if (this.$refs.log) {
  48. this.$refs.log.scrollBy(0, this.$refs.log.scrollHeight + 100)
  49. }
  50. })
  51. },
  52. methods: {
  53. getSourcePrefix,
  54. },
  55. })
  56. </script>
  57. <style scoped lang="scss">
  58. .realtime-log {
  59. @apply p-4;
  60. @apply bg-transparent;
  61. @apply text-secondary;
  62. @apply overflow-auto;
  63. height: 256px;
  64. &,
  65. span {
  66. @apply select-text;
  67. }
  68. span {
  69. @apply block;
  70. @apply break-words break-all;
  71. }
  72. }
  73. </style>