master
2022-02-14 1684d66eaf39f77980b987359f413d2ff5714940
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<template>
    <div class="page-login">
        <div class="box">
            <img class="logo" src="../../static/images/logo.png" alt="" />
            <!-- <p class="desc">{{ app.name }}-华能二厂料场煤堆实时三维建模</p> -->
            <p class="desc">{{ app.name }}-华能二厂料场煤堆实时三维建模</p>            
 
            <el-form label-position="top" class="form" size="medium" :disabled="saving">
                <el-form-item label="用户名">
                    <el-input
                        v-model="form.username"
                        placeholder="请输入用户名"
                        maxlength="20"
                        auto-complete="off"
                    />
                </el-form-item>
 
                <el-form-item label="密码">
                    <el-input
                        v-model="form.password"
                        type="password"
                        placeholder="请输入密码"
                        maxlength="20"
                        auto-complete="off"
                    />
                </el-form-item>
 
                <el-form-item label="验证码" class="captcha">
                    <el-input
                        v-model="form.verifyCode"
                        placeholder="请输入图片验证码"
                        maxlength="4"
                        auto-complete="off"
                        @keyup.enter="toLogin"
                    />
 
                    <captcha
                        :ref="setRefs('captcha')"
                        v-model="form.captchaId"
                        class="value"
                        @change="
                            () => {
                                form.verifyCode = '';
                            }
                        "
                    />
                </el-form-item>
            </el-form>
 
            <el-button round size="small" class="submit-btn" :loading="saving" @click="toLogin"
                >登录</el-button
            >
        </div>
    </div>
</template>
 
<script lang="ts">
import { defineComponent, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import Captcha from "./components/captcha.vue";
import { useEps, useCool } from "/@/cool";
 
export default defineComponent({
    cool: {
        route: {
            path: "/login"
        }
    },
 
    components: {
        Captcha
    },
 
    setup() {
        const { refs, setRefs, store, router, app }: any = useCool();
 
        const saving = ref<boolean>(false);
 
        // 登录表单数据
        const form = reactive({
            username: "",
            password: "",
            captchaId: "",
            verifyCode: ""
        });
 
        // 登录
        async function toLogin() {
            if (!form.username) {
                return ElMessage.warning("用户名不能为空");
            }
 
            if (!form.password) {
                return ElMessage.warning("密码不能为空");
            }
 
            if (!form.verifyCode) {
                return ElMessage.warning("图片验证码不能为空");
            }
 
            saving.value = true;
 
            try {
                // 登录
                await store.dispatch("userLogin", form);
 
                // 用户信息
                await store.dispatch("userInfo");
 
                // 读取Eps
                await useEps();
 
                // 权限菜单
                const [first] = await store.dispatch("permMenu");
 
                if (!first) {
                    ElMessage.error("该账号没有权限");
                } else {
                    router.push("/");
                }
            } catch (err: any) {
                ElMessage.error(err);
                refs.value.captcha.refresh();
            }
 
            saving.value = false;
        }
 
        return {
            refs,
            setRefs,
            form,
            saving,
            toLogin,
            app
        };
    }
});
</script>
 
<style lang="scss">
.page-login {
    height: 100vh;
    width: 100vw;
    position: relative;
    background-color: #2f3447;
 
    .box {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        height: 500px;
        width: 500px;
        position: absolute;
        left: calc(50% - 250px);
        top: calc(50% - 250px);
 
        .logo {
            height: 50px;
            margin-bottom: 20px;
        }
 
        .desc {
            color: #ccc;
            font-size: 12px;
            margin-bottom: 60px;
            letter-spacing: 1px;
        }
 
        .el-form {
            width: 300px;
            border-radius: 3px;
 
            .el-form-item {
                margin-bottom: 20px;
 
                &__label {
                    color: #ccc;
                }
            }
 
            .el-input {
                .el-input__inner {
                    border: 0;
                    border-bottom: 0.5px solid #999;
                    border-radius: 0;
                    padding: 0 5px;
                    background-color: transparent;
                    color: #ccc;
                    transition: border-color 0.3s;
                    position: relative;
 
                    &:focus {
                        border-color: #fff;
                        color: #fff;
                    }
 
                    &:-webkit-autofill {
                        -webkit-text-fill-color: #fff !important;
                        -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
                        transition: background-color 50000s ease-in-out 0s;
                    }
                }
            }
 
            .captcha {
                position: relative;
 
                .value {
                    position: absolute;
                    bottom: 1px;
                    right: 0;
                }
            }
        }
 
        .submit-btn {
            margin-top: 40px;
            padding: 9px 40px;
            color: #000;
        }
    }
}
</style>