<template>
  <div class="main">
    <el-row>
      <el-col :span="24" class="animate__animated animate__backInRight" v-loading="loading">
        <div class="one">
          <el-row>
            <el-col :span="14" class="left">
              <el-image class="image" :src="siteInfo.logoUrl" fit="fill" />
              <div class="content">
                <text class="title">{{ siteInfo.zhTitle }}</text>
                <!-- <text class="english">{{ siteInfo.zhBrief }}</text> -->
              </div>
            </el-col>
            <el-col :span="10" class="right">
              <el-row align="middle">
                <el-col :span="6" class="right_1" @click="toCommon(0)">帮助中心</el-col>
                <el-col :span="14" class="right_2">
                  <a-input-search
                    v-model:value="searchValue"
                    placeholder="请输入您想要搜索的内容"
                    style="width: 240px"
                    enter-button
                    @search="onSearch"
                  />
                </el-col>
                <el-col :span="4" v-if="user && user.id" class="right_3">
                  <el-dropdown>
                    <el-button type="primary">
                      {{ user.nick_name || '游客' }}
                    </el-button>
                    <template #dropdown>
                      <el-dropdown-menu>
                        <el-dropdown-menu>
                          <el-dropdown-item @click="toOpen">管理中心</el-dropdown-item>
                          <el-dropdown-item @click="toCenter">个人中心</el-dropdown-item>
                          <el-dropdown-item @click="toLogout">注销</el-dropdown-item>
                        </el-dropdown-menu>
                      </el-dropdown-menu>
                    </template>
                  </el-dropdown>
                </el-col>
                <el-col :span="4" v-else class="right_3">
                  <el-button @click="toCommon(1)" type="primary">登录</el-button>
                  <el-button @click="toCommon(2)" type="primary">注册</el-button>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </div>
        <div class="two" @click="switchMenu('one')">
          <div class="two_1">
            <el-image class="image" :src="homeBg" fit="fill" />
          </div>
          <div class="two_2">
            <text>{{ siteInfo.zhTitle }}</text>
          </div>
        </div>
        <div class="w_1200">
          <div class="thr">
            <el-col
              class="list"
              :span="4"
              v-for="(item, index) in menu"
              :key="index"
              @click="switchMenu(item.href)"
            >
              <div class="thr_1">
                <div class="title">{{ item.title }}</div>
                <div class="English">{{ item.English }}</div>
              </div>
            </el-col>
          </div>
        </div>
        <div class="four">
          {{ footInfo.Copyright }}
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
// 基础
import homeBg from '/images/homebg.png'

import { siteInfo, footInfo, menuList } from '@/layout/site'
import { UserStore } from '@/store/user'
const userStore = UserStore()
const user = computed(() => userStore.user)
// 加载中
const loading = ref(false)
// 路由
const router = useRouter()
// 搜索
const searchValue = ref('')
const menu = ref(menuList)
// 请求
onMounted(async () => {
  loading.value = true
  search()
  loading.value = false
})
const search = async () => {
  const menuList = menu.value.filter((item) => {
    if (item.route != 'one') return item
  })
  menu.value = menuList
}
// 搜索
const onSearch = (data) => {
  const query = { type: 'search' }
  if (data) query.searchValue = data
  router.push({ path: '/search', query })
}
const toCommon = (type) => {
  if (type === 0) router.push({ path: '/help' })
  else if (type === 1) router.push({ path: '/login' })
  else router.push({ path: '/register' })
}
// 点击指定模块
const switchMenu = async (item) => {
  router.push({ path: `/${item}` })
}
// 打开管理端
const toOpen = async () => {
  window.location.href = import.meta.env.VITE_APP_HOME
}
// 基础跳转
const toCenter = () => {
  router.push('/center')
}
// 退出登录
const toLogout = () => {
  userStore.logOut()
  router.push('/login')
}
</script>
<style scoped lang="scss">
.main {
  height: 100vh;
  width: 100%;
  position: relative;
  background: url('./images/home.jpg');
  background-size: 100% 100%;
  padding: 0px;
  margin: 0px;
  color: #fff;
  font-family: '微软雅黑';
  .one {
    width: 1200px;
    min-width: 1200px;
    margin: 0 auto;
    padding-top: 32px;
    padding-bottom: 12px;

    .left {
      display: flex;
      align-items: center;

      .image {
        height: 45px;
        width: 45px;
        margin: 0 10px 0 0;
      }

      .images {
        height: auto;
        width: 335px;
      }
      .left_1 {
        margin: 0 0 0 5px;

        .title {
          margin: 0 0 5px 0;
          font-size: 23px;
          font-weight: bold;
        }

        .English {
          font-size: 12px;
          color: #fff;
        }
      }
    }

    .right {
      font-size: 16px;
      letter-spacing: 0;
      color: #fff;
      font-weight: 500;

      .right_3 {
        display: flex;
        justify-content: space-between;
        .example-showcase .el-dropdown-link {
          cursor: pointer;
          color: #1c66e7;
          display: flex;
          align-items: center;
        }
      }
    }
  }

  .two {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1200px;
    min-width: 1200px;
    margin: 0 auto;
    height: 60vh;
    .two_1 {
      .image {
        width: 400px;
        height: 400px;
        animation: animationName 5s linear infinite;
      }
      @keyframes animationName {
        100% {
          transform: rotate(1turn);
        }
      }
    }
    .two_2 {
      position: absolute;
      left: 38%;
      text {
        font-size: 22px;
        color: #ffffff;
        text-align: center;
      }
    }
  }
  .thr {
    display: flex;
    flex-wrap: wrap;
    .list {
      margin: 10px 0;
      .thr_1 {
        font-family: PingFangSC-Semibold;
        color: #fff;
        margin-left: 14px;
        text-align: center;
        .title {
          font-size: 20px;
          font-weight: 600;
          margin: 0 0 10px 0;
        }
        .English {
          font-size: 14px;
          font-weight: 400;
        }
      }
    }
  }

  .four {
    margin: 100px 0 10px 0;
    width: 100%;
    text-align: center;
    font-size: 12px;
    color: #fff;
  }
}
</style>
