艺术家
2025-06-11 e00d1817afd6f86154aaa4c870571c724ebfecfc
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
<template>
  <div class="login-container">
    <div class="login-header">
      <img src="../assets/login/login-text.png" alt="" />
      <div>
        <img
          v-if="!isFullscreen"
          style="
            width: 1.88rem;
            height: 1.88rem;
            margin-right: 1.81rem;
            cursor: pointer;
          "
          src="@/assets/screen.png"
          alt=""
          @click="screenonToggle"
        />
        <img
          v-if="isFullscreen"
          style="
            width: 1.88rem;
            height: 1.88rem;
            margin-right: 1.81rem;
            cursor: pointer;
          "
          src="@/assets/exitscreen.png"
          alt=""
          @click="screenonToggle"
        />
      </div>
    </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 class="min_title">WELCOME TO LOGIN</div>
 
          <el-form-item prop="userName">
            <el-input
              v-model="loginForm.userName"
              class="login-input"
              style="height: 3.13rem; width: 20.19rem"
              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"
              class="login-input"
              style="height: 3.13rem; width: 20.19rem"
              type="password"
              size="large"
              auto-complete="off"
              placeholder="请输入密码"
            >
            </el-input>
          </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"
              class="login-btn"
              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
                class="login-face"
                style="
                  color: #4386ff;
                  border-bottom: 1px solid #4386ff;
                  font-weight: bold;
                  cursor: pointer;
                  font-size: 1rem;
                "
                @click="recognition"
                >人脸识别登录</span
              >
            </div>
          </el-form-item>
        </el-form>
        <div class="face-login" v-else>
          <span
            class="face_text"
            style="
              text-align: center;
              font-size: 0.88rem;
              font-weight: bold;
              color: #333333;
            "
            >请将脸部正对蓝色显示框内,并保持光线充足</span
          >
          <div style="width: 100%; display: flex; justify-content: center">
            <a href="myapp://">
              <div
                class="camera"
                style="
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  border: 1px solid #4386ff;
                  border-radius: 50% 50%;
                  width: 18.75rem;
                  height: 18.75rem;
                  margin: 2.06rem 0;
                  background-color: #f1fcff;
                "
                @click="begin(2)"
              >
                <!-- v-if="!face" -->
                <img
                  style="width: 16rem; height: 16rem"
                  src="@/assets/login/face.png"
                  alt=""
                />
                <!-- <canvas v-else ref="canvasDom" /> -->
                <!-- <div v-else> -->
                <!-- 播放器,用来播放拍摄的视频 -->
                <!-- <video class="camera_video" ref="videoDom" /> -->
                <!-- </div> -->
              </div>
            </a>
          </div>
          <p style="font-size: 2rem">点击进行人脸识别登录</p>
          <div class="button-group">
            <button @click="download(1)" class="download-plugin">
              <i class="fas fa-download"></i> 下载人脸识别插件
            </button>
            <button
              @click="showConfigModal"
              class="configure-plugin"
              id="configure-plugin"
            >
              <i class="fas fa-cog"></i> 人脸识别插件配置
            </button>
          </div>
          <!-- <el-button
            type="primary"
            size="small"
            style="width: 100%; margin-top: 1rem"
            class="reBtn"
            @click="registerdialogVisible = true"
            >人脸注册</el-button
          > -->
          <!-- <div style="width: 100%; margin-top: 1rem; display: flex">
            <el-button
              v-if="show"
              type="primary"
              size="small"
              style="width: 100%"
              class="reBtn"
              @click="recognition"
              >开始识别</el-button
            >
            <el-button
              v-else
              type="primary"
              size="small"
              style="width: 100%"
              class="reBtn"
              @click="recognition"
              >重新获取摄像头</el-button
            >
            <el-select
              v-if="videoArr.length > 1"
              v-model="constraints"
              placeholder="请选择摄像头"
              size="samll"
              @change="changeconstraints"
              style="height: 2rem"
              :disabled="!videoArr.length > 1"
            >
              <el-option
                v-for="item in videoArr"
                :key="item.id"
                :label="item.label"
                :value="item.id"
              />
            </el-select>
          </div> -->
          <div
            style="
              display: flex;
              justify-content: center;
              align-items: center;
              width: 100%;
              margin-top: 1.25rem;
            "
          >
            <span
              class="login-face"
              style="
                color: #4386ff;
                border-bottom: 1px solid #4386ff;
                font-weight: bold;
                cursor: pointer;
                font-size: 1rem;
              "
              @click="accountlogin"
              >账号登录</span
            >
          </div>
        </div>
      </div>
    </div>
    <!-- 配置模态框 -->
    <el-dialog
      v-model="dialogVisible"
      title="插件配置"
      width="500"
      :before-close="handleClose"
      top="30vh"
    >
      <template #header="{ titleId }">
        <div class="my-header">
          <h2 :id="titleId" style="font-size: 2rem">插件配置</h2>
        </div>
      </template>
      <el-input
        class="downloainput"
        v-model="pathvalue"
        placeholder="请输入插件解压路径"
      />
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" class="downloadreBtn" @click="download(2)"
            >提交配置</el-button
          >
        </div>
      </template>
    </el-dialog>
 
    <!-- 人脸注册 -->
    <el-dialog
      v-model="registerdialogVisible"
      title="插件配置"
      width="500"
      :before-close="handleClose"
      top="5vh"
    >
      <template #header="{ titleId }">
        <div class="my-header">
          <h2 :id="titleId" style="font-size: 2rem">人脸录入</h2>
        </div>
      </template>
      <div class="content">
        <div class="image-container">
          <img
            src="@/assets/login/headimg.jpg"
            id="img"
            style="width: 100%"
            class="profile-image"
          />
        </div>
        <div class="action-buttons" @click="begin(1)">
          <a href="myapp://" class="btn face-register">
            <i class="fas fa-user-plus"></i> 人脸录入</a
          >
          <button class="btn submit-data" @click="faceEnter()">
            <i class="fas fa-paper-plane"></i> 提交数据
          </button>
        </div>
      </div>
      <template #footer>
        <!-- <div class="dialog-footer">
          <el-button type="primary" class="downloadreBtn" @click="download(2)"
            >提交配置</el-button
          >
        </div> -->
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { getCodeImg, login, CleanUnusedImages } from "@/api/login";
import { useRouter, useRoute } from "vue-router";
import { getCurrentInstance, ref, nextTick, onMounted, onUnmounted } from "vue";
import { ElMessage, ElLoading } from "element-plus";
import screenfull from "screenfull";
import store from "@/store";
import axios from "axios";
 
