AuthenticationPanel.vue
46.6 KB
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
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
<!--
* @Author: 赵丽婷
* @Date: 2025-12-01
* @LastEditors: 赵丽婷
* @LastEditTime: 2026-01-06 15:03:44
* @FilePath: \LinkMed\linkmed-vue3\src\components\Settings\AuthenticationPanel.vue
* @Description: 信息认证组件
* Copyright (c) 2025 by 北京连心医疗科技有限公司, All Rights Reserved.
-->
<template>
<div class="authentication-panel">
<div class="settings-content-header">
<div class="header-row">
<div>
<h1>{{ t("settings.authentication.title") }}</h1>
<p v-if="!isEditing">{{ t("settings.authentication.desc") }}</p>
</div>
<div class="status-wrapper" v-if="!isEditing">
<div>
{{ t("settings.authentication.statusLabel") }}:
<span :style="{ color: certificationStatusColor }">
{{ certificationStatusText }}
</span>
</div>
<span
v-if="certificationStatus === 'REJECTED'"
style="color: #f56c6c"
>{{ certificationNotes }}</span
>
</div>
</div>
</div>
<!-- 展示模式 -->
<div v-if="!isEditing" class="view-mode">
<div class="section">
<div class="section-title">
{{ t("settings.authentication.basicInfo") }}
</div>
<div class="info-rows">
<!-- 第一排 -->
<div class="info-row">
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.realName")
}}</label>
<div class="info-value">{{ authData.realName || "-" }}</div>
</div>
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.gender")
}}</label>
<div class="info-value">{{ getGenderText(authData.gender) }}</div>
</div>
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.hospital")
}}</label>
<div class="info-value">{{ authData.hospital || "-" }}</div>
</div>
</div>
<!-- 第二排 -->
<div class="info-row">
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.field")
}}</label>
<div class="info-value">
{{
authData.field
? fieldOptions.find(
(opt) => opt.value === String(authData.field),
)?.label || authData.field
: "-"
}}
</div>
</div>
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.position")
}}</label>
<div class="info-value">
{{ formatArrayOrString(authData.position, allPositionOptions) }}
</div>
</div>
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.department")
}}</label>
<div class="info-value">{{ authData.department || "-" }}</div>
</div>
</div>
<!-- 第三排 -->
<div class="info-row">
<div class="info-item">
<label class="info-label">{{
t("settings.authentication.location")
}}</label>
<div class="info-value">
{{ convertLocationCodesToNames(authData.location) }}
</div>
</div>
</div>
<!-- 第四排 -->
<div class="info-row">
<div class="info-item">
<label class="info-label">
{{ t("settings.authentication.introduction") }}
</label>
<div class="intro-display">
{{
authData.introduction ||
t("settings.authentication.noIntroduction")
}}
</div>
</div>
</div>
</div>
</div>
<div class="section">
<div class="section-title">
{{ t("settings.authentication.verificationCode") }}
</div>
<div class="qrcode-display">
<template v-if="authData.qrCodes && authData.qrCodes.length > 0">
<div
v-for="(code, index) in authData.qrCodes"
:key="index"
class="qrcode-item"
>
<img
:src="code.url"
alt="认证二维码"
class="qrcode-image"
@click="
showPreview = true;
previewIndex = index;
"
/>
</div>
</template>
<div v-else class="qrcode-placeholder">
{{ t("settings.authentication.noQrCode") }}
</div>
</div>
<!-- 图片预览器 -->
<el-image-viewer
v-if="showPreview && authData.qrCodes && authData.qrCodes.length > 0"
show-progress
:url-list="authData.qrCodes.map((c) => c.url)"
:initial-index="previewIndex"
@close="showPreview = false"
>
<template #viewer-error>
<div class="image-slot viewer-error">
<el-icon><IconPicture /></el-icon>
<span>
{{
t("settings.authentication.imageLoadError") || "图片加载失败"
}}
</span>
</div>
</template>
</el-image-viewer>
</div>
<div class="action-buttons">
<el-button
v-if="!isEditing"
class="edit-btn"
type="primary"
@click="handleEdit"
>
{{ t("settings.authentication.edit") }}
</el-button>
</div>
</div>
<!-- 编辑模式 -->
<div v-else class="edit-mode">
<div class="section">
<div class="section-title">
{{ t("settings.authentication.basicInfo") }}
</div>
<div class="form-rows">
<!-- 第一排 -->
<div class="form-row">
<div class="form-group">
<label class="form-label">
<span class="required">*</span>
{{ t("settings.authentication.realName") }}
</label>
<el-input
v-model="editData.realName"
class="input"
type="text"
:placeholder="t('settings.authentication.realNamePlaceholder')"
/>
</div>
<div class="form-group">
<label class="form-label">
<span class="required">*</span>
{{ t("settings.authentication.gender") }}
</label>
<el-select
v-model="editData.gender"
class="select-input"
:placeholder="t('settings.authentication.genderPlaceholder')"
>
<el-option
:label="t('settings.authentication.male')"
value="男"
/>
<el-option
:label="t('settings.authentication.female')"
value="女"
/>
</el-select>
</div>
<div class="form-group">
<label class="form-label">
<span class="required">*</span>
{{ t("settings.authentication.hospital") }}
</label>
<el-input
v-model="editData.hospital"
class="input"
type="text"
:placeholder="t('settings.authentication.hospitalPlaceholder')"
/>
</div>
</div>
<!-- 第二排 -->
<div class="form-row">
<div class="form-group">
<label class="form-label">
<span class="required">*</span
>{{ t("settings.authentication.field") }}</label
>
<el-select-v2
v-model="editData.field"
:options="fieldOptions"
:placeholder="t('settings.authentication.fieldPlaceholder')"
class="input"
style="width: 100%"
/>
</div>
<div class="form-group">
<label class="form-label">
<span class="required">*</span
>{{ t("settings.authentication.position") }}</label
>
<el-select-v2
v-model="editData.position"
:options="positionOptions"
:placeholder="t('settings.authentication.positionPlaceholder')"
class="input"
multiple
collapse-tags
:max-collapse-tags="2"
style="width: 100%"
/>
</div>
<div class="form-group">
<label class="form-label">
<span class="required">*</span
>{{ t("settings.authentication.department") }}</label
>
<el-input
v-model="editData.department"
class="input"
type="text"
:placeholder="
t('settings.authentication.departmentPlaceholder')
"
/>
</div>
</div>
<!-- 第三排 -->
<div class="form-row">
<div class="form-group">
<label class="form-label">
<span class="required">*</span>
{{ t("settings.authentication.location") }}
</label>
<el-cascader
v-model="editData.location"
class="select-input"
:options="locationOptions"
:placeholder="t('settings.authentication.locationPlaceholder')"
/>
</div>
</div>
<!-- 第四排 -->
<div class="form-row">
<div class="form-group">
<label class="form-label">
{{ t("settings.authentication.introduction") }}
</label>
<div class="form-group full-width">
<textarea
v-model="editData.introduction"
class="textarea"
:placeholder="
t('settings.authentication.introductionPlaceholder')
"
rows="3"
/>
</div>
</div>
</div>
</div>
</div>
<div class="section">
<div class="section-title">
{{ t("settings.authentication.verificationCode") }}
</div>
<div class="upload-section">
<div class="upload-tips">
{{ t("settings.authentication.uploadTips") }}
</div>
<el-upload
class="qrcode-uploader"
list-type="picture-card"
:file-list="editFileList"
:on-change="handleQrCodeChange"
:on-remove="handleQrCodeRemove"
:auto-upload="false"
multiple
accept="image/*"
>
<el-icon><Plus /></el-icon>
<template #tip>
<div class="el-upload__tip">
{{ t("settings.authentication.uploadQrCode") }}
</div>
</template>
</el-upload>
</div>
</div>
<div class="action-buttons">
<el-button class="cancel-btn" @click="handleCancel">
{{ t("settings.authentication.cancel") }}
</el-button>
<el-button class="cancel-btn" @click="handleSave">
{{ t("settings.authentication.save") }}
</el-button>
<el-button
class="submit-btn"
type="primary"
:loading="submitting"
@click="handleSubmit"
>
{{ t("settings.authentication.submit") }}
</el-button>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import { ElMessage, ElImageViewer } from "element-plus";
import { Plus, Picture as IconPicture } from "@element-plus/icons-vue";
import type { UploadFile } from "element-plus";
import {
apiGetRegionsTree,
apiGetDictItems,
getUserProfile,
apiUpdateProfile,
apiGetVerificationImage,
apiGetVerificationImages,
apiUpdateVerificationImages,
apiDeleteVerificationImage,
apiSubmitCertification,
apiGetCertificationStatus,
} from "@/api/user";
import type {
RegionNode,
DictItem,
CertificationStatus,
VerificationImageItem,
} from "@/api/user";
const { t } = useI18n();
interface AuthenticationData {
realName: string; // 真实姓名
gender: string; // 性别
hospital: string; // 所属医院/公司/机构
field: string | string[]; // 领域
position: string | string[]; // 职称
department: string; //所属部门
location: string; // 所在地区
qrCodes: VerificationImageItem[]; // 认证信息
introduction: string; // 个人简介
}
const isEditing = ref(false);
const submitting = ref(false);
const userId = ref<number | null>(null);
const showPreview = ref(false);
const previewIndex = ref(0);
const certificationStatus = ref<CertificationStatus | null>(null);
const certificationNotes = ref<string | null>("");
const authData = reactive<AuthenticationData>({
realName: "",
gender: "",
hospital: "",
field: "", // 单选模式,使用字符串
position: [],
department: "",
location: "",
qrCodes: [],
introduction: "",
});
const editData = reactive<AuthenticationData>({
realName: "",
gender: "",
hospital: "",
field: "", // 单选模式,使用字符串
position: [],
department: "",
location: "",
qrCodes: [],
introduction: "",
});
// 用于 el-upload 的文件列表
const editFileList = ref<any[]>([]);
// 监听 editData.qrCodes 的变化,同步到 editFileList
watch(
() => editData.qrCodes,
(newCodes) => {
editFileList.value = newCodes.map((item) => ({
name: item.path || item.url,
url: item.url,
}));
},
{ immediate: true },
);
// 地址选项
const locationOptions = ref<
Array<{
value: string | number;
label: string;
children?: Array<{
value: string | number;
label: string;
children?: Array<{ value: string | number; label: string }>;
}>;
}>
>([]);
// 将 API 返回的地区树数据转换为 Cascader 需要的格式
const convertRegionNodeToCascaderOption = (
node: RegionNode,
): {
value: string | number;
label: string;
children?: Array<any>;
} => {
const option: {
value: string | number;
label: string;
children?: Array<any>;
} = {
value: node.code || node.id || "",
label: node.name || "",
};
if (node.children && node.children.length > 0) {
option.children = node.children.map(convertRegionNodeToCascaderOption);
}
return option;
};
// 加载地区树数据
const loadRegionsTree = async () => {
try {
const { data } = await apiGetRegionsTree();
if (Array.isArray(data)) {
// 跳过国家级别,直接从省份开始
// 查找"中国"节点,使用其子节点(省份)作为第一级
const chinaNode = data.find(
(node: RegionNode) => node.name === "中国" || node.code === "000000",
);
if (chinaNode && chinaNode.children) {
// 使用中国的省份作为第一级选项
locationOptions.value = chinaNode.children.map(
convertRegionNodeToCascaderOption,
);
} else {
// 如果没有找到中国节点,尝试使用所有节点的子节点(省份级别)
const provinceNodes: RegionNode[] = [];
data.forEach((node: RegionNode) => {
if (node.children) {
provinceNodes.push(...node.children);
}
});
if (provinceNodes.length > 0) {
locationOptions.value = provinceNodes.map(
convertRegionNodeToCascaderOption,
);
} else {
// 如果都没有,则使用原始数据(降级处理)
locationOptions.value = data.map(convertRegionNodeToCascaderOption);
}
}
}
} catch (error) {
console.error("获取地区树失败:", error);
ElMessage.error("获取地区数据失败,请稍后重试");
}
};
// 领域选项(包含 code 信息用于判断)
const fieldOptions = ref<
Array<{
id: number;
value: string;
label: string;
code?: string;
pinyinCode?: string;
}>
>([]);
// 所有职称选项(原始数据,包含 code 信息用于过滤)
const allPositionOptions = ref<
Array<{
id: number;
value: string;
label: string;
code?: string;
pinyinCode?: string;
}>
>([]);
// 根据选中的领域过滤职称选项
const positionOptions = computed(() => {
// 单选模式下,field 是字符串
if (!editData.field) {
return [];
}
// 通过查找 fieldOptions 来获取对应的 code
const fieldOption = fieldOptions.value.find(
(option) => option.value === editData.field,
);
const selectedFieldCode = fieldOption?.code || editData.field;
// 在 allPositionOptions 中过滤出 code 与选中领域 code 相同的项
return allPositionOptions.value.filter(
(item) => item.code === selectedFieldCode,
);
});
// 获取认证状态的国际化文本
const certificationStatusText = computed(() => {
if (!certificationStatus.value) {
return "-";
}
switch (certificationStatus.value) {
case "UNVERIFIED":
return t("settings.authentication.statusUnverified");
case "PENDING":
return t("settings.authentication.statusPending");
case "APPROVED":
return t("settings.authentication.statusApproved");
case "REJECTED":
return t("settings.authentication.statusRejected");
default:
return certificationStatus.value;
}
});
// 获取认证状态的颜色
const certificationStatusColor = computed(() => {
if (!certificationStatus.value) {
return "#999999"; // 默认灰色
}
switch (certificationStatus.value) {
case "UNVERIFIED":
return "#999999"; // 灰色 - 未认证
case "PENDING":
return "#FF9800"; // 橙色 - 审核中
case "APPROVED":
return "#67C23A"; // 绿色 - 已认证
case "REJECTED":
return "#F56C6C"; // 红色 - 已驳回
default:
return "#999999";
}
});
// 监听领域变化,当领域改变时清空职称选择
watch(
() => editData.field,
(newField, oldField) => {
// 只有在编辑模式下,且领域确实发生变化时才清空职称
// oldField !== undefined 确保不是初始化时的赋值
// oldField !== "" 确保不是从空值初始化
if (
isEditing.value &&
newField !== oldField &&
oldField !== undefined &&
oldField !== ""
) {
editData.position = [];
}
},
);
// 将字典项转换为 Select 选项格式
const convertDictItemToOption = (
item: DictItem,
): {
id: number;
value: string;
label: string;
code?: string;
pinyinCode?: string;
} => {
return {
id: item.id || 0,
value: item.id ? String(item.id) : "",
label: item.name || "",
code: item.code || "",
pinyinCode: item.pinyinCode || "",
};
};
// 加载领域选项
const loadFieldOptions = async () => {
try {
const { data } = await apiGetDictItems("domain");
if (Array.isArray(data)) {
fieldOptions.value = data.map(convertDictItemToOption);
}
} catch (error) {
console.error("获取领域选项失败:", error);
ElMessage.error("获取领域数据失败,请稍后重试");
}
};
// 加载职称选项(加载所有数据)
const loadPositionOptions = async () => {
try {
const { data } = await apiGetDictItems("domain_title");
if (Array.isArray(data)) {
allPositionOptions.value = data.map(convertDictItemToOption);
}
} catch (error) {
console.error("获取职称选项失败:", error);
ElMessage.error("获取职称数据失败,请稍后重试");
}
};
const getGenderText = (gender: string) => {
if (gender === "男") return t("settings.authentication.male");
if (gender === "女") return t("settings.authentication.female");
return "-";
};
// 将ID数组转换为名称数组(用于领域和职称)
const convertIdsToLabels = (
ids: string | string[] | undefined,
options: Array<{ value: string; label: string }>,
): string[] => {
if (!ids) return [];
const idArray = Array.isArray(ids) ? ids : [ids];
return idArray
.map((id) => {
const option = options.find((opt) => opt.value === String(id));
return option ? option.label : id;
})
.filter(Boolean);
};
// 将名称数组转换为ID数组(用于领域和职称的回显)
const convertLabelsToIds = (
labels: string | string[] | undefined,
options: Array<{ value: string; label: string }>,
): string[] => {
if (!labels) return [];
const labelArray = Array.isArray(labels) ? labels : [labels];
return labelArray
.map((label) => {
const option = options.find((opt) => opt.label === String(label));
return option ? option.value : label;
})
.filter(Boolean);
};
// 根据地区名称数组查找对应的code数组(用于回显)
const findLocationCodesByLabels = (
labels: string | string[],
options: typeof locationOptions.value,
): string[] => {
if (!labels) return [];
const labelArray = Array.isArray(labels) ? labels : labels.split("/");
const findCodeByLabel = (
opts: typeof locationOptions.value,
targetLabel: string,
level: number = 0,
): string | null => {
for (const option of opts) {
if (option.label === targetLabel) {
return String(option.value);
}
if (option.children && level < labelArray.length - 1) {
const found = findCodeByLabel(option.children, targetLabel, level + 1);
if (found) return found;
}
}
return null;
};
const codes: string[] = [];
for (let i = 0; i < labelArray.length; i++) {
const labelItem = labelArray[i];
if (!labelItem) continue;
const label = String(labelItem).trim();
if (!label) continue;
// 从当前层级开始查找
let currentOptions = options;
for (let j = 0; j < i; j++) {
const parentCode = codes[j];
if (!parentCode) break;
const parentOption = findLocationOptionByCode(currentOptions, parentCode);
if (parentOption?.children) {
currentOptions = parentOption.children;
} else {
break;
}
}
const code = findCodeByLabel(currentOptions, label, i);
if (code) {
codes.push(code);
}
}
return codes;
};
// 根据code查找地区选项
const findLocationOptionByCode = (
options: typeof locationOptions.value,
code: string,
): { value: string | number; label: string; children?: any[] } | null => {
for (const option of options) {
if (String(option.value) === String(code)) {
return option;
}
if (option.children) {
const found = findLocationOptionByCode(option.children, code);
if (found) return found;
}
}
return null;
};
// 根据地区code数组获取label数组(用于保存)
const getLocationLabelsByCodes = (
codes: string | string[],
options: typeof locationOptions.value,
): string[] => {
if (!codes) return [];
const codeArray = Array.isArray(codes) ? codes : codes.split("/");
const labels: string[] = [];
let currentOptions = options;
for (const code of codeArray) {
const option = findLocationOptionByCode(currentOptions, code);
if (option) {
labels.push(option.label);
if (option.children) {
currentOptions = option.children;
} else {
break;
}
} else {
break;
}
}
return labels;
};
// 将地区code数组转换为名称字符串
const convertLocationCodesToNames = (
codes: string | string[] | undefined,
): string => {
if (!codes) return "-";
const codeArray = Array.isArray(codes) ? codes : [codes];
if (codeArray.length === 0) return "-";
const findLocationName = (
options: typeof locationOptions.value,
targetCode: string | number,
): string | null => {
for (const option of options) {
if (
option.value === targetCode ||
String(option.value) === String(targetCode)
) {
return option.label;
}
if (option.children) {
const found = findLocationName(option.children, targetCode);
if (found) return found;
}
}
return null;
};
const names = codeArray
.map((code) => findLocationName(locationOptions.value, code))
.filter((name): name is string => name !== null);
return names.length > 0 ? names.join("/") : "-";
};
// 格式化数组或字符串为显示文本(用于领域和职称,将ID转换为名称)
const formatArrayOrString = (
value: string | string[] | undefined,
options?: Array<{ value: string; label: string }>,
): string => {
if (!value) return "-";
// 如果提供了选项,说明需要将ID转换为名称
if (options) {
const labels = convertIdsToLabels(value, options);
return labels.length > 0 ? labels.join("、") : "-";
}
// 否则直接格式化
if (Array.isArray(value)) {
return value.length > 0 ? value.join("、") : "-";
}
return value;
};
const handleEdit = () => {
// 复制当前数据到编辑数据,确保类型正确
Object.assign(editData, {
...authData,
// 领域改为单选,如果是数组则取第一个值,否则直接使用
field: Array.isArray(authData.field)
? authData.field[0] || ""
: authData.field || "",
position: Array.isArray(authData.position)
? [...authData.position]
: authData.position
? [authData.position]
: [],
qrCodes: [...authData.qrCodes],
location: Array.isArray(authData.location)
? [...authData.location]
: authData.location
? authData.location.includes("/")
? authData.location.split("/").filter(Boolean)
: [authData.location]
: [],
});
isEditing.value = true;
};
const handleCancel = () => {
isEditing.value = false;
};
// 根据选中的地区 code 数组,从 locationOptions 中查找对应的地区信息
const getLocationDictJson = (
locationCodes: string | string[] | undefined,
): string => {
if (!locationCodes) return "";
const codes = Array.isArray(locationCodes) ? locationCodes : [locationCodes];
if (codes.length === 0) return "";
const findLocationInfo = (
options: typeof locationOptions.value,
targetCode: string | number,
level: number = 0,
): { code: string | number; label: string; level: number } | null => {
for (const option of options) {
if (
option.value === targetCode ||
String(option.value) === String(targetCode)
) {
return {
code: option.value,
label: option.label,
level,
};
}
if (option.children) {
const found = findLocationInfo(option.children, targetCode, level + 1);
if (found) return found;
}
}
return null;
};
// 查找所有地区信息,按顺序匹配codes数组
const locationInfo: Array<{
code: string | number;
label: string;
level: number;
}> = [];
// 按顺序查找每个code对应的地区信息
for (let i = 0; i < codes.length; i++) {
const code = codes[i];
if (!code) continue; // 跳过空值
const found = findLocationInfo(locationOptions.value, code, 0);
if (found) {
// 根据在codes数组中的位置确定层级(因为已经跳过了国家级别)
// codes[0] = province (level 0)
// codes[1] = city (level 1)
// codes[2] = district (level 2)
// codes[3] = county (level 3)
locationInfo.push({
code: found.code,
label: found.label,
level: i,
});
}
}
if (locationInfo.length === 0) return "";
// 构建 JSON 对象,包含省市区县信息
const dictJson: any = {};
locationInfo.forEach((info) => {
const levelNames = ["province", "city", "district", "county"];
const levelName = levelNames[info.level] || `level${info.level}`;
dictJson[levelName] = {
code: String(info.code),
name: info.label,
};
});
return JSON.stringify(dictJson);
};
// 保存用户信息
const handleSave = async (): Promise<boolean> => {
// 验证必填项
if (!editData.realName) {
ElMessage.error(t("settings.authentication.realNameRequired"));
return false;
}
if (!editData.gender) {
ElMessage.error(t("settings.authentication.genderRequired"));
return false;
}
if (!editData.hospital) {
ElMessage.error(t("settings.authentication.hospitalRequired"));
return false;
}
if (!editData.field) {
ElMessage.error(t("settings.authentication.fieldRequired"));
return false;
}
if (
!editData.position ||
(Array.isArray(editData.position) && editData.position.length === 0)
) {
ElMessage.error(t("settings.authentication.positionRequired"));
return false;
}
if (
!editData.location ||
(Array.isArray(editData.location) && editData.location.length === 0)
) {
ElMessage.error(t("settings.authentication.locationRequired"));
return false;
}
if (!editData.department) {
ElMessage.error(t("settings.authentication.departmentRequired"));
return false;
}
submitting.value = true;
try {
// 处理 领域 字段:将 value(代码)转换为 label(显示名称)
let fieldStr = "";
if (editData.field) {
const fieldOption = fieldOptions.value.find(
(opt) => opt.value === String(editData.field),
);
fieldStr = fieldOption ? fieldOption.label : String(editData.field);
}
// 处理 职称 字段:将 value(代码)数组转换为 label(显示名称)数组,然后用、分隔
let titleStr = "";
if (editData.position) {
const positionArray = Array.isArray(editData.position)
? editData.position
: [editData.position];
const positionLabels = positionArray
.map((value) => {
const option = allPositionOptions.value.find(
(opt) => opt.value === String(value),
);
return option ? option.label : String(value);
})
.filter(Boolean);
titleStr = positionLabels.join("、");
}
// 处理 所在地区 字段:将 value(代码)数组转换为 label(显示名称)数组,然后用/分隔
let regionStr = "";
if (editData.location) {
const locationArray = Array.isArray(editData.location)
? editData.location
: editData.location.split("/");
const locationLabels = getLocationLabelsByCodes(
locationArray,
locationOptions.value,
);
regionStr = locationLabels.join("/");
}
// 生成地区字典 JSON(使用原始的 code 数组)
const dictJson = getLocationDictJson(editData.location);
// 构建更新参数
const updateParams = {
realName: editData.realName,
gender: editData.gender,
institution: editData.hospital,
field: fieldStr,
title: titleStr,
department: editData.department,
region: regionStr,
bio: editData.introduction,
dictJson: dictJson,
};
// 调用 API 保存数据
await apiUpdateProfile(updateParams);
// 保存成功后重新加载数据,确保数据一致性
await loadAuthenticationData();
ElMessage.success(t("settings.authentication.submitSuccess"));
return true;
} catch (error: any) {
console.error("保存用户信息失败:", error);
ElMessage.error(
error?.response?.data?.message ||
error?.message ||
t("settings.authentication.submitFailed") ||
"保存失败,请稍后重试",
);
return false;
} finally {
submitting.value = false;
}
};
const handleQrCodeChange = async (file: UploadFile) => {
if (file.raw) {
try {
// 调用接口上传图片(使用多图上传接口)
const { data } = await apiUpdateVerificationImages([file.raw]);
ElMessage.success(t("settings.authentication.uploadQrCodeSuccess"));
// 上传成功后,将返回的图片信息添加到预览列表
if (Array.isArray(data) && data.length > 0) {
data.forEach((item) => {
if (!editData.qrCodes.some((c) => c.url === item.url)) {
editData.qrCodes.push(item);
}
});
}
} catch (error: any) {
console.error("上传认证图片失败:", error);
ElMessage.error(
error?.response?.data?.message ||
error?.message ||
t("settings.authentication.uploadQrCodeFailed"),
);
// 上传失败时,从文件列表中移除
const index = editFileList.value.findIndex((f) => f.uid === file.uid);
if (index > -1) {
editFileList.value.splice(index, 1);
}
}
}
};
const handleQrCodeRemove = async (file: UploadFile) => {
try {
// 找到对应的图片对象
const targetItem = editData.qrCodes.find((c) => c.url === file.url);
if (targetItem) {
// 从 URL 或 path 中提取文件名(仅提取最后一部分)
const fullPath = targetItem.path || targetItem.url;
const filename = fullPath.split("/").pop() || "";
if (filename) {
await apiDeleteVerificationImage(filename);
}
const index = editData.qrCodes.indexOf(targetItem);
if (index > -1) {
editData.qrCodes.splice(index, 1);
}
}
} catch (error: any) {
console.error("删除认证图片失败:", error);
ElMessage.error("删除图片失败,请稍后重试");
}
};
const handleSubmit = async () => {
// 验证证件是否上传
if (!editData.qrCodes || editData.qrCodes.length === 0) {
ElMessage.error(t("settings.authentication.uploadQrCodeRequired"));
return;
}
submitting.value = true;
try {
const saveSuccess = await handleSave();
// 返回 false(验证失败或保存失败),则不继续后续接口调用
if (!saveSuccess) {
return;
}
await apiSubmitCertification();
// 提交成功后重新加载认证状态
await loadCertificationStatus();
isEditing.value = false;
} catch (error: any) {
ElMessage.error(
error?.message || t("settings.authentication.submitFailed"),
);
} finally {
submitting.value = false;
}
};
// 加载数据
const loadAuthenticationData = async () => {
try {
// 调用 getUserProfile 获取真实用户信息
let userData;
try {
userData = await getUserProfile();
} catch (error) {
console.warn("⚠️ 获取真实用户信息失败,使用模拟数据:", error);
// 如果获取失败,使用模拟数据作为后备
userData = {
name: "小强语",
gender: "女",
institution: "华西医院华西医院公司",
field: "学校或科研机构、公司",
title: "经理",
department: "科室",
region: "四川省/成都市/市辖区",
bio: "您的个人简介",
};
}
// 处理 location 字段:优先使用 dictJson 回显,否则使用 region 字符串(label)转换为 code
let locationValue: string | string[] = "";
if ((userData as any).dictJson) {
try {
const dictJson = JSON.parse((userData as any).dictJson);
// 从 dictJson 中提取 code 值,按省市区顺序组成数组
const locationCodes: string[] = [];
const levelOrder = ["province", "city", "district", "county"];
levelOrder.forEach((level) => {
if (dictJson[level] && dictJson[level].code) {
locationCodes.push(String(dictJson[level].code));
}
});
if (locationCodes.length > 0) {
locationValue = locationCodes;
} else {
// 如果没有 code,尝试从 region 字符串(label)转换为 code
if (userData.region) {
const regionLabels = userData.region.includes("/")
? userData.region.split("/").filter(Boolean)
: [userData.region];
locationValue = findLocationCodesByLabels(
regionLabels,
locationOptions.value,
);
}
}
} catch (error) {
console.warn("解析 dictJson 失败:", error);
// 解析失败时,尝试从 region 字符串(label)转换为 code
if (userData.region) {
const regionLabels = userData.region.includes("/")
? userData.region.split("/").filter(Boolean)
: [userData.region];
locationValue = findLocationCodesByLabels(
regionLabels,
locationOptions.value,
);
}
}
} else {
// 如果没有 dictJson,region 字符串是 label(显示名称),需要转换为 code(代码)
if (userData.region) {
const regionLabels = userData.region.includes("/")
? userData.region.split("/").filter(Boolean)
: [userData.region];
locationValue = findLocationCodesByLabels(
regionLabels,
locationOptions.value,
);
}
}
// 保存用户ID,用于获取认证图片
userId.value = userData.id || null;
// 将 UserProfile 数据映射到 AuthenticationData
const mappedData: any = {
realName: userData.realName ?? "",
gender: userData.gender || "",
hospital: userData.institution || "",
department: userData.department || "",
location: locationValue,
qrCodes: [], // 二维码需要单独获取
introduction: userData.bio || "",
};
// 获取用户认证图片
if (userData.id) {
try {
// 使用新的获取多图列表接口
const response = await apiGetVerificationImages(userData.id);
const responseData = response.data;
if (Array.isArray(responseData)) {
mappedData.qrCodes = responseData;
} else {
mappedData.qrCodes = [];
}
} catch (error: any) {
// 如果获取多图失败,尝试降级使用单图接口
try {
const response = await apiGetVerificationImage(userData.id);
const responseData = response.data;
if (responseData instanceof Blob && responseData.size > 0) {
mappedData.qrCodes = [
{
url: URL.createObjectURL(responseData),
path: "verification-image",
size: responseData.size,
lastModifiedEpochMs: Date.now(),
contentType: responseData.type,
},
];
} else {
mappedData.qrCodes = [];
}
} catch (innerError) {
mappedData.qrCodes = [];
}
}
}
// 处理 field 字段:后端返回的是 label(显示名称),需要转换为 value(代码)以便编辑模式回显
if (userData.field) {
if (typeof userData.field === "string") {
// 如果包含分隔符,取第一个值
const parts = userData.field
.split(/[、/,,]/)
.map((s: string) => s.trim())
.filter(Boolean);
const fieldLabel = parts.length > 0 ? parts[0] : "";
// 根据 label 查找对应的 value
const fieldOption = fieldOptions.value.find(
(opt) => opt.label === fieldLabel,
);
mappedData.field = fieldOption ? fieldOption.value : fieldLabel;
} else {
// 如果是数字或代码,尝试查找对应的 label,如果找不到则直接使用
const fieldOption = fieldOptions.value.find(
(opt) => opt.value === String(userData.field),
);
mappedData.field = fieldOption
? fieldOption.value
: String(userData.field);
}
} else {
mappedData.field = "";
}
// 处理 position/title 字段:后端返回的是 label(显示名称)数组,需要转换为 value(代码)数组以便编辑模式回显
if (userData.title) {
if (typeof userData.title === "string") {
// 支持多种分隔符:、/ ,
const titleLabels = userData.title
.split(/[、/,,]/)
.map((s: string) => s.trim())
.filter(Boolean);
// 将 label 数组转换为 value 数组
mappedData.position = convertLabelsToIds(
titleLabels,
allPositionOptions.value,
);
} else if (Array.isArray(userData.title)) {
// 如果是数组,假设是 label 数组,转换为 value 数组
mappedData.position = convertLabelsToIds(
userData.title,
allPositionOptions.value,
);
} else {
mappedData.position = [];
}
} else {
mappedData.position = [];
}
Object.assign(authData, mappedData);
} catch (error) {
console.error("Failed to load authentication data:", error);
ElMessage.error("加载认证信息失败,请稍后重试");
}
};
// 加载认证状态
const loadCertificationStatus = async () => {
try {
const { data } = await apiGetCertificationStatus();
certificationStatus.value = data.status || null;
certificationNotes.value = data.notes || null;
} catch (error) {
console.error("Failed to load certification status:", error);
// 不显示错误消息,静默失败
}
};
onMounted(() => {
loadAuthenticationData();
loadRegionsTree();
loadFieldOptions();
loadPositionOptions();
loadCertificationStatus();
});
</script>
<style scoped lang="scss">
.authentication-panel {
color: var(--color-text);
background: var(--color-bg);
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.settings-content-header {
margin-bottom: 20px;
text-align: left;
.header-row {
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.status-wrapper {
display: flex;
flex-direction: column;
align-items: flex-end;
}
h1 {
font-size: 28px;
font-weight: 800;
color: var(--color-text);
margin-bottom: 8px;
}
p {
font-size: 14px;
color: var(--color-secondary);
}
.edit-btn {
flex-shrink: 0;
}
}
.section {
width: 100%;
margin-bottom: 24px;
}
.section-title {
font-size: 18px;
font-weight: 700;
color: var(--color-text);
margin-bottom: 20px;
}
// 展示模式样式
.view-mode {
.info-rows {
display: flex;
flex-direction: column;
gap: 24px;
background: var(--color-card);
padding: 24px;
border-radius: 8px;
}
.info-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px 40px;
&:last-child {
grid-template-columns: 1fr;
}
}
.info-item {
display: flex;
flex-direction: column;
gap: 8px;
}
.info-label {
font-size: 14px;
font-weight: 600;
color: var(--color-secondary);
}
.info-value {
font-size: 15px;
color: var(--color-text);
word-break: break-word;
}
.qrcode-display {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap;
gap: 16px;
}
.qrcode-item {
width: 200px;
height: 200px;
}
.qrcode-image {
width: 100%;
height: 100%;
object-fit: contain;
border: 1px solid var(--color-border);
border-radius: 8px;
cursor: pointer;
transition: opacity 0.2s;
&:hover {
opacity: 0.8;
}
}
.image-slot.viewer-error {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
color: var(--color-secondary);
font-size: 14px;
}
.qrcode-placeholder {
width: 150px;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
border: 2px dashed var(--color-border);
border-radius: 8px;
color: var(--color-secondary);
font-size: 14px;
}
.intro-display {
color: var(--color-text);
font-size: 14px;
line-height: 1.6;
min-height: 40px;
white-space: pre-wrap;
word-break: break-word;
}
}
// 编辑模式样式
.edit-mode {
.form-rows {
display: flex;
flex-direction: column;
gap: 22px;
}
.form-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 22px 24px;
&:last-child {
grid-template-columns: 1fr;
}
}
.form-group {
display: flex;
flex-direction: column;
gap: 10px;
&.full-width {
grid-column: 1 / -1;
}
}
.form-label {
font-size: 14px;
font-weight: 600;
color: var(--color-secondary);
.required {
color: #f56c6c;
margin-right: 4px;
}
}
.input {
color: var(--color-text-secondary);
font-size: 14px;
outline: none;
width: 100%;
box-sizing: border-box;
transition: border-color 0.2s;
&:focus {
border-color: var(--color-primary);
box-shadow: 0 0 0 2px rgba(51, 153, 255, 0.1);
}
&::placeholder {
color: var(--color-placeholder);
}
}
.textarea {
background: var(--color-card);
color: var(--color-text-secondary);
border: 1.5px solid var(--color-border);
border-radius: 8px;
padding: 12px 16px;
font-size: 14px;
outline: none;
width: 100%;
box-sizing: border-box;
transition: border-color 0.2s;
resize: vertical;
font-family: inherit;
line-height: 1.6;
&:focus {
border-color: var(--color-primary);
box-shadow: 0 0 0 2px rgba(51, 153, 255, 0.1);
}
&::placeholder {
color: var(--color-placeholder);
}
}
:deep(.select-input) {
width: 100%;
.el-input__wrapper {
border: 1.5px solid var(--color-border);
box-shadow: none;
transition: border-color 0.2s;
&:hover,
&.is-focus {
border-color: var(--color-primary);
box-shadow: 0 0 0 2px rgba(51, 153, 255, 0.1);
}
}
.el-input__inner {
color: var(--color-text-secondary);
}
}
.upload-section {
display: flex;
flex-direction: column;
gap: 16px;
}
.upload-tips {
font-size: 14px;
color: var(--color-secondary);
}
.qrcode-uploader {
:deep(.el-upload--picture-card) {
background-color: var(--color-card);
border: 2px dashed var(--color-border);
border-radius: 8px;
transition: border-color 0.2s;
&:hover {
border-color: var(--color-primary);
}
}
}
.action-buttons {
display: flex;
justify-content: flex-start;
margin-top: 16px;
.submit-btn {
background: var(--color-primary);
color: var(--color-bg);
border: none;
padding: 10px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 600;
transition: all 0.2s;
&:hover {
background: var(--color-btn-hover);
}
}
.cancel-btn {
padding: 10px 24px;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
}
}
}
@media (max-width: 1024px) {
.authentication-panel {
max-width: 100%;
padding: 0 4px 20px 4px;
}
.view-mode .info-row,
.edit-mode .form-row {
grid-template-columns: 1fr !important;
gap: 20px;
}
}
</style>