This commit is contained in:
HuangHai
2026-01-20 08:09:13 +08:00
parent b0b4533f57
commit 34501faafb
20 changed files with 2360 additions and 859 deletions

421
static/css/degree.css Normal file
View File

@@ -0,0 +1,421 @@
body {
background: radial-gradient(circle at top, #1e293b 0, #020617 55%, #000 100%);
color: #e5e7eb;
}
.header {
background: rgba(15, 23, 42, 0.95);
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.8);
border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}
.logo {
color: #e5e7eb;
}
.degree-container {
max-width: 1000px;
margin: 40px auto;
padding: 0 20px;
}
.query-section {
background: rgba(15, 23, 42, 0.96);
border-radius: 12px;
padding: 30px;
box-shadow: 0 24px 60px rgba(15, 23, 42, 0.9);
margin-bottom: 30px;
text-align: center;
}
.page-title {
font-size: 32px;
background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 16px;
font-weight: 700;
letter-spacing: -0.025em;
}
.page-subtitle {
margin-bottom: 32px;
color: #94a3b8;
font-size: 16px;
opacity: 0.9;
}
.input-wrapper {
max-width: 700px;
margin: 0 auto;
position: relative;
}
/* 搜索框样式优化 */
.search-input.el-input {
--el-input-border-color: rgba(148, 163, 184, 0.5);
--el-input-hover-border-color: rgba(56, 189, 248, 0.9);
--el-input-focus-border-color: rgba(56, 189, 248, 0.9);
--el-input-bg-color: rgba(15, 23, 42, 0.9);
--el-input-text-color: #e5e7eb;
}
.search-input .el-input__wrapper {
padding-left: 20px;
padding-right: 20px;
box-shadow: 0 2px 18px rgba(15, 23, 42, 0.6);
background-color: rgba(15, 23, 42, 0.9);
border: 1px solid rgba(148, 163, 184, 0.5);
transition: all 0.3s ease;
}
.search-input.el-input-group--append .el-input__wrapper {
border-radius: 24px 0 0 24px;
border-right: none;
}
.search-input:not(.el-input-group--append) .el-input__wrapper {
border-radius: 24px;
}
.search-input .el-input-group__append {
background-color: rgba(56, 189, 248, 0.9);
border: 1px solid rgba(56, 189, 248, 0.9);
border-left: none;
border-radius: 0 24px 24px 0;
padding: 0;
box-shadow: 0 2px 18px rgba(15, 23, 42, 0.6);
}
.search-input .el-input-group__append .el-button,
.search-input .el-input-group__append .el-button.el-button--primary {
border: none;
margin: 0;
padding: 0 30px;
height: 48px;
color: #fff;
background-color: transparent;
font-weight: 600;
font-size: 16px;
transition: all 0.2s;
border-radius: 0;
}
.search-input .el-input-group__append .el-button:hover,
.search-input .el-input-group__append .el-button.el-button--primary:hover {
background-color: rgba(14, 165, 233, 1);
color: #fff;
}
.search-input .el-input-group__append .el-button:active {
transform: scale(0.98);
}
.search-input .el-input__wrapper:hover,
.search-input .el-input__wrapper.is-focus {
box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.9), 0 20px 40px rgba(15, 23, 42, 0.9);
border-color: rgba(56, 189, 248, 0.9);
z-index: 1;
}
.search-input .el-input-group__append:hover {
border-color: rgba(56, 189, 248, 0.9);
}
.search-input .el-input__inner {
height: 48px;
font-size: 16px;
color: #e5e7eb;
}
.search-input .el-input__inner::placeholder {
color: rgba(148, 163, 184, 0.8);
}
.example-tags {
margin-top: 16px;
display: flex;
justify-content: center;
gap: 10px;
flex-wrap: wrap;
}
.example-tag {
cursor: pointer;
transition: all 0.2s;
border-color: rgba(148, 163, 184, 0.6);
color: #cbd5f5;
background-color: rgba(15, 23, 42, 0.8);
}
.example-tag:hover {
transform: translateY(-2px);
border-color: rgba(56, 189, 248, 0.9);
color: #e0f2fe;
background-color: rgba(15, 23, 42, 1);
}
.result-section {
background: rgba(15, 23, 42, 0.96);
border-radius: 12px;
padding: 30px;
box-shadow: 0 24px 60px rgba(15, 23, 42, 0.9);
min-height: 200px;
}
.result-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 15px;
}
.result-title {
font-size: 18px;
font-weight: 600;
color: #e5e7eb;
display: flex;
align-items: center;
gap: 8px;
}
.markdown-body {
font-size: 16px;
line-height: 1.7;
color: #e5e7eb;
}
.markdown-body table {
width: 100%;
border-collapse: collapse;
margin: 16px 0;
}
.markdown-body th,
.markdown-body td {
padding: 12px;
border: 1px solid rgba(51, 65, 85, 0.9);
}
.markdown-body th {
background-color: rgba(30, 64, 175, 0.95);
font-weight: 600;
}
.markdown-body tr:nth-child(even) {
background-color: rgba(15, 23, 42, 0.9);
}
.loading-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 0;
color: rgba(148, 163, 184, 0.9);
}
/* Cursor blink animation for streaming effect */
.cursor-blink {
display: inline-block;
width: 2px;
height: 1em;
background-color: #38bdf8;
vertical-align: text-bottom;
animation: blink 1s step-end infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
/* 二维码容器 */
.qr-sidebar {
position: fixed;
right: 20px;
bottom: 20px;
background: rgba(15, 23, 42, 0.95);
border: 1px solid rgba(148, 163, 184, 0.25);
border-radius: 12px;
padding: 16px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
z-index: 1000;
text-align: center;
transition: all 0.3s ease;
box-sizing: border-box;
}
.qr-sidebar:hover {
transform: translateY(-5px);
border-color: rgba(56, 189, 248, 0.5);
background: rgba(15, 23, 42, 1);
}
.qr-code {
width: 128px;
height: 128px;
background: #fff;
padding: 8px;
border-radius: 8px;
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
overflow: hidden;
}
.qr-code canvas, .qr-code img {
max-width: 100% !important;
max-height: 100% !important;
height: auto !important;
display: block;
}
.qr-text {
font-size: 13px;
font-weight: 500;
color: #94a3b8;
margin: 0;
letter-spacing: 0.5px;
}
/* 响应式调整 */
@media screen and (max-width: 1200px) {
.qr-sidebar {
display: none;
}
}
/* ECharts 图表容器 */
.echarts-container {
width: 100%;
height: 400px;
margin: 24px 0;
background: rgba(15, 23, 42, 0.4);
border: 1px solid rgba(56, 189, 248, 0.1);
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
overflow: hidden;
transition: all 0.3s ease;
}
.echarts-container:hover {
border-color: rgba(56, 189, 248, 0.3);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}
@media (max-width: 768px) {
.echarts-container {
height: 300px;
margin: 16px 0;
padding: 10px !important;
}
.degree-container {
margin-top: 20px !important;
padding: 0 15px;
}
.query-section {
padding: 20px 10px;
}
.page-title {
font-size: 22px;
margin-bottom: 10px;
}
.page-subtitle {
font-size: 14px;
margin-bottom: 20px;
}
.result-section {
padding: 15px;
}
.input-wrapper {
max-width: 100%;
}
.search-input .el-input__inner {
height: 40px;
font-size: 14px;
}
.search-input .el-input-group__append .el-button {
padding: 0 12px;
height: 40px;
font-size: 14px;
}
.example-tags {
gap: 6px;
}
.example-tag {
font-size: 12px;
padding: 0 8px;
}
.result-section {
padding: 15px;
margin-top: 20px;
}
.markdown-body {
font-size: 14px;
}
.markdown-body table {
display: block;
width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
margin: 16px 0;
border-collapse: collapse;
/* 增加一个细小的滚动条样式,提示可以滚动 */
}
.markdown-body table::-webkit-scrollbar {
height: 4px;
}
.markdown-body table::-webkit-scrollbar-thumb {
background: rgba(56, 189, 248, 0.5);
border-radius: 2px;
}
.markdown-body th,
.markdown-body td {
white-space: nowrap;
padding: 10px 15px;
font-size: 13px;
min-width: 100px;
}
/* 手机端首列固定 */
.markdown-body table tr th:first-child,
.markdown-body table tr td:first-child {
position: sticky;
left: 0;
z-index: 2;
box-shadow: 2px 0 5px rgba(0,0,0,0.3);
}
.markdown-body table tr th:first-child {
background-color: #1e40af !important; /* 统一使用深蓝色 */
}
.markdown-body table tr:nth-child(odd) td:first-child {
background-color: #0f172a !important; /* 与容器背景一致 */
}
.markdown-body table tr:nth-child(even) td:first-child {
background-color: #1e293b !important; /* 稍亮的条纹背景 */
}
}

File diff suppressed because one or more lines are too long

724
static/css/style.css Normal file
View File

@@ -0,0 +1,724 @@
:root {
--primary-blue: #0066FF;
--secondary-green: #00C389;
--text-dark: #333333;
--text-light: #666666;
--bg-light: #F5F7FA;
--white: #FFFFFF;
--shadow: 0 4px 20px rgba(0, 102, 255, 0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
color: var(--text-dark);
background-color: var(--white);
line-height: 1.6;
}
/* 顶部导航 */
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
z-index: 1000;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 40px;
}
.logo {
display: flex;
align-items: center;
font-size: 24px;
font-weight: bold;
color: var(--primary-blue);
}
.logo i {
margin-right: 10px;
font-size: 28px;
}
.nav-menu {
display: flex;
align-items: center;
gap: 30px;
}
.nav-item {
position: relative;
font-size: 16px;
color: var(--text-dark);
cursor: pointer;
transition: all 0.3s ease;
}
.nav-item:hover {
color: var(--primary-blue);
}
.nav-item::after {
content: '';
position: absolute;
bottom: -5px;
left: 0;
width: 0;
height: 2px;
background-color: var(--primary-blue);
transition: width 0.3s ease;
}
.nav-item:hover::after {
width: 100%;
}
.header-actions {
display: flex;
align-items: center;
gap: 20px;
}
.btn {
padding: 8px 20px;
border-radius: 25px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
border: none;
outline: none;
}
.btn-primary {
background-color: var(--primary-blue);
color: var(--white);
}
.btn-primary:hover {
background-color: #0052CC;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3);
}
.btn-outline {
background-color: transparent;
border: 1px solid var(--primary-blue);
color: var(--primary-blue);
}
.btn-outline:hover {
background-color: var(--primary-blue);
color: var(--white);
transform: translateY(-2px);
}
/* Hero区域 */
.hero {
margin-top: 70px;
height: calc(100vh - 70px);
background: linear-gradient(135deg, #f5f7fa 0%, #e9f1fb 100%);
position: relative;
overflow: hidden;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 80px;
}
.hero-content {
max-width: 500px;
z-index: 10;
}
.hero-title {
font-size: 48px;
font-weight: bold;
color: var(--primary-blue);
line-height: 1.2;
margin-bottom: 20px;
}
.hero-subtitle {
font-size: 24px;
color: var(--text-light);
margin-bottom: 40px;
}
.hero-cta {
display: flex;
gap: 20px;
}
.hero-image {
position: relative;
width: 50%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.hero-image img {
max-width: 100%;
max-height: 80%;
border-radius: 20px;
box-shadow: var(--shadow);
animation: float 6s ease-in-out infinite;
}
/* 轮播图样式 */
.carousel-container {
position: relative;
width: 100%;
height: 100%;
}
.carousel {
width: 100%;
height: 100%;
position: relative;
}
.carousel-item {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 80px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
.carousel-item.active {
opacity: 1;
z-index: 10;
}
/* 轮播控制按钮 */
.carousel-control {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 50px;
height: 50px;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.8);
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
z-index: 20;
color: var(--primary-blue);
font-size: 24px;
}
.carousel-control:hover {
background-color: var(--white);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transform: translateY(-50%) scale(1.1);
}
.carousel-control.prev {
left: 20px;
}
.carousel-control.next {
right: 20px;
}
/* 轮播指示点 */
.carousel-indicators {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
z-index: 20;
}
.carousel-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.5);
cursor: pointer;
transition: all 0.3s ease;
}
.carousel-indicator.active {
background-color: var(--white);
width: 30px;
border-radius: 6px;
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-20px); }
100% { transform: translateY(0px); }
}
/* 波浪背景 - 使用CSS替代图片 */
.wave {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100px;
background: linear-gradient(135deg, rgba(0,102,255,0.1) 0%, rgba(0,195,137,0.1) 100%);
animation: wave-animation 15s linear infinite;
border-radius: 50% 50% 0 0;
}
@keyframes wave-animation {
0% { transform: translateX(0); }
100% { transform: translateX(-1000px); }
}
/* 核心功能区 */
.features {
padding: 80px 40px;
background-color: var(--white);
}
.section-title {
text-align: center;
font-size: 36px;
font-weight: bold;
color: var(--primary-blue);
margin-bottom: 60px;
position: relative;
}
.section-title::after {
content: '';
position: absolute;
bottom: -15px;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 4px;
background-color: var(--secondary-green);
border-radius: 2px;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 40px;
max-width: 1400px;
margin: 0 auto;
}
/* 新增特色服务区块样式 */
.services {
padding: 80px 40px;
background-color: var(--bg-light);
}
.services-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 40px;
max-width: 1400px;
margin: 0 auto;
}
.service-card {
background-color: var(--white);
border-radius: 15px;
padding: 30px;
box-shadow: var(--shadow);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.service-card:hover {
transform: translateY(-10px);
box-shadow: 0 10px 30px rgba(0, 102, 255, 0.15);
}
.service-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 100%;
background-color: var(--primary-blue);
}
.service-icon {
font-size: 48px;
color: var(--primary-blue);
margin-bottom: 20px;
}
.service-title {
font-size: 24px;
font-weight: bold;
margin-bottom: 15px;
color: var(--text-dark);
}
.service-description {
font-size: 16px;
color: var(--text-light);
line-height: 1.6;
}
.feature-card {
background-color: var(--white);
border-radius: 15px;
padding: 30px;
box-shadow: var(--shadow);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.feature-card:hover {
transform: translateY(-10px);
box-shadow: 0 10px 30px rgba(0, 102, 255, 0.15);
}
.feature-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 100%;
background-color: var(--primary-blue);
}
.feature-icon {
font-size: 48px;
color: var(--primary-blue);
margin-bottom: 20px;
}
.feature-title {
font-size: 24px;
font-weight: bold;
margin-bottom: 15px;
color: var(--text-dark);
}
.feature-description {
font-size: 16px;
color: var(--text-light);
line-height: 1.6;
}
/* 联盟与学科工坊 */
.alliance {
padding: 80px 40px;
background-color: var(--bg-light);
}
.alliance-container {
display: flex;
flex-wrap: wrap;
gap: 40px;
max-width: 1400px;
margin: 0 auto;
}
.alliance-banner {
flex: 1;
min-width: 400px;
background-color: var(--white);
border-radius: 15px;
padding: 40px;
box-shadow: var(--shadow);
display: flex;
flex-direction: column;
justify-content: center;
}
.workshops {
flex: 1;
min-width: 400px;
}
.workshop-tabs {
background-color: var(--white);
border-radius: 15px;
overflow: hidden;
box-shadow: var(--shadow);
}
.tab-header {
display: flex;
background-color: var(--bg-light);
}
.tab-item {
flex: 1;
padding: 15px 30px;
text-align: center;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.tab-item.active {
background-color: var(--primary-blue);
color: var(--white);
}
.tab-content {
padding: 30px;
}
/* 数据统计区 */
.stats {
padding: 80px 40px;
background-color: var(--primary-blue);
color: var(--white);
text-align: center;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 40px;
max-width: 1400px;
margin: 0 auto;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.stat-number {
font-size: 48px;
font-weight: bold;
margin-bottom: 10px;
animation: countUp 2s ease-out forwards;
}
.stat-label {
font-size: 16px;
opacity: 0.9;
}
@keyframes countUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
/* 页脚 */
.footer {
background-color: var(--text-dark);
color: var(--white);
padding: 60px 40px 20px;
}
.footer-container {
display: flex;
flex-wrap: wrap;
gap: 40px;
max-width: 1400px;
margin: 0 auto 40px;
}
.footer-column {
flex: 1;
min-width: 200px;
}
.footer-logo {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
color: var(--white);
}
.footer-description {
font-size: 14px;
opacity: 0.8;
margin-bottom: 20px;
}
.footer-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 20px;
color: var(--white);
}
.footer-links {
list-style: none;
}
.footer-links li {
margin-bottom: 10px;
}
.footer-links a {
color: var(--white);
opacity: 0.8;
text-decoration: none;
transition: opacity 0.3s ease;
}
.footer-links a:hover {
opacity: 1;
}
/* 响应式设计 */
@media (max-width: 1200px) {
.hero {
padding: 0 40px;
}
.hero-title {
font-size: 36px;
}
.hero-subtitle {
font-size: 20px;
}
}
@media (max-width: 992px) {
.header {
padding: 0 20px;
}
.nav-menu {
display: none;
}
.hero {
flex-direction: column;
text-align: center;
padding: 40px 20px;
}
.hero-content {
max-width: 100%;
margin-bottom: 40px;
}
.hero-image {
width: 100%;
}
.hero-cta {
justify-content: center;
}
}
@media (max-width: 768px) {
.section-title {
font-size: 28px;
}
.features,
.alliance,
.stats {
padding: 60px 20px;
}
.alliance-container {
flex-direction: column;
}
}
@media (max-width: 576px) {
.header {
height: 60px;
}
.hero {
margin-top: 60px;
height: auto;
min-height: calc(100vh - 60px);
}
.hero-title {
font-size: 28px;
}
.hero-subtitle {
font-size: 18px;
}
.btn {
padding: 6px 16px;
font-size: 12px;
}
.feature-card {
padding: 20px;
}
}
/* AI资源工坊页面样式 */
.page-header {
padding: 60px 0;
background-color: var(--primary-blue);
color: white;
text-align: center;
}
.resource-generator {
background-color: white;
border-radius: 10px;
padding: 30px;
margin-bottom: 40px;
box-shadow: var(--shadow);
}
.generator-form {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-top: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 500;
}
.resource-library {
margin-bottom: 40px;
}
.resource-filters {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
flex-wrap: wrap;
gap: 15px;
}
.resources-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 25px;
margin-top: 20px;
}
.resource-card {
border: 1px solid #eee;
border-radius: 8px;
overflow: hidden;
transition: all 0.3s ease;
}

