Upload.vue 12 KB

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