<!-- eslint-disable @typescript-eslint/ban-ts-comment -->
<template>
  <div class="content">
    <div style="margin-top: -15vh;"><van-image :src="logoimg" /></div>
    <div style="font-size: 20px;font-weight: 600;margin-top:15px">文件管理系统</div>
    <div style="margin-top: 40px;">
      <div>
        <van-cell-group inset>
          <van-field v-model="loginForm.username" label="用户名" placeholder="请输入用户名" />
        </van-cell-group>
      </div>
      <div style="margin-top: 10px;">
        <van-cell-group inset>
          <van-field v-model="loginForm.password" label="密码" type="password" placeholder="请输入密码" />
        </van-cell-group>
      </div>

      <van-button style="margin-top: 40px;" type="primary" round size="large" @click="dologin">登录</van-button>
    </div>
  </div>
</template>
<script setup lang="ts">
import logoimg from '@/assets/logo/logo.png';
import { useUserStore } from '@/store/modules/user';
import { LoginData, TenantVO } from '@/api/types';
import { to } from 'await-to-js';

const userStore = useUserStore();
const router = useRouter();
const loginForm = ref<LoginData>({
  tenantId: '000000',
  username: 'admin',
  password: 'admin123',
  rememberMe: false,
  code: '',
  uuid: ''
} as LoginData);

const redirect = ref(undefined);
watch(() => router.currentRoute.value, (newRoute: any) => {
  redirect.value = newRoute.query && newRoute.query.redirect;
  if ((redirect.value ?? "").indexOf("h5") == -1) {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    //@ts-ignore
    redirect.value = "/h5/project";
  }
}, { immediate: true });



const dologin = ()=>{
  to(userStore.login(loginForm.value)).then(res => {
      router.push({ path: redirect.value || '/h5/project' });
  }).catch((e) => {
    //  console.log(e)
  })
}
</script>
<style lang="scss" scoped>
.content{
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  height: 100vh;
  background: #eff2f5;
}
</style>