const router = useRouter();
const route = useRoute();
 
const { proxy } = getCurrentInstance();
 
const show = ref(true); // 是否显示登录框
 
const codeUrl = ref(""); // 验证码
const loading = ref(false); // 登录加载状态
const face = ref(false); // 人脸识别登录
const registerdialogVisible = ref(false); // 人脸注册模态框是否可见
// 照片路径
const imgurl = ref(null);
// canvas控件对象
const canvasDom = ref(null);
// video 控件对象
const videoDom = ref(null);
const reBtn = ref(false);
const loginForm = ref({
  userName: "",
  password: "",
  verificationCode: "1234",
  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: "请输入公司唯一码" }],
};
const pathvalue = ref(""); // 插件解压路径
const dialogVisible = ref(false); // 配置模态框是否可见
 
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();
});
const videoArr = ref([]);
//选择的摄像头的id
const constraints = ref("");
const videoConstraints = ref({});
//人脸识别登录
const recognition = () => {
  show.value = false;
  videoArr.value = [];
  // setTimeout(async () => {
  //   face.value = true;
  //   navigator.mediaDevices
  //     .enumerateDevices()
  //     .then((devices) => {
  //       devices.forEach(function (device) {
  //         if (device.kind == "videoinput") {
  //           videoArr.value.push({
  //             label: device.label,
  //             id: device.deviceId,
  //           });
  //           constraints.value = videoArr.value[0].id;
  //         }
  //       });
  //       openCamera();
  //     })
  //     .catch(function (err) {
  //       layer.msg(err.name + ": " + err.message);
  //     });
  // }, 1000);
  // ElMessage({
  //   message: "正在调用摄像头,请稍等...",
  //   type: "warning",
  //   plain: true,
  //   duration: 1000,
  // });
  // 人脸识别登录逻辑
};
 