92
static/degree.html Normal file
View File

@@ -0,0 +1,92 @@
<!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="css/element-plus.index.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/degree.css">
</head>
<body>
<div id="app">
<!-- 悬浮二维码 -->
<div class="qr-sidebar">
<div id="qrcode" class="qr-code"></div>
<p class="qr-text">手机扫码访问</p>
</div>
<div class="degree-container" style="margin-top: 100px;">
<div class="query-section">
<h1 class="page-title">驿来特AI智能数据查询</h1>
<p class="page-subtitle">基于大语言模型,为您提供实时、精准的业务数据分析</p>
<div class="input-wrapper">
<el-input
v-model="query"
placeholder="请输入您的问题,例如:帮我查询12月份充电量TOP 10场站的充电情况"
class="search-input"
size="large"
@keyup.enter="handleSearch"
:disabled="loading"
>
<template #append>
<el-button @click="handleSearch" :loading="loading" type="primary">
{{ loading ? '分析中...' : '开始查询' }}
</el-button>
</template>
</el-input>
</div>
<div class="example-tags">
<el-tag
v-for="(text, index) in examples"
:key="index"
class="example-tag"
effect="plain"
round
size="large"
@click="setExample(text)"
>
{{ text }}
</el-tag>
</div>
</div>
<div class="result-section" v-if="result || loading">
<div class="result-header">
<div class="result-title">
<span>分析结果</span>
<el-tag size="small" type="success" effect="dark" v-if="!loading">完成</el-tag>
<el-tag size="small" type="warning" effect="dark" v-if="loading">生成中</el-tag>
</div>
<el-button
v-if="loading"
type="danger"
link
@click="stopGeneration"
>
停止生成
</el-button>
</div>
<div class="markdown-body" v-html="renderedResult"></div>
<div v-if="loading && !result" class="loading-container">
<p>正在分析数据,请稍候...</p>
</div>
<span v-if="loading" class="cursor-blink">|</span>
</div>
</div>
</div>
<!-- Scripts -->
<script src="js/vue.global.js"></script>
<script src="js/element-plus.index.full.js"></script>
<script src="js/element-plus.zh-cn.min.js"></script>
<script src="js/marked.min.js"></script>
<script src="js/qrcode.min.js"></script>
<script src="js/echarts.min.js"></script>
<script src="js/degree.js"></script>
</body>
</html>

