File size: 60,296 Bytes
cad2e0b |
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 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI学习助手</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<!-- KaTeX 用于渲染数学公式 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css">
<!-- Highlight.js 样式 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
:root {
/* 主要配色 */
--primary-color: #0f2d49;
--primary-light: #234a70;
--secondary-color: #4a6cfd;
--secondary-light: #7b91ff;
--tertiary-color: #f7f9fe;
/* 功能颜色 */
--success-color: #10b981;
--success-light: #d1fae5;
--warning-color: #f59e0b;
--warning-light: #fef3c7;
--danger-color: #ef4444;
--danger-light: #fee2e2;
--info-color: #3b82f6;
--info-light: #dbeafe;
/* 中性色 */
--neutral-50: #f9fafb;
--neutral-100: #f3f4f6;
--neutral-200: #e5e7eb;
--neutral-300: #d1d5db;
--neutral-400: #9ca3af;
--neutral-500: #6b7280;
--neutral-600: #4b5563;
--neutral-700: #374151;
--neutral-800: #1f2937;
--neutral-900: #111827;
/* 界面元素 */
--border-radius-sm: 0.25rem;
--border-radius: 0.375rem;
--border-radius-lg: 0.5rem;
--border-radius-xl: 0.75rem;
--border-radius-xxl: 1rem;
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
--shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
--shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
--transition-base: all 0.2s ease-in-out;
--transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
--font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
body {
font-family: var(--font-family);
margin: 0;
padding: 0;
height: 100vh;
background-color: var(--neutral-50);
color: var(--neutral-800);
display: flex;
flex-direction: column;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* 头部样式 */
.header {
background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
color: white;
padding: 1rem 1.5rem;
box-shadow: var(--shadow-md);
position: relative;
z-index: 10;
}
.header-content {
max-width: 1600px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.header h1 {
margin: 0;
font-size: 1.5rem;
font-weight: 600;
color: white;
display: flex;
align-items: center;
}
.header h1 i {
margin-right: 0.75rem;
color: rgba(255, 255, 255, 0.8);
}
.header .badge {
background-color: rgba(255, 255, 255, 0.15);
color: white;
font-weight: 500;
padding: 0.35em 0.75em;
font-size: 0.85rem;
border-radius: 9999px;
}
/* 主容器样式 */
.main-container {
flex: 1;
display: flex;
max-width: 1600px;
margin: 0 auto;
padding: 1.5rem;
width: 100%;
box-sizing: border-box;
height: calc(100vh - 70px); /* Header height + padding */
overflow: hidden;
}
.chat-container {
flex: 1;
display: flex;
flex-direction: column;
background-color: white;
border-radius: var(--border-radius-xl);
box-shadow: var(--shadow);
overflow: hidden;
height: 100%;
max-width: 800px;
margin: 0 auto;
transition: var(--transition-smooth);
position: relative;
}
/* 聊天对话区域样式 */
.chat-messages {
flex: 1;
overflow-y: auto;
padding: 1.5rem;
display: flex;
flex-direction: column;
background-color: var(--neutral-50);
gap: 1rem;
scroll-behavior: smooth;
}
/* 自定义滚动条 */
.chat-messages::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.chat-messages::-webkit-scrollbar-track {
background: var(--neutral-100);
border-radius: 10px;
}
.chat-messages::-webkit-scrollbar-thumb {
background: var(--neutral-300);
border-radius: 10px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
background: var(--neutral-400);
}
/* 消息气泡样式 */
.message {
max-width: 85%;
border-radius: var(--border-radius-lg);
padding: 1rem;
position: relative;
line-height: 1.5;
box-shadow: var(--shadow-sm);
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
}
.message .message-content {
padding: 0 10px;
margin: 0;
}
.user-message {
background: linear-gradient(135deg, #e9f5ff, #c2e4ff);
align-self: flex-end;
color: var(--primary-color);
border-bottom-right-radius: 0.2rem;
border-left: 1px solid rgba(74, 108, 253, 0.1);
border-top: 1px solid rgba(255, 255, 255, 0.5);
}
.bot-message {
background-color: white;
align-self: flex-start;
color: var(--neutral-800);
border-bottom-left-radius: 0.2rem;
border-left: 3px solid var(--secondary-color);
box-shadow: var(--shadow);
}
/* 输入区域样式 */
.input-container {
padding: 1rem 1.5rem;
border-top: 1px solid var(--neutral-200);
background-color: white;
position: relative;
}
.input-row {
display: flex;
gap: 0.75rem;
position: relative;
}
.input-field {
flex: 1;
padding: 0.85rem 1rem;
border: 1px solid var(--neutral-200);
border-radius: var(--border-radius-lg);
resize: none;
font-size: 0.95rem;
box-shadow: var(--shadow-inner);
transition: var(--transition-base);
}
.input-field:focus {
outline: none;
border-color: var(--secondary-color);
box-shadow: 0 0 0 3px rgba(74, 108, 253, 0.15);
}
.send-button {
padding: 0 1.25rem;
background: linear-gradient(135deg, var(--secondary-color), var(--secondary-light));
color: white;
border: none;
border-radius: var(--border-radius-lg);
cursor: pointer;
font-weight: 500;
transition: var(--transition-base);
display: flex;
align-items: center;
justify-content: center;
}
.send-button:hover {
box-shadow: 0 4px 10px rgba(74, 108, 253, 0.25);
transform: translateY(-1px);
}
.send-button:disabled {
background: var(--neutral-300);
cursor: not-allowed;
transform: none;
box-shadow: none;
}
/* 插件容器样式 */
.plugin-container {
display: none;
flex-direction: column;
background-color: white;
border-radius: var(--border-radius-xl);
box-shadow: var(--shadow);
overflow: hidden;
height: 100%;
flex: 2;
margin-left: 1.5rem;
transition: var(--transition-smooth);
}
.plugin-header {
padding: 0.85rem 1.25rem;
border-bottom: 1px solid var(--neutral-200);
background-color: var(--neutral-50);
display: flex;
justify-content: space-between;
align-items: center;
}
.plugin-title {
margin: 0;
font-size: 1rem;
font-weight: 600;
color: var(--primary-color);
display: flex;
align-items: center;
}
.plugin-title i {
margin-right: 0.5rem;
color: var(--secondary-color);
}
.plugin-close {
width: 32px;
height: 32px;
background: var(--neutral-100);
border: none;
border-radius: 50%;
cursor: pointer;
font-size: 0.85rem;
color: var(--neutral-700);
display: flex;
align-items: center;
justify-content: center;
transition: var(--transition-base);
}
.plugin-close:hover {
background-color: var(--neutral-200);
color: var(--neutral-900);
}
.plugin-content {
flex: 1;
overflow-y: auto;
padding: 0;
background-color: var(--neutral-50);
}
/* 当插件激活时的样式 */
.main-container.with-plugin .chat-container {
max-width: 380px;
margin: 0;
}
/* 代码块样式 */
pre {
margin: 1rem 0;
padding: 1rem;
background-color: var(--neutral-800);
border-radius: var(--border-radius);
overflow-x: auto;
position: relative;
}
pre code {
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
font-size: 0.9rem;
color: #e5e7eb;
padding: 0;
background: none;
}
.copy-button {
position: absolute;
top: 0.5rem;
right: 0.5rem;
padding: 0.25rem 0.5rem;
background-color: rgba(255, 255, 255, 0.1);
color: rgba(255, 255, 255, 0.6);
border: none;
border-radius: var(--border-radius-sm);
font-size: 0.75rem;
cursor: pointer;
transition: var(--transition-base);
display: flex;
align-items: center;
gap: 0.25rem;
}
.copy-button:hover {
background-color: rgba(255, 255, 255, 0.2);
color: rgba(255, 255, 255, 0.9);
}
/* 代码执行结果样式 */
.code-result {
margin-top: 0.5rem;
padding: 0.75rem;
background-color: var(--neutral-900);
border-radius: var(--border-radius);
color: white;
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
font-size: 0.85rem;
white-space: pre-wrap;
}
/* 内联代码样式 */
code:not(pre code) {
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
font-size: 0.9em;
color: var(--primary-color);
background-color: var(--neutral-100);
padding: 0.2em 0.4em;
border-radius: 3px;
}
/* 参考资料样式 */
.reference-container {
margin-top: 1rem;
border-top: 1px dashed var(--neutral-300);
padding-top: 0.75rem;
}
.reference-toggle {
color: var(--neutral-600);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
display: flex;
align-items: center;
transition: var(--transition-base);
}
.reference-toggle:hover {
color: var(--secondary-color);
}
.reference-toggle i {
margin-right: 0.35rem;
font-size: 0.9rem;
}
.reference-content {
display: none;
margin-top: 0.75rem;
padding: 0.75rem;
background-color: var(--neutral-100);
border-radius: var(--border-radius);
font-size: 0.85rem;
}
.reference-item {
margin-bottom: 0.75rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--neutral-200);
}
.reference-item:last-child {
margin-bottom: 0;
padding-bottom: 0;
border-bottom: none;
}
.reference-item-source {
color: var(--neutral-600);
font-size: 0.8rem;
margin-top: 0.25rem;
}
/* 欢迎消息样式 */
.welcome-message {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
margin-bottom: 1.5rem;
}
.welcome-icon {
width: 64px;
height: 64px;
background: linear-gradient(135deg, var(--secondary-color), var(--secondary-light));
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 1rem;
color: white;
font-size: 2rem;
box-shadow: 0 4px 12px rgba(74, 108, 253, 0.25);
}
.welcome-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--primary-color);
}
.welcome-description {
color: var(--neutral-700);
max-width: 400px;
margin-bottom: 0;
}
/* 思维导图和可视化插件内容样式 */
.visualization-result, .mindmap-result {
padding: 1.5rem;
text-align: center;
}
.visualization-image, .mindmap-image {
max-width: 100%;
border-radius: var(--border-radius);
box-shadow: var(--shadow);
}
/* 响应式样式 */
@media (max-width: 1200px) {
.main-container.with-plugin .chat-container {
max-width: 320px;
}
}
@media (max-width: 992px) {
.main-container {
flex-direction: column;
padding: 1rem;
}
.main-container.with-plugin .chat-container {
max-width: 100%;
margin-bottom: 1rem;
height: 40vh;
}
.plugin-container {
margin-left: 0;
height: calc(60vh - 32px);
}
}
@media (max-width: 768px) {
.main-container {
padding: 0.75rem;
}
.message {
max-width: 95%;
}
}
/* 增强的卡塔赫和Markdown样式 */
.katex {
font-size: 1.1em;
}
.message h1, .message h2, .message h3,
.message h4, .message h5, .message h6 {
margin-top: 1em;
margin-bottom: 0.5em;
line-height: 1.3;
}
.message h1 {
font-size: 1.6em;
border-bottom: 1px solid var(--neutral-200);
padding-bottom: 0.3em;
}
.message h2 {
font-size: 1.4em;
border-bottom: 1px solid var(--neutral-200);
padding-bottom: 0.3em;
}
.message h3 {
font-size: 1.2em;
}
.message h4 {
font-size: 1.1em;
}
.message h5, .message h6 {
font-size: 1em;
}
.message p {
margin: 0.5em 0;
}
.message ul, .message ol {
margin: 0.5em 0;
padding-left: 1.5em;
}
.message li {
margin: 0.25em 0;
}
.message blockquote {
margin: 0.5em 0;
padding-left: 1em;
border-left: 4px solid var(--neutral-300);
color: var(--neutral-700);
}
.message img {
max-width: 100%;
border-radius: var(--border-radius);
}
.message table {
border-collapse: collapse;
margin: 1em 0;
width: 100%;
}
.message table th,
.message table td {
border: 1px solid var(--neutral-300);
padding: 0.5em;
}
.message table th {
background-color: var(--neutral-100);
font-weight: 600;
}
.message table tr:nth-child(even) {
background-color: var(--neutral-50);
}
/* 动画效果 */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message {
animation: fadeIn 0.3s ease forwards;
}
/* 输入提示区域 */
.input-suggestions {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: white;
border-top-left-radius: var(--border-radius-lg);
border-top-right-radius: var(--border-radius-lg);
box-shadow: var(--shadow-md);
padding: 0.75rem;
display: none;
border: 1px solid var(--neutral-200);
border-bottom: none;
}
.suggestion-title {
font-size: 0.85rem;
font-weight: 600;
color: var(--neutral-700);
margin-bottom: 0.5rem;
}
.suggestion-buttons {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.suggestion-button {
padding: 0.5rem 0.75rem;
background-color: var(--neutral-100);
border: 1px solid var(--neutral-200);
border-radius: var(--border-radius);
font-size: 0.85rem;
color: var(--neutral-800);
cursor: pointer;
transition: var(--transition-base);
}
.suggestion-button:hover {
background-color: var(--secondary-light);
color: white;
border-color: var(--secondary-light);
}
/* 打字机效果 */
.typing-indicator {
display: inline-block;
margin-left: 5px;
}
.typing-dot {
display: inline-block;
width: 6px;
height: 6px;
border-radius: 50%;
background-color: var(--neutral-500);
margin-right: 3px;
animation: typingDot 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
0%, 60%, 100% { transform: translateY(0); }
30% { transform: translateY(-5px); }
}
/* 打字机控制样式 */
.typewriter-controls {
display: flex;
gap: 8px;
margin-top: 12px;
align-items: center;
justify-content: flex-end;
}
.typewriter-btn {
width: 32px;
height: 32px;
border-radius: 50%;
border: none;
background-color: var(--neutral-100);
color: var(--neutral-600);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: var(--transition-base);
}
.typewriter-btn:hover {
background-color: var(--neutral-200);
color: var(--neutral-900);
}
.typewriter-btn.pause-btn {
color: var(--danger-color);
}
.typewriter-btn.continue-btn {
color: var(--success-color);
}
.typewriter-btn.speed-btn {
color: var(--warning-color);
}
/* 打字机光标效果 */
.typing-cursor {
display: inline-block;
width: 2px;
height: 1em;
background-color: var(--neutral-700);
margin-left: 2px;
vertical-align: middle;
animation: blink 1s infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
/* 确保代码块内文本溢出有滚动条 */
pre {
position: relative;
white-space: pre;
word-wrap: normal;
overflow-x: auto;
}
/* 保证消息区内容正常显示 */
.message-content p {
word-break: break-word;
}
/* 确保代码复制按钮正确显示 */
.copy-button {
opacity: 0.8;
z-index: 10;
}
</style>
</head>
<body>
<header class="header">
<div class="header-content">
<h1><i class="bi bi-mortarboard"></i> {{ agent_name }}</h1>
<div>
<span class="badge">AI学习助手</span>
</div>
</div>
</header>
<div class="main-container" id="main-container">
<div class="chat-container">
<div class="chat-messages" id="chat-messages">
<div class="welcome-message">
<div class="welcome-icon">
<i class="bi bi-robot"></i>
</div>
<h2 class="welcome-title">欢迎使用 {{ agent_name }}</h2>
{% if agent_description %}
<p class="welcome-description">{{ agent_description }}</p>
{% else %}
<p class="welcome-description">我是您的AI学习助手,有任何问题都可以随时向我提问</p>
{% endif %}
</div>
<div class="message bot-message">
<div class="message-content">
<p>您好!我是{{ agent_name }},很高兴能够帮助您学习。请问有什么我可以协助您的问题吗?</p>
</div>
</div>
</div>
<div class="input-container">
<div class="input-suggestions" id="input-suggestions">
<div class="suggestion-title">推荐问题:</div>
<div class="suggestion-buttons">
<button class="suggestion-button">介绍一下这门课程的主要内容</button>
<button class="suggestion-button">这门课程有哪些重点知识?</button>
<button class="suggestion-button">请给我一些学习建议</button>
</div>
</div>
<div class="input-row">
<textarea class="input-field" id="user-input" placeholder="输入您的问题..." rows="2"></textarea>
<button class="send-button" id="send-button">
<i class="bi bi-send"></i>
</button>
</div>
</div>
</div>
<!-- 代码执行插件 -->
<div class="plugin-container code-plugin" id="code-plugin">
<div class="plugin-header">
<h3 class="plugin-title"><i class="bi bi-code-square"></i> Python代码执行</h3>
<button class="plugin-close" id="close-code-plugin">
<i class="bi bi-x-lg"></i>
</button>
</div>
<div class="plugin-content">
<iframe id="code-execution-frame" src="" style="width: 100%; height: 100%; border: none;"></iframe>
</div>
</div>
<!-- 3D可视化插件 -->
<div class="plugin-container visualization-plugin" id="visualization-plugin">
<div class="plugin-header">
<h3 class="plugin-title"><i class="bi bi-graph-up"></i> 3D可视化</h3>
<button class="plugin-close" id="close-visualization-plugin">
<i class="bi bi-x-lg"></i>
</button>
</div>
<div class="plugin-content">
<div class="visualization-result" id="visualization-result">
<div class="text-center py-4">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">加载中...</span>
</div>
<p class="mt-3">正在准备3D可视化...</p>
</div>
</div>
</div>
</div>
<!-- 思维导图插件 -->
<div class="plugin-container mindmap-plugin" id="mindmap-plugin">
<div class="plugin-header">
<h3 class="plugin-title"><i class="bi bi-diagram-3"></i> 思维导图</h3>
<button class="plugin-close" id="close-mindmap-plugin">
<i class="bi bi-x-lg"></i>
</button>
</div>
<div class="plugin-content">
<div class="mindmap-result" id="mindmap-result">
<div class="text-center py-4">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">加载中...</span>
</div>
<p class="mt-3">正在生成思维导图...</p>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js"></script>
<script>
// 全局变量
const agentId = "{{ agent_id }}";
const token = "{{ token }}";
let executionContext = null;
const mainContainer = document.getElementById('main-container');
let isTyping = false;
let typewriterInterval = null;
let typewriterPaused = false;
let currentMessageQueue = [];
let typewriterSpeed = 20; // 打字速度(ms)
let currentMessageElement = null;
// DOM元素
const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
// 代码执行插件元素
const codePlugin = document.getElementById('code-plugin');
const closeCodePlugin = document.getElementById('close-code-plugin');
const codeExecutionFrame = document.getElementById('code-execution-frame');
// 3D可视化插件元素
const visualizationPlugin = document.getElementById('visualization-plugin');
const closeVisualizationPlugin = document.getElementById('close-visualization-plugin');
const visualizationResult = document.getElementById('visualization-result');
// 思维导图插件元素
const mindmapPlugin = document.getElementById('mindmap-plugin');
const closeMindmapPlugin = document.getElementById('close-mindmap-plugin');
const mindmapResult = document.getElementById('mindmap-result');
// 输入建议
const inputSuggestions = document.getElementById('input-suggestions');
// Markdown-it 实例
const md = window.markdownit({
html: false,
linkify: true,
typographer: true,
breaks: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
const highlighted = hljs.highlight(str, { language: lang }).value;
return `<pre><code class="hljs language-${lang}">${highlighted}</code><button class="copy-button" onclick="copyToClipboard(this)"><i class="bi bi-clipboard"></i> 复制</button></pre>`;
} catch (__) {}
}
return `<pre><code class="hljs">${md.utils.escapeHtml(str)}</code><button class="copy-button" onclick="copyToClipboard(this)"><i class="bi bi-clipboard"></i> 复制</button></pre>`;
}
});
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
// 初始化发送按钮事件
sendButton.addEventListener('click', sendMessage);
// 初始化输入框回车事件
userInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// 初始化问题建议按钮
document.querySelectorAll('.suggestion-button').forEach(button => {
button.addEventListener('click', function() {
userInput.value = this.textContent;
sendMessage();
});
});
// 初始化插件关闭事件
closeCodePlugin.addEventListener('click', () => {
codePlugin.style.display = 'none';
// 清空iframe源以停止任何运行中的代码
codeExecutionFrame.src = '';
updateMainContainerLayout();
});
closeVisualizationPlugin.addEventListener('click', () => {
visualizationPlugin.style.display = 'none';
updateMainContainerLayout();
});
closeMindmapPlugin.addEventListener('click', () => {
mindmapPlugin.style.display = 'none';
updateMainContainerLayout();
});
// 焦点事件
userInput.addEventListener('focus', function() {
// inputSuggestions.style.display = 'block';
});
userInput.addEventListener('blur', function(e) {
// 延迟执行,以便点击建议按钮事件先触发
setTimeout(() => {
// inputSuggestions.style.display = 'none';
}, 100);
});
});
// 更新主容器布局
function updateMainContainerLayout() {
// 检查是否有任何插件处于显示状态
const isAnyPluginVisible =
codePlugin.style.display === 'flex' ||
visualizationPlugin.style.display === 'flex' ||
mindmapPlugin.style.display === 'flex';
// 更新主容器类名
if (isAnyPluginVisible) {
mainContainer.classList.add('with-plugin');
} else {
mainContainer.classList.remove('with-plugin');
}
}
// 发送消息
async function sendMessage() {
const message = userInput.value.trim();
if (!message || isTyping) return;
// 添加用户消息
addMessage(message, true);
// 清空输入框
userInput.value = '';
// 禁用发送按钮
sendButton.disabled = true;
isTyping = true;
// 添加机器人正在输入的指示
const typingIndicator = addTypingIndicator();
try {
// 发送请求
const response = await fetch(`/api/student/chat/${agentId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: message,
token: token
})
});
const data = await response.json();
// 移除输入指示器
if (typingIndicator) {
typingIndicator.remove();
}
if (data.success) {
// 处理回复内容,移除参考来源部分
const processedContent = processResponseContent(data.message);
// 添加机器人回复(带打字机效果)
const messageElement = addMessage(processedContent, false);
// 添加参考信息(如果有)
if (data.references && data.references.length > 0) {
// 等待打字机效果完成后添加参考信息
const checkTypewriterComplete = setInterval(() => {
if (!typewriterInterval) {
clearInterval(checkTypewriterComplete);
addReferences(messageElement, data.references);
}
}, 100);
}
// 检查是否需要显示工具
if (data.tools && data.tools.length > 0) {
// 隐藏所有插件
hideAllPlugins();
// 使用新的插件激活函数
activatePlugins(data.message, data.tools);
}
} else {
// 添加错误消息
addMessage(`错误: ${data.message}`, false);
}
} catch (error) {
console.error('发送请求出错:', error);
// 移除输入指示器
if (typingIndicator) {
typingIndicator.remove();
}
addMessage('发送请求时出错,请重试', false);
} finally {
// 恢复发送按钮
sendButton.disabled = false;
isTyping = false;
}
}
// 添加打字指示器
function addTypingIndicator() {
const botMessage = document.createElement('div');
botMessage.className = 'message bot-message';
const content = document.createElement('div');
content.className = 'message-content';
content.innerHTML = `
<p>
<span class="typing-indicator">
<span class="typing-dot"></span>
<span class="typing-dot"></span>
<span class="typing-dot"></span>
</span>
</p>
`;
botMessage.appendChild(content);
chatMessages.appendChild(botMessage);
// 滚动到底部
chatMessages.scrollTop = chatMessages.scrollHeight;
return botMessage;
}
// 处理回复内容,移除参考来源部分
function processResponseContent(content) {
// 移除 "===参考来源开始===" 到 "===参考来源结束===" 之间的内容
return content.replace(/===参考来源开始===[\s\S]*?===参考来源结束===/, '');
}
// 添加参考信息显示函数
function addReferences(messageElement, references) {
// 创建参考容器
const referenceContainer = document.createElement('div');
referenceContainer.className = 'reference-container';
// 创建参考切换按钮
const toggleButton = document.createElement('div');
toggleButton.className = 'reference-toggle';
toggleButton.innerHTML = '<i class="bi bi-journal-text"></i> 参考来源';
// 创建参考内容
const referenceContent = document.createElement('div');
referenceContent.className = 'reference-content';
// 添加参考项
references.forEach(ref => {
const refItem = document.createElement('div');
refItem.className = 'reference-item';
refItem.innerHTML = `
<div><strong>[${ref.index}]</strong> ${ref.summary}</div>
<div class="reference-item-source">来源: ${ref.file_name}</div>
`;
referenceContent.appendChild(refItem);
});
// 添加切换功能
toggleButton.addEventListener('click', () => {
if (referenceContent.style.display === 'block') {
referenceContent.style.display = 'none';
toggleButton.innerHTML = '<i class="bi bi-journal-text"></i> 参考来源';
} else {
referenceContent.style.display = 'block';
toggleButton.innerHTML = '<i class="bi bi-journal-arrow-up"></i> 收起参考来源';
}
});
// 组装并添加到消息
referenceContainer.appendChild(toggleButton);
referenceContainer.appendChild(referenceContent);
messageElement.appendChild(referenceContainer);
}
// 添加消息函数
function addMessage(content, isUser) {
const messageDiv = document.createElement('div');
messageDiv.className = isUser ? 'message user-message' : 'message bot-message';
const messageContent = document.createElement('div');
messageContent.className = 'message-content';
if (isUser) {
// 直接显示用户消息,仅替换换行符
messageContent.innerHTML = `<p>${content.replace(/\n/g, '<br>')}</p>`;
} else {
// 为AI消息添加打字机效果
messageContent.innerHTML = '<p></p>';
// 添加控制按钮
const controlsDiv = document.createElement('div');
controlsDiv.className = 'typewriter-controls';
controlsDiv.innerHTML = `
<button class="typewriter-btn pause-btn" title="暂停"><i class="bi bi-pause-fill"></i></button>
<button class="typewriter-btn continue-btn" style="display:none;" title="继续"><i class="bi bi-play-fill"></i></button>
<button class="typewriter-btn speed-btn" title="加速"><i class="bi bi-lightning-fill"></i></button>
`;
messageContent.appendChild(controlsDiv);
// 添加事件监听器
const pauseBtn = controlsDiv.querySelector('.pause-btn');
const continueBtn = controlsDiv.querySelector('.continue-btn');
const speedBtn = controlsDiv.querySelector('.speed-btn');
pauseBtn.addEventListener('click', () => {
pauseTypewriter();
pauseBtn.style.display = 'none';
continueBtn.style.display = 'inline-block';
});
continueBtn.addEventListener('click', () => {
continueTypewriter();
continueBtn.style.display = 'none';
pauseBtn.style.display = 'inline-block';
});
speedBtn.addEventListener('click', () => {
toggleTypewriterSpeed();
});
// 开始打字机效果
startTypewriter(content, messageContent.querySelector('p'));
}
messageDiv.appendChild(messageContent);
chatMessages.appendChild(messageDiv);
// 滚动到底部
chatMessages.scrollTop = chatMessages.scrollHeight;
return messageDiv;
}
// 打字机效果函数
function startTypewriter(text, element) {
// 清除之前的打字机效果(如果有)
if (typewriterInterval) {
clearInterval(typewriterInterval);
}
// 保存当前消息元素引用
currentMessageElement = element;
// 初始化
typewriterPaused = false;
let mdContent = md.render(text);
// 将HTML内容转换为文本节点和元素节点的队列
parseHTMLToQueue(mdContent);
// 开始逐字显示
typewriterInterval = setInterval(typeNextChar, typewriterSpeed);
}
// 解析HTML到队列
function parseHTMLToQueue(html) {
// 清空队列
currentMessageQueue = [];
// 创建临时容器
const tempDiv = document.createElement('div');
tempDiv.innerHTML = html;
// 递归处理所有子节点
processNode(tempDiv);
}
// 递归处理节点
function processNode(node) {
// 遍历节点的所有子节点
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes[i];
if (child.nodeType === Node.TEXT_NODE) {
// 文本节点,将每个字符加入队列
for (let j = 0; j < child.textContent.length; j++) {
currentMessageQueue.push({
type: 'text',
content: child.textContent[j]
});
}
} else if (child.nodeType === Node.ELEMENT_NODE) {
// 元素节点,将开始标签加入队列
currentMessageQueue.push({
type: 'element-start',
tagName: child.tagName.toLowerCase(),
attributes: Array.from(child.attributes)
});
// 递归处理子节点
processNode(child);
// 将结束标签加入队列
currentMessageQueue.push({
type: 'element-end',
tagName: child.tagName.toLowerCase()
});
}
}
}
// 显示下一个字符
function typeNextChar() {
if (typewriterPaused || currentMessageQueue.length === 0 || !currentMessageElement) {
return;
}
let item = currentMessageQueue.shift();
if (item.type === 'text') {
// 处理文本
currentMessageElement.innerHTML += item.content;
} else if (item.type === 'element-start') {
// 处理元素开始标签
const el = document.createElement(item.tagName);
if (item.attributes) {
item.attributes.forEach(attr => {
el.setAttribute(attr.name, attr.value);
});
}
currentMessageElement.appendChild(el);
// 更新当前元素引用
currentMessageElement = el;
} else if (item.type === 'element-end') {
// 处理元素结束标签
// 将当前元素引用更新为父元素
if (currentMessageElement.parentElement) {
currentMessageElement = currentMessageElement.parentElement;
}
}
// 滚动到底部
chatMessages.scrollTop = chatMessages.scrollHeight;
// 如果队列为空,需要渲染数学公式
if (currentMessageQueue.length === 0) {
clearInterval(typewriterInterval);
typewriterInterval = null;
// 找到最近添加的机器人消息
const botMessage = chatMessages.querySelector('.bot-message:last-child');
if (botMessage) {
try {
renderMathInElement(botMessage.querySelector('.message-content'), {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
throwOnError: false
});
} catch (e) {
console.error('渲染LaTeX出错:', e);
}
// 为代码块添加复制按钮
botMessage.querySelectorAll('pre').forEach(pre => {
if (!pre.querySelector('.copy-button')) {
const copyButton = document.createElement('button');
copyButton.className = 'copy-button';
copyButton.innerHTML = '<i class="bi bi-clipboard"></i> 复制';
copyButton.onclick = function() { copyToClipboard(this); };
pre.appendChild(copyButton);
}
});
}
}
}
// 暂停打字机效果
function pauseTypewriter() {
typewriterPaused = true;
}
// 继续打字机效果
function continueTypewriter() {
typewriterPaused = false;
// 如果之前的定时器已清除,重新启动
if (!typewriterInterval && currentMessageQueue.length > 0) {
typewriterInterval = setInterval(typeNextChar, typewriterSpeed);
}
}
// 切换打字速度
function toggleTypewriterSpeed() {
if (typewriterSpeed === 20) {
typewriterSpeed = 5; // 快速
} else {
typewriterSpeed = 20; // 正常速度
}
// 如果正在运行,更新速度
if (typewriterInterval) {
clearInterval(typewriterInterval);
typewriterInterval = setInterval(typeNextChar, typewriterSpeed);
}
}
// 复制代码到剪贴板
function copyToClipboard(button) {
const codeBlock = button.parentNode.querySelector('code');
const text = codeBlock.textContent;
navigator.clipboard.writeText(text).then(() => {
button.innerHTML = '<i class="bi bi-check"></i> 已复制';
setTimeout(() => {
button.innerHTML = '<i class="bi bi-clipboard"></i> 复制';
}, 2000);
}).catch(err => {
console.error('复制失败:', err);
button.innerHTML = '<i class="bi bi-exclamation-triangle"></i> 失败';
setTimeout(() => {
button.innerHTML = '<i class="bi bi-clipboard"></i> 复制';
}, 2000);
});
}
// 隐藏所有插件
function hideAllPlugins() {
codePlugin.style.display = 'none';
visualizationPlugin.style.display = 'none';
mindmapPlugin.style.display = 'none';
updateMainContainerLayout();
}
// 提取代码块
function extractCodeBlocks(message) {
const codeBlocks = [];
const codeRegex = /```python\n([\s\S]*?)\n```/g;
let match;
while ((match = codeRegex.exec(message)) !== null) {
codeBlocks.push(match[1]);
}
return codeBlocks;
}
// 提取3D可视化函数代码
function extract3DVisualizationCode(message) {
// 尝试提取函数代码块
const codeRegex = /```python\s*(import[\s\S]*?def create_3d_plot\(\):[\s\S]*?return[\s\S]*?})\s*```/i;
const match = codeRegex.exec(message);
if (match) {
return match[1].trim();
}
return null;
}
// 提取思维导图内容
function extractMindmapContent(message) {
// 尝试提取@startmindmap和@endmindmap之间的内容
const mindmapRegex = /@startmindmap\n([\s\S]*?)@endmindmap/;
const match = mindmapRegex.exec(message);
if (match) {
return `@startmindmap\n${match[1]}\n@endmindmap`;
}
return null;
}
// 激活代码执行插件
function activateCodePlugin(message) {
// 提取代码块
const codeBlocks = extractCodeBlocks(message);
if (codeBlocks.length > 0) {
const isAlreadyVisible = codePlugin.style.display === 'flex';
// 显示插件容器
codePlugin.style.display = 'flex';
updateMainContainerLayout();
// 获取iframe
const iframe = document.getElementById('code-execution-frame');
// 如果插件已经可见且iframe已加载
if (isAlreadyVisible && iframe.contentWindow) {
// 发送新代码到现有iframe
iframe.contentWindow.postMessage({
type: 'setCode',
code: codeBlocks[0]
}, '*');
} else {
// 设置iframe源
let src = '/code_execution.html';
if (codeBlocks.length > 0) {
src += `?code=${encodeURIComponent(codeBlocks[0])}`;
}
iframe.src = src;
// 设置iframe加载事件处理程序
iframe.onload = function() {
if (codeBlocks.length > 0) {
iframe.contentWindow.postMessage({
type: 'setCode',
code: codeBlocks[0]
}, '*');
}
};
}
}
}
// 激活3D可视化插件
function activate3DVisualization(message) {
const code = extract3DVisualizationCode(message);
if (code) {
// 显示插件容器
visualizationPlugin.style.display = 'flex';
updateMainContainerLayout();
// 显示加载状态
visualizationResult.innerHTML = `
<div class="text-center py-4">
<div class="spinner-border" style="color: var(--secondary-color);" role="status">
<span class="visually-hidden">生成中...</span>
</div>
<p class="mt-3">正在生成3D图形,请稍候...</p>
</div>
`;
// 自动生成可视化
fetch('/api/visualization/3d-surface', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ code: code })
})
.then(response => response.json())
.then(data => {
if (data.success) {
// 直接嵌入HTML
visualizationResult.innerHTML = `
<div class="visualization-iframe-container" style="width:100%; height:500px;">
<iframe src="${data.html_url}" style="width:100%; height:100%; border:none;"></iframe>
</div>
<div class="text-center mt-3">
<p>3D图形生成成功</p>
<a href="${data.html_url}" class="btn btn-sm btn-outline-primary" target="_blank">
<i class="bi bi-arrows-fullscreen"></i> 全屏查看
</a>
</div>
`;
} else {
visualizationResult.innerHTML = `
<div class="alert alert-danger">
<i class="bi bi-exclamation-triangle-fill me-2"></i>
生成失败: ${data.message}
</div>
`;
}
})
.catch(error => {
console.error('生成3D图形出错:', error);
visualizationResult.innerHTML = `
<div class="alert alert-danger">
<i class="bi bi-exclamation-triangle-fill me-2"></i>
生成3D图形时发生错误,请重试
</div>
`;
});
}
}
// 激活思维导图插件
function activateMindmap(message) {
const content = extractMindmapContent(message);
if (content) {
// 显示插件容器
mindmapPlugin.style.display = 'flex';
updateMainContainerLayout();
// 显示加载状态
mindmapResult.innerHTML = `
<div class="text-center py-4">
<div class="spinner-border" style="color: var(--secondary-color);" role="status">
<span class="visually-hidden">生成中...</span>
</div>
<p class="mt-3">正在生成思维导图,请稍候...</p>
</div>
`;
// 自动生成思维导图
fetch('/api/visualization/mindmap', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ content: content })
})
.then(response => response.json())
.then(data => {
if (data.success) {
mindmapResult.innerHTML = `
<div class="text-center">
<img src="${data.url}" class="mindmap-image" alt="思维导图">
<p class="mt-3">生成成功!</p>
<a href="${data.url}" class="btn btn-sm btn-outline-primary mt-2" target="_blank">
<i class="bi bi-download"></i> 下载图片
</a>
</div>
`;
} else {
mindmapResult.innerHTML = `
<div class="alert alert-danger">
<i class="bi bi-exclamation-triangle-fill me-2"></i>
生成失败: ${data.message}
</div>
`;
}
})
.catch(error => {
console.error('生成思维导图出错:', error);
mindmapResult.innerHTML = `
<div class="alert alert-danger">
<i class="bi bi-exclamation-triangle-fill me-2"></i>
生成思维导图时发生错误,请重试
</div>
`;
});
}
}
// 根据消息内容激活适当的插件
function activatePlugins(message, tools) {
// 检查并激活代码执行插件
if (tools.includes('code') && message.includes('```python')) {
activateCodePlugin(message);
}
// 检查并激活3D可视化插件
if (tools.includes('visualization') &&
(message.includes('def create_3d_plot') ||
message.includes('3D') || message.includes('可视化'))) {
activate3DVisualization(message);
}
// 检查并激活思维导图插件
if (tools.includes('mindmap') &&
(message.includes('@startmindmap') ||
message.includes('思维导图'))) {
activateMindmap(message);
}
}
</script>
<!-- 添加highlight.js用于代码高亮 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/python.min.js"></script>
</body>
</html> |