<template>
  <div class="elrow-top" :class="elrowtop">
    <el-row justify="center">
      <el-col :span="4" v-if="windowwidth">
        <div class="grid-content ep-bg-purple-dark">
          <!-- <div><img src="../public/favicon.ico" alt=""></div> -->
          <div>清疯不颠</div>
        </div>
      </el-col>
      <el-col :span="14" justify="center">
        <div class="grid-content ep-bg-purple-dark">
          <el-menu :default-active="activeIndex" class="el-menu-demo" :collapse="false"
            @select="handleSelect">
            <el-menu-item index="/:type">
              首页
            </el-menu-item>
            <el-menu-item index="/aericle">
              文章
            </el-menu-item>
            <el-menu-item index="/nonsense">
              疯言疯语
            </el-menu-item>
            <el-menu-item index="/about">
              关于
            </el-menu-item>
            <el-menu-item index="/message">
              留言板
            </el-menu-item>
          </el-menu>
        </div>
      </el-col>
      <el-col :span="2" class="search-container" v-if="windowwidth">

      </el-col>
    </el-row>
  </div>
  <div class="hero" :class="{ 'newhero': classhero }" v-if="windowwidth">
    <h1>如果感到累了撸一管就好了</h1>
  </div>

  <div id="content-section" :class="{ 'visible': isconts }">
    <div class="nonsensetitle" v-if="classnonsenset">
      <div class="nonsensetitleconst" v-if="windowwidth">
        <h1>发癫中QAQ</h1>
      </div>
    </div>
    <!-- 状态模块 -->
    <leftmodlue class="leftmodluepage" :class="{ 'nonsensetmargintop': classnonsenset }" v-if="windowwidth" />
    <!-- 内容模块 -->
    <RouterView class="RouterViewpage" :class="{ 'nonsensetmargintop': classnonsenset }" />
  </div>
  <!-- 分页 -->
  <div class="Pagination">
  </div>
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { useRouter } from 'vue-router'
import leftmodlue from '@/views/leftmodlue.vue'

// hero 的高度更新
const classhero = ref(false);
const isconts = ref(false); // 内容
const isScrollingleftmodlue = ref(false);
const elrowtop = ref(); // 导航
const classnonsenset = ref(false) // 疯言疯语
const windowwidth = ref(true) // 屏幕
// 路由
const router = useRouter()
const handleSelect = (key: string) => {
  router.push({
    path: key
  })
}
// 是否在某页面
const isclass = (url: any) => {
  classhero.value = url != '/:type';
  classnonsenset.value = url == '/nonsense'
}

// url监听
// 使用router.beforeEach或router.afterEach全局守卫
router.beforeEach((to) => {
  // console.log("从", from.path, "到", to.path);
  isclass(to.path)
  // 回到顶部
  window.scrollTo({
    top: 0,
    behavior: 'smooth' // 平滑滚动
  });

});
// 滚动事件
const handleScroll = () => {
  const scrollYmo = window.scrollY;
  // 只有首页才会执行页面内容滚动效果
  if (location.pathname == '/:type') {
    isconts.value = window.scrollY > 200;
    isScrollingleftmodlue.value = window.scrollY > 600;
  }else{
    isconts.value = true;
    isScrollingleftmodlue.value = true;
  }
  // 导航
  if (scrollYmo > 1200) {
    elrowtop.value = 'hide'
  } else {
    elrowtop.value = window.scrollY > 100 ? 'solid' : 'transparent';
  }
};
const addScrollListener = () => {
  window.addEventListener('scroll', handleScroll);
};
const removeScrollListener = () => {
  window.removeEventListener('scroll', handleScroll);
};

const mediaquery = () => {
  // 在这里处理屏幕大小变化
  if (window.innerWidth < 768) {
    removeScrollListener();
    windowwidth.value = false
    isScrollingleftmodlue.value = true
    classnonsenset.value = false
    isconts.value = true;
  } else {
    addScrollListener();
    windowwidth.value = true
  }
};

