ZipTranslate.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <script setup lang="ts">
  2. import { ref, reactive, watch, computed } from "vue";
  3. import { useMainStore } from "@/stores/main";
  4. import { useI18n } from "vue-i18n";
  5. const { t } = useI18n();
  6. const mainStore = useMainStore();
  7. const valid = ref(true);
  8. const file = ref();
  9. const Form = ref();
  10. let langOptions = reactive([
  11. {
  12. title: "中文",
  13. id: "zh-TW",
  14. },
  15. {
  16. title: "英文",
  17. id: "en",
  18. },
  19. {
  20. title: "印尼",
  21. id: "id",
  22. },
  23. {
  24. title: "越南",
  25. id: "vi",
  26. },
  27. ]);
  28. let lang = ref("");
  29. let loading = ref(false);
  30. const zipFile = ref(); // 儲存 ZIP 檔案
  31. async function submit() {
  32. console.log("lang", lang.value);
  33. console.log("file", file.value[0]);
  34. zipFile.value = null;
  35. loading.value = true;
  36. const response: any = await mainStore.zipTranslate(lang.value, file.value[0]);
  37. zipFile.value = new Blob([response[0].data], { type: "application/zip" });
  38. loading.value = false;
  39. console.log("response", response);
  40. console.log("zipFile.value", zipFile.value);
  41. }
  42. // ZIP 檔案下載
  43. function downloadZipFile() {
  44. if (!zipFile.value) {
  45. console.error("沒有 ZIP 檔案可下載");
  46. return;
  47. }
  48. // 生成 Blob URL
  49. const url = URL.createObjectURL(zipFile.value);
  50. const link = document.createElement("a");
  51. link.href = url;
  52. link.download = "影片素材.zip"; // 設定下載檔名
  53. document.body.appendChild(link);
  54. link.click();
  55. document.body.removeChild(link);
  56. // 釋放 Blob URL
  57. URL.revokeObjectURL(url);
  58. }
  59. </script>
  60. <template>
  61. <v-container fluid>
  62. <v-card class="ma-3 pa-3">
  63. <v-card-title primary-title>
  64. <h3 class="card-title mb-3">{{ t("zipTranslate") }}</h3>
  65. </v-card-title>
  66. <v-card-text>
  67. <v-form v-model="valid" ref="Form" class="d-flex">
  68. <v-file-input
  69. v-model="file"
  70. :rules="[(v) => v.length || 'select zip file.']"
  71. accept=".zip"
  72. :label="$t('fileInput')"
  73. prepend-icon="folder_zip"
  74. ></v-file-input>
  75. <v-select
  76. v-model="lang"
  77. label="語言"
  78. :items="langOptions"
  79. item-title="title"
  80. item-value="id"
  81. variant="solo"
  82. class="mx-5 lang-list"
  83. style="width: 100px"
  84. :rules="[(v) => v.length || '尚未選擇語言']"
  85. ></v-select>
  86. </v-form>
  87. </v-card-text>
  88. </v-card>
  89. <div class="ma-3 mt-5 pt-3">
  90. <v-btn
  91. @click="submit()"
  92. size="large"
  93. color="primary"
  94. variant="flat"
  95. class="w-100"
  96. :loading="loading"
  97. prepend-icon="translate_variant"
  98. >
  99. {{ t("translate") }}
  100. </v-btn>
  101. <v-btn
  102. v-if="zipFile"
  103. @click="downloadZipFile()"
  104. size="large"
  105. color="primary"
  106. variant="outlined"
  107. class="w-100 mt-5"
  108. prepend-icon="download"
  109. >
  110. {{ t("download") }}
  111. </v-btn>
  112. </div>
  113. </v-container>
  114. </template>
  115. <style lang="scss" scoped></style>