mistpe commited on
Commit
9ac6a1f
·
verified ·
1 Parent(s): 547bdb0

Create index2.html

Browse files
Files changed (1) hide show
  1. index2.html +595 -0
index2.html ADDED
@@ -0,0 +1,595 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>浙江水利水电学院学风督查工作证</title>
7
+ <style>
8
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&display=swap');
9
+ body {
10
+ font-family: 'Noto Sans SC', sans-serif;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ height: 100vh;
15
+ margin: 0;
16
+ background-color: #f0f0f0;
17
+ }
18
+ .id-card-container {
19
+ display: flex;
20
+ gap: 30px;
21
+ }
22
+ .id-card {
23
+ width: 255px;
24
+ height: 380px;
25
+ perspective: 1000px;
26
+ cursor: pointer;
27
+ }
28
+ .id-card-inner {
29
+ position: relative;
30
+ width: 100%;
31
+ height: 100%;
32
+ text-align: center;
33
+ transition: transform 0.6s;
34
+ transform-style: preserve-3d;
35
+ }
36
+ .id-card:hover .id-card-inner {
37
+ transform: rotateY(180deg);
38
+ }
39
+ .id-card-front, .id-card-back {
40
+ position: absolute;
41
+ width: 100%;
42
+ height: 100%;
43
+ backface-visibility: hidden;
44
+ border-radius: 20px;
45
+ box-shadow: 0 15px 35px rgba(0,0,0,0.1);
46
+ overflow: hidden;
47
+ }
48
+ .id-card-front {
49
+ background-color: #fff;
50
+ }
51
+ .id-card-back {
52
+ background-color: #fff;
53
+ transform: rotateY(180deg);
54
+ }
55
+ .water-bg {
56
+ position: absolute;
57
+ top: 0;
58
+ left: 0;
59
+ width: 100%;
60
+ height: 100%;
61
+ background: linear-gradient(45deg, rgba(173,216,230,0.2) 0%, rgba(0,191,255,0.2) 100%);
62
+ clip-path: polygon(0 0, 100% 0, 100% 75%, 75% 100%, 0 100%);
63
+ }
64
+ .content {
65
+ position: relative;
66
+ z-index: 1;
67
+ padding: 20px;
68
+ display: flex;
69
+ flex-direction: column;
70
+ height: 100%;
71
+ box-sizing: border-box;
72
+ }
73
+ .header {
74
+ display: flex;
75
+ justify-content: space-between;
76
+ align-items: center;
77
+ margin-bottom: 15px;
78
+ }
79
+ .title-container {
80
+ text-align: left;
81
+ }
82
+ .title {
83
+ font-size: 14px;
84
+ font-weight: bold;
85
+ text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
86
+ margin-bottom: 2px;
87
+ }
88
+ .title-en {
89
+ font-size: 8px;
90
+ color: #666;
91
+ }
92
+ .logo {
93
+ width: 50px;
94
+ height: 50px;
95
+ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="%230066cc"/><path d="M30 70 Q 50 20, 70 70 T 90 50" stroke="white" fill="none" stroke-width="8"/></svg>') no-repeat center/contain;
96
+ }
97
+ .info {
98
+ display: flex;
99
+ flex-direction: column;
100
+ align-items: center;
101
+ flex-grow: 1;
102
+ }
103
+ .photo {
104
+ width: 90px;
105
+ height: 117px;
106
+ background-color: #eee;
107
+ border-radius: 10px;
108
+ margin-bottom: 15px;
109
+ box-shadow: 0 5px 15px rgba(0,0,0,0.1);
110
+ }
111
+ .details {
112
+ width: 100%;
113
+ text-align: left;
114
+ padding: 0 10px;
115
+ }
116
+ .details p {
117
+ margin: 8px 0;
118
+ font-size: 12px;
119
+ color: #333;
120
+ }
121
+ .footer {
122
+ margin-top: auto;
123
+ text-align: center;
124
+ }
125
+ .qr-code {
126
+ width: 80px;
127
+ height: 80px;
128
+ background-color: #fff;
129
+ border-radius: 5px;
130
+ overflow: hidden;
131
+ margin: 0 auto;
132
+ }
133
+ .qr-code img {
134
+ width: 100%;
135
+ height: 100%;
136
+ object-fit: contain;
137
+ }
138
+ .watermark {
139
+ position: absolute;
140
+ bottom: 10px;
141
+ right: 10px;
142
+ font-size: 30px;
143
+ color: rgba(0,102,204,0.1);
144
+ transform: rotate(-30deg);
145
+ }
146
+ .student .water-bg { background: linear-gradient(45deg, rgba(173,216,230,0.3) 0%, rgba(0,191,255,0.3) 100%); }
147
+ .staff .water-bg { background: linear-gradient(45deg, rgba(144,238,144,0.3) 0%, rgba(0,255,127,0.3) 100%); }
148
+ .student .title, .student .logo { color: #0066cc; }
149
+ .staff .title, .staff .logo { color: #009933; }
150
+ .back-title {
151
+ font-size: 16px;
152
+ font-weight: bold;
153
+ margin-bottom: 15px;
154
+ text-align: center;
155
+ }
156
+ .student .back-title { color: #0066cc; }
157
+ .staff .back-title { color: #009933; }
158
+ .back-content {
159
+ display: flex;
160
+ flex-direction: column;
161
+ justify-content: space-between;
162
+ align-items: center;
163
+ flex-grow: 1;
164
+ }
165
+ .back-text {
166
+ font-size: 12px;
167
+ color: #333;
168
+ text-align: left;
169
+ margin-bottom: 15px;
170
+ }
171
+ .wave-bg {
172
+ position: absolute;
173
+ bottom: 0;
174
+ left: 0;
175
+ width: 100%;
176
+ height: 50%;
177
+ opacity: 0.5;
178
+ }
179
+ .student .wave-bg {
180
+ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%230066cc" fill-opacity="0.1" d="M0,64L48,80C96,96,192,128,288,128C384,128,480,96,576,85.3C672,75,768,85,864,122.7C960,160,1056,224,1152,245.3C1248,267,1344,245,1392,234.7L1440,224L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom/cover;
181
+ }
182
+ .staff .wave-bg {
183
+ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%23009933" fill-opacity="0.1" d="M0,96L48,112C96,128,192,160,288,165.3C384,171,480,149,576,149.3C672,149,768,171,864,165.3C960,160,1056,128,1152,117.3C1248,107,1344,117,1392,122.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom/cover;
184
+ }
185
+ .back-footer {
186
+ font-size: 10px;
187
+ color: #666;
188
+ margin-top: 10px;
189
+ }
190
+ .edit-form-container {
191
+ position: fixed;
192
+ top: 20px;
193
+ right: 20px;
194
+ width: 340px;
195
+ height: 95vh;
196
+ background-color: #ffffff;
197
+ border-radius: 12px;
198
+ box-shadow: 0 0 20px rgba(0,0,0,0.1);
199
+ overflow: hidden;
200
+ z-index: 1000;
201
+ }
202
+ .edit-form {
203
+ height: 100%;
204
+ overflow-y: auto;
205
+ padding: 20px;
206
+ box-sizing: border-box;
207
+ }
208
+ .edit-form h2 {
209
+ margin-top: 0;
210
+ color: #333;
211
+ font-size: 24px;
212
+ text-align: center;
213
+ margin-bottom: 20px;
214
+ }
215
+ .edit-form label {
216
+ display: block;
217
+ margin-top: 15px;
218
+ color: #555;
219
+ font-weight: bold;
220
+ }
221
+ .edit-form input[type="text"],
222
+ .edit-form input[type="file"],
223
+ .edit-form select,
224
+ .edit-form textarea {
225
+ width: 100%;
226
+ padding: 8px;
227
+ margin-top: 5px;
228
+ border: 1px solid #ddd;
229
+ border-radius: 4px;
230
+ font-size: 14px;
231
+ box-sizing: border-box;
232
+ }
233
+ .edit-form input[type="file"] {
234
+ border: none;
235
+ }
236
+ .edit-form textarea {
237
+ resize: vertical;
238
+ min-height: 100px;
239
+ }
240
+ .edit-form button {
241
+ width: 100%;
242
+ margin-top: 20px;
243
+ padding: 12px;
244
+ background-color: #4CAF50;
245
+ color: white;
246
+ border: none;
247
+ border-radius: 4px;
248
+ font-size: 16px;
249
+ cursor: pointer;
250
+ transition: background-color 0.3s;
251
+ }
252
+ .edit-form button:hover {
253
+ background-color: #45a049;
254
+ }
255
+ /* 修改导出按钮样式 */
256
+ #export-button {
257
+ width: 30vh;
258
+ position: fixed;
259
+ bottom: 20px;
260
+ right: 20px;
261
+ padding: 10px 20px;
262
+ background-color: #4CAF50;
263
+ color: white;
264
+ border: none;
265
+ border-radius: 4px;
266
+ font-size: 16px;
267
+ cursor: pointer;
268
+ transition: background-color 0.3s;
269
+ }
270
+ #export-button:hover {
271
+ background-color: #45a049;
272
+ }
273
+ </style>
274
+ <!-- 只需要 html2canvas 库 -->
275
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js"></script>
276
+ </head>
277
+
278
+ <body>
279
+ <div class="id-card-container">
280
+ <!-- 学生卡片 -->
281
+ <div class="id-card student">
282
+ <div class="id-card-inner">
283
+ <div class="id-card-front">
284
+ <div class="water-bg"></div>
285
+ <div class="content">
286
+ <div class="header">
287
+ <div class="title-container">
288
+ <div class="title" id="student-title">学生学风督察员</div>
289
+ <div class="title-en" id="student-title-en">Student Academic Integrity Inspector</div>
290
+ </div>
291
+ <div class="logo" id="student-logo"></div>
292
+ </div>
293
+ <div class="info">
294
+ <div class="photo" id="student-photo"></div>
295
+ <div class="details">
296
+ <p><strong>姓名 / Name:</strong> <span id="student-name">王小明</span></p>
297
+ <p><strong>学院 / College:</strong> <span id="student-college">环境科学学院</span></p>
298
+ <p><strong>学号 / Student ID:</strong> <span id="student-id">2024002</span></p>
299
+ <p><strong>所属部门 / Dept.:</strong> <span id="student-department">学风督察委员会</span></p>
300
+ </div>
301
+ </div>
302
+ <div class="footer">
303
+ <div style="font-size: 10px; color: #666;">
304
+ <div id="student-school">浙江水利水电学院</div>
305
+ <div id="student-school-en">Zhejiang University of Water Resources and Electric Power</div>
306
+ </div>
307
+ </div>
308
+ </div>
309
+ <div class="watermark">水利水电</div>
310
+ </div>
311
+ <div class="id-card-back">
312
+ <div class="content">
313
+ <div class="back-title">学生学风督察员工作守则</div>
314
+ <div class="back-content">
315
+ <div class="back-text" id="student-rules">
316
+ 1. 严格遵守学校规章制度<br>
317
+ 2. 公正公平,不徇私舞弊<br>
318
+ 3. 尊重隐私,保护个人信息<br>
319
+ 4. 及时反馈,协助改进学风<br>
320
+ 5. 积极参与,推广优良学风
321
+ </div>
322
+ <div class="qr-code">
323
+ <img id="student-qr" src="" alt="QR Code">
324
+ </div>
325
+ </div>
326
+ <div class="back-footer" id="student-footer">
327
+ 本证件由浙江水利水电学院授权发行<br>
328
+ 如有遗失,请及时与学生工作处联系<br>
329
+ 联系电话:0571-88888888
330
+ </div>
331
+ </div>
332
+ <div class="wave-bg"></div>
333
+ </div>
334
+ </div>
335
+ </div>
336
+
337
+ <!-- 教职工卡片 -->
338
+ <div class="id-card staff">
339
+ <div class="id-card-inner">
340
+ <div class="id-card-front">
341
+ <div class="water-bg"></div>
342
+ <div class="content">
343
+ <div class="header">
344
+ <div class="title-container">
345
+ <div class="title" id="staff-title">教职工学风督察员</div>
346
+ <div class="title-en" id="staff-title-en">Faculty Academic Integrity Inspector</div>
347
+ </div>
348
+ <div class="logo" id="staff-logo"></div>
349
+ </div>
350
+ <div class="info">
351
+ <div class="photo" id="staff-photo"></div>
352
+ <div class="details">
353
+ <p><strong>姓名 / Name:</strong> <span id="staff-name">陈教授</span></p>
354
+ <p><strong>学院 / College:</strong> <span id="staff-college">环境科学学院</span></p>
355
+ <p><strong>工号 / Staff ID:</strong> <span id="staff-id">T2024002</span></p>
356
+ <p><strong>所属部门 / Dept.:</strong> <span id="staff-department">教务处</span></p>
357
+ </div>
358
+ </div>
359
+ <div class="footer">
360
+ <div style="font-size: 10px; color: #666;">
361
+ <div id="staff-school">浙江水利水电学院</div>
362
+ <div id="staff-school-en">Zhejiang University of Water Resources and Electric Power</div>
363
+ </div>
364
+ </div>
365
+ </div>
366
+ <div class="watermark">水利水电</div>
367
+ </div>
368
+ <div class="id-card-back">
369
+ <div class="content">
370
+ <div class="back-title">教职工学风督察员职责</div>
371
+ <div class="back-content">
372
+ <div class="back-text" id="staff-rules">
373
+ 1. 引导和督促学生遵守学习纪律<br>
374
+ 2. 组织开展学风建设相关活动<br>
375
+ 3. 定期评估并报告学风状况<br>
376
+ 4. 制定学风改进方案并实施<br>
377
+ 5. 参与学风评估和奖惩决策
378
+ </div>
379
+ <div class="qr-code">
380
+ <img id="staff-qr" src="" alt="QR Code">
381
+ </div>
382
+ </div>
383
+ <div class="back-footer" id="staff-footer">
384
+ 本证件由浙江水利水电学院授权发行<br>
385
+ 如有遗失,请及时与人事处联系<br>
386
+ 联系电话:0571-99999999
387
+ </div>
388
+ </div>
389
+ <div class="wave-bg"></div>
390
+ </div>
391
+ </div>
392
+ </div>
393
+ </div>
394
+
395
+ <!-- 编辑表单 -->
396
+ <div class="edit-form-container">
397
+ <div class="edit-form">
398
+ <h2>编辑卡片信息</h2>
399
+ <label for="card-type">选择卡片类型:</label>
400
+ <select id="card-type">
401
+ <option value="student">学生卡片</option>
402
+ <option value="staff">教职工卡片</option>
403
+ </select>
404
+ <label for="edit-title">标题:</label>
405
+ <input type="text" id="edit-title">
406
+ <label for="edit-title-en">英文标题:</label>
407
+ <input type="text" id="edit-title-en">
408
+ <label for="edit-logo">Logo:</label>
409
+ <input type="file" id="edit-logo" accept="image/*">
410
+ <label for="edit-photo">照片:</label>
411
+ <input type="file" id="edit-photo" accept="image/*">
412
+ <label for="edit-name">姓名:</label>
413
+ <input type="text" id="edit-name">
414
+ <label for="edit-college">学院:</label>
415
+ <input type="text" id="edit-college">
416
+ <label for="edit-id">学号/工号:</label>
417
+ <input type="text" id="edit-id">
418
+ <label for="edit-department">所属部门:</label>
419
+ <input type="text" id="edit-department">
420
+ <label for="edit-school">学校名称:</label>
421
+ <input type="text" id="edit-school">
422
+ <label for="edit-school-en">学校英文名称:</label>
423
+ <input type="text" id="edit-school-en">
424
+ <label for="edit-rules">背面规则:</label>
425
+ <textarea id="edit-rules" rows="5"></textarea>
426
+ <label for="edit-footer">背面页脚:</label>
427
+ <textarea id="edit-footer" rows="3"></textarea>
428
+ <button id="export-button" onclick="exportToImages()">导出为图片</button>
429
+ </div>
430
+ </div>
431
+
432
+ <script>
433
+ // 预设文本
434
+ const defaultTexts = {
435
+ student: {
436
+ title: "学生学风督察员",
437
+ titleEn: "Student Academic Integrity Inspector",
438
+ name: "王小明",
439
+ college: "环境科学学院",
440
+ id: "2024002",
441
+ department: "学风督察委员会",
442
+ school: "浙江水利水电学院",
443
+ schoolEn: "Zhejiang University of Water Resources and Electric Power",
444
+ rules: "1. 严格遵守学校规章制度\n2. 公正公平,不徇私舞弊\n3. 尊重隐私,保护个人信息\n4. 及时反馈,协助改进学风\n5. 积极参与,推广优良学风",
445
+ footer: "本证件由浙江水利水电学院授权发行\n如有遗失,请及时与学生工作处联系\n联系电话:0571-88888888"
446
+ },
447
+ staff: {
448
+ title: "教职工学风督察员",
449
+ titleEn: "Faculty Academic Integrity Inspector",
450
+ name: "陈教授",
451
+ college: "环境科学学院",
452
+ id: "T2024002",
453
+ department: "教务处",
454
+ school: "浙江水利水电学院",
455
+ schoolEn: "Zhejiang University of Water Resources and Electric Power",
456
+ rules: "1. 引导和督促学生遵守学习纪律\n2. 组织开展学风建设相关活动\n3. 定期评估并报告学风状况\n4. 制定学风改进方案并实施\n5. 参与学风评估和奖惩决策",
457
+ footer: "本证件由浙江水利水电学院授权发行\n如有遗失,请及时与人事处联系\n联系电话:0571-99999999"
458
+ }
459
+ };
460
+ // 加载时生成初始二维码
461
+ window.onload = function() {
462
+ generateQRCode('student');
463
+ generateQRCode('staff');
464
+ loadDefaultValues();
465
+ }
466
+ function loadDefaultValues() {
467
+ const type = document.getElementById('card-type').value;
468
+ const defaults = defaultTexts[type];
469
+ document.getElementById('edit-title').value = defaults.title;
470
+ document.getElementById('edit-title-en').value = defaults.titleEn;
471
+ document.getElementById('edit-name').value = defaults.name;
472
+ document.getElementById('edit-college').value = defaults.college;
473
+ document.getElementById('edit-id').value = defaults.id;
474
+ document.getElementById('edit-department').value = defaults.department;
475
+ document.getElementById('edit-school').value = defaults.school;
476
+ document.getElementById('edit-school-en').value = defaults.schoolEn;
477
+ document.getElementById('edit-rules').value = defaults.rules;
478
+ document.getElementById('edit-footer').value = defaults.footer;
479
+ // 更新卡片显示
480
+ updateCard();
481
+ }
482
+ // 当卡片类型改变时,重新加载默认值
483
+ document.getElementById('card-type').addEventListener('change', loadDefaultValues);
484
+ function generateQRCode(type) {
485
+ const content = JSON.stringify({
486
+ name: document.getElementById(`${type}-name`).textContent,
487
+ id: document.getElementById(`${type}-id`).textContent,
488
+ college: document.getElementById(`${type}-college`).textContent,
489
+ department: document.getElementById(`${type}-department`).textContent
490
+ });
491
+
492
+ fetch(`https://mistpe-qr.hf.space/generate_qr/${encodeURIComponent(content)}`)
493
+ .then(response => response.blob())
494
+ .then(blob => {
495
+ const url = URL.createObjectURL(blob);
496
+ document.getElementById(`${type}-qr`).src = url;
497
+ });
498
+ }
499
+ function updateCard() {
500
+ const type = document.getElementById('card-type').value;
501
+
502
+ updateIfChanged(`${type}-title`, 'edit-title');
503
+ updateIfChanged(`${type}-title-en`, 'edit-title-en');
504
+ updateIfChanged(`${type}-name`, 'edit-name');
505
+ updateIfChanged(`${type}-college`, 'edit-college');
506
+ updateIfChanged(`${type}-id`, 'edit-id');
507
+ updateIfChanged(`${type}-department`, 'edit-department');
508
+ updateIfChanged(`${type}-school`, 'edit-school');
509
+ updateIfChanged(`${type}-school-en`, 'edit-school-en');
510
+ // 更新规则和页脚
511
+ const rulesElement = document.getElementById(`${type}-rules`);
512
+ const newRules = document.getElementById('edit-rules').value;
513
+ rulesElement.innerHTML = newRules.replace(/\n/g, '<br>');
514
+ const footerElement = document.getElementById(`${type}-footer`);
515
+ const newFooter = document.getElementById('edit-footer').value;
516
+ footerElement.innerHTML = newFooter.replace(/\n/g, '<br>');
517
+ // 更新Logo
518
+ updateImage(`${type}-logo`, 'edit-logo');
519
+ // 更新照片
520
+ updateImage(`${type}-photo`, 'edit-photo');
521
+ // 重新生成二维码
522
+ generateQRCode(type);
523
+ }
524
+ function updateIfChanged(targetId, sourceId) {
525
+ const targetElement = document.getElementById(targetId);
526
+ const newValue = document.getElementById(sourceId).value;
527
+ if (targetElement.textContent !== newValue) {
528
+ targetElement.textContent = newValue;
529
+ }
530
+ }
531
+ function updateImage(targetId, sourceId) {
532
+ const file = document.getElementById(sourceId).files[0];
533
+ if (file) {
534
+ const reader = new FileReader();
535
+ reader.onload = function(e) {
536
+ const img = new Image();
537
+ img.onload = function() {
538
+ const targetElement = document.getElementById(targetId);
539
+ targetElement.style.backgroundImage = `url(${e.target.result})`;
540
+ targetElement.style.backgroundSize = 'cover';
541
+ targetElement.style.backgroundPosition = 'center';
542
+ }
543
+ img.src = e.target.result;
544
+ }
545
+ reader.readAsDataURL(file);
546
+ }
547
+ }
548
+ // 为所有输入字段添加事件监听器,实现自动更新
549
+ document.querySelectorAll('.edit-form input, .edit-form textarea').forEach(input => {
550
+ input.addEventListener('input', updateCard);
551
+ });
552
+ document.getElementById('card-type').addEventListener('change', updateCard);
553
+ function exportToImages() {
554
+ const type = document.getElementById('card-type').value;
555
+ const card = document.querySelector(`.id-card.${type}`);
556
+ const cardInner = card.querySelector('.id-card-inner');
557
+ const frontSide = card.querySelector('.id-card-front');
558
+ const backSide = card.querySelector('.id-card-back');
559
+ // 导出正面
560
+ html2canvas(frontSide, { scale: 2 }).then(canvas => {
561
+ saveAs(canvas.toDataURL(), `${type}_id_card_front.png`);
562
+
563
+ // 在捕获背面之前,移除翻转效果
564
+ cardInner.style.transform = 'rotateY(0deg)';
565
+ backSide.style.transform = 'rotateY(0deg)';
566
+
567
+ // 给DOM一点时间来更新
568
+ setTimeout(() => {
569
+ // 导出背面
570
+ html2canvas(backSide, { scale: 2 }).then(canvas => {
571
+ saveAs(canvas.toDataURL(), `${type}_id_card_back.png`);
572
+
573
+ // 恢复原有的翻转效果
574
+ cardInner.style.transform = '';
575
+ backSide.style.transform = '';
576
+ });
577
+ }, 100);
578
+ });
579
+ }
580
+ // 辅助函数:将数据URL保存为文件
581
+ function saveAs(uri, filename) {
582
+ var link = document.createElement('a');
583
+ if (typeof link.download === 'string') {
584
+ link.href = uri;
585
+ link.download = filename;
586
+ document.body.appendChild(link);
587
+ link.click();
588
+ document.body.removeChild(link);
589
+ } else {
590
+ window.open(uri);
591
+ }
592
+ }
593
+ </script>
594
+ </body>
595
+ </html>