// 页面加载完成后执行
const activeIndex = ref('/:type')
const isactiveindex = () => {
  // 获取当前路径
  const currentPath = window.location.pathname;
  // 判断路径并设置hero值
  activeIndex.value = currentPath;
}

window.addEventListener('DOMContentLoaded', () => {
  isactiveindex();
  mediaquery();
});

window.addEventListener('resize', mediaquery);

window.addEventListener('DOMContentLoaded', isactiveindex);
// 输入框

</script>
<style></style>
<!-- <style>
body {
  /* background-image: url(./img/8.21.1.jpg); */
  background-size: 120% 120%;
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
}

body ul {
  border-bottom: 0px;
}

.h1,
.h2,
.h3,
.h4,
.h5,
.h6,
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: inherit;
  font-weight: 400;
  line-height: 1.5;
  margin-bottom: .5rem;
  color: #32325d;
}

p {
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.7;
}

.cont {
  margin-top: 5%;
}

/* 导航 */
.elrow-top {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  padding: 20px 40px;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
  transition: all 0.4s ease;
  font-size: inherit;
}

.elrow-top.transparent {
  background-color: transparent;
}

.elrow-top.solid {
  background-color: rgba(145, 196, 238, 0.85);
  padding: 15px 40px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.elrow-top.hide {
  background-color: rgba(145, 196, 238, 0);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0);
  top: -100px;
  transition: all 0.8s ease;
}

.elrow-top .el-row .el-col .grid-content .el-menu--horizontal {
  border-bottom: 0px;
}

.el-menu--horizontal {
  background: rgb(0, 0, 0, 0);
}

.el-menu-demo {
  font-weight: bold;
  font-size: 20px;
  left: 10%;
}

.el-menu-demo .el-menu-item {
  margin-left: 10px;
}

.el-menu.el-menu--horizontal.el-menu-demo .el-menu-item {
  font-size: inherit;
}

.el-menu.el-menu--horizontal.el-menu-demo .el-menu-item:hover,
.el-menu.el-menu--horizontal.el-menu-demo .el-menu-item.is-active {
  background-color: rgb(0, 0, 0, 0);
}


/* 内容 */
#content-section {
  min-height: 100vh;
  padding: 100px 10%;
  opacity: 0;
  transform: translateY(50px);
  transition: all 0.8s ease-out;
  /* margin: 20px 0; */
  border-radius: 10px;
  display: flex;
}

#content-section.visible {
  opacity: 1;
  transform: translateY(0);
}

.search {
  margin-top: 12px;
}

.grid-content {
  text-align: center;
}

.RouterViewpage {
  width: 80%;
  margin-left: 5%;
  margin-right: 5%;
}

/* 分页 */
.Pagination {
  align-self: center;
  background-color: aqua;
}

#search {
  display: flex;
}

.el-button {
  background-color: rgb(0, 0, 0, 0);
  border: 0px;
}

/* 状态栏 */
.leftmodluepage {
  width: 20%;
}


/* 开头标题样式*/
.hero {
  height: 600px;
  margin-top: 5%;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: white;
}

.hero.newhero {
  height: 200px;
  transition: all 0.3s ease;
}

.hero h1 {
  font-size: 3.5rem;
  margin-bottom: 20px;
}

.hero p {
  font-size: 1.5rem;
  max-width: 700px;
  margin: 0 auto 30px;
}

/* 疯言疯语标题 */
.nonsensetitle {
  text-align: center;
  position: absolute;
  top: 0;
  width: 76.5%;
  padding: 20px;
  margin-bottom: 50px;
  background: rgba(255, 255, 255, 0.1) !important;
  backdrop-filter: blur(10px);
  border-radius: 20px;
}

.nonsensetitle .nonsensetitleconst {
  padding: 1.5rem;
  flex: 1 1 auto;
  box-sizing: border-box;
}

.nonsensetitle .nonsensetitleconst p {
  font-size: 1rem;
}

/* 调整样式 */
.nonsensetmargintop {
  margin-top: 130px;
}

/* 输入框 */
</style> -->