<template>
    <div>
        <div class="bigBox">
            <div class="winBox">
                <button class="winBtn" @click="WinMin">-</button>
                <button class="winBtn" @click="WinClose">×</button>
            </div>
            <!-- 信息 -->
            <div class="imgBox">
                <img src="../../assets/image/loginImg.png" alt="">
                <!-- <p>登录</p> -->
            </div>
            <!-- 登录信息 -->
            <div class="formBox">
                <el-form :model="loginForm" label-width="45px" style="padding-top: 24px;">
                    <el-form-item label="账号">
                        <el-input class="loginInp" v-model="loginForm.username" placeholder="你的账号..." maxlength="32" />
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-input class="loginInp" type="password" v-model="loginForm.userpass" show-password
                            placeholder="你的密码..." maxlength="32" />
                    </el-form-item>
                </el-form>
                <el-button class="loginBtn" type="primary" @click="sureLog" @keyup.enter="sureLog">登录</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import { ref, onMounted } from "vue"
import { useRouter } from 'vue-router'
import { ElMessage } from "element-plus"
import login from "@/api/login"
export default {
    setup() {
        let less = ref("")
        let loginForm = ref({
            username: "",
            userpass: ""
        })
        let isLogin = ref(false)
        let router = useRouter()
        function encryptPassword(password) {
            let val = SmCrypto.doSm3AndSm2Encrypt(password) + '0000'
            let ascCode = 0
            for (var i = 0; i < password.length; i++) {
                ascCode = password.charCodeAt(i).toString(16);
                // console.log(ascCode,'asc');
                if (ascCode.length == 1) {
                    val += '00' + ascCode
                } else if (ascCode.length == 2) {
                    val += '0' + ascCode
                } else {
                    val += ascCode
                }
            }
            console.log(val, 'val');
            return val
        }
        function sureLog() {
            let kis = encryptPassword(loginForm.value.userpass)

            login.LoginNow({
                login_account: loginForm.value.username,
                pwd: kis
            }).then(res => {
                console.log(res, 'login');
                if (res.returncode === 200) {
                    isLogin.value = true
                    sessionStorage.setItem("loginStatus", isLogin.value)
                    sessionStorage.setItem("userInfo", JSON.stringify(res.data))
                    if (typeof (window.windowEx) != "undefined") {
                        windowEx.Size(0, 0) //全屏
                        windowEx.Position('center')
                    }
                    router.push('/home/mission')
                    ElMessage({
                        message: '登陆成功！',
                        type: "success"
                    })
                    // windowEx.Size(0, 0)
                    // windowEx.Size(1920, 1040)
                    // windowEx.Position('center')
                } else {
                    ElMessage({
                        message: res.msg,
                        type: "error"
                    })
                }
            })

        }
        function WinClose() {
            windowEx.Exit()
        }
        function WinMin() {
            windowEx.Min()
        }
        onMounted(() => {
        })
        return {
            encryptPassword,
            less,
            sureLog,
            loginForm,
            isLogin,
            WinMin,
            WinClose
        }
    }
}
</script>

<style scoped>
.bigBox {
    width: 31.8rem;
    height: 35.5rem;
    margin: 0;
    background: #FFFFFF;
    box-shadow: 0px 1px 1.25rem 2px rgba(61, 128, 177, 0.13);
    position: relative;
    border: 1px solid #ededed;
    border-radius: 3px;
}

.formBox {
    width: 320px;
    height: 244px;
    text-align: center;
    background: #FFFFFF;
    box-shadow: 0px 1px 1.67rem 3px rgba(52, 123, 231, 0.12);
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
    margin: 0 auto;
}

.imgBox {
    width: 22.67rem;
    height: 8.33rem;
    margin: 0 auto;
    margin-left: 90px;
    padding-top: 40px;
}

.loginInp {
    width: 22.5rem;
    height: 3.33rem;
    margin-top: 5px;
    border: 1px solid #A3ADE0;
}

.loginBtn {
    width: 22.67rem;
    height: 3.33rem;
    margin-top: 10px;
    background-color: #255CE7;
}

.winBox {
    width: 5.67rem;
    height: 5.67rem;
    position: absolute;
    top: 0px;
    right: 0px;
    color: #676767;
}

.winBtn {
    width: 2.83rem;
    height: 2.83rem;
    background-color: transparent;
    border: none;
    font-size: 2.5rem;
    text-align: center;
    line-height: 2.83rem;
    color: #676767;
}

.winBtn:nth-child(1):hover {
    border: 1px black solid;
}

.winBtn:nth-child(2):hover {
    background-color: red;
}
</style>