//账号登录
function accountlogin() {
  setTimeout(() => {
    show.value = true;
    face.value = false;
  }, 500);
}
//打开摄像头
const openCamera = async () => {
  videoConstraints.value.deviceId = { exact: constraints.value };
 
  // 检测浏览器是否支持mediaDevices
  if (navigator.mediaDevices) {
    navigator.mediaDevices
      // 开启视频,关闭音频
      .getUserMedia({
        audio: false,
        video: {
          width: 300, // 设置视频宽度
          height: 300, // 设置视频高度
          facingMode: "user", // 使用前置摄像头
          deviceId: videoConstraints.value.deviceId,
        },
      })
      .then((stream) => {
        // 将视频流传入viedo控件
        videoDom.value.srcObject = stream;
        // 播放
        videoDom.value.play();
        Facerecognition();
        ElMessage({
          message: "摄像头调用成功",
          type: "success",
          plain: true,
        });
      })
      .catch((err) => {
        console.log(err);
      });
  } else {
    window.alert("该浏览器不支持开启摄像头,请更换最新版浏览器");
  }
};
const changeconstraints = (res) => {
  openCamera();
};
 
const getData = (flag) => {
  let url = "http://localhost:9298";
  let xmlResquest = new XMLHttpRequest();
  xmlResquest.open("post", url, true);
  xmlResquest.onload = function (e) {
    if (xmlResquest.status == 200) {
      clearTimeout(interval.value);
      imgbase64.value = xmlResquest.response;
      if (flag == 2) {
        // const faceContainer = document.getElementById("face-recognition");
        // const faceIcon = faceContainer.querySelector(".face-icon");
        // const capturedFace = document.getElementById("captured-face");
        // capturedFace.src = "data:image/png;base64," + xmlResquest.response;
        // faceIcon.style.display = "none";
        // capturedFace.style.display = "block";
        window.URL.revokeObjectURL(url);
        faceRecognitionEvent();
        return;
      } else {
        let img = document.getElementById("img");
        img.src = "data:image/png;base64," + xmlResquest.response;
        window.URL.revokeObjectURL(url);
        // hideLoading();
        onloading.value.close();
        return;
      }
    }
    // hideLoading();
    onloading.value.close();
  };
 
  xmlResquest.send();
};
 
const baseUrl = "http://192.168.1.103:9093";
const token = ref("");
const imgbase64 = ref("");
let urlPlugin = baseUrl + "/api/UserFace/DownlodaFacePlugin";
let urlPReg = baseUrl + "/api/UserFace/DownloadRegFile";
const download = (flag, callBack) => {
  let url = "";
  if (flag == 1) {
    url = urlPlugin;
  } else {
    url = urlPReg;
  }
  let xmlRequest = new XMLHttpRequest();
  // 设置超时时间(毫秒)
  xmlRequest.timeout = 10000;
  xmlRequest.open("POST", url, true);
  xmlRequest.setRequestHeader("Content-type", "application/json");
  xmlRequest.responseType = "blob";
  // 成功处理
  xmlRequest.onload = function (e) {
    if (xmlRequest.status === 200) {
      const contentType = xmlRequest.getResponseHeader("Content-Type");
      if (contentType && contentType.includes("application/json")) {
        // 处理JSON响应
        const reader = new FileReader();
        reader.onload = function () {
          try {
            const jsonResponse = JSON.parse(reader.result);
            if (!jsonResponse.status) {
              ElMessage({
                message: "失败:" + jsonResponse.message,
                type: "error",
              });
            }
            // 处理JSON数据...
          } catch (e) {
            ElMessage({
              message: "JSON解析错误:" + e.message,
              type: "error",
            });
            console.error("JSON解析错误:", e);
          }
        };
        reader.readAsText(xmlRequest.response);
      } else if (
        contentType &&
        (contentType.includes("application/octet-stream") ||
          contentType.includes("application/zip") ||
          contentType.includes("application/x-registry"))
      ) {
        try {
          let blob = xmlRequest.response;
          if (!blob || blob.size === 0) {
            throw new Error("下载内容为空");
          }
          let a = document.createElement("a");
          let url = window.URL.createObjectURL(blob);
          a.href = url;
          if (flag == 1) {
            a.download = "face-plugin.zip";
          } else {
            a.download = "reg.reg";
          }
 
          document.body.appendChild(a);
          a.click();
 
          // 清理
          setTimeout(() => {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);
          }, 100);
 
          // 成功回调
          if (callBack) callBack(true, "下载成功");
          dialogVisible.value = false;
          // closeConfigModal();
        } catch (error) {
          ElMessage({
            message: "下载处理失败" + error.message,
            type: "error",
          });
          if (callBack) callBack(false, "下载处理失败");
        }
      }
    } else {
      let errorMsg = `服务器错误: ${xmlRequest.status} ${xmlRequest.statusText}`;
      ElMessage({
        message: errorMsg,
        type: "error",
      });
      if (callBack) callBack(false, errorMsg);
    }
  };
 
  // 错误处理
  xmlRequest.onerror = function () {
    let errorMsg = "网络错误,请检查网络连接";
    ElMessage.error(errorMsg);
    if (callBack) callBack(false, errorMsg);
  };
 
  // 超时处理
  xmlRequest.ontimeout = function () {
    let errorMsg = "请求超时,请重试";
    ElMessage.error(errorMsg);
    if (callBack) callBack(false, errorMsg);
  };
 
  // 发送请求
  try {
    if (flag == 1) {
      xmlRequest.send();
    } else {
      let path = pathvalue.value;
      if (path == "") {
        ElMessage({
          message: "请输入插件解压路径",
          type: "warning",
        });
        return;
      }
      xmlRequest.send(JSON.stringify({ Path: path }));
    }
  } catch (error) {
    ElMessage({
      message: "请求发送失败:" + error.message,
      type: "error",
    });
    if (callBack) callBack(false, "请求发送失败");
  }
};
 
