123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <script setup>
- import { ref, reactive, onMounted } from "vue";
- import { useRouter } from "vue-router";
- import { useMainStore } from "@/stores/store";
- import { useI18n } from "vue-i18n";
- import Login from "@/views/Login.vue";
- const router = useRouter();
- const store = useMainStore();
- const { t, locale } = useI18n();
- let menuShow = ref(false);
- let collegeMenuShow = ref(false);
- let otherMenuShow = ref(false);
- let loginMenuShow = ref(false);
- function toggleMenu() {
- collegeMenuShow.value = false;
- menuShow.value = !menuShow.value;
- }
- function handleClose() {
- store.loginDialog = false;
- }
- function handleMouseEvents(name, event) {
- const screenWidth = window.innerWidth;
- if (screenWidth >= 1280) {
- if (name === "college") {
- collegeMenuShow.value = event;
- } else if (name === "other") {
- otherMenuShow.value = event;
- } else {
- loginMenuShow.value = event;
- }
- } else {
- return;
- }
- }
- function handleClick(url) {
- menuShow.value = false;
- collegeMenuShow.value = false;
- otherMenuShow.value = false;
- router.push(url);
- }
- const collegeList = reactive([
- {
- title: "未來工藝",
- url: "/college-group/future",
- },
- {
- title: "技藝工藝",
- url: "/college-group/craft",
- },
- {
- title: "跨域增能",
- url: "/college-group/cross",
- },
- {
- title: "線上工藝",
- url: "/college-group/online",
- },
- {
- title: "希望工程",
- url: "/college-group/craft-for-all",
- },
- {
- title: "生活工藝",
- url: "/college-group/life",
- },
- // {
- // title: "修護工藝",
- // url: "/college-group/repair",
- // },
- // {
- // title: "世代工藝",
- // url: "/college-group/generation",
- // },
- // {
- // title: "青年工藝",
- // url: "/college-group/teenager",
- // },
- ]);
- const otherList = reactive([
- // {
- // title: "我要開課",
- // url: "/setup-courses",
- // },
- // {
- // title: "網站架構",
- // url: "/",
- // },
- ]);
- onMounted(() => {
- console.log("onMounted");
- localStorage.setItem("lang", "zh");
- });
- function changeLang() {
- let lang = localStorage.getItem("lang");
- console.log("lang", lang);
- if (lang === "zh") {
- locale.value = "en";
- localStorage.setItem("lang", "en");
- } else if (lang === "en") {
- locale.value = "zh";
- localStorage.setItem("lang", "zh");
- }
- }
- function handleLogout() {
- localStorage.removeItem("token");
- window.location.reload();
- }
- </script>
- <template>
- <div class="d-flex justify-space-between align-center navbar">
- <router-link :to="'/'">
- <img src="@/assets/img/logo.png" alt="" />
- </router-link>
- <ul class="menu align-center" :class="{ slider: menuShow }">
- <li>
- <router-link :to="'/crafts'">工藝學</router-link>
- </li>
- <li class="position-relative">
- <a
- href="javascript:;"
- @mouseover="collegeMenuShow = true"
- @mouseleave="collegeMenuShow = false"
- class="d-none d-lg-block"
- >工藝學群</a
- >
- <a
- href="javascript:;"
- @click="collegeMenuShow = !collegeMenuShow"
- class="d-block d-lg-none"
- >工藝學群
- <v-icon
- icon="mdi-chevron-down"
- class="toggle-icon"
- :class="{ slider: collegeMenuShow }"
- ></v-icon
- ></a>
- <div
- class="college-slider"
- :class="{ slider: collegeMenuShow }"
- @mouseover="handleMouseEvents('college', true)"
- @mouseleave="handleMouseEvents('college', false)"
- >
- <ul>
- <li v-for="(item, index) in collegeList" :key="index">
- <a href="javascript:;" @click="handleClick(item.url)">{{
- item.title
- }}</a>
- <!-- <router-link :to="item.url">{{ item.title }}</router-link> -->
- </li>
- </ul>
- </div>
- </li>
- <li>
- <router-link :to="'/news'">重要訊息</router-link>
- </li>
- <li>
- <router-link :to="'/course-list'">探索課程</router-link>
- </li>
- <!-- <li>
- <router-link :to="'/article'">知識文章</router-link>
- </li> -->
- <li class="position-relative">
- <v-dialog
- v-model="store.loginDialog"
- max-width="450"
- v-if="!store.loginState"
- >
- <template v-slot:activator="{ props }">
- <a href="javascript:;" v-bind="props">會員登入</a>
- </template>
- <Login @close="handleClose" />
- </v-dialog>
- <div v-else>
- <router-link
- :to="'/user/profile'"
- @mouseover="loginMenuShow = true"
- @mouseleave="loginMenuShow = false"
- class="d-none d-lg-block"
- >會員專區</router-link
- >
- <router-link :to="'/user/profile'" class="d-block d-lg-none"
- >會員專區</router-link
- >
- </div>
- <div
- v-if="store.loginState"
- class="college-slider"
- :class="{ slider: loginMenuShow }"
- @mouseover="handleMouseEvents('login', true)"
- @mouseleave="handleMouseEvents('login', false)"
- >
- <ul>
- <li>
- <a href="javascript:;" @click="handleLogout()"> 登出 </a>
- </li>
- </ul>
- </div>
- <!-- <router-link :to="'/user/profile'" v-else>會員專區</router-link> -->
- </li>
- <li>
- <router-link :to="'/setup-courses'">我要開課</router-link>
- </li>
- <li>
- <a href="javascript:;" @click="changeLang()">中/EN</a>
- </li>
- <li class="d-none d-lg-block">
- <v-icon icon="mdi-magnify"></v-icon>
- </li>
- <li class="d-none d-lg-block position-relative">
- <a
- href="javascript:;"
- @mouseover="otherMenuShow = true"
- @mouseleave="otherMenuShow = false"
- class="d-none d-lg-block"
- >
- <v-icon icon="mdi-menu"></v-icon
- ></a>
- <div
- class="college-slider"
- :class="{ slider: otherMenuShow }"
- @mouseover="handleMouseEvents('other', true)"
- @mouseleave="handleMouseEvents('other', false)"
- >
- <ul>
- <li v-for="(item, index) in otherList" :key="index">
- <a href="javascript:;" @click="handleClick(item.url)">{{
- item.title
- }}</a>
- </li>
- </ul>
- </div>
- </li>
- <li
- v-for="(item, index) in otherList"
- :key="index"
- class="d-block d-lg-none"
- >
- <a href="javascript:;" @click="handleClick(item.url)">{{
- item.title
- }}</a>
- <!-- <router-link :to="item.url">{{ item.title }}</router-link> -->
- </li>
- </ul>
- <a href="javascript:;" class="icon" @click="toggleMenu()">
- <v-icon icon="mdi-menu" class="mx-2"></v-icon>
- </a>
- </div>
- </template>
- <style lang="scss" scoped>
- .navbar {
- width: 90%;
- max-width: 1300px;
- margin: 0 auto 40px;
- padding: 0 35px 0 15px;
- border: 1px solid;
- position: relative;
- z-index: 1000;
- background: transparent;
- top: 40px;
- left: 0;
- right: 0;
- @media (max-width: 1280px) {
- padding: 10px 20px 10px 10px;
- }
- img {
- width: 100%;
- max-width: 370px;
- margin-top: 5px;
- @media (max-width: 600px) {
- max-width: 300px;
- }
- }
- .menu {
- display: flex;
- align-items: center;
- list-style: none;
- @media (max-width: 1280px) {
- position: absolute;
- top: 81px;
- left: 0;
- right: 0;
- z-index: 100;
- overflow: hidden;
- flex-direction: column;
- max-height: 0;
- transition: max-height 0.3s ease-in-out;
- box-shadow: 1px 1px 15px #c8c8c8;
- }
- @media (max-width: 600px) {
- top: 103%;
- }
- &.slider {
- max-height: 700px;
- overflow: initial;
- // border: 1px solid;
- // border-top: none;
- }
- & > li {
- margin-left: 27px;
- font-weight: 400;
- @media (max-width: 1280px) {
- width: 100%;
- margin-left: 0;
- background: #fff;
- border-bottom: 1px solid #f0f0f0;
- font-weight: 500;
- text-align: center;
- }
- a {
- width: 100%;
- display: block;
- padding: 40px 0;
- color: #000;
- text-decoration: none;
- transition: all 0.3s;
- &:hover {
- opacity: 0.8;
- }
- @media (max-width: 1280px) {
- padding: 20px 0;
- }
- }
- }
- .college-slider {
- display: none;
- position: absolute;
- top: 80px;
- left: -30px;
- width: 130px;
- background: #fff;
- text-align: center;
- box-shadow: 1px 1px 15px #c8c8c8;
- transition: all 0.3s;
- @media (max-width: 1280px) {
- position: initial;
- width: auto;
- max-height: 0;
- box-shadow: none;
- transition: none;
- overflow: hidden;
- }
- // @media (max-width: 1280px) {
- // top: 30px;
- // left: 50vw;
- // }
- // @media (max-width: 600px) {
- // left: 58vw;
- // width: 100px;
- // }
- &.slider {
- display: block;
- @media (max-width: 1280px) {
- max-height: 100%;
- }
- }
- ul {
- @media (max-width: 1280px) {
- padding-bottom: 15px;
- }
- li {
- transition: all 0.3s;
- &:last-child {
- border-bottom: none;
- }
- &:hover {
- background-color: #eee;
- @media (max-width: 1280px) {
- opacity: 0.8;
- background-color: #fff;
- }
- }
- a {
- display: block;
- width: 100%;
- padding: 15px 10px;
- @media (max-width: 1280px) {
- padding: 15px 10px 15px 40px;
- }
- }
- }
- }
- }
- }
- .toggle-icon {
- margin-left: 5px;
- position: absolute;
- top: 17px;
- transition: all 0.3s;
- &.slider {
- transform: rotate(180deg);
- }
- }
- .icon {
- display: none;
- transition: all 0.3s;
- @media (max-width: 1280px) {
- display: block;
- }
- &:hover {
- opacity: 0.8;
- }
- .v-icon {
- font-size: 2rem;
- }
- }
- &::before {
- content: "";
- position: absolute;
- top: 6px;
- left: 6px;
- width: 99%;
- height: 88%;
- background-color: rgba(255, 255, 255, 0.5);
- z-index: -1;
- @media (max-width: 960px) {
- top: 7px;
- left: 1.3vw;
- width: 97%;
- height: 83%;
- }
- }
- }
- </style>
|