Step_4_backup.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <script setup>
  2. import { ref, computed, onMounted } from "vue";
  3. import { useMainStore } from "@/stores/store";
  4. import { useRouter } from "vue-router";
  5. import { useI18n } from "vue-i18n";
  6. import "animate.css";
  7. import axios from "axios";
  8. import Footer from "../components/Footer.vue";
  9. const { t } = useI18n();
  10. const router = useRouter();
  11. const store = useMainStore();
  12. const apiUrl = import.meta.env.VITE_API_URL;
  13. const imgUrl = import.meta.env.VITE_API_IMG_URL;
  14. console.log("VITE_API_URL", apiUrl);
  15. let assignBgImg = ref("");
  16. function handleBgImg(item) {
  17. console.log("name", item);
  18. assignBgImg.value = item;
  19. store.assignBgImg = item;
  20. parameterList.value.filter((e, index) => {
  21. if (e.bg_img === item.bg_img) {
  22. store.styleNum = index;
  23. }
  24. });
  25. console.log("store.assignBgImg", store.assignBgImg);
  26. console.log("store.styleNum", store.styleNum);
  27. }
  28. onMounted(() => {
  29. getParameters();
  30. });
  31. const currentPhotos = computed(() => {
  32. const start = currentIndex.value;
  33. const end = start + perPage.value;
  34. return parameter.value.slice(start, end);
  35. });
  36. console.log("currentPhotos", currentPhotos);
  37. let currentIndex = ref(0);
  38. let perPage = ref(2);
  39. function prev() {
  40. if (currentIndex.value > 0) {
  41. currentIndex.value -= perPage.value;
  42. }
  43. }
  44. function next() {
  45. if (currentIndex.value + perPage.value < parameter.value.length) {
  46. currentIndex.value += perPage.value;
  47. }
  48. }
  49. // 計算頁數
  50. const totalPages = computed(() =>
  51. Math.ceil(parameter.value.length / perPage.value)
  52. );
  53. const currentPage = computed(
  54. () => Math.floor(currentIndex.value / perPage.value) + 1
  55. );
  56. let parameterList = ref([]);
  57. // 背景清單
  58. let parameter = ref([
  59. {
  60. bg_img: "臺北陽明山-母親節.png",
  61. title: "taipei_yangmingshan",
  62. description: "taipei_yangmingshan_description",
  63. },
  64. {
  65. bg_img: "台南孔廟.png",
  66. title: "tainan_confucius_temple",
  67. description: "tainan_confucius_temple_description",
  68. },
  69. {
  70. bg_img: "臺北中正紀念堂-2.png",
  71. title: "taipei_chiang_kai_shek_memorial_hall_2",
  72. description: "taipei_chiang_kai_shek_memorial_hall_2_description",
  73. },
  74. {
  75. bg_img: "台東嘉明湖.png",
  76. title: "taitung_jiaming_lake",
  77. description: "taitung_jiaming_lake_description",
  78. },
  79. {
  80. bg_img: "中秋節.png",
  81. title: "mid_autumn_festival",
  82. description: "mid_autumn_festival_description",
  83. },
  84. {
  85. bg_img: "新北野柳女王頭.png",
  86. title: "new_taipei_yehliu_queen_head",
  87. description: "new_taipei_yehliu_queen_head_description",
  88. },
  89. {
  90. bg_img: "基隆和平島公園.png",
  91. title: "keelung_heping_island_park",
  92. description: "keelung_heping_island_park_description",
  93. },
  94. {
  95. bg_img: "南投日月潭.png",
  96. title: "taichung_sun_moon_lake",
  97. description: "taichung_sun_moon_lake_description",
  98. },
  99. {
  100. bg_img: "臺北中正紀念堂.png",
  101. title: "taipei_chiang_kai_shek_memorial_hall",
  102. description: "taipei_chiang_kai_shek_memorial_hall_description",
  103. },
  104. {
  105. bg_img: "台南鹽田.png",
  106. title: "tainan_salt_field",
  107. description: "tainan_salt_field_description",
  108. },
  109. {
  110. bg_img: "高雄美麗島.png",
  111. title: "kaohsiung_formosa_boulevard_station",
  112. description: "kaohsiung_formosa_boulevard_station_description",
  113. },
  114. {
  115. bg_img: "新北十分瀑布.png",
  116. title: "new_taipei_shifen_waterfall",
  117. description: "new_taipei_shifen_waterfall_description",
  118. },
  119. {
  120. bg_img: "臺北故宮.png",
  121. title: "taipei_national_palace_museum",
  122. description: "taipei_national_palace_museum_description",
  123. },
  124. {
  125. bg_img: "臺北故宮-2.png",
  126. title: "taipei_national_palace_museum_2",
  127. description: "taipei_national_palace_museum_2_description",
  128. },
  129. {
  130. bg_img: "台中歌劇院.png",
  131. title: "national_taichung_theater",
  132. description: "national_taichung_theater_description",
  133. },
  134. {
  135. bg_img: "嘉義森林之歌.png",
  136. title: "chiayi_song_of_forest",
  137. description: "chiayi_song_of_forest_description",
  138. },
  139. {
  140. bg_img: "基隆八斗子鐵路.png",
  141. title: "keelung_baduzi_railway",
  142. description: "keelung_baduzi_railway_description",
  143. },
  144. {
  145. bg_img: "花蓮清水斷崖.png",
  146. title: "hualien_qingshui_cliff",
  147. description: "hualien_qingshui_cliff_description",
  148. },
  149. {
  150. bg_img: "澎湖.png",
  151. title: "penghu",
  152. description: "penghu_description",
  153. },
  154. {
  155. bg_img: "南投清境農場.png",
  156. title: "nantou_qingjing_farm",
  157. description: "nantou_qingjing_farm_description",
  158. },
  159. {
  160. bg_img: "高雄流行音樂中心.png",
  161. title: "kaohsiung_music_center",
  162. description: "kaohsiung_music_center_description",
  163. },
  164. {
  165. bg_img: "花蓮金針花山.png",
  166. title: "hualien_daylily_mountain",
  167. description: "hualien_daylily_mountain_description",
  168. },
  169. {
  170. bg_img: "新北九份老街.png",
  171. title: "new_taipei_jiufen_old_street",
  172. description: "new_taipei_jiufen_old_street_description",
  173. },
  174. {
  175. bg_img: "嘉義阿里山小火車.png",
  176. title: "chiayi_alishan_forest_railways",
  177. description: "chiayi_alishan_forest_railways_description",
  178. },
  179. {
  180. bg_img: "台中高美濕地.png",
  181. title: "taichung_gaomei_wetland",
  182. description: "taichung_gaomei_wetland_description",
  183. },
  184. ]);
  185. console.log("parameter", parameter.value);
  186. async function getParameters() {
  187. let url = `${apiUrl}/sd/parameters`;
  188. try {
  189. let response = await axios.get(url);
  190. parameterList.value = response.data;
  191. console.log("parameterList", parameterList.value);
  192. } catch (error) {
  193. console.log("error", error);
  194. }
  195. }
  196. let alertShow = ref(false);
  197. function checkImg() {
  198. if (store.assignBgImg && store.assignBgImg !== "") {
  199. alertShow.value = false;
  200. router.push("/step5");
  201. } else {
  202. alertShow.value = true;
  203. setTimeout(() => {
  204. alertShow.value = false;
  205. }, 2000);
  206. }
  207. }
  208. </script>
  209. <template>
  210. <div class="content">
  211. <p class="title">{{ t("postcard.step2.text_2") }}</p>
  212. <div class="img-content">
  213. <div class="slider-btn">
  214. <button class="prev" @click="prev">
  215. <img class="arrow" src="../assets/img/arrow_l.png" alt="" />
  216. </button>
  217. <button class="next" @click="next">
  218. <img class="arrow" src="../assets/img/arrow_r.png" alt="" />
  219. </button>
  220. </div>
  221. <div
  222. @click="handleBgImg(item)"
  223. v-for="item in currentPhotos"
  224. class="bg-img"
  225. >
  226. <v-img
  227. cover
  228. class="cover"
  229. :lazy-src="`https://cmm.ai/postcard/static/assets/img/bg/${item.bg_img}`"
  230. :src="`https://cmm.ai/postcard/static/assets/img/bg/${item.bg_img}`"
  231. >
  232. <template v-slot:placeholder>
  233. <div class="d-flex align-center justify-center fill-height">
  234. <v-progress-circular
  235. color="grey-lighten-4"
  236. indeterminate
  237. ></v-progress-circular>
  238. </div>
  239. </template>
  240. </v-img>
  241. <p>{{ t(item.title) }}</p>
  242. <img
  243. v-if="item === assignBgImg"
  244. class="icon active"
  245. src="../assets/img/confirm.png"
  246. alt=""
  247. />
  248. <img v-else class="icon" src="../assets/img/confirm-solid.png" alt="" />
  249. </div>
  250. <span class="page-num">{{ currentPage }} / {{ totalPages }}</span>
  251. <a @click="checkImg()" href="javascript:;" class="main-btn">
  252. {{ t("next_step") }}
  253. </a>
  254. <div v-if="alertShow" class="alert-item">
  255. <v-alert border="top" type="warning" variant="outlined" class="mt-5">
  256. 尚未選擇背景
  257. </v-alert>
  258. </div>
  259. </div>
  260. <Footer url="/step3" />
  261. </div>
  262. </template>
  263. <style lang="scss" scoped>
  264. .img-content {
  265. // height: 80vh;
  266. padding: 0 2rem;
  267. display: flex;
  268. flex-direction: column;
  269. align-items: center;
  270. @media (max-width: 600px) {
  271. height: 100%;
  272. padding: 0 4rem;
  273. }
  274. .bg-img {
  275. margin-bottom: 2rem;
  276. cursor: pointer;
  277. position: relative;
  278. .cover {
  279. max-width: 100%;
  280. width: 17rem;
  281. height: 20vh;
  282. object-fit: cover;
  283. }
  284. }
  285. p {
  286. margin-top: 0.5rem;
  287. }
  288. .icon {
  289. width: 5rem;
  290. position: absolute;
  291. top: 0.5rem;
  292. right: 0.5rem;
  293. }
  294. }
  295. .slider-btn {
  296. width: 100%;
  297. position: absolute;
  298. z-index: 100;
  299. top: 50vh;
  300. img {
  301. width: 100px;
  302. transition: all 0.2s;
  303. @media (max-width: 600px) {
  304. width: 50px;
  305. }
  306. }
  307. .prev,
  308. .next {
  309. position: absolute;
  310. cursor: pointer;
  311. border: none;
  312. background-color: transparent;
  313. &:hover {
  314. img {
  315. opacity: 0.7;
  316. }
  317. }
  318. }
  319. .prev {
  320. left: 0;
  321. }
  322. .next {
  323. right: 0;
  324. }
  325. }
  326. .page-num {
  327. margin: auto auto 2.2rem;
  328. color: white;
  329. letter-spacing: 0.2rem;
  330. }
  331. .content {
  332. @media (max-width: 600px) {
  333. min-height: 100vh;
  334. }
  335. }
  336. .alert-item {
  337. position: absolute;
  338. top: 50%;
  339. left: 50%;
  340. transform: translate(-50%, -50%);
  341. .v-alert {
  342. background-color: var(--sub-color);
  343. }
  344. .text-warning {
  345. color: var(--main-color) !important;
  346. }
  347. }
  348. </style>