const faceRecognitionEvent = () => {
  let url = baseUrl + "/api/UserFace/FaceRecognition";
  let xmlResquest = new XMLHttpRequest();
  xmlResquest.open("post", url, true);
  xmlResquest.setRequestHeader("Content-Type", "application/json");
  xmlResquest.onload = function (e) {
    img.src = "headimg.jpg";
    if (xmlResquest.status == 200) {
      let response = JSON.parse(xmlResquest.response);
      if (response.status) {
        token.value = response.data.token;
      } else {
        ElMessage.error("识别失败");
      }
    } else {
      ElMessage.error("数据提交失败");
    }
  };
  xmlResquest.send(JSON.stringify({ Base64Image: imgbase64.value }));
};
 
function faceEnter() {
  let url = baseUrl + "/api/UserFace/faceEnter";
  let xmlResquest = new XMLHttpRequest();
  xmlResquest.open("post", url, true);
  xmlResquest.setRequestHeader("Content-Type", "application/json");
  xmlResquest.setRequestHeader("Authorization", "Bearer " + token.value);
  xmlResquest.onload = function (e) {
    img.src = "headimg.jpg";
    if (xmlResquest.status == 200) {
      let response = JSON.parse(xmlResquest.response);
      if (response.status) {
        ElMessage.success("人脸录入成功,图片名称:" + response.data);
        onloading.value.close();
        // hideLoading();
      } else {
        ElMessage.error("人脸录入失败,错误信息:" + response.message);
        onloading.value.close();
        // hideLoading();
      }
    } else {
      ElMessage.error("数据提交失败");
      onloading.value.close();
      // hideLoading();
    }
  };
  xmlResquest.send(JSON.stringify({ Base64Image: imgbase64.value }));
}
 
const interval = ref(null);
const onloading = ref(null);
const begin = (flag) => {
  if (interval.value) {
    clearTimeout(interval.value);
  }
  onloading.value = ElLoading.service({
    lock: true,
    text: "正在处理中,请稍后...",
    background: "rgba(0, 0, 0, 0.7)",
  });
  interval.value = setInterval(() => {
    getData(flag);
  }, 10000);
};
 
