Upload.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <script setup lang="ts">
  2. import { ref, reactive, watch, computed } from "vue";
  3. import { useMainStore } from "@/stores/main";
  4. import { required } from "@/utils";
  5. import { useI18n } from "vue-i18n";
  6. import { wsUrl } from "@/env";
  7. import type { VideoCreate } from "@/interfaces";
  8. import type { VideoUploaded } from "@/interfaces";
  9. import router from "@/router";
  10. import Dialog from "@/components/Dialog.vue";
  11. const { t } = useI18n();
  12. const mainStore = useMainStore();
  13. const WS = mainStore.videosWebSocket;
  14. const valid = ref(true);
  15. const title = ref("");
  16. const zipFiles = ref();
  17. const Form = ref();
  18. let anchor = ref(0);
  19. let templateId = ref(0);
  20. let selectAnchor = ref("angela");
  21. let selectTemplate = ref("style1");
  22. // props
  23. let dialog = reactive({
  24. msg: "",
  25. state: "info",
  26. show: false,
  27. });
  28. const anchorList = reactive([
  29. {
  30. anchor_id: "hannah1",
  31. name: "Hannah-1",
  32. },
  33. {
  34. anchor_id: "hannah2",
  35. name: "Hannah-2",
  36. },
  37. {
  38. anchor_id: "nelly",
  39. name: "Nelly",
  40. },
  41. {
  42. anchor_id: "teresa2",
  43. name: "Teresa-2",
  44. },
  45. {
  46. anchor_id: "zoya1",
  47. name: "Zoya-1",
  48. },
  49. {
  50. anchor_id: "zoya2",
  51. name: "Zoya-2",
  52. },
  53. {
  54. anchor_id: "aima",
  55. name: "Aima",
  56. },
  57. {
  58. anchor_id: "alitia",
  59. name: "Alitia",
  60. },
  61. {
  62. anchor_id: "cora",
  63. name: "Cora",
  64. },
  65. {
  66. anchor_id: "elara",
  67. name: "Elara",
  68. },
  69. {
  70. anchor_id: "sporty",
  71. name: "Sporty",
  72. },
  73. {
  74. anchor_id: "angela",
  75. name: "Angela",
  76. },
  77. {
  78. anchor_id: "jocelyn",
  79. name: "Jocelyn",
  80. },
  81. {
  82. anchor_id: "summer",
  83. name: "Summer",
  84. },
  85. {
  86. anchor_id: "peggy",
  87. name: "Peggy",
  88. },
  89. {
  90. anchor_id: "itri-1",
  91. name: "ITRI-1",
  92. },
  93. {
  94. anchor_id: "itri-2",
  95. name: "ITRI-2",
  96. },
  97. {
  98. anchor_id: "itri-3",
  99. name: "ITRI-3",
  100. },
  101. {
  102. anchor_id: "syscom",
  103. name: "James Liu",
  104. },
  105. ]);
  106. const templateList = reactive([
  107. {
  108. template_id: "style1",
  109. img: "鏡面-01",
  110. },
  111. {
  112. template_id: "style2",
  113. img: "鏡面-02",
  114. },
  115. {
  116. template_id: "style3",
  117. img: "鏡面-03",
  118. },
  119. {
  120. template_id: "style4",
  121. img: "鏡面-04",
  122. },
  123. {
  124. template_id: "style5",
  125. img: "鏡面-05",
  126. },
  127. {
  128. template_id: "ITRI_1",
  129. img: "ITRI背景-1",
  130. },
  131. {
  132. template_id: "ITRI_2",
  133. img: "ITRI背景-2",
  134. },
  135. {
  136. template_id: "ITRI_3",
  137. img: "ITRI背景-3",
  138. },
  139. {
  140. template_id: "ITRI_4",
  141. img: "ITRI背景-4",
  142. },
  143. {
  144. template_id: "ITRI_5",
  145. img: "ITRI背景-5",
  146. },
  147. {
  148. template_id: "ITRI_6",
  149. img: "ITRI背景-6",
  150. },
  151. {
  152. template_id: "ITRI_7",
  153. img: "ITRI背景-7",
  154. },
  155. {
  156. template_id: "ITRI_8",
  157. img: "ITRI背景-8",
  158. },
  159. {
  160. template_id: "ITRI_9",
  161. img: "ITRI背景-9",
  162. },
  163. {
  164. template_id: "ITRI_10",
  165. img: "ITRI背景-10",
  166. },
  167. {
  168. template_id: "syscom",
  169. img: "syscom",
  170. },
  171. ]);
  172. let anchorLang = ref("中文");
  173. let items = reactive([
  174. { lang: "中文", id: 0 },
  175. { lang: "英文", id: 1 },
  176. ]);
  177. // 取得圖片路徑
  178. const getImageUrl = (imgFolder: string, name: string) => {
  179. return new URL(`../../assets/img/${imgFolder}/${name}.webp`, import.meta.url)
  180. .href;
  181. };
  182. watch(dialog, (newVal) => {
  183. if (!newVal.show && newVal.state === "error") {
  184. return;
  185. } else if (!newVal.show && newVal.state === "success") {
  186. router.push("/main/progress");
  187. }
  188. });
  189. watch(anchor, (newVal) => {
  190. selectAnchor.value = anchorList[newVal].anchor_id;
  191. console.log("selectAnchor", selectAnchor.value);
  192. });
  193. watch(templateId, (newVal) => {
  194. selectTemplate.value = templateList[newVal].template_id;
  195. });
  196. async function Submit() {
  197. WS.send("subscribe");
  198. await (Form as any).value.validate();
  199. if (valid.value) {
  200. valid.value = false;
  201. const video_data: VideoCreate = {
  202. title: title.value,
  203. anchor: selectAnchor.value,
  204. style: selectTemplate.value,
  205. lang: "zh",
  206. };
  207. const ret: VideoUploaded = await mainStore.uploadPlot(
  208. video_data,
  209. zipFiles.value[0]
  210. );
  211. if (ret.accepted) {
  212. dialog.msg = t("acceptZipMessage");
  213. dialog.state = "success";
  214. dialog.show = true;
  215. } else {
  216. dialog.msg = ret.error_message!;
  217. dialog.state = "error";
  218. dialog.show = true;
  219. }
  220. valid.value = true;
  221. // (Form as any).value.reset();
  222. }
  223. }
  224. </script>
  225. <template>
  226. <v-container fluid>
  227. <v-card class="ma-3 pa-3">
  228. <v-card-title primary-title>
  229. <h3 class="card-title mb-3">{{ t("makeVideo") }}</h3>
  230. </v-card-title>
  231. <v-card-text>
  232. <v-form v-model="valid" ref="Form">
  233. <v-text-field
  234. :label="$t('videoTitle')"
  235. v-model="title"
  236. :rules="required()"
  237. prepend-icon="title"
  238. >
  239. </v-text-field>
  240. <v-file-input
  241. v-model="zipFiles"
  242. :rules="[(v) => v.length || 'select zip file.']"
  243. accept=".zip"
  244. :label="$t('fileInput')"
  245. prepend-icon="folder_zip"
  246. ></v-file-input>
  247. <!-- <v-select
  248. v-model="anchorLang"
  249. :items="items"
  250. item-title="lang"
  251. item-value="id"
  252. prepend-icon="language"
  253. label="選擇語言"
  254. ></v-select> -->
  255. </v-form>
  256. <v-expansion-panels class="anchor-list">
  257. <v-expansion-panel title="選擇主播">
  258. <v-expansion-panel-text class="p-0">
  259. <v-item-group mandatory v-model="anchor">
  260. <v-container fluid>
  261. <ul>
  262. <li v-for="n in anchorList" :key="n.anchor_id">
  263. <v-item v-slot="{ isSelected, toggle }">
  264. <v-card
  265. :color="isSelected ? 'primary' : ''"
  266. class="d-flex flex-column align-center"
  267. dark
  268. @click="toggle"
  269. :title="n.name"
  270. >
  271. <v-scroll-y-transition>
  272. <!-- <div v-if="n.anchor_id !== 0" class="img-disabled">
  273. <img
  274. :src="getImageUrl('anchor', n.name)"
  275. alt=""
  276. />
  277. <p>Coming Soon</p>
  278. </div> -->
  279. <img :src="getImageUrl('anchor', n.name)" alt="" />
  280. </v-scroll-y-transition>
  281. </v-card>
  282. </v-item>
  283. </li>
  284. </ul>
  285. </v-container>
  286. </v-item-group>
  287. </v-expansion-panel-text>
  288. </v-expansion-panel>
  289. </v-expansion-panels>
  290. <v-expansion-panels class="template-list mt-6">
  291. <v-expansion-panel title="選擇模板">
  292. <v-expansion-panel-text class="p-0">
  293. <v-sheet class="mx-auto">
  294. <v-slide-group
  295. v-model="templateId"
  296. selected-class="bg-primary"
  297. show-arrows
  298. >
  299. <v-slide-group-item
  300. v-for="n in templateList"
  301. :key="n.template_id"
  302. v-slot="{ isSelected, toggle, selectedClass }"
  303. >
  304. <v-card
  305. color="grey-lighten-1"
  306. :class="['ma-4', selectedClass]"
  307. @click="toggle"
  308. >
  309. <span
  310. class="choose-btn"
  311. :class="{ 'active-color': isSelected }"
  312. >
  313. <v-icon icon="done" color="white" />
  314. </span>
  315. <img :src="getImageUrl('template', n.img)" alt="" />
  316. <!-- <div :class="{ 'img-disabled': n.template_id !== 0 }">
  317. <img :src="getImageUrl('template', n.img)" alt="" />
  318. <p v-if="n.template_id !== 0">Coming Soon</p>
  319. </div> -->
  320. </v-card>
  321. </v-slide-group-item>
  322. </v-slide-group>
  323. </v-sheet>
  324. </v-expansion-panel-text>
  325. </v-expansion-panel>
  326. </v-expansion-panels>
  327. </v-card-text>
  328. <v-card-actions>
  329. <v-spacer></v-spacer>
  330. <v-btn @click="Submit" :disabled="!valid" variant="outlined">
  331. {{ t("send") }}
  332. </v-btn>
  333. </v-card-actions>
  334. </v-card>
  335. <v-card class="ma-3 pa-3 mt-8">
  336. <v-card-title primary-title>
  337. <h3 class="text-center">使用教學</h3>
  338. </v-card-title>
  339. <v-card-text>
  340. <ul class="mt-5 step-list">
  341. <li>
  342. <h4>1. 取得快速製作模板</h4>
  343. <p class="excerpt">請點擊下方按鈕取得模板範例</p>
  344. <div class="mb-5">
  345. <a :href="'/example/影片範例.zip'" class="link-btn" download
  346. >點我下載</a
  347. >
  348. </div>
  349. </li>
  350. <li>
  351. <h4>2. 準備影片內容</h4>
  352. <p class="excerpt text-center">
  353. 範例的資料夾內,有 "素材資料夾" 跟 "EXCEL 檔" <br />
  354. (您也可以自行創建資料夾)
  355. </p>
  356. <img src="@/assets/img/step/step-01.png" alt="" class="mb-4" />
  357. <p class="excerpt">素材資料夾裡面放照片或影片</p>
  358. <img src="@/assets/img/step/step-02.png" alt="" />
  359. <small class="d-block ms-4"
  360. >包含內容:圖片/影片(.jpg/.mp4)</small
  361. >
  362. <p class="mt-5 excerpt">
  363. EXCEL 檔整理成這個格式-大標、字幕、素材、發音
  364. </p>
  365. <img src="@/assets/img/step/step-03.png" alt="" />
  366. <ul class="point-list">
  367. <li>
  368. 1. 字幕之間的斷句請使用符號【\】進行換行
  369. <br />
  370. (建議 10 個字內,若超過請使用換行符號)
  371. </li>
  372. <li>2. 大標字數勿超過中文 15 字、英文 30 字</li>
  373. <li>3. 音檔請留空白</li>
  374. </ul>
  375. <p class="mt-5 excerpt">以下為顯示效果:</p>
  376. <img src="@/assets/img/step/step-04.png" alt="" />
  377. <p class="mt-5 excerpt">
  378. 接下來同時選素材資料夾跟 EXCEL 檔,壓縮成 ZIP 檔
  379. </p>
  380. <img src="@/assets/img/step/step-05.png" alt="" class="my-5" />
  381. </li>
  382. <li>
  383. <h4>3. 上傳 ZIP 資料夾至 AI Spokesgirl 平台</h4>
  384. <p class="excerpt">影片檔名請寫上影片名稱</p>
  385. <img src="@/assets/img/step/step-06.png" alt="" />
  386. <h4 class="my-5 caption">
  387. 點選“送出”之後需等待一段影片製作的時間 <br />
  388. 請您耐心等候,待製作完畢可於影片清單查看
  389. </h4>
  390. </li>
  391. </ul>
  392. </v-card-text>
  393. </v-card>
  394. <template>
  395. <div class="text-center">
  396. <Dialog
  397. :msg="dialog.msg"
  398. :state="dialog.state"
  399. :dialog="dialog.show"
  400. @close="dialog.show = false"
  401. ></Dialog>
  402. </div>
  403. </template>
  404. </v-container>
  405. </template>
  406. <style lang="scss">
  407. .anchor-list {
  408. ul {
  409. display: grid;
  410. grid-template-columns: repeat(auto-fit, minmax(185px, max-content));
  411. grid-gap: 20px;
  412. justify-content: center;
  413. padding: initial;
  414. li {
  415. list-style-type: none;
  416. }
  417. }
  418. img {
  419. width: 190px;
  420. height: 155px;
  421. object-fit: cover;
  422. }
  423. .v-card--variant-elevated {
  424. box-shadow: 0px 2px 5px 1px
  425. var(--v-shadow-key-umbra-opacity, rgba(0, 0, 0, 0.2)),
  426. 0px 1px 1px 0px var(--v-shadow-key-penumbra-opacity, rgba(0, 0, 0, 0.14)),
  427. 0px 1px 3px 0px var(--v-shadow-key-penumbra-opacity, rgba(0, 0, 0, 0.12));
  428. }
  429. .v-card-item {
  430. padding: 0;
  431. text-align: center;
  432. .v-card-title {
  433. font-size: 18px;
  434. }
  435. }
  436. .bg-success {
  437. background: linear-gradient(
  438. -225deg,
  439. rgb(234, 84, 19) 35%,
  440. rgb(178, 69, 146) 100%
  441. ) !important;
  442. }
  443. .v-expansion-panel-text__wrapper {
  444. padding: 0 !important;
  445. }
  446. }
  447. .anchor-list,
  448. .template-list {
  449. padding-left: 40px;
  450. .v-expansion-panel-title {
  451. height: 55px;
  452. min-height: 0;
  453. }
  454. }
  455. .template-list {
  456. img {
  457. width: 100%;
  458. height: 180px;
  459. }
  460. .choose-btn {
  461. padding: 5px;
  462. position: absolute;
  463. right: 8px;
  464. bottom: 13px;
  465. background: #ccc;
  466. border-radius: 100px;
  467. }
  468. .active-color {
  469. background: #ea5413;
  470. }
  471. }
  472. .step-list {
  473. list-style: none;
  474. img {
  475. width: 100%;
  476. max-width: 800px;
  477. }
  478. li {
  479. display: flex;
  480. flex-direction: column;
  481. align-items: center;
  482. font-size: 16px;
  483. p {
  484. line-height: 32px;
  485. }
  486. h4 {
  487. margin: 20px auto;
  488. color: #ea5413;
  489. font-weight: bold;
  490. text-align: center;
  491. line-height: 34px;
  492. font-size: 20px;
  493. }
  494. }
  495. .link-btn {
  496. display: inline-block;
  497. padding: 12px 20px;
  498. margin-top: 25px;
  499. border-radius: 100px;
  500. text-decoration: none;
  501. color: #fff;
  502. background: #ea5413;
  503. transition: all 0.3s;
  504. &:hover {
  505. opacity: 0.8;
  506. }
  507. }
  508. .point-list {
  509. display: flex;
  510. flex-direction: column;
  511. align-items: baseline;
  512. margin-left: 40px;
  513. }
  514. .excerpt::before {
  515. content: "";
  516. font-weight: bold;
  517. display: inline-block;
  518. border: 5px solid #ea5413;
  519. border-radius: 20px;
  520. margin-right: 10px;
  521. margin-bottom: 2px;
  522. }
  523. }
  524. .img-disabled {
  525. position: relative;
  526. z-index: 999;
  527. background-color: #ccc;
  528. margin-bottom: -5px;
  529. img {
  530. opacity: 0.7;
  531. }
  532. p {
  533. position: absolute;
  534. top: 50%;
  535. left: 50%;
  536. color: #fff;
  537. transform: translate(-50%, -50%);
  538. font-size: 16px;
  539. text-align: center;
  540. letter-spacing: 1px;
  541. text-shadow: 2px 2px 6px #000;
  542. }
  543. }
  544. .v-card--disabled > :not(.v-card__loader) {
  545. opacity: 1 !important;
  546. }
  547. </style>