Home.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <script setup>
  2. import { ref, reactive, onMounted, onBeforeUnmount } from "vue";
  3. import axios from "axios";
  4. import Map from "@/components/Map.vue";
  5. import Navbar from "@/components/Navbar.vue";
  6. (async function getData() {
  7. try {
  8. const response = await axios.get("https://cmm.ai:8088/api/get_school");
  9. console.log("response.data", response.data);
  10. } catch (error) {
  11. console.error(error);
  12. }
  13. })();
  14. const scrollLeft = ref(0);
  15. let shouldAnimate = ref(false);
  16. let shouldFadeOut = ref(false);
  17. let scrollCount = 1;
  18. const handleScroll = () => {
  19. const windowWidth = window.innerWidth; // 螢幕寬度
  20. const windowHeight = window.innerHeight;
  21. const documentHeight = document.body.scrollHeight - windowHeight;
  22. const windowScrollable = windowWidth * scrollCount; // 可捲動寬度
  23. const scrollTop = window.pageYOffset;
  24. const steps = windowScrollable / documentHeight;
  25. const goLeft = scrollTop * steps;
  26. // console.log('windowWidth',windowWidth);
  27. // console.log('windowScrollable',windowScrollable);
  28. if (scrollTop > 0) {
  29. shouldAnimate.value = true;
  30. shouldFadeOut.value = false;
  31. } else {
  32. shouldFadeOut.value = true;
  33. }
  34. scrollLeft.value = goLeft;
  35. };
  36. let innerWidth = ref("");
  37. const handleResize = () => {
  38. innerWidth.value = window.innerWidth;
  39. console.log(innerWidth.value);
  40. if (window.innerWidth <= 991) {
  41. scrollCount = 2;
  42. } else {
  43. scrollCount = 1;
  44. }
  45. };
  46. onMounted(() => {
  47. handleResize(); // 初始化檢查一次
  48. window.addEventListener("resize", handleResize);
  49. });
  50. let classes = reactive({
  51. data: [],
  52. });
  53. // 取得該據點所有課程
  54. const getClassList = async (locationId) => {
  55. console.log("locationId", locationId);
  56. try {
  57. const response = await axios.get(
  58. `https://cmm.ai:8088/api/get_class_name?location_id=${locationId}`
  59. );
  60. console.log("response", response);
  61. classes.data = response.data.classes;
  62. console.log("classes.data", classes.data);
  63. } catch (error) {
  64. console.log("error", error);
  65. }
  66. };
  67. onMounted(() => {
  68. window.addEventListener("scroll", handleScroll);
  69. });
  70. onBeforeUnmount(() => {
  71. window.removeEventListener("scroll", handleScroll);
  72. });
  73. const previous = () => {
  74. window.scrollTo({ top: 0, behavior: "smooth" });
  75. };
  76. </script>
  77. <template>
  78. <div class="home-container">
  79. <div class="wrapper">
  80. <div>
  81. </div>
  82. <div class="scrollable" :style="{ transform: `translateX(-${scrollLeft}px)` }">
  83. <section class="main-block">
  84. <Navbar />
  85. <div class="img-item">
  86. <img src="@/assets/img/banner-0615.webp" alt="" />
  87. <p v-show="shouldAnimate" :class="{
  88. animate__animated: shouldAnimate,
  89. animate__fadeInRight: shouldAnimate && !shouldFadeOut,
  90. animate__fadeOutRight: shouldAnimate && shouldFadeOut,
  91. }">
  92. 臺灣工藝學校 <br />
  93. 以佈局具國際視野之工藝學習共享平台為目標,藉由「工藝學校」的主體概念,推動臺灣工藝學校全球學習平台,以共享、友善、全人、全民的終身工藝手作台進行人才、課程、知識、教材之工藝資源嫁接媒合與內容設計,以在地、就近、線上、線下等多元方式提供不同型態之學習體驗內容及選擇。
  94. </p>
  95. </div>
  96. </section>
  97. <section class="map-block">
  98. <div class="back-btn">
  99. <p @click="previous()">回到首頁</p>
  100. </div>
  101. <div class="content">
  102. <div class="map">
  103. <Map @locationId="getClassList" />
  104. </div>
  105. <v-list lines="three" class="list">
  106. <v-list-item v-for="item in classes.data" :key="item.id">
  107. <div class="d-flex align-center">
  108. <img :src="`https://cmm.ai/ntcri/${item.cover_img}`" alt="" />
  109. <section>
  110. <h2>{{ item.name }}</h2>
  111. <p>主辦單位:{{ item.organizer }}</p>
  112. <p>據點名稱:{{ item.school }}</p>
  113. </section>
  114. </div>
  115. </v-list-item>
  116. </v-list>
  117. </div>
  118. </section>
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. <style lang="scss">
  124. @import "animate.css/animate.min.css";
  125. .home-container {
  126. height: 150vw; // 捲軸高度
  127. overflow: hidden;
  128. @media (max-width: 960px) {
  129. height: 300vw;
  130. }
  131. .wrapper {
  132. overflow: hidden;
  133. position: fixed;
  134. }
  135. .scrollable {
  136. height: 100vh;
  137. display: flex;
  138. align-items: end;
  139. .img-item {
  140. width: 100%;
  141. height: 100%;
  142. position: relative;
  143. img {
  144. width: 100%;
  145. height: 100%;
  146. object-fit: cover;
  147. object-position: top;
  148. }
  149. p {
  150. width: 600px;
  151. top: 170px;
  152. right: 7.5%;
  153. position: absolute;
  154. z-index: 100;
  155. font-size: 24px;
  156. line-height: 38px;
  157. color: #fff;
  158. text-shadow: 2px 2px 5px #333;
  159. @media (max-width: 1700px) {
  160. width: 33vw;
  161. top: 140px;
  162. right: 6%;
  163. }
  164. @media (max-width: 767px) {
  165. display: none !important;
  166. }
  167. }
  168. }
  169. &::after {
  170. content: "";
  171. display: table;
  172. clear: both;
  173. }
  174. .main-block,
  175. .map-block {
  176. width: 100vw;
  177. display: flex;
  178. align-items: center;
  179. @media (max-width: 1200px) {
  180. height: 84vh;
  181. }
  182. @media (max-width: 960px) {
  183. width: 150vw;
  184. }
  185. }
  186. .main-block {
  187. height: 82vh;
  188. .navbar {
  189. right: 50.5%;
  190. position: absolute;
  191. }
  192. }
  193. .map-block {
  194. height: 100vh;
  195. .content {
  196. width: 100%;
  197. height: 100%;
  198. display: flex;
  199. .map,
  200. .list {
  201. @media (max-width: 960px) {
  202. width: 100%;
  203. }
  204. }
  205. .map {
  206. width: 60%;
  207. }
  208. .list {
  209. width: 40%;
  210. img {
  211. width: 200px;
  212. margin-right: 20px;
  213. border-radius: 5px;
  214. box-shadow: 2px 2px 4px #aaaaaa;
  215. }
  216. h2 {
  217. font-size: 18px;
  218. }
  219. h2,
  220. p {
  221. line-height: 30px;
  222. }
  223. .v-list-item {
  224. padding: 30px 20px;
  225. border-bottom: 1px solid #cccccc;
  226. .v-list-item__content {
  227. overflow: initial !important;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. .back-btn {
  235. height: 18vh;
  236. position: absolute;
  237. // top: 0;
  238. // right: 80px;
  239. top: -4%;
  240. right: 22%;
  241. z-index: 1000;
  242. display: flex;
  243. align-items: center;
  244. @media (max-width: 1200px) {
  245. height: 16vh;
  246. }
  247. p {
  248. cursor: pointer;
  249. transition: all 0.3s;
  250. &:hover {
  251. opacity: 0.8;
  252. }
  253. }
  254. }
  255. }</style>