// 开始识别
const takePhoto = async () => {
  // console.log(videoDom.value.videoWidth, videoDom.value.videoHeight);
  // 创建一个画布元素,设置画布尺寸为视频流的尺寸
  const canvas = document.createElement("canvas");
  // 设置画布大小与摄像大小一致
  canvas.width = videoDom.value.videoWidth;
  canvas.height = videoDom.value.videoHeight;
  // 获取画布上下文对象
  const ctx = canvas.getContext("2d");
  // 绘制当前视频帧到画布上
  ctx.drawImage(videoDom.value, 0, 0, canvas.width, canvas.height);
  // 将画布内容转为 Base64 数据
  const imageDataUrl = canvas.toDataURL("image/png");
  // 存储图片路径
  imgurl.value = imageDataUrl;
 
  // // 创建一个图片元素
  // const imageElement = new Image();
  // // 将 Base64 数据设置为图片的 src 属性
  // imageElement.src = imageDataUrl;
  // console.log(imageElement, imageDataUrl, "图片路径");
  // return;
  // canvasDom.value.width = videoDom.value.videoWidth;
  // canvasDom.value.height = videoDom.value.videoHeight;
  // // 执行画的操作
  // canvasDom.value.getContext("2d").drawImage(videoDom.value, 0, 0);
  // // 将结果转换为可展示的格式
  // imgurl.value = canvasDom.value.toDataURL("image/webp");
  // 关闭摄像头
  let files = dataURLtoFile(imgurl.value, new Date().getTime() + ".png");
  const formdata = new FormData();
  formdata.append("files", files);
  let response = await axios.post("/api/User/SaveFiles", formdata, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  ElMessage({
    message: "开始识别中,请稍等...",
    type: "warning",
    plain: true,
    duration: 2000,
  });
  setTimeout(() => {
    login({
      userName: "",
      password: "",
      path: response.data.data,
    })
      .then((res) => {
        if (res.status) {
          store.commit("setUserInfo", { ...res.data });
          ElMessage({
            message: "识别成功,开始登录",
            type: "success",
            plain: true,
            duration: 2000,
          });
          CleanUnusedImages();
          stop();
          setTimeout(() => {
            router.push({ path: "/" });
          }, 1000);
        }
      })
      .catch((err) => {
        loading.value = false;
        return proxy.$message.error(err.message);
      });
    setTimeout(() => {
      loading.value = false;
    }, 1000);
  }, 1000);
  reBtn.value = true;
};
// 将 base64 转换为 Blob
const dataURLtoFile = (dataurl, filename) => {
  let arr = dataurl.split(","),
    mime = arr[0].match(/:(.*?);/)[1],
    bstr = atob(arr[1]),
    n = bstr.length,
    u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new File([u8arr], filename, {
    type: mime,
  });
};
// 关闭摄像头
const stop = () => {
  let stream = videoDom.value.srcObject;
  if (!stream) return;
  let tracks = stream.getTracks();
  tracks.forEach((x) => {
    x.stop();
  });
  clearInterval(timer.value);
};
// 显示配置模态框
const modal = ref(false);
const showConfigModal = () => {
  dialogVisible.value = true;
};
//定时人脸识别
const timer = ref(null);
const Facerecognition = () => {
  clearInterval(timer.value);
  if (!show.value) {
    timer.value = setInterval(() => {
      takePhoto();
    }, 3000);
  }
};
// 是否全屏
const isFullscreen = ref(false);
// 监听变化
const screenchange = () => {
  isFullscreen.value = screenfull.isFullscreen;
};
 
// 切换事件
const screenonToggle = () => {
  screenfull.toggle();
};
// 设置侦听器
onMounted(() => {
  screenfull.on("screenchange", screenchange);
});
 
// 删除侦听器
onUnmounted(() => {
  screenfull.off("screenchange", screenchange);
});
</script>
 
<style lang="less" scoped>
.login-container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  .login-header {
    display: flex;
    justify-content: space-between;
    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;
      }
      .min_title {
        color: #666666;
        font-size: 0.8rem;
        margin: 0.5rem 0;
      }
    }
    .face-login {
      width: 30rem;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-content: center;
      text-align: center;
    }
  }
}
.camera_video {
  width: 18.75rem;
  height: 18.75rem;
  border: 1px black solid;
  border-radius: 50% 50%;
}
.button-group {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
  /* 确保按钮垂直居中 */
}
/* 基础按钮样式 - 确保所有按钮使用相同的参数 */
.download-plugin,
.configure-plugin {
  padding: 10px 20px;
  border: none;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 内容居中 */
  gap: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  height: 40px;
  /* 固定高度 */
  line-height: 1;
  /* 确保文字垂直居中 */
  min-width: 120px;
  /* 最小宽度 */
}
/* 下载按钮样式 */
.download-plugin {
  background-color: #4285f4;
  color: white;
}
 
/* 配置按钮样式 */
.configure-plugin {
  background-color: #f1f3f4;
  color: #5f6368;
}
/* 下载按钮样式 */
.download-plugin {
  background-color: #4285f4;
  color: white;
}
 
/* 配置按钮样式 */
.configure-plugin {
  background-color: #f1f3f4;
  color: #5f6368;
}
 
/* 确保图标大小一致 */
.download-plugin i,
.configure-plugin i {
  font-size: 14px;
  width: 14px;
  /* 固定图标宽度 */
  text-align: center;
  /* 图标居中 */
}
 
