Navbar.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. <li class="position-relative">
  229. <!-- <v-dialog
  230. v-model="store.loginDialog"
  231. max-width="450"
  232. v-if="!store.loginState"
  233. >
  234. <template v-slot:activator="{ props }">
  235. <a href="javascript:;" v-bind="props" title="點擊以開啟會員登入介面"
  236. >會員登入</a
  237. >
  238. </template>
  239. <Login @close="handleClose" />
  240. </v-dialog> -->
  241. <a
  242. v-if="!store.loginState"
  243. href="https://member.moc.gov.tw/MOCMC/A0001/list?SYS_ID=CRAFT_NTCRI"
  244. >{{ t("navbar.login") }}</a
  245. >
  246. <div v-else>
  247. <router-link
  248. :to="'/user/profile'"
  249. @mouseover="loginMenuShow = true"
  250. @mouseleave="loginMenuShow = false"
  251. class="d-none d-lg-block"
  252. >
  253. <span class="d-flex align-center">
  254. {{ t("navbar.member") }} <v-icon icon="mdi-chevron-down"></v-icon>
  255. </span>
  256. </router-link>
  257. <router-link :to="'/user/profile'" class="d-block d-lg-none">{{
  258. t("navbar.member")
  259. }}</router-link>
  260. </div>
  261. <div
  262. v-if="store.loginState"
  263. class="college-slider"
  264. :class="{ slider: loginMenuShow }"
  265. @mouseover="handleMouseEvents('login', true)"
  266. @mouseleave="handleMouseEvents('login', false)"
  267. >
  268. <ul>
  269. <li>
  270. <router-link :to="'/user/profile'">
  271. {{ t("navbar.profile") }}
  272. </router-link>
  273. </li>
  274. <li>
  275. <router-link :to="'/user/passport'">
  276. {{ t("navbar.passport") }}
  277. </router-link>
  278. </li>
  279. <li>
  280. <router-link :to="'/user/courses'">
  281. {{ t("navbar.courses") }}
  282. </router-link>
  283. </li>
  284. <li>
  285. <router-link :to="'/user/favorite-class'">
  286. {{ t("navbar.collections") }}
  287. </router-link>
  288. </li>
  289. <li>
  290. <a
  291. href="javascript:;"
  292. @click="
  293. store.logout();
  294. store.mocLogout();
  295. "
  296. title="點擊以登出"
  297. >
  298. {{ t("navbar.logout") }}
  299. </a>
  300. </li>
  301. </ul>
  302. </div>
  303. <!-- <router-link :to="'/user/profile'" v-else>會員專區</router-link> -->
  304. </li>
  305. <li>
  306. <a href="javascript:;" @click="changeLang()" title="點擊切換語言"
  307. >中/EN</a
  308. >
  309. </li>
  310. <!-- <li class="d-none d-lg-block">
  311. <v-icon icon="mdi-magnify"></v-icon>
  312. </li> -->
  313. <!-- <li class="d-none d-lg-block position-relative">
  314. <a
  315. href="javascript:;"
  316. @mouseover="otherMenuShow = true"
  317. @mouseleave="otherMenuShow = false"
  318. class="d-none d-lg-block"
  319. title="查看選單"
  320. >
  321. <span class="d-none">查看選單</span>
  322. <v-icon icon="mdi-menu"></v-icon
  323. ></a>
  324. <div
  325. class="college-slider"
  326. :class="{ slider: otherMenuShow }"
  327. @mouseover="handleMouseEvents('other', true)"
  328. @mouseleave="handleMouseEvents('other', false)"
  329. >
  330. <ul>
  331. <li v-for="(item, index) in otherList" :key="index">
  332. <a
  333. href="javascript:;"
  334. @click="handleClick(item.url)"
  335. :title="`前往${item.title}頁面`"
  336. >{{ item.title }}</a
  337. >
  338. </li>
  339. </ul>
  340. </div>
  341. </li> -->
  342. <li
  343. v-for="(item, index) in otherList"
  344. :key="index"
  345. class="d-block d-lg-none"
  346. >
  347. <a
  348. href="javascript:;"
  349. @click="handleClick(item.url)"
  350. :title="`前往${item.title}頁面`"
  351. >{{ item.title }}</a
  352. >
  353. <!-- <router-link :to="item.url">{{ item.title }}</router-link> -->
  354. </li>
  355. </ul>
  356. <a href="javascript:;" class="icon" @click="toggleMenu()" title="查看選單">
  357. <span class="d-none">查看選單</span>
  358. <v-icon icon="mdi-menu" class="mx-2"></v-icon>
  359. </a>
  360. </div>
  361. </template>
  362. <style lang="scss" scoped>
  363. .navbar {
  364. max-width: 90em;
  365. margin: 40px auto 0;
  366. padding: 0 2.1875em 0 0.9375em;
  367. position: sticky;
  368. top: 0;
  369. z-index: 2000;
  370. background: #fff;
  371. border: 0.0625em solid;
  372. @media (max-width: 1280px) {
  373. margin: 40px 40px 0;
  374. padding: 0.625em 1.25em 0.625em 0.625em;
  375. }
  376. @media (max-width: 600px) {
  377. margin: 20px 20px 0;
  378. padding: 0.625em 1.25em 0.625em 0.625em;
  379. }
  380. img {
  381. width: 100%;
  382. max-width: 300px;
  383. margin-top: 0.3125em;
  384. @media (max-width: 600px) {
  385. max-width: 230px;
  386. }
  387. }
  388. .menu {
  389. display: flex;
  390. align-items: center;
  391. list-style: none;
  392. @media (max-width: 1280px) {
  393. position: absolute;
  394. top: 6.2em;
  395. left: 0;
  396. right: 0;
  397. z-index: 100;
  398. overflow: hidden;
  399. flex-direction: column;
  400. max-height: 0;
  401. transition: max-height 0.3s ease-in-out;
  402. box-shadow: 0.0625em 0.0625em 0.9375em #c8c8c8;
  403. }
  404. @media (max-width: 600px) {
  405. top: 103%;
  406. }
  407. &.slider {
  408. max-height: 43.75em;
  409. overflow: initial;
  410. // border: 0.0625em solid;
  411. // border-top: none;
  412. }
  413. & > li {
  414. margin-left: 1.6875em;
  415. font-weight: 400;
  416. @media (max-width: 1280px) {
  417. width: 100%;
  418. margin-left: 0;
  419. background: #fff;
  420. border-bottom: 0.0625em solid #f0f0f0;
  421. font-weight: 500;
  422. text-align: center;
  423. }
  424. a {
  425. width: 100%;
  426. display: block;
  427. padding: 2.5em 0;
  428. color: #000;
  429. text-decoration: none;
  430. line-height: 1.3;
  431. transition: all 0.3s;
  432. &:hover {
  433. opacity: 0.8;
  434. }
  435. @media (max-width: 1280px) {
  436. padding: 1.25em 0;
  437. }
  438. }
  439. }
  440. .college-slider {
  441. display: none;
  442. position: absolute;
  443. top: 5em;
  444. left: -1.875em;
  445. width: 8.125em;
  446. background: #fff;
  447. text-align: center;
  448. border-radius: 5px;
  449. box-shadow: 0.0625em 0.0625em 0.9375em #c8c8c8;
  450. transition: all 0.3s;
  451. @media (max-width: 1280px) {
  452. position: initial;
  453. width: auto;
  454. max-height: 0;
  455. box-shadow: none;
  456. transition: none;
  457. overflow: hidden;
  458. }
  459. // @media (max-width: 1280px) {
  460. // top: 1.875em;
  461. // left: 50vw;
  462. // }
  463. // @media (max-width: 600px) {
  464. // left: 58vw;
  465. // width: 6.25em;
  466. // }
  467. &.slider {
  468. display: block;
  469. @media (max-width: 1280px) {
  470. max-height: 100%;
  471. }
  472. }
  473. ul {
  474. @media (max-width: 1280px) {
  475. padding-bottom: 0.9375em;
  476. }
  477. li {
  478. transition: all 0.3s;
  479. &:last-child {
  480. border-bottom: none;
  481. }
  482. &:hover {
  483. background-color: #eee;
  484. @media (max-width: 1280px) {
  485. opacity: 0.8;
  486. background-color: #fff;
  487. }
  488. }
  489. a {
  490. display: block;
  491. width: 100%;
  492. padding: 0.9375em 0.625em;
  493. @media (max-width: 1280px) {
  494. padding: 0.9375em 0.625em 0.9375em 2.5em;
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. .toggle-icon {
  502. margin-left: 0.3125em;
  503. position: absolute;
  504. top: 0.7em;
  505. transition: all 0.3s;
  506. &.slider {
  507. transform: rotate(180deg);
  508. }
  509. }
  510. .icon {
  511. display: none;
  512. transition: all 0.3s;
  513. @media (max-width: 1280px) {
  514. display: block;
  515. }
  516. &:hover {
  517. opacity: 0.8;
  518. }
  519. .v-icon {
  520. font-size: 2rem;
  521. }
  522. }
  523. &::before {
  524. content: "";
  525. position: absolute;
  526. top: 0.375em;
  527. left: 0.375em;
  528. width: 99%;
  529. height: 88%;
  530. background-color: rgba(255, 255, 255, 0.5);
  531. z-index: -1;
  532. @media (max-width: 960px) {
  533. top: 0.4375em;
  534. left: 1.3vw;
  535. width: 97%;
  536. height: 83%;
  537. }
  538. }
  539. }
  540. </style>