Progress.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <script setup lang="ts">
  2. import { useMainStore } from "@/stores/main";
  3. import { storeToRefs } from "pinia";
  4. import { onMounted } from "vue";
  5. import { useI18n } from "vue-i18n";
  6. const { t } = useI18n();
  7. const mainStore = useMainStore();
  8. const mainStoreRef = storeToRefs(mainStore);
  9. const videos = mainStoreRef.readVideos;
  10. const WS = mainStore.videosWebSocket;
  11. const headers = [
  12. {
  13. title: t("videoTitle"),
  14. sortable: true,
  15. key: "title",
  16. align: "left",
  17. },
  18. {
  19. title: t("state"),
  20. sortable: true,
  21. key: "progress_state",
  22. align: "left",
  23. },
  24. {
  25. title: t("preview"),
  26. key: "id",
  27. },
  28. {
  29. title: t("green_screen"),
  30. key: "green_screen",
  31. },
  32. ];
  33. function previewVideo(name: String) {
  34. window.open(`http://172.104.93.163:30080/${name}.mp4`);
  35. }
  36. onMounted(async () => {
  37. await mainStore.actionGetVideos();
  38. WS.onmessage = function (e) {
  39. console.log("onmessage", e);
  40. const data = e.data.split(":");
  41. mainStore.videos.map((e) => {
  42. if (e.stored_filename === data[0]) {
  43. e.progress_state = data[1]; // 影片狀態
  44. if (mainStore.userProfile && data[2]) {
  45. mainStore.userProfile.available_time =
  46. mainStore.userProfile.available_time - parseInt(data[2]); // 使用秒數
  47. }
  48. }
  49. });
  50. };
  51. });
  52. </script>
  53. <template>
  54. <div>
  55. <v-toolbar light>
  56. <v-toolbar-title>
  57. <h3>{{ t("progress") }}</h3>
  58. </v-toolbar-title>
  59. </v-toolbar>
  60. <v-data-table
  61. :headers="headers"
  62. :items="videos"
  63. :sort-by="[{ key: 'id', order: 'desc' }]"
  64. >
  65. <template v-slot:item.progress_state="{ item }">
  66. <span v-if="item.raw.progress_state === 'SUCCESS'">
  67. <v-icon icon="check_circle" color="success" />
  68. 完成
  69. </span>
  70. <span v-else-if="item.raw.progress_state === 'PENDING'">
  71. <v-icon icon="pending" color="warning" />
  72. 等待中
  73. </span>
  74. <span v-else-if="item.raw.progress_state === 'STARTED'">
  75. <v-progress-circular
  76. indeterminate
  77. color="info"
  78. style="width: 20px"
  79. ></v-progress-circular>
  80. 處理中
  81. </span>
  82. <span v-else>
  83. <v-icon icon="warning" color="error" />
  84. 失敗
  85. </span>
  86. </template>
  87. <template v-slot:item.id="{ item }">
  88. <v-btn
  89. flat
  90. :disabled="item.raw.progress_state !== 'SUCCESS'"
  91. @click="previewVideo(item.raw.stored_filename)"
  92. >
  93. <v-icon icon="play_circle" />
  94. </v-btn>
  95. </template>
  96. <template v-slot:item.green_screen="{ item }">
  97. <a
  98. :href="`http://172.104.93.163:30080/${item.raw.stored_filename}_bg.mp4`"
  99. target="_blank"
  100. >
  101. <v-icon icon="file_download" />
  102. </a>
  103. </template>
  104. </v-data-table>
  105. </div>
  106. </template>
  107. <style>
  108. .v-data-table-footer {
  109. margin-top: 10px;
  110. }
  111. </style>