452
static/js/degree.js Normal file
View File

@@ -0,0 +1,452 @@
const { createApp, ref, computed, watch, nextTick, onMounted } = Vue;
const app = createApp({
setup() {
const query = ref('');
const loading = ref(false);
const result = ref('');
const eventSource = ref(null);
const isMobile = ref(window.innerWidth <= 768);
// Handle window resize
window.addEventListener('resize', () => {
isMobile.value = window.innerWidth <= 768;
});
// Initialize QR Code
onMounted(() => {
if (!isMobile.value && typeof QRCode !== 'undefined') {
new QRCode(document.getElementById("qrcode"), {
text: window.location.href,
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
}
});
// Examples for the user
const examples = [
"查询12月份充电量TOP 10场站的充电情况",
"查询净月商贸城站12月的充电量",
"查询12月企业充电量排名的TOP 10",
"查询所有场站的近3个月的充电情况,找出变化最大的前10名"
];
// Helpers: convert payloads to readable markdown
const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]';
const colSynonyms = {
name: ['name', 'station', 'station_name', 'site', '场站', '场站名称', '站点', '站名'],
total: ['total', 'total_kwh', 'sum_kwh', 'energy_total', '总电量', '总充电量', '总度', '总度数'],
peak: ['peak', 'peak_kwh', 'energy_peak', '峰', '峰时电量'],
flat: ['flat', 'flat_kwh', 'energy_flat', '平', '平时电量'],
valley: ['valley', 'valley_kwh', 'energy_valley', '谷', '谷时电量'],
};
const pickKey = (obj, keys) => keys.find(k => Object.prototype.hasOwnProperty.call(obj, k));
const pickVal = (obj, keys) => {
const k = pickKey(obj, keys);
return k ? obj[k] : undefined;
};
const rowsAcc = ref([]);
const bufferRow = ref(null);
const formatNumber = (n) => {
if (n === null || n === undefined || n === '') return '';
const v = parseFloat(String(n).replace(/,/g, ''));
if (isNaN(v)) return String(n);
return v.toLocaleString('zh-CN', { maximumFractionDigits: 2 });
};
const buildTableFromRows = (rows) => {
if (!rows || rows.length === 0) return '';
const header = `| 场站名称 | 总电量 | 峰 | 平 | 谷 |\n| --- | ---: | ---: | ---: | ---: |`;
const lines = rows.map(r => `| ${r.name ?? ''} | ${formatNumber(r.total)} | ${formatNumber(r.peak)} | ${formatNumber(r.flat)} | ${formatNumber(r.valley)} |`).join('\n');
return `${header}\n${lines}`;
};
const pushRow = (row) => {
if (!row || !row.name) return;
rowsAcc.value.push(row);
// Append the new row to result.value instead of rebuilding the whole table
// This allows mixed content (raw markdown + parsed rows) to coexist
const r = row;
const line = `| ${r.name ?? ''} | ${formatNumber(r.total)} | ${formatNumber(r.peak)} | ${formatNumber(r.flat)} | ${formatNumber(r.valley)} |`;
// If this is the first row, add the header
if (rowsAcc.value.length === 1) {
const header = `| 场站名称 | 总电量 | 峰 | 平 | 谷 |\n| --- | ---: | ---: | ---: | ---: |`;
// If result already has content (e.g. summary text), append header with newline
if (result.value && !result.value.endsWith('\n')) {
result.value += '\n\n';
} else if (result.value) {
result.value += '\n';
}
result.value += header + '\n';
}
result.value += line + '\n';
};
const ingestColumnsRows = (data) => {
const nameCol = data.columns.find(c => colSynonyms.name.includes(c));
const totalCol = data.columns.find(c => colSynonyms.total.includes(c));
const peakCol = data.columns.find(c => colSynonyms.peak.includes(c));
const flatCol = data.columns.find(c => colSynonyms.flat.includes(c));
const valleyCol = data.columns.find(c => colSynonyms.valley.includes(c));
data.rows.forEach(r => pushRow({
name: r[nameCol],
total: r[totalCol],
peak: r[peakCol],
flat: r[flatCol],
valley: r[valleyCol],
}));
};
const ingestDataArray = (arr) => {
arr.forEach(obj => {
const row = toSelectedRow(obj);
if (row) pushRow(row);
});
};
const tryStationName = (line) => {
const m1 = line.match(/(?:站点|场站|充电站|站名)[::]\s*([^\s,,]+)/);
if (m1) return m1[1];
const m2 = line.match(/^\s*(?:\d+[\.\)]\s*)?(.+?(?:充电站|场站|站))(?:(.*))?\s*$/);
if (m2) return m2[1];
return null;
};
const tryMetric = (line, label) => {
const re = new RegExp(label + '\\s*[::]\\s*([\\d.,]+)');
const m = line.match(re);
if (m) return parseFloat(m[1].replace(/,/g, ''));
return null;
};
const ingestChunkText = (text) => {
if (!text || /^\s*$/.test(text)) return false;
let consumed = false;
const lines = String(text).split(/[\r\n]+/);
lines.forEach(line => {
const name = tryStationName(line);
if (name) {
if (bufferRow.value && (bufferRow.value.total != null || bufferRow.value.peak != null || bufferRow.value.flat != null || bufferRow.value.valley != null)) {
pushRow(bufferRow.value);
}
bufferRow.value = { name, total: null, peak: null, flat: null, valley: null };
consumed = true;
return;
}
if (!bufferRow.value) return;
const total = tryMetric(line, '(?:总(?:充电)?电量|总电量)');
const peak = tryMetric(line, '(?:峰(?:时)?电量|峰)');
const flat = tryMetric(line, '(?:平(?:时)?电量|平)');
const valley = tryMetric(line, '(?:谷(?:时)?电量|谷)');
if (total != null) { bufferRow.value.total = total; consumed = true; }
if (peak != null) { bufferRow.value.peak = peak; consumed = true; }
if (flat != null) { bufferRow.value.flat = flat; consumed = true; }
if (valley != null) { bufferRow.value.valley = valley; consumed = true; }
if (bufferRow.value.name && (bufferRow.value.total != null || bufferRow.value.peak != null || bufferRow.value.flat != null || bufferRow.value.valley != null)) {
pushRow(bufferRow.value);
bufferRow.value = null;
}
});
return consumed;
};
const toSelectedRow = (row) => {
if (!isPlainObject(row)) return null;
const name = pickVal(row, colSynonyms.name);
const total = pickVal(row, colSynonyms.total);
const peak = pickVal(row, colSynonyms.peak);
const flat = pickVal(row, colSynonyms.flat);
const valley = pickVal(row, colSynonyms.valley);
if (name === undefined) return null;
return { name, total, peak, flat, valley };
};
const toMarkdownTableFromArray = (arr) => {
if (!Array.isArray(arr) || arr.length === 0) return '';
const selected = arr.map(toSelectedRow).filter(Boolean);
if (selected.length === 0) {
// 如果不能识别出目标字段,避免展示冗余JSON
return '';
}
const header = `| 场站名称 | 总电量 | 峰 | 平 | 谷 |\n| --- | ---: | ---: | ---: | ---: |`;
const rows = selected.map(r => {
const fmt = (v) => v === null || v === undefined ? '' : String(v);
return `| ${fmt(r.name)} | ${fmt(r.total)} | ${fmt(r.peak)} | ${fmt(r.flat)} | ${fmt(r.valley)} |`;
}).join('\n');
return `${header}\n${rows}`;
};
const toMarkdownTableFromObject = (obj) => {
const selected = toSelectedRow(obj);
if (!selected) return '';
const header = `| 场站名称 | 总电量 | 峰 | 平 | 谷 |\n| --- | ---: | ---: | ---: | ---: |`;
const fmt = (v) => v === null || v === undefined ? '' : String(v);
const row = `| ${fmt(selected.name)} | ${fmt(selected.total)} | ${fmt(selected.peak)} | ${fmt(selected.flat)} | ${fmt(selected.valley)} |`;
return `${header}\n${row}`;
};
const payloadToMarkdown = (data) => {
if (data == null) return '';
if (typeof data === 'string') {
// 文本直接作为markdown,但避免无用状态文本
const trimmed = data.trim();
if (/^(analyzing|generating|loading)/i.test(trimmed)) return '';
return trimmed;
}
if (isPlainObject(data)) {
if (typeof data.markdown === 'string') return data.markdown;
if (typeof data.content === 'string') return data.content;
if (typeof data.text === 'string') return data.text;
// 过滤仅含无用状态字段的对象
const keys = Object.keys(data);
const statusKeys = ['step', 'message', 'chunk', 'status'];
if (keys.every(k => statusKeys.includes(k))) return '';
if (Array.isArray(data.rows) && Array.isArray(data.columns)) {
// 映射选择列
const colMap = {
name: data.columns.find(c => colSynonyms.name.includes(c)),
total: data.columns.find(c => colSynonyms.total.includes(c)),
peak: data.columns.find(c => colSynonyms.peak.includes(c)),
flat: data.columns.find(c => colSynonyms.flat.includes(c)),
valley: data.columns.find(c => colSynonyms.valley.includes(c)),
};
const header = `| 场站名称 | 总电量 | 峰 | 平 | 谷 |\n| --- | ---: | ---: | ---: | ---: |`;
const rows = data.rows.map(r => {
const fmt = (v) => v === null || v === undefined ? '' : String(v);
return `| ${fmt(r[colMap.name])} | ${fmt(r[colMap.total])} | ${fmt(r[colMap.peak])} | ${fmt(r[colMap.flat])} | ${fmt(r[colMap.valley])} |`;
}).join('\n');
return `${header}\n${rows}`;
}
if (Array.isArray(data.data)) {
return toMarkdownTableFromArray(data.data);
}
// Fallback: 仅当识别出目标字段时才展示;否则忽略
return toMarkdownTableFromObject(data);
}
if (Array.isArray(data)) {
return toMarkdownTableFromArray(data);
}
return String(data);
};
// 配置 marked
marked.use({
gfm: true,
breaks: true,
mangle: false,
headerIds: false,
renderer: {
code(code, language) {
if (language === 'echarts') {
const id = 'chart-' + Math.random().toString(36).substr(2, 9);
return `<div class="echarts-container" id="${id}" style="width: 100%; height: 400px; margin: 20px 0; background: rgba(30, 41, 59, 0.5); border: 1px solid rgba(148, 163, 184, 0.1); border-radius: 12px; padding: 20px;" data-config="${encodeURIComponent(code)}"></div>`;
}
return false; // 返回 false 使用默认渲染器
}
}
});
// Convert markdown to HTML
const renderedResult = computed(() => {
if (!result.value) return '';
try {
// 修复 LLM 常见的错误转义问题,例如 \*\*加粗\*\*
const cleanText = result.value.replace(/\\([\*_`#\[\]\(\)!>-])/g, '$1');
return marked.parse(cleanText);
} catch (e) {
console.error('Markdown parsing error:', e);
return result.value;
}
});
// 渲染图表函数
const renderCharts = () => {
if (typeof echarts === 'undefined') {
console.warn('ECharts is not loaded yet.');
return;
}
nextTick(() => {
const containers = document.querySelectorAll('.echarts-container');
containers.forEach(container => {
// 如果已经成功渲染,不再重复渲染
if (container.getAttribute('data-rendered') === 'true') return;
try {
const configStr = decodeURIComponent(container.getAttribute('data-config')).trim();
// 检查 JSON 是否完整(简单判断:以 { 开始,以 } 结束)
if (!configStr.startsWith('{') || !configStr.endsWith('}')) {
return; // 还在流式传输中,不完整则跳过
}
const config = JSON.parse(configStr);
// 如果容器还没有 init,则初始化
let chart = echarts.getInstanceByDom(container);
if (!chart) {
chart = echarts.init(container, 'dark');
// 响应式
window.addEventListener('resize', () => chart.resize());
}
chart.setOption(config);
container.setAttribute('data-rendered', 'true');
container.style.opacity = '1';
} catch (e) {
// 忽略流式传输中的解析错误
if (loading.value) return;
console.error('ECharts rendering error:', e);
container.innerHTML = `<p style="color: #ef4444; padding: 10px;">图表渲染失败: ${e.message}</p>`;
}
});
});
};
// 监听结果变化,尝试渲染图表
watch(result, (newVal) => {
if (newVal && newVal.includes('```echarts')) {
renderCharts();
}
});
const setExample = (text) => {
query.value = text;
handleSearch();
};
const handleSearch = () => {
if (!query.value.trim()) {
ElementPlus.ElMessage.warning('请输入您的问题');
return;
}
if (loading.value) {
// If already loading, stop the previous request?
// For now, let's just ignore or maybe cancel.
// closing existing connection
if (eventSource.value) {
eventSource.value.close();
}
}
loading.value = true;
result.value = '';
// Construct the SSE URL
// Assuming the backend endpoint is /api/ai/query or similar.
// We use a relative path so it works if served from the same domain.
// Adjust this URL based on actual backend route.
const url = `/degree/chat?q=${encodeURIComponent(query.value)}`;
try {
const es = new EventSource(url);
eventSource.value = es;
es.onopen = () => {
console.log('Connection opened');
};
es.onmessage = (event) => {
const eventData = event.data.trim();
if (eventData === '[DONE]') {
loading.value = false;
es.close();
return;
}
try {
const data = JSON.parse(event.data);
// 处理流式内容
let chunk = '';
if (data.content) chunk = data.content;
else if (data.markdown) chunk = data.markdown;
else if (data.chunk) chunk = data.chunk;
else if (typeof data === 'string') chunk = data;
if (chunk) {
// 保持原始文本,不对 markdown 符号进行手动转义处理
// marked 会处理大部分情况
result.value += chunk;
}
// 处理状态更新
if (data.step || data.message) {
// 可以根据需要处理状态,比如更新进度条等
// 目前主要依赖流式内容展示
}
} catch (e) {
// 非 JSON 内容直接追加
if (eventData && eventData !== '[DONE]') {
result.value += event.data;
}
}
};
es.onerror = (err) => {
console.error('SSE Error:', err);
loading.value = false;
es.close();
// 如果之前已经有结果,就保持现状;否则给出简单提示
if (!result.value) {
result.value = '查询过程出现异常,未能获取到数据';
}
};
// Listen for a specific 'done' event if the backend sends one
es.addEventListener('done', () => {
if (bufferRow.value && (bufferRow.value.total != null || bufferRow.value.peak != null || bufferRow.value.flat != null || bufferRow.value.valley != null)) {
pushRow(bufferRow.value);
bufferRow.value = null;
}
if (!result.value) {
result.value = '未查询到数据';
}
es.close();
loading.value = false;
});
} catch (err) {
console.error('Failed to create EventSource:', err);
loading.value = false;
ElementPlus.ElMessage.error('无法建立连接');
}
};
const stopGeneration = () => {
if (eventSource.value) {
eventSource.value.close();
eventSource.value = null;
}
loading.value = false;
ElementPlus.ElMessage.info('已停止生成');
};
onMounted(() => {
// 生成二维码
const qrEl = document.getElementById('qrcode');
if (qrEl) {
// 清空可能存在的旧内容
qrEl.innerHTML = '';
new QRCode(qrEl, {
text: window.location.href,
width: 256, // 生成高分辨率图片
height: 256,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.M // 中等纠错等级,平衡密度和可靠性
});
}
});
return {
query,
loading,
result,
renderedResult,
examples,
isMobile,
handleSearch,
setExample,
stopGeneration
};
}
});
app.use(ElementPlus);
app.mount('#app');

2
static/js/qrcode.min.js vendored Normal file

File diff suppressed because one or more lines are too long