zhangxiao
2024-08-26 57b66478e7e335379435b31c20da4619bd1411f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
    <div class="login">
        <img class="info" src="@/assets/images/login/login.png" />
        <div class="content">
            <h3>管理系统 - 登录</h3>
            <arco-form ref="baseForm1" v-model="formData" :config="formConfig" size="medium"></arco-form>
            <a-button type="primary" long :loading="loading" :disabled="loading" @click="handleSubmit">登录</a-button>
        </div>
    </div>
</template>
<script setup lang="ts">
// import { login, autoLogin } from "@/config/apis/login";
import { ArcoForm, formHelper, ruleHelper } from "@easyfe/admin-component";
import sleep from "@/utils/tools/sleep";
import { Message } from "@arco-design/web-vue";
import { getDefaultRoute } from "@/packages/vue-router";
import { initGlobal, clearLoingInfo } from "@/views/utils/index";
const router = useRouter();
 
const loading = ref(false);
 
const formData = ref({
    username: "admin",
    password: "admin"
});
const formConfig = computed(() => {
    return [
        formHelper.input("", "username", {
            onPressEnter: handleSubmit,
            hideLabel: true,
            placeholder: "用户名",
            span: 24,
            rules: [ruleHelper.require("用户名必填", "blur")]
        }),
        formHelper.input("", "password", {
            onPressEnter: handleSubmit,
            hideLabel: true,
            span: 24,
            type: "password",
            placeholder: "密码",
            inputTips: "用户名admin,密码dmin"
        })
    ];
});
const baseForm1 = ref();
const handleSubmit = async (): Promise<any> => {
    const v = await baseForm1.value.validate();
    if (v) return;
    loading.value = true;
    await sleep(3000);
    await initGlobal();
    Message.success("登录成功");
    loading.value = false;
    router.replace(getDefaultRoute() || { path: "/" });
 
    // if (!res?.errors) {
    //     /**
    //      * 开发环境调用登录接口
    //      */
    //     try {
    //         loading.value = true;
    //         const xToken = await login(formData);
    //         if (xToken) {
    //             cookie.set("X-Token", xToken);
    //             /**
    //              * 手动登录之后
    //              * 换取 acccess_token
    //              */
    //             autoLogin({
    //                 token: xToken,
    //                 isFalse: 1
    //             })
    //                 .then((res) => {
    //                     storage.setToken(res.access_token);
    //                     storage.setUserInfo(res.user_info);
    //                     useMessage().success("登录成功");
    //                     loading.value = false;
    //                     router.push({
    //                         name: "store-decoration-fine"
    //                     });
    //                 })
    //                 .catch((err) => {
    //                     loading.value = false;
    //                     console.log(err);
    //                 });
    //         }
    //     } catch (error: any) {
    //         loading.value = false;
    //         useMessage().error(error.message);
    //     }
    // }
};
 
onMounted(() => {
    clearLoingInfo();
});
</script>
 
<style scoped lang="scss">
.login {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: url("@/assets/images/login/login-bg.png") center no-repeat;
    background-size: cover;
    .info {
        width: 650px;
        position: fixed;
        top: 11%;
        right: 55%;
        animation: turn 100s linear infinite;
    }
 
    .content {
        position: fixed;
        top: 30%;
        right: 15%;
        width: 400px;
        padding: 60px 30px;
        border-radius: 8px;
        background-color: var(--color-bg-1);
        z-index: 9999;
        h3 {
            margin: 0 0 32px 0;
            font-size: 22px;
            font-weight: 600;
        }
        input {
            width: 100%;
        }
    }
}
@keyframes turn {
    0% {
        -webkit-transform: rotate(0deg);
    }
    25% {
        -webkit-transform: rotate(90deg);
    }
    50% {
        -webkit-transform: rotate(180deg);
    }
    75% {
        -webkit-transform: rotate(270deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
    }
}
</style>