/* 悬停效果 */
.download-plugin:hover {
  background-color: #3367d6;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(66, 133, 244, 0.3);
}
 
.configure-plugin:hover {
  background-color: #e0e0e0;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
 
/* 点击效果 */
.download-plugin:active,
.configure-plugin:active {
  transform: translateY(0);
}
/* 添加字体图标库 */
.content {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  background-color: #f8f9fa;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  max-width: 800px;
  margin: 0 auto;
}
 
.image-container {
  margin-bottom: 25px;
  border: 3px solid #e9ecef;
  border-radius: 8px;
  overflow: hidden;
}
 
.profile-image {
  display: block;
  width: 200px;
  height: 360px;
  object-fit: cover;
}
 
.action-buttons {
  display: flex;
  gap: 20px;
}
 
.btn,
a.btn {
  padding: 12px 25px;
  border: none;
  border-radius: 50px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: white;
}
 
.face-register {
  background-color: #4e73df;
}
 
.submit-data {
  background-color: #1cc88a;
}
 
/* 确保a标签可点击区域 */
.btn {
  position: relative;
  z-index: 1;
}
 
/* 添加点击反馈 */
.btn:active {
  transform: scale(0.98);
}
@media screen and (max-width: 1080px) {
  .login-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    .login-header {
      display: flex;
      justify-content: space-between;
      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: 5rem;
          font-weight: 600;
          position: relative;
        }
        .title::after {
          position: absolute;
          bottom: 0;
          content: "";
          display: block;
          width: 10rem;
          height: 1rem;
          background: linear-gradient(to right, #006eff, #ffffff);
          opacity: 0.5;
        }
        .min_title {
          color: #666666;
          font-size: 2rem;
          margin: 0.5rem 0;
        }
        .login-input {
          width: 30rem !important;
          font-size: 2rem !important;
          height: 5rem !important;
        }
        .login-btn {
          font-size: 2rem !important;
          height: 5rem !important;
        }
        .login-face {
          font-size: 2.5rem !important;
          margin-top: 2rem !important;
        }
      }
      .face-login {
        width: 40rem;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-content: center;
        text-align: center;
        .face_text {
          font-size: 2rem !important;
          font-weight: bold;
          color: #333333;
        }
        .reBtn {
          font-size: 2rem !important;
          height: 5rem !important;
        }
      }
    }
  }
  .camera_video {
    width: 40rem !important;
    height: 40rem !important;
    border: 1px black solid;
    border-radius: 50% 50%;
  }
  .camera {
    width: 40rem !important;
    height: 40rem !important;
    margin: 2.5rem 0 !important;
    background-color: #f1fcff !important;
  }
  .button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    /* 确保按钮垂直居中 */
  }
  /* 基础按钮样式 - 确保所有按钮使用相同的参数 */
  .download-plugin,
  .configure-plugin {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* 内容居中 */
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    height: 40px;
    /* 固定高度 */
    line-height: 1;
    /* 确保文字垂直居中 */
    min-width: 120px;
    /* 最小宽度 */
  }
  /* 下载按钮样式 */
  .download-plugin {
    background-color: #4285f4;
    color: white;
  }
 
  /* 配置按钮样式 */
  .configure-plugin {
    background-color: #f1f3f4;
    color: #5f6368;
  }
  /* 下载按钮样式 */
  .download-plugin {
    background-color: #4285f4;
    color: white;
  }
 
  /* 配置按钮样式 */
  .configure-plugin {
    background-color: #f1f3f4;
    color: #5f6368;
  }
 
  /* 确保图标大小一致 */
  .download-plugin i,
  .configure-plugin i {
    font-size: 14px;
    width: 14px;
    /* 固定图标宽度 */
    text-align: center;
    /* 图标居中 */
  }
 
  /* 悬停效果 */
  .download-plugin:hover {
    background-color: #3367d6;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(66, 133, 244, 0.3);
  }
 
  .configure-plugin:hover {
    background-color: #e0e0e0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  }
 
  /* 点击效果 */
  .download-plugin:active,
  .configure-plugin:active {
    transform: translateY(0);
  }
  .downloadreBtn {
    font-size: 2rem !important;
    height: 6rem !important;
    width: 100% !important;
  }
  .downloainput {
    height: 6rem !important;
    font-size: 2rem !important;
  }
  :deep(.el-select__wrapper) {
    min-height: 5rem !important;
    font-size: 2rem !important;
  }
}
</style>