Upload.vue 13 KB

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