pengwei
2025-03-20 2591e298a3fd1332ad0ca33059f6ba0b7d426f51
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<template>
  <div class="login-container">
    <div class="login-header">
      <img src="../assets/login/login-text.png" alt="" />
    </div>
    <div class="login-box">
      <!-- 左侧图片 -->
      <div class="left-img">
        <img src="../assets/login/bg.png" alt="" />
      </div>
      <!-- 右侧登录 -->
      <div class="login-formbox">
        <el-form
          v-if="show"
          ref="loginRef"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
        >
          <div class="title">欢迎登录...</div>
          <div style="color: #666666; font-size: 0.8rem; margin: 0.5rem 0">
            WELCOME TO LOGIN
          </div>
 
          <el-form-item prop="userName">
            <el-input
              v-model="loginForm.userName"
              style="height: 3.13rem"
              ref="userNameRef"
              type="text"
              size="large"
              autocomplete="off"
              placeholder="请输入您的登录账号"
            />
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              show-password
              v-model="loginForm.password"
              style="height: 3.13rem"
              type="password"
              size="large"
              auto-complete="off"
              placeholder="请输入密码"
            >
            </el-input>
          </el-form-item>
          <!-- <el-form-item prop="tenantId">
            <el-input
              v-model="loginForm.tenantId"
              style="height: 3.13rem"
              ref="tenantId"
              type="text"
              size="large"
              auto-complete="off"
              placeholder="请输入公司唯一码"
            />
          </el-form-item> -->
          <el-form-item prop="verificationCode">
            <div style="display: flex">
              <el-input
                v-model="loginForm.verificationCode"
                size="large"
                @keyup.enter="handleLogin"
                style="height: 3.13rem; width: 17.19rem; margin-right: 0.63rem"
                auto-complete="off"
                placeholder="验证码"
              >
              </el-input>
              <div class="login-code" style="">
                <img
                  :src="codeUrl"
                  @click="getCode"
                  style="width: 7.19rem; height: 3.13rem"
                  class="login-code-img"
                />
              </div>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button
              :loading="loading"
              color="#1F63FF"
              size="large"
              style="width: 100%; height: 3.13rem"
              @click.prevent="handleLogin"
            >
              <span v-if="!loading">登 录</span>
              <span v-else>登 录 中...</span>
            </el-button>
            <div
              style="
                display: flex;
                justify-content: center;
                align-items: center;
                width: 100%;
                margin-top: 1.25rem;
              "
            >
              <span
                style="
                  color: #4386ff;
                  border-bottom: 1px solid #4386ff;
                  font-weight: bold;
                  cursor: pointer;
                  font-size: 1rem;
                "
                @click="show = false"
                >人脸识别登录</span
              >
            </div>
          </el-form-item>
        </el-form>
        <div class="face-login" v-else>
          <span style="font-size: 0.88rem; font-weight: bold; color: #333333"
            >请将脸部正对蓝色显示框内,并保持光线充足</span
          >
          <div
            style="
              display: flex;
              justify-content: center;
              align-items: center;
              border: 1px solid #4386ff;
              border-radius: 50%;
              width: 18.75rem;
              height: 18.75rem;
              margin: 2.06rem 0;
              background-color: #f1fcff;
            "
          >
            <img src="@/assets/login/face.png" alt="" />
          </div>
          <el-button type="primary" size="small" style="width: 100%"
            >开始识别</el-button
          >
          <div
            style="
              display: flex;
              justify-content: center;
              align-items: center;
              width: 100%;
              margin-top: 1.25rem;
            "
          >
            <span
              style="
                color: #4386ff;
                border-bottom: 1px solid #4386ff;
                font-weight: bold;
                cursor: pointer;
                font-size: 1rem;
              "
              @click="show = true"
              >账号登录</span
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { getCodeImg, login } from "@/api/login";
import { useRouter, useRoute } from "vue-router";
import { getCurrentInstance, ref, nextTick, onMounted } from "vue";
import { ElMessage } from "element-plus";
import store from "@/store";
 
const router = useRouter();
const route = useRoute();
 
const { proxy } = getCurrentInstance();
 
const show = ref(true); // 是否显示登录框
 
const codeUrl = ref(""); // 验证码
const loading = ref(false); // 登录加载状态
 
const loginForm = ref({
  userName: "",
  password: "",
  verificationCode: "",
  UUID: undefined,
  tenantId: "0",
});
// tenantId: route.query.tenantId ? route.query.tenantId : "",
const loginRules = {
  userName: [
    { required: true, trigger: "blur", message: "请输入您的登录账号" },
  ],
  password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
  verificationCode: [
    { required: true, trigger: "blur", message: "请输入验证码" },
  ],
  // tenantId: [{ required: true, trigger: "blur", message: "请输入公司唯一码" }],
};
 
function handleLogin() {
  proxy.$refs.loginRef.validate((valid) => {
    if (valid) {
      loading.value = true;
      login(loginForm.value)
        .then((res) => {
          if (res.status) {
            store.commit("setUserInfo", { ...res.data });
            router.push({ path: "/" });
          }
        })
        .catch((err) => {
          loginForm.value.verificationCode = "";
          getCode();
          loading.value = false;
          return proxy.$message.error(res.message);
        });
      setTimeout(() => {
        loading.value = false;
      }, 1000);
    }
  });
}
 
//获取验证码方法
function getCode() {
  getCodeImg().then((res) => {
    if (res.Code == 500) {
      getCode();
      return;
    }
    codeUrl.value = "data:image/gif;base64," + res.img;
    loginForm.value.UUID = res.uuid;
  });
}
//绑定输入框焦点对象
const userNameRef = ref();
nextTick(() => {
  userNameRef.value.focus();
});
 
//获取验证码
getCode();
</script>
 
<style lang="less" scoped>
// * {
//   box-sizing: border-box;
//   padding: 0;
//   margin: 0;
// }
.login-container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  .login-header {
    display: flex;
    align-items: center;
    height: 4.38rem;
    background-color: #006eff;
    padding-left: 2.06rem;
    box-sizing: border-box;
    img {
      width: 16rem;
      height: 3.38rem;
    }
  }
  .login-box {
    width: 100%;
    height: calc(100vh - 4.57rem);
    display: flex;
    background-color: #f6f7fc;
    .left-img {
      width: 100%;
      height: 100%;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .login-formbox {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      .title {
        color: rgb(16, 16, 16);
        font-size: 2rem;
        font-weight: 600;
        position: relative;
      }
      .title::after {
        position: absolute;
        bottom: 0;
        content: "";
        display: block;
        width: 9rem;
        height: 1rem;
        background: linear-gradient(to right, #006eff, #ffffff);
        opacity: 0.5;
      }
    }
    .face-login {
      display: flex;
      flex-direction: column;
    }
  }
}
</style>