Navbar.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <script setup>
  2. import { ref, reactive, onMounted } from "vue";
  3. import { useRouter } from "vue-router";
  4. import { useMainStore } from "@/stores/store";
  5. import { useI18n } from "vue-i18n";
  6. // import Login from "@/views/Login.vue";
  7. const router = useRouter();
  8. const store = useMainStore();
  9. const { t, locale } = useI18n();
  10. let menuShow = ref(false);
  11. let collegeMenuShow = ref(false);
  12. let otherMenuShow = ref(false);
  13. let loginMenuShow = ref(false);
  14. let coursesMenuShow = ref(false);
  15. function toggleMenu() {
  16. collegeMenuShow.value = false;
  17. menuShow.value = !menuShow.value;
  18. }
  19. function handleClose() {
  20. store.loginDialog = false;
  21. }
  22. function handleMouseEvents(name, event) {
  23. const screenWidth = window.innerWidth;
  24. if (screenWidth >= 1280) {
  25. if (name === "college") {
  26. collegeMenuShow.value = event;
  27. } else if (name === "courses") {
  28. coursesMenuShow.value = event;
  29. } else if (name === "other") {
  30. otherMenuShow.value = event;
  31. } else {
  32. loginMenuShow.value = event;
  33. }
  34. } else {
  35. return;
  36. }
  37. }
  38. function handleClick(url) {
  39. menuShow.value = false;
  40. collegeMenuShow.value = false;
  41. otherMenuShow.value = false;
  42. router.push(url);
  43. }
  44. const collegeList = reactive([
  45. // {
  46. // title: "college_group_1",
  47. // url: "/college-group/future",
  48. // },
  49. {
  50. title: "college_group_2",
  51. url: "/college-group/craft",
  52. },
  53. {
  54. title: "college_group_3",
  55. url: "/college-group/cross",
  56. },
  57. // {
  58. // title: "college_group_4",
  59. // url: "/college-group/online",
  60. // },
  61. // {
  62. // title: "college_group_5",
  63. // url: "/college-group/craft-for-all",
  64. // },
  65. // {
  66. // title: "college_group_6",
  67. // url: "/college-group/life",
  68. // },
  69. {
  70. title: "成果展現",
  71. url: "/achievement",
  72. },
  73. // {
  74. // title: "修護工藝",
  75. // url: "/college-group/repair",
  76. // },
  77. // {
  78. // title: "世代工藝",
  79. // url: "/college-group/generation",
  80. // },
  81. // {
  82. // title: "青年工藝",
  83. // url: "/college-group/teenager",
  84. // },
  85. ]);
  86. const otherList = reactive([
  87. // {
  88. // title: "我要開課",
  89. // url: "/setup-courses",
  90. // },
  91. // {
  92. // title: "網站架構",
  93. // url: "/",
  94. // },
  95. ]);
  96. onMounted(() => {
  97. console.log("onMounted");
  98. localStorage.setItem("lang", "zh");
  99. });
  100. function changeLang() {
  101. let lang = localStorage.getItem("lang");
  102. console.log("lang", lang);
  103. if (lang === "zh") {
  104. locale.value = "en";
  105. localStorage.setItem("lang", "en");
  106. } else if (lang === "en") {
  107. locale.value = "zh";
  108. localStorage.setItem("lang", "zh");
  109. }
  110. }
  111. function handleLogout() {
  112. sessionStorage.removeItem("token");
  113. sessionStorage.removeItem("AuthToken");
  114. window.location.href =
  115. "https://member.moc.gov.tw/MOCMC/M0003/ottLogout?SYS_ID=CRAFT_NTCRI&urlRedirectTo=https://craftsplatform.ntcri.gov.tw/";
  116. // window.location.reload();
  117. }
  118. </script>
  119. <template>
  120. <div class="d-flex justify-space-between align-center navbar">
  121. <router-link :to="'/'">
  122. <img src="@/assets/img/logo.png" alt="臺灣工藝學習平台" />
  123. </router-link>
  124. <ul class="menu align-center" :class="{ slider: menuShow }">
  125. <li>
  126. <router-link :to="'/crafts'">{{ t("navbar.crafts") }}</router-link>
  127. </li>
  128. <li class="position-relative">
  129. <a
  130. href="javascript:;"
  131. @mouseover="collegeMenuShow = true"
  132. @mouseleave="collegeMenuShow = false"
  133. class="d-none d-lg-block"
  134. title="前往工藝學群頁面"
  135. >
  136. <span class="d-flex align-center">
  137. {{ t("navbar.craft_groups") }}
  138. <v-icon icon="mdi-chevron-down"></v-icon>
  139. </span>
  140. </a>
  141. <a
  142. href="javascript:;"
  143. @click="collegeMenuShow = !collegeMenuShow"
  144. class="d-block d-lg-none"
  145. title="前往工藝學群頁面"
  146. >{{ t("navbar.craft_groups") }}
  147. <v-icon
  148. icon="mdi-chevron-down"
  149. class="toggle-icon"
  150. :class="{ slider: collegeMenuShow }"
  151. ></v-icon
  152. ></a>
  153. <div
  154. class="college-slider"
  155. :class="{ slider: collegeMenuShow }"
  156. @mouseover="handleMouseEvents('college', true)"
  157. @mouseleave="handleMouseEvents('college', false)"
  158. >
  159. <ul>
  160. <li v-for="(item, index) in collegeList" :key="index">
  161. <a
  162. href="javascript:;"
  163. @click="handleClick(item.url)"
  164. :title="`前往${item.title}頁面`"
  165. >{{ t(`${item.title}`) }}</a
  166. >
  167. <!-- <router-link :to="item.url">{{ item.title }}</router-link> -->
  168. </li>
  169. </ul>
  170. </div>
  171. </li>
  172. <li>
  173. <router-link :to="'/news'">{{ t("news") }}</router-link>
  174. </li>
  175. <!-- <li>
  176. <router-link :to="'/course-list'">{{
  177. t("navbar.craft_course")
  178. }}</router-link>
  179. </li> -->
  180. <!-- <li>
  181. <router-link :to="'/article'">知識文章</router-link>
  182. </li> -->
  183. <!-- <li>
  184. <router-link :to="'/setup-courses'">我要開課</router-link>
  185. </li> -->
  186. <li class="position-relative">
  187. <router-link
  188. :to="'/setup-courses'"
  189. @mouseover="coursesMenuShow = true"
  190. @mouseleave="coursesMenuShow = false"
  191. class="d-none d-lg-flex align-center"
  192. title="前往我要開課頁面"
  193. >{{ t("navbar.create_course")
  194. }}<v-icon icon="mdi-chevron-down"></v-icon
  195. ></router-link>
  196. <a
  197. href="javascript:;"
  198. @click="coursesMenuShow = !coursesMenuShow"
  199. class="d-block d-lg-none"
  200. title="前往我要開課頁面"
  201. >{{ t("navbar.create_course") }}
  202. <v-icon
  203. icon="mdi-chevron-down"
  204. class="toggle-icon"
  205. :class="{ slider: coursesMenuShow }"
  206. ></v-icon
  207. ></a>
  208. <div
  209. class="college-slider"
  210. :class="{ slider: coursesMenuShow }"
  211. @mouseover="handleMouseEvents('courses', true)"
  212. @mouseleave="handleMouseEvents('courses', false)"
  213. >
  214. <ul>
  215. <li>
  216. <router-link :to="'/setup-courses/tutorial'">{{
  217. t("tutorial.title")
  218. }}</router-link>
  219. </li>
  220. <li>
  221. <router-link :to="'/setup-courses'">{{
  222. t("navbar.create_course")
  223. }}</router-link>
  224. </li>
  225. </ul>
  226. </div>
  227. </li>
  228. <!-- 暫時隱藏 -->
  229. <li class="position-relative d-none">
  230. <!-- <v-dialog
  231. v-model="store.loginDialog"
  232. max-width="450"
  233. v-if="!store.loginState"
  234. >
  235. <template v-slot:activator="{ props }">
  236. <a href="javascript:;" v-bind="props" title="點擊以開啟會員登入介面"
  237. >會員登入</a
  238. >
  239. </template>
  240. <Login @close="handleClose" />
  241. </v-dialog> -->
  242. <a
  243. v-if="!store.loginState"
  244. href="https://member.moc.gov.tw/MOCMC/A0001/list?SYS_ID=CRAFT_NTCRI"
  245. >{{ t("navbar.login") }}</a
  246. >
  247. <div v-else>
  248. <router-link
  249. :to="'/user/profile'"
  250. @mouseover="loginMenuShow = true"
  251. @mouseleave="loginMenuShow = false"
  252. class="d-none d-lg-block"
  253. >
  254. <span class="d-flex align-center">
  255. {{ t("navbar.member") }} <v-icon icon="mdi-chevron-down"></v-icon>
  256. </span>
  257. </router-link>
  258. <router-link :to="'/user/profile'" class="d-block d-lg-none">{{
  259. t("navbar.member")
  260. }}</router-link>
  261. </div>
  262. <div
  263. v-if="store.loginState"
  264. class="college-slider"
  265. :class="{ slider: loginMenuShow }"
  266. @mouseover="handleMouseEvents('login', true)"
  267. @mouseleave="handleMouseEvents('login', false)"
  268. >
  269. <ul>
  270. <li>
  271. <router-link :to="'/user/profile'">
  272. {{ t("navbar.profile") }}
  273. </router-link>
  274. </li>
  275. <li>
  276. <router-link :to="'/user/passport'">
  277. {{ t("navbar.passport") }}
  278. </router-link>
  279. </li>
  280. <li>
  281. <router-link :to="'/user/courses'">
  282. {{ t("navbar.courses") }}
  283. </router-link>
  284. </li>
  285. <li>
  286. <router-link :to="'/user/favorite-class'">
  287. {{ t("navbar.collections") }}
  288. </router-link>
  289. </li>
  290. <li>
  291. <a
  292. href="javascript:;"
  293. @click="
  294. store.logout();
  295. store.mocLogout();
  296. "
  297. title="點擊以登出"
  298. >
  299. {{ t("navbar.logout") }}
  300. </a>
  301. </li>
  302. </ul>
  303. </div>
  304. <!-- <router-link :to="'/user/profile'" v-else>會員專區</router-link> -->
  305. </li>
  306. <li>
  307. <a href="javascript:;" @click="changeLang()" title="點擊切換語言"
  308. >中/EN</a
  309. >
  310. </li>
  311. <!-- <li class="d-none d-lg-block">
  312. <v-icon icon="mdi-magnify"></v-icon>
  313. </li> -->
  314. <!-- <li class="d-none d-lg-block position-relative">
  315. <a
  316. href="javascript:;"
  317. @mouseover="otherMenuShow = true"
  318. @mouseleave="otherMenuShow = false"
  319. class="d-none d-lg-block"
  320. title="查看選單"
  321. >
  322. <span class="d-none">查看選單</span>
  323. <v-icon icon="mdi-menu"></v-icon
  324. ></a>
  325. <div
  326. class="college-slider"
  327. :class="{ slider: otherMenuShow }"
  328. @mouseover="handleMouseEvents('other', true)"
  329. @mouseleave="handleMouseEvents('other', false)"
  330. >
  331. <ul>
  332. <li v-for="(item, index) in otherList" :key="index">
  333. <a
  334. href="javascript:;"
  335. @click="handleClick(item.url)"
  336. :title="`前往${item.title}頁面`"
  337. >{{ item.title }}</a
  338. >
  339. </li>
  340. </ul>
  341. </div>
  342. </li> -->
  343. <li
  344. v-for="(item, index) in otherList"
  345. :key="index"
  346. class="d-block d-lg-none"
  347. >
  348. <a
  349. href="javascript:;"
  350. @click="handleClick(item.url)"
  351. :title="`前往${item.title}頁面`"
  352. >{{ item.title }}</a
  353. >
  354. <!-- <router-link :to="item.url">{{ item.title }}</router-link> -->
  355. </li>
  356. </ul>
  357. <a href="javascript:;" class="icon" @click="toggleMenu()" title="查看選單">
  358. <span class="d-none">查看選單</span>
  359. <v-icon icon="mdi-menu" class="mx-2"></v-icon>
  360. </a>
  361. </div>
  362. </template>
  363. <style lang="scss" scoped>
  364. .navbar {
  365. max-width: 90em;
  366. margin: 40px auto 0;
  367. padding: 0 2.1875em 0 0.9375em;
  368. position: sticky;
  369. top: 0;
  370. z-index: 2000;
  371. background: #fff;
  372. border: 0.0625em solid;
  373. @media (max-width: 1280px) {
  374. margin: 40px 40px 0;
  375. padding: 0.625em 1.25em 0.625em 0.625em;
  376. }
  377. @media (max-width: 600px) {
  378. margin: 20px 20px 0;
  379. padding: 0.625em 1.25em 0.625em 0.625em;
  380. }
  381. img {
  382. width: 100%;
  383. max-width: 300px;
  384. margin-top: 0.3125em;
  385. @media (max-width: 600px) {
  386. max-width: 230px;
  387. }
  388. }
  389. .menu {
  390. display: flex;
  391. align-items: center;
  392. list-style: none;
  393. @media (max-width: 1280px) {
  394. position: absolute;
  395. top: 6.2em;
  396. left: 0;
  397. right: 0;
  398. z-index: 100;
  399. overflow: hidden;
  400. flex-direction: column;
  401. max-height: 0;
  402. transition: max-height 0.3s ease-in-out;
  403. box-shadow: 0.0625em 0.0625em 0.9375em #c8c8c8;
  404. }
  405. @media (max-width: 600px) {
  406. top: 103%;
  407. }
  408. &.slider {
  409. max-height: 43.75em;
  410. overflow: initial;
  411. // border: 0.0625em solid;
  412. // border-top: none;
  413. }
  414. & > li {
  415. margin-left: 1.6875em;
  416. font-weight: 400;
  417. @media (max-width: 1280px) {
  418. width: 100%;
  419. margin-left: 0;
  420. background: #fff;
  421. border-bottom: 0.0625em solid #f0f0f0;
  422. font-weight: 500;
  423. text-align: center;
  424. }
  425. a {
  426. width: 100%;
  427. display: block;
  428. padding: 2.5em 0;
  429. color: #000;
  430. text-decoration: none;
  431. line-height: 1.3;
  432. transition: all 0.3s;
  433. &:hover {
  434. opacity: 0.8;
  435. }
  436. @media (max-width: 1280px) {
  437. padding: 1.25em 0;
  438. }
  439. }
  440. }
  441. .college-slider {
  442. display: none;
  443. position: absolute;
  444. top: 5em;
  445. left: -1.875em;
  446. width: 8.125em;
  447. background: #fff;
  448. text-align: center;
  449. border-radius: 5px;
  450. box-shadow: 0.0625em 0.0625em 0.9375em #c8c8c8;
  451. transition: all 0.3s;
  452. @media (max-width: 1280px) {
  453. position: initial;
  454. width: auto;
  455. max-height: 0;
  456. box-shadow: none;
  457. transition: none;
  458. overflow: hidden;
  459. }
  460. // @media (max-width: 1280px) {
  461. // top: 1.875em;
  462. // left: 50vw;
  463. // }
  464. // @media (max-width: 600px) {
  465. // left: 58vw;
  466. // width: 6.25em;
  467. // }
  468. &.slider {
  469. display: block;
  470. @media (max-width: 1280px) {
  471. max-height: 100%;
  472. }
  473. }
  474. ul {
  475. @media (max-width: 1280px) {
  476. padding-bottom: 0.9375em;
  477. }
  478. li {
  479. transition: all 0.3s;
  480. &:last-child {
  481. border-bottom: none;
  482. }
  483. &:hover {
  484. background-color: #eee;
  485. @media (max-width: 1280px) {
  486. opacity: 0.8;
  487. background-color: #fff;
  488. }
  489. }
  490. a {
  491. display: block;
  492. width: 100%;
  493. padding: 0.9375em 0.625em;
  494. @media (max-width: 1280px) {
  495. padding: 0.9375em 0.625em 0.9375em 2.5em;
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. .toggle-icon {
  503. margin-left: 0.3125em;
  504. position: absolute;
  505. top: 0.7em;
  506. transition: all 0.3s;
  507. &.slider {
  508. transform: rotate(180deg);
  509. }
  510. }
  511. .icon {
  512. display: none;
  513. transition: all 0.3s;
  514. @media (max-width: 1280px) {
  515. display: block;
  516. }
  517. &:hover {
  518. opacity: 0.8;
  519. }
  520. .v-icon {
  521. font-size: 2rem;
  522. }
  523. }
  524. &::before {
  525. content: "";
  526. position: absolute;
  527. top: 0.375em;
  528. left: 0.375em;
  529. width: 99%;
  530. height: 88%;
  531. background-color: rgba(255, 255, 255, 0.5);
  532. z-index: -1;
  533. @media (max-width: 960px) {
  534. top: 0.4375em;
  535. left: 1.3vw;
  536. width: 97%;
  537. height: 83%;
  538. }
  539. }
  540. }
  541. </style>