<route lang="yaml">
meta:
  title: 登录
  constant: true
  layout: false
</route>

<script lang="ts" setup name="Login">
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import { getUserMenus } from '@/api/system/login'
import useUserStore from '@/store/modules/user'
import useMenuStore from '@/store/modules/menu'
import useRouteStore from '@/store/modules/route'
const routeStore = useRouteStore()

const route = useRoute()
const router = useRouter()
const menuStore = useMenuStore()
const userStore = useUserStore()
// localStorage.removeItem('currentSys')
// 获取用户子系统列表
const sysList = ref()
const common = ref({ name: '' })
const fetchSyatemList = () => {
  getUserMenus({ resourceType: '02', parentCode: '' }).then((res) => {
    // 子系统列表
    sysList.value = res.data.menus.filter((item: any) => item.code !== 'common')
    // 通用用户设置
    const user = res.data.menus.filter((item: any) => item.code === 'common')
    if (user.length) {
      common.value = user[0]
    }
  })
}
fetchSyatemList()
const title = import.meta.env.VITE_APP_TITLE
const changeSys = async (system: any) => {
  // 判断是否外部系统
  if (system.url.includes('http')) {
    const token = userStore.token
    const params = `?token=${token}`
    console.log(system.url + params)
    window.open(system.url + params)
  }
  else {
    localStorage.setItem('currentSys', JSON.stringify({ name: system.name, code: system.code }))
    routeStore.generateRoutesAtBack({ name: system.name, code: system.code }).then((res) => {
      if (menuStore.sidebarMenus.length > 0) {
        router.replace({ path: menuStore.sidebarMenusFirstDeepestPath })
      }
      else {
        ElMessage.error('子系统无菜单')
      }
    })
  }
}
</script>

<template>
  <div>
    <div class="bg-top-banner">
      {{ title }}
    </div>
    <div class="bg-banner" />
    <!-- 子系统 -->
    <div class="container-all-sys">
      <div v-for="(item, index) in sysList" :key="index" class="sys-container" @click="changeSys(item)">
        {{ item.name }}
      </div>
    </div>
    <!-- 通用设置 -->
    <div v-if="common.name" class="common-container" @click="changeSys(common)">
      <!-- {{ common.name }} -->
      账户管理
    </div>
    <copyright />
  </div>
</template>

<style lang="scss" scoped>
.container-all-sys {
  width: 100%;
  position: absolute;
  z-index: 99999;
  top: 50%;
  display: flex;
  justify-content: space-around;
}

.sys-container {
  // position: absolute;
  // z-index: 99999;
  width: 18%;
  height: 170px;
  font-size: 26px;
  font-weight: 700;
  border: 6px solid #04419c;
  background-color: #002047;
  color: #fff;
  padding: 40px;
  text-align: center;
  line-height: 8.5vh;
  // top: 50%;

  &:hover {
    cursor: pointer;
  }
}

.common-container {
  position: absolute;
  z-index: 99999;
  width: 12%;
  height: 80px;
  font-size: 20px;
  font-weight: 700;
  border: 6px solid #04419c;
  background-color: #002047;
  color: #fff;
  padding: 30px;
  text-align: center;
  line-height: 1.7vh;
  top: 5%;
  right: 3%;

  &:hover {
    cursor: pointer;
  }
}

[data-mode="mobile"] {
  #login-box {
    position: relative;
    width: 100%;
    height: 100%;
    top: inherit;
    left: inherit;
    transform: translateX(0) translateY(0);
    flex-direction: column;
    justify-content: start;
    border-radius: 0;
    box-shadow: none;

    .login-banner {
      width: 100%;
      padding: 20px 0;

      .banner {
        position: relative;
        right: inherit;
        width: 100%;
        max-width: 375px;
        margin: 0 auto;
        display: inherit;
        top: inherit;
        transform: translateY(0);
      }
    }

    .login-form {
      width: 100%;
      min-height: auto;
      padding: 30px;
    }
  }

  .copyright {
    position: relative;
    bottom: 0;
    padding-bottom: 10px;
  }
}

:deep(input[type="password"]::-ms-reveal) {
  display: none;
}

.bg-top-banner {
  position: fixed;
  top: 0;
  width: 100%;
  height: 17vh;
  z-index: 999;
  line-height: 10vh;
  text-align: center;
  font-size: 30px;
  color: #fff;
  background: url("../assets/images/login-image/banner.png") no-repeat center / cover;
}

.bg-banner {
  position: fixed;
  z-index: 0;
  width: 100%;
  height: 100%;
  // background: radial-gradient(circle at center, var(--el-fill-color-lighter), var(--el-bg-color-page));
  background: url("../assets/images/login-image/bg.png") no-repeat center / cover;
}

#login-box {
  display: flex;
  justify-content: space-between;
  position: absolute;
  // top: 50%;
  // left: 50%;
  // transform: translateX(-50%) translateY(-50%);
  // background-color: var(--el-bg-color);

  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--el-box-shadow);

  .login-banner {
    position: relative;
    width: 450px;
    background-color: var(--el-fill-color-light);
    overflow: hidden;

    .banner {
      width: 100%;

      @include position-center(y);
    }

    .logo {
      position: absolute;
      top: 20px;
      left: 20px;
      width: 30px;
      height: 30px;
      border-radius: 4px;
      background: url("../assets/images/logo.png") no-repeat;
      background-size: contain;
      box-shadow: var(--el-box-shadow-light);
    }
  }

  .login-form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 500px;
    width: 500px;
    padding: 50px;
    background: url("../assets/images/login-image/frame.png") no-repeat center / cover;
    overflow: hidden;

    .title-container {
      position: relative;

      .title {
        font-size: 1.3em;
        color: #fff;
        margin: 0 auto 30px;
        text-align: center;
        font-weight: bold;
      }
    }
  }

  .el-form-item {
    margin-bottom: 24px;

    :deep(.el-input) {
      height: 48px;
      line-height: inherit;
      width: 100%;

      input {
        height: 48px;
      }

      .el-input__prefix,
      .el-input__suffix {
        display: flex;
        align-items: center;
      }

      .el-input__prefix {
        left: 10px;
      }

      .el-input__suffix {
        right: 10px;
      }
    }
  }

  .flex-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
  }

  .sub-link {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--el-text-color-secondary);

    .text {
      margin-right: 10px;
    }
  }
}

.copyright {
  position: absolute;
  bottom: 30px;
  width: 100%;
  margin: 0;
}

:deep .el-input__wrapper {
  background-color: transparent !important;
}

:deep .el-input__inner {
  color: #fff !important;
}
</style>

<style lang="scss">
// 详情页面隐藏小红点
.isDetail {
  ::v-deep {
    .el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap > .el-form-item__label::before,
    .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label::before {
      content: "";
      display: none;
    }
  }
}
</style>
