更新数据截止日2026.01.08

This commit is contained in:
lychang
2026-01-08 01:06:27 +08:00
commit ce02565b09
37 changed files with 12587 additions and 0 deletions

358
static/css/daily_report.css Normal file
View File

@@ -0,0 +1,358 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.2em;
opacity: 0.9;
}
.controls {
background: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.control-group {
display: flex;
gap: 20px;
align-items: center;
flex-wrap: wrap;
}
.control-group label {
font-weight: bold;
color: #555;
}
.control-group input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 14px;
}
.btn {
background: #667eea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background 0.3s;
}
.btn:hover {
background: #5a6fd8;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.report-container {
background: white;
border-radius: 10px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
.report-content {
white-space: pre-wrap;
font-family: 'Courier New', monospace;
line-height: 1.8;
font-size: 14px;
}
.loading {
text-align: center;
padding: 40px;
color: #666;
}
.error {
background: #ffe6e6;
color: #d63031;
padding: 15px;
border-radius: 5px;
margin: 10px 0;
border-left: 4px solid #d63031;
}
.statistics {
background: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
}
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 15px;
}
.stat-item {
background: white;
padding: 15px;
border-radius: 8px;
text-align: center;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.stat-value {
font-size: 1.8em;
font-weight: bold;
color: #667eea;
}
.stat-label {
font-size: 0.9em;
color: #666;
margin-top: 5px;
}
.nav {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.nav-btn {
padding: 8px 16px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 5px;
text-decoration: none;
color: #333;
transition: all 0.3s;
}
.nav-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
}
.export-btn {
background: #28a745;
color: white;
border: none;
padding: 8px 16px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
margin-left: auto;
}
.export-btn:hover {
background: #218838;
}
/* 预览控制样式 */
.preview-controls {
display: flex;
gap: 10px;
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 15px;
}
.preview-btn {
background: #f8f9fa;
color: #666;
border: 1px solid #ddd;
padding: 8px 16px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s;
}
.preview-btn:hover {
background: #e9ecef;
border-color: #adb5bd;
}
.preview-btn.active {
background: #667eea;
color: white;
border-color: #667eea;
}
/* Markdown源代码显示样式 */
.markdown-source {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 5px;
padding: 20px;
font-family: 'Courier New', monospace;
font-size: 13px;
line-height: 1.5;
white-space: pre-wrap;
word-wrap: break-word;
max-height: 600px;
overflow-y: auto;
}
.markdown-source pre {
margin: 0;
background: none;
border: none;
padding: 0;
}
.markdown-source code {
background: none;
border: none;
padding: 0;
color: #333;
}
/* 增强的报告内容样式 */
.report-content {
white-space: pre-wrap;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.8;
font-size: 14px;
background: white;
padding: 20px;
border-radius: 5px;
border: 1px solid #e9ecef;
}
/* Markdown渲染样式 */
.report-content h1,
.report-content h2,
.report-content h3,
.report-content h4,
.report-content h5,
.report-content h6 {
margin: 20px 0 10px 0;
color: #333;
font-weight: 600;
}
.report-content h1 {
font-size: 1.8em;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.report-content h2 {
font-size: 1.5em;
border-bottom: 1px solid #ddd;
padding-bottom: 8px;
}
.report-content h3 {
font-size: 1.3em;
}
.report-content p {
margin: 10px 0;
}
.report-content ul,
.report-content ol {
margin: 10px 0 10px 20px;
}
.report-content li {
margin: 5px 0;
}
.report-content blockquote {
border-left: 4px solid #667eea;
background: #f8f9fa;
padding: 10px 15px;
margin: 15px 0;
font-style: italic;
}
.report-content code {
background: #f1f3f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
}
.report-content pre {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 5px;
padding: 15px;
overflow-x: auto;
margin: 15px 0;
}
.report-content pre code {
background: none;
padding: 0;
}
.report-content table {
border-collapse: collapse;
width: 100%;
margin: 15px 0;
}
.report-content th,
.report-content td {
border: 1px solid #ddd;
padding: 8px 12px;
text-align: left;
}
.report-content th {
background: #f8f9fa;
font-weight: 600;
}
.report-content tr:nth-child(even) {
background: #f8f9fa;
}
/* 水平分隔线样式 */
.report-content hr {
border: none;
border-top: 2px solid #667eea;
margin: 30px 0;
height: 0;
}

471
static/css/index.css Normal file
View File

@@ -0,0 +1,471 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background-color: #f5f5f5;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 15px;
margin-bottom: 30px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.1em;
opacity: 0.9;
margin-bottom: 15px;
}
.nav {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.nav-btn {
padding: 8px 16px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 5px;
text-decoration: none;
color: #333;
transition: all 0.3s;
}
.nav-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background: white;
padding: 25px;
border-radius: 12px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
text-align: center;
transition: transform 0.3s ease;
}
.stat-card:hover {
transform: translateY(-5px);
}
.stat-number {
font-size: 2.5em;
font-weight: bold;
color: #667eea;
margin-bottom: 5px;
}
.stat-label {
color: #666;
font-size: 0.9em;
}
.view-switcher {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.view-btn {
padding: 10px 20px;
border: 2px solid #667eea;
background: white;
color: #667eea;
border-radius: 25px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: bold;
}
.view-btn.active {
background: #667eea;
color: white;
}
.view-btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}
.chat-container {
display: grid;
grid-template-columns: 300px 1fr;
gap: 20px;
height: 70vh;
}
.sidebar {
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
overflow-y: auto;
}
.sidebar h3 {
margin-bottom: 15px;
color: #333;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.group-list {
list-style: none;
margin-bottom: 20px;
}
.group-item {
padding: 15px;
margin-bottom: 10px;
background: #f8f9fa;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
border-left: 4px solid transparent;
}
.group-item:hover {
background: #e9ecef;
transform: translateX(5px);
}
.group-item.active {
background: #667eea;
color: white;
border-left-color: #764ba2;
}
.group-name {
font-weight: bold;
margin-bottom: 5px;
}
.group-info {
font-size: 0.8em;
color: #666;
display: flex;
justify-content: space-between;
}
.group-item.active .group-info {
color: rgba(255, 255, 255, 0.8);
}
.chat-area {
background: white;
border-radius: 12px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
display: flex;
flex-direction: column;
}
.chat-header {
padding: 20px;
border-bottom: 1px solid #eee;
background: #f8f9fa;
border-radius: 12px 12px 0 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.current-group {
font-size: 1.2em;
font-weight: bold;
color: #333;
}
.group-stats {
font-size: 0.9em;
color: #666;
}
.controls {
padding: 20px;
border-bottom: 1px solid #eee;
background: #f8f9fa;
border-radius: 0 0 0 0;
text-align: center;
}
.load-more {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 24px;
border-radius: 25px;
cursor: pointer;
font-size: 1em;
transition: transform 0.3s ease;
}
.load-more:hover {
transform: scale(1.05);
}
.chat-messages {
flex: 1;
overflow-y: auto;
overflow-x: hidden;
padding: 20px;
}
.message {
margin-bottom: 20px;
display: flex;
align-items: flex-start;
}
.message.own {
flex-direction: row-reverse;
}
.avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
margin: 0 10px;
}
.message-content {
max-width: 70%;
padding: 12px 16px;
border-radius: 18px;
background: #f1f3f5;
position: relative;
word-wrap: break-word;
overflow-wrap: break-word;
white-space: normal;
}
.message.own .message-content {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.message-sender {
font-weight: bold;
margin-bottom: 5px;
font-size: 0.9em;
}
.message-time {
font-size: 0.8em;
color: #999;
margin-top: 5px;
}
.message.own .message-time {
color: rgba(255, 255, 255, 0.8);
}
.loading {
text-align: center;
padding: 20px;
color: #666;
}
.error {
background: #ffe6e6;
color: #d63031;
padding: 10px;
border-radius: 8px;
margin: 10px 0;
text-align: center;
}
@media (max-width: 768px) {
.chat-container {
grid-template-columns: 1fr;
}
.sidebar {
display: none;
}
.message-content {
max-width: 85%;
}
}
body, .container {
overflow-x: hidden;
}
/* 聊天记录按钮样式 */
.chatrecord-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 8px 16px;
border-radius: 15px;
cursor: pointer;
font-size: 0.9em;
transition: all 0.3s ease;
text-align: left;
max-width: 100%;
word-wrap: break-word;
overflow-wrap: break-word;
white-space: normal;
}
.chatrecord-btn:hover {
transform: scale(1.05);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}
/* 模态框样式 */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
animation: fadeIn 0.3s;
}
.modal-content {
background-color: white;
margin: 5% auto;
padding: 0;
border-radius: 15px;
width: 80%;
max-width: 800px;
max-height: 80vh;
overflow: hidden;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
animation: slideIn 0.3s;
}
.modal-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-header h3 {
margin: 0;
font-size: 1.3em;
}
.close {
color: white;
font-size: 28px;
font-weight: bold;
cursor: pointer;
transition: opacity 0.3s;
}
.close:hover {
opacity: 0.7;
}
.modal-body {
padding: 0;
max-height: calc(80vh - 80px);
overflow-y: auto;
}
.chat-record-content {
padding: 20px;
}
.chat-record-item {
margin-bottom: 15px;
padding: 15px;
background: #f8f9fa;
border-radius: 10px;
border-left: 4px solid #667eea;
}
.chat-record-sender {
font-weight: bold;
margin-bottom: 5px;
color: #333;
}
.chat-record-text {
margin-bottom: 5px;
line-height: 1.4;
}
.chat-record-time {
font-size: 0.8em;
color: #666;
text-align: right;
}
.chat-record-image {
max-width: 200px;
max-height: 200px;
border-radius: 8px;
margin: 5px 0;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes slideIn {
from {
transform: translateY(-50px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.container {
max-width: 100%;
overflow-x: hidden;
}

274
static/css/markdown.css Normal file
View File

@@ -0,0 +1,274 @@
:root {
--primary-color: #2c3e50;
--secondary-color: #3498db;
--accent-color: #e74c3c;
--light-bg: #f8f9fa;
--dark-bg: #2c3e50;
--text-color: #333;
--border-color: #e0e0e0;
--shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
* {
margin: 5px;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 1400px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.header {
text-align: center;
margin-bottom: 30px;
color: white;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.header p {
font-size: 1.1rem;
opacity: 0.9;
}
.main-content {
background: white;
border-radius: 15px;
padding: 30px;
box-shadow: var(--shadow);
margin-bottom: 30px;
}
.container {
display: flex;
gap: 30px;
margin-bottom: 40px;
}
.editor, .preview {
flex: 1;
border: 2px solid var(--border-color);
padding: 25px;
border-radius: 10px;
background: white;
transition: all 0.3s ease;
}
.editor:hover, .preview:hover {
border-color: var(--secondary-color);
box-shadow: 0 4px 15px rgba(52, 152, 219, 0.2);
}
.editor h3, .preview h3 {
color: var(--primary-color);
margin-bottom: 15px;
font-size: 1.3rem;
border-bottom: 2px solid var(--secondary-color);
padding-bottom: 10px;
}
textarea {
width: 100%;
height: 400px;
font-family: 'Fira Code', 'Courier New', monospace;
font-size: 14px;
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 15px;
resize: vertical;
transition: all 0.3s ease;
background: #fafafa;
}
textarea:focus {
outline: none;
border-color: var(--secondary-color);
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
background: white;
}
.toolbar {
margin-top: 20px;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
padding: 12px 24px;
background: linear-gradient(135deg, var(--secondary-color), #2980b9);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}
button:active {
transform: translateY(0);
}
#htmlPreview {
min-height: 400px;
padding: 15px;
border: 1px solid var(--border-color);
border-radius: 8px;
background: #fafafa;
overflow-y: auto;
}
#htmlPreview::-webkit-scrollbar {
display: none;
}
.syntax-guide {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.guide-card {
background: var(--light-bg);
padding: 20px;
border-radius: 10px;
border-left: 4px solid var(--secondary-color);
}
.guide-card h3 {
color: var(--primary-color);
margin-bottom: 15px;
font-size: 1.2rem;
}
.syntax {
background: #2c3e50;
color: white;
padding: 8px 12px;
border-radius: 5px;
font-family: 'Fira Code', monospace;
font-size: 13px;
margin: 5px 0;
display: inline-block;
}
@keyframes slideIn {
from {
transform: translateY(-10px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
/* Blockquote 样式 - 注释样式,字体变小,颜色变灰 */
blockquote {
background: linear-gradient(135deg, #f8f9fa, #e9ecef);
border-left: 4px solid #6c757d;
margin: 20px 0;
padding: 15px 20px;
font-size: 0.9em;
color: #6c757d;
font-style: italic;
border-radius: 0 8px 8px 0;
position: relative;
}
blockquote::before {
content: "❝";
font-size: 2em;
color: #adb5bd;
position: absolute;
left: 10px;
top: 5px;
opacity: 0.5;
}
blockquote p {
margin: 0;
line-height: 1.5;
}
/* CodeBlock 样式 - 更鲜艳的样式 */
pre {
background: linear-gradient(135deg, #2d3748, #4a5568);
border: 1px solid #4a5568;
border-radius: 8px;
padding: 20px;
margin: 20px 0;
overflow-x: auto;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
position: relative;
white-space: pre;
font-family: 'Fira Code', monospace;
font-size: 13px;
line-height: 1.4;
color: #e2e8f0;
}
pre::before {
content: "</>";
position: absolute;
top: 10px;
right: 15px;
color: #81e6d9;
font-size: 0.8em;
font-weight: bold;
opacity: 0.7;
}
/* 行内代码样式 */
:not(pre) > code {
background: linear-gradient(135deg, #fed7e2, #fbb6ce);
color: #702459;
padding: 2px 6px;
border-radius: 4px;
line-height: 1.4;
border: 1px solid #fbb6ce;
}
.footer {
text-align: center;
color: white;
margin-top: 30px;
opacity: 0.8;
}
@media (max-width: 768px) {
.container {
flex-direction: column;
}
.syntax-guide {
grid-template-columns: 1fr;
}
.header h1 {
font-size: 2rem;
}
}

848
static/css/qa.css Normal file
View File

@@ -0,0 +1,848 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f5f5f5;
color: #333;
line-height: 1.6;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px 0;
text-align: center;
border-radius: 10px;
margin-bottom: 30px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.1em;
opacity: 0.9;
}
.controls {
background: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
/* 过滤区域样式 */
.filter-section {
margin-bottom: 20px;
background: #f8f9fa;
border-radius: 8px;
padding: 20px;
border: 1px solid #e9ecef;
}
.filter-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 1px solid #dee2e6;
}
.filter-header h3 {
font-size: 18px;
color: #495057;
margin: 0;
font-weight: 600;
}
.filter-actions {
display: flex;
gap: 10px;
}
.filter-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
}
.filter-item {
display: flex;
flex-direction: column;
}
.filter-item label {
font-weight: 600;
margin-bottom: 8px;
font-size: 14px;
color: #495057;
}
.filter-item input,
.filter-item select {
padding: 10px 12px;
border: 1px solid #ced4da;
border-radius: 6px;
font-size: 14px;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.filter-item input:focus,
.filter-item select:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.action-section {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background: white;
border-radius: 8px;
border: 1px solid #e9ecef;
margin-top: 20px;
}
.stats-section {
flex: 1;
}
.stats-info {
font-size: 15px;
color: #6c757d;
font-weight: 600;
padding: 8px 0;
}
.create-section {
display: flex;
gap: 10px;
}
/* 批量操作区域样式 */
.batch-actions {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 5px;
padding: 15px;
margin-bottom: 20px;
}
.batch-header {
display: flex;
align-items: center;
justify-content: space-between;
}
.batch-select {
display: flex;
align-items: center;
gap: 10px;
}
.batch-select input[type="checkbox"] {
width: 18px;
height: 18px;
}
.batch-select label {
font-weight: bold;
color: #495057;
margin: 0;
}
.batch-info {
font-size: 14px;
color: #6c757d;
font-weight: bold;
}
.batch-buttons {
display: flex;
gap: 10px;
}
/* QA项目选中状态 */
.qa-item.selected {
background-color: #e3f2fd;
border-color: #2196f3;
}
.qa-checkbox {
margin-right: 10px;
}
.qa-checkbox input[type="checkbox"] {
width: 16px;
height: 16px;
}
.search-box {
display: flex;
gap: 10px;
margin-bottom: 15px;
}
.search-box input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 14px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
}
.btn-primary {
background: #667eea;
color: white;
}
.btn-primary:hover {
background: #5a6fd8;
transform: translateY(-2px);
}
.btn-success {
background: #28a745;
color: white;
}
.btn-success:hover {
background: #218838;
}
.btn-danger {
background: #dc3545;
color: white;
}
.btn-danger:hover {
background: #c82333;
}
.btn-outline {
background: transparent;
color: #6c757d;
border: 1px solid #6c757d;
}
.btn-outline:hover {
background: #6c757d;
color: white;
}
.qa-list {
background: white;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.qa-item {
background: white;
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
margin-bottom: 15px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
display: flex;
flex-direction: column;
}
.qa-item:hover {
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
transform: translateY(-2px);
}
.qa-item.selected {
background-color: #e3f2fd;
border-color: #2196f3;
box-shadow: 0 4px 15px rgba(33, 150, 243, 0.2);
}
.qa-header {
display: flex;
align-items: center;
margin-bottom: 15px;
gap: 15px;
}
.qa-checkbox {
flex-shrink: 0;
}
.qa-id {
font-weight: bold;
color: #667eea;
font-size: 16px;
}
.qa-group {
background: #f0f0f0;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
color: #666;
}
.qa-id {
font-weight: bold;
color: #667eea;
font-size: 1.2em;
}
.qa-group {
background: #e9ecef;
padding: 5px 10px;
border-radius: 15px;
font-size: 0.9em;
}
.qa-content {
margin-bottom: 15px;
}
.nav {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.nav-btn {
padding: 8px 16px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 5px;
text-decoration: none;
color: #333;
transition: all 0.3s;
}
.nav-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
}
.qa-section {
margin-bottom: 10px;
}
.qa-section h4 {
color: #495057;
margin-bottom: 5px;
font-size: 1em;
}
.message-list {
background: #f8f9fa;
padding: 10px;
border-radius: 5px;
max-height: 150px;
overflow-y: auto;
}
.message-item {
padding: 5px;
margin-bottom: 5px;
background: white;
border-radius: 3px;
font-size: 0.9em;
border-left: 3px solid #667eea;
}
.qa-actions {
display: flex;
gap: 10px;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: white;
margin: 5% auto;
padding: 30px;
border-radius: 10px;
width: 80%;
max-width: 800px;
max-height: 80vh;
overflow-y: auto;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.close {
font-size: 28px;
font-weight: bold;
cursor: pointer;
color: #aaa;
}
.close:hover {
color: #000;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input,
.form-group textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 14px;
}
.message-selector {
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
margin-bottom: 15px;
}
.search-results {
max-height: 200px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 5px;
margin-top: 10px;
}
.search-result-item {
padding: 10px;
border-bottom: 1px solid #eee;
cursor: pointer;
transition: background-color 0.2s;
}
.search-result-item:hover {
background-color: #f0f0f0;
}
.selected-messages {
background: #f8f9fa;
padding: 10px;
border-radius: 5px;
margin-top: 10px;
}
.selected-message {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px;
margin-bottom: 5px;
background: white;
border-radius: 3px;
}
.loading {
text-align: center;
padding: 20px;
color: #666;
}
.empty-state {
text-align: center;
padding: 40px;
color: #666;
}
.empty-state i {
font-size: 48px;
margin-bottom: 10px;
opacity: 0.5;
}
/* 搜索相关样式 */
.search-container {
position: relative;
}
.search-input-wrapper {
position: relative;
}
.search-suggestions {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: white;
border: 1px solid #ddd;
border-top: none;
border-radius: 0 0 5px 5px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
z-index: 1000;
display: none;
}
.search-suggestion-item {
padding: 10px 15px;
cursor: pointer;
border-bottom: 1px solid #f0f0f0;
transition: background-color 0.2s;
}
.search-suggestion-item:hover {
background-color: #f8f9fa;
}
.search-suggestion-item:last-child {
border-bottom: none;
}
.search-history {
margin-top: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background: white;
display: none;
}
.search-history-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
border-bottom: 1px solid #eee;
background: #f8f9fa;
}
.search-history-header span {
font-weight: bold;
color: #495057;
}
.btn-clear-history {
background: none;
border: none;
color: #6c757d;
cursor: pointer;
font-size: 12px;
text-decoration: underline;
}
.btn-clear-history:hover {
color: #495057;
}
.search-history-items {
max-height: 200px;
overflow-y: auto;
}
.search-history-item {
padding: 8px 15px;
cursor: pointer;
border-bottom: 1px solid #f8f9fa;
transition: background-color 0.2s;
}
.search-history-item:hover {
background-color: #f8f9fa;
}
.search-history-item:last-child {
border-bottom: none;
}
/* 按钮样式增强 */
.btn-secondary {
background-color: #6c757d;
border-color: #6c757d;
}
.btn-secondary:hover {
background-color: #5a6268;
border-color: #545b62;
}
.btn-info {
background-color: #17a2b8;
border-color: #17a2b8;
}
.btn-info:hover {
background-color: #138496;
border-color: #117a8b;
}
/* 搜索结果样式 */
.search-results-header {
background: #f8f9fa;
padding: 15px 20px;
border-radius: 5px;
margin-bottom: 15px;
border-left: 4px solid #667eea;
}
.search-results-header h3 {
margin: 0 0 5px 0;
color: #495057;
}
.search-summary {
color: #6c757d;
font-size: 0.9em;
}
.search-result-item {
border-left: 3px solid #28a745;
background: #f8fff9;
}
.message-content {
background: white;
padding: 10px;
border-radius: 3px;
border: 1px solid #e9ecef;
margin-top: 5px;
line-height: 1.5;
}
.message-content mark {
background-color: #fff3cd;
padding: 2px 4px;
border-radius: 2px;
font-weight: bold;
}
/* 聊天记录预览样式 */
.chat-preview {
background: white;
border-radius: 10px;
overflow: hidden;
}
.chat-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
text-align: center;
}
.chat-header h3 {
margin: 0 0 10px 0;
font-size: 1.5em;
}
.chat-info {
opacity: 0.9;
font-size: 0.9em;
}
.chat-container {
padding: 20px;
max-height: 400px;
overflow-y: auto;
background: #f8f9fa;
}
.chat-message {
display: flex;
margin-bottom: 15px;
animation: fadeIn 0.3s ease;
}
.chat-message.question {
flex-direction: row;
}
.chat-message.answer {
flex-direction: row-reverse;
}
.chat-message.other {
flex-direction: row;
opacity: 0.7;
}
.message-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
margin: 0 10px;
flex-shrink: 0;
}
.chat-message.question .message-avatar {
background: #e3f2fd;
color: #1976d2;
}
.chat-message.answer .message-avatar {
background: #f3e5f5;
color: #7b1fa2;
}
.chat-message.other .message-avatar {
background: #f5f5f5;
color: #757575;
}
.message-content {
flex: 1;
max-width: 70%;
}
.message-header {
display: flex;
align-items: center;
margin-bottom: 5px;
gap: 10px;
}
.sender {
font-weight: bold;
color: #333;
}
.time {
font-size: 0.8em;
color: #666;
}
.message-type-badge {
padding: 2px 8px;
border-radius: 12px;
font-size: 0.7em;
font-weight: bold;
}
.message-type-badge.question {
background: #e3f2fd;
color: #1976d2;
}
.message-type-badge.answer {
background: #f3e5f5;
color: #7b1fa2;
}
.message-type-badge.other {
background: #f5f5f5;
color: #757575;
}
.message-text {
background: white;
padding: 12px 15px;
border-radius: 18px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
line-height: 1.4;
word-wrap: break-word;
}
.chat-message.question .message-text {
background: #e3f2fd;
border-bottom-left-radius: 5px;
}
.chat-message.answer .message-text {
background: #f3e5f5;
border-bottom-right-radius: 5px;
}
.chat-message.other .message-text {
background: #f5f5f5;
border-radius: 18px;
}
.message-meta {
display: flex;
justify-content: space-between;
margin-top: 5px;
font-size: 0.7em;
color: #999;
}
.chat-summary {
background: white;
padding: 15px 20px;
border-top: 1px solid #eee;
display: flex;
justify-content: space-around;
}
.summary-item {
text-align: center;
}
.summary-label {
display: block;
font-size: 0.8em;
color: #666;
margin-bottom: 5px;
}
.summary-value {
display: block;
font-size: 1.2em;
font-weight: bold;
color: #667eea;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

View File

@@ -0,0 +1,534 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.2em;
opacity: 0.9;
}
.controls {
background: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.control-group {
display: flex;
gap: 20px;
align-items: center;
flex-wrap: wrap;
}
.control-group label {
font-weight: bold;
color: #555;
}
.control-group input {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 14px;
}
.btn {
background: #667eea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background 0.3s;
}
.btn:hover {
background: #5a6fd8;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.report-container {
background: white;
border-radius: 10px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.report-content {
white-space: pre-wrap;
font-family: 'Courier New', monospace;
line-height: 1.8;
font-size: 14px;
}
.loading {
text-align: center;
padding: 40px;
color: #666;
}
.error {
background: #ffe6e6;
color: #d63031;
padding: 15px;
border-radius: 5px;
margin: 10px 0;
border-left: 4px solid #d63031;
}
.statistics {
background: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
}
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 15px;
}
.stat-item {
background: white;
padding: 15px;
border-radius: 8px;
text-align: center;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.stat-value {
font-size: 1.8em;
font-weight: bold;
color: #667eea;
}
.stat-label {
font-size: 0.9em;
color: #666;
margin-top: 5px;
}
.category-chart {
margin: 20px 0;
}
.category-item {
display: flex;
align-items: center;
margin: 10px 0;
padding: 10px;
background: #f8f9fa;
border-radius: 5px;
}
.category-bar {
height: 20px;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 10px;
margin: 0 10px;
min-width: 50px;
}
.nav {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.nav-btn {
padding: 8px 16px;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 5px;
text-decoration: none;
color: #333;
transition: all 0.3s;
}
.nav-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
}
.nav-btn.active {
background: #667eea;
color: white;
border-color: #667eea;
}
.api-version {
background-color: #e7f3ff;
border-left: 4px solid #1890ff;
padding: 10px 15px;
margin: 10px 0;
border-radius: 4px;
color: #1890ff;
font-size: 14px;
line-height: 1.5;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.api-version strong {
color: #096dd9;
font-weight: 600;
}
.api-version:hover {
background-color: #d4e6ff;
transition: background-color 0.3s ease;
}
/* 表格样式 - 控制长文本换行 */
.report-content table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-size: 14px;
table-layout: fixed;
}
.report-content th,
.report-content td {
border: 1px solid #ddd;
padding: 8px 12px;
text-align: left;
word-wrap: break-word;
word-break: break-all;
overflow-wrap: break-word;
hyphens: auto;
}
.report-content th {
background-color: #f8f9fa;
font-weight: bold;
color: #333;
}
.report-content tr:nth-child(even) {
background-color: #f8f9fa;
}
.report-content tr:hover {
background-color: #e9ecef;
}
/* 针对特定列设置不同的宽度 */
.report-content td:nth-child(1) { /* 第一列 - 客户群名称 */
width: 20%;
min-width: 120px;
}
.report-content td:nth-child(2), /* 第二列 - 消息总量 */
.report-content td:nth-child(3) { /* 第三列 - 活跃人数 */
width: 10%;
min-width: 80px;
text-align: center;
}
.report-content td:nth-child(4) { /* 第四列 - 核心互动时段 */
width: 20%;
min-width: 150px;
}
.report-content td:nth-child(5) { /* 第五列 - 平均每日消息量 */
width: 15%;
min-width: 100px;
text-align: center;
}
/* 问题分类表格样式 */
.report-content td:nth-child(1) { /* 问题类别 */
width: 15%;
min-width: 100px;
}
.report-content td:nth-child(2) { /* 具体问题描述 */
width: 40%;
min-width: 200px;
}
.report-content td:nth-child(3), /* 出现频次 */
.report-content td:nth-child(4), /* 涉及群聊 */
.report-content td:nth-child(5) { /* 当前状态 */
width: 15%;
min-width: 80px;
text-align: center;
}
/* 响应式表格 */
@media (max-width: 768px) {
.report-content table {
font-size: 12px;
}
.report-content th,
.report-content td {
padding: 6px 8px;
}
.report-content td:nth-child(n) {
width: auto;
min-width: 60px;
}
}
.export-btn{
background: #28a745;
color: white;
border: none;
padding: 8px 16px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
margin-left: auto;
}
.export-btn:hover {
background: #218838;
}
/* 图片导出按钮样式 */
.image-export-btn {
background: #17a2b8;
color: white;
border: none;
padding: 8px 16px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
margin-left: 10px;
transition: all 0.3s ease;
}
.image-export-btn:hover:not(.disabled) {
background: #138496;
transform: translateY(-1px);
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.image-export-btn.disabled {
background: #6c757d;
cursor: not-allowed;
opacity: 0.6;
}
.image-export-btn.disabled:hover {
background: #6c757d;
transform: none;
box-shadow: none;
}
/* 预览控制样式 */
.preview-controls {
display: flex;
gap: 10px;
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 15px;
}
.preview-btn {
background: #f8f9fa;
color: #666;
border: 1px solid #ddd;
padding: 8px 16px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s;
}
.preview-btn:hover {
background: #e9ecef;
border-color: #adb5bd;
}
.preview-btn.active {
background: #667eea;
color: white;
border-color: #667eea;
}
/* Markdown源代码显示样式 */
.markdown-source {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 5px;
padding: 20px;
font-family: 'Courier New', monospace;
font-size: 13px;
line-height: 1.5;
white-space: pre-wrap;
word-wrap: break-word;
max-height: 600px;
overflow-y: auto;
}
.markdown-source pre {
margin: 0;
background: none;
border: none;
padding: 0;
}
.markdown-source code {
background: none;
border: none;
padding: 0;
color: #333;
}
/* 增强的报告内容样式 */
.report-content {
white-space: pre-wrap;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.8;
font-size: 14px;
background: white;
padding: 20px;
border-radius: 5px;
border: 1px solid #e9ecef;
}
/* Markdown渲染样式 */
.report-content h1,
.report-content h2,
.report-content h3,
.report-content h4,
.report-content h5,
.report-content h6 {
margin: 20px 0 10px 0;
color: #333;
font-weight: 600;
}
.report-content h1 {
font-size: 1.8em;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.report-content h2 {
font-size: 1.5em;
border-bottom: 1px solid #ddd;
padding-bottom: 8px;
}
.report-content h3 {
font-size: 1.3em;
}
.report-content p {
margin: 10px 0;
}
.report-content ul,
.report-content ol {
margin: 10px 0 10px 20px;
}
.report-content li {
margin: 5px 0;
}
.report-content blockquote {
border-left: 4px solid #667eea;
background: #f8f9fa;
padding: 10px 15px;
margin: 15px 0;
font-style: italic;
}
.report-content code {
background: #f1f3f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
}
.report-content pre {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 5px;
padding: 15px;
overflow-x: auto;
margin: 15px 0;
}
.report-content pre code {
background: none;
padding: 0;
}
.report-content table {
border-collapse: collapse;
width: 100%;
margin: 15px 0;
}
.report-content th,
.report-content td {
border: 1px solid #ddd;
padding: 8px 12px;
text-align: left;
}
.report-content th {
background: #f8f9fa;
font-weight: 600;
}
.report-content tr:nth-child(even) {
background: #f8f9fa;
}
/* 水平分隔线样式 */
.report-content hr {
border: none;
border-top: 2px solid #667eea;
margin: 30px 0;
height: 0;
}

148
static/js/daily_report.js Normal file
View File

@@ -0,0 +1,148 @@
togglePreview = function (mode) {
const previewBtn = document.getElementById('preview-toggle');
const sourceBtn = document.getElementById('source-toggle');
const reportContent = document.getElementById('report-content');
const markdownSource = document.getElementById('markdown-source');
const sourceContent = document.getElementById('source-content');
if (mode === 'preview') {
previewBtn.classList.add('active');
sourceBtn.classList.remove('active');
reportContent.style.display = 'block';
markdownSource.style.display = 'none';
} else {
previewBtn.classList.remove('active');
sourceBtn.classList.add('active');
reportContent.style.display = 'none';
markdownSource.style.display = 'block';
// 显示原始Markdown源代码
const markdown = reportContent.getAttribute('data-markdown');
sourceContent.textContent = markdown;
}
};
// 设置默认日期为今天
document.getElementById('date').value = new Date().toISOString().split('T')[0];
function showLoading() {
document.getElementById('loading').style.display = 'block';
document.getElementById('report-container').style.display = 'none';
document.getElementById('error').style.display = 'none';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
}
function showError(message) {
document.getElementById('error').style.display = 'block';
document.getElementById('error').textContent = message;
}
function generateTodayReport() {
document.getElementById('date').value = new Date().toISOString().split('T')[0];
generateReport();
}
function generateReport() {
const date = document.getElementById('date').value;
if (!date) {
showError('请选择日期');
return;
}
showLoading();
fetch(`api/reports/daily?date=${date}`)
.then(response => response.json())
.then(data => {
hideLoading();
if (data.success) {
// 保存原始Markdown内容到data属性
document.getElementById('report-content').setAttribute('data-markdown', data.report);
// 使用专业的Markdown解析器将Markdown转换为HTML并显示
const htmlContent = parseMarkdownWithTables(data.report);
document.getElementById('report-content').innerHTML = htmlContent;
// 重置为预览模式
togglePreview('preview');
document.getElementById('report-container').style.display = 'block';
// 显示统计数据
if (data.statistics) {
displayStatistics(data.statistics);
document.getElementById('statistics').style.display = 'block';
}
} else {
showError('生成日报失败:' + data.error);
}
})
.catch(error => {
hideLoading();
showError('网络错误:' + error.message);
});
}
function displayStatistics(stats) {
const statGrid = document.getElementById('stat-grid');
statGrid.innerHTML = '';
const statistics = [
{label: '今日消息量', value: stats.today_message_count, unit: '条'},
{label: '昨日消息量', value: stats.yesterday_message_count, unit: '条'},
{label: '消息变化率', value: stats.message_change_rate.toFixed(1), unit: '%'},
{label: '今日活跃用户', value: stats.today_active_users, unit: '人'},
{label: '昨日活跃用户', value: stats.yesterday_active_users, unit: '人'},
{label: '用户变化率', value: stats.user_change_rate.toFixed(1), unit: '%'},
{label: '群组数量', value: stats.group_count, unit: '个'},
{label: '成员总数', value: stats.member_count, unit: '人'}
];
statistics.forEach(stat => {
const statItem = document.createElement('div');
statItem.className = 'stat-item';
statItem.innerHTML = `
<div class="stat-value">${stat.value}${stat.unit}</div>
<div class="stat-label">${stat.label}</div>
`;
statGrid.appendChild(statItem);
});
}
function exportReport() {
const reportContent = document.getElementById('report-content').getAttribute('data-markdown');
if (!reportContent) {
showError('请先生成日报');
return;
}
const blob = new Blob([reportContent], {type: 'text/markdown'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `运营日报_${document.getElementById('date').value}.md`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// 页面加载时自动生成今日日报
window.addEventListener('load', function () {
generateTodayReport();
});
// 使用专业的Markdown解析器解析Markdown文本,支持表格
function parseMarkdownWithTables(markdown) {
if (typeof MarkdownParser !== 'undefined' && typeof MergeTableParser !== 'undefined') {
const parser = new MarkdownParser();
return parser.parseFull(markdown);
} else {
// 回退到简单的markdown渲染
return markdownToHtml(markdown);
}
}

182
static/js/h2p.js Normal file
View File

@@ -0,0 +1,182 @@
/**
* HTML转图片工具
* 支持将HTML元素转换为PNG、JPEG格式的图片
* 使用html2canvas库实现
*/
class HTMLToImage {
constructor(options = {}) {
this.options = {
scale: 2, // 缩放比例,提高图片清晰度
useCORS: true, // 启用跨域图片支持
allowTaint: false, // 不允许污染画布
backgroundColor: '#ffffff', // 背景颜色
width: null, // 自定义宽度
height: null, // 自定义高度
...options
};
// 检查是否已加载html2canvas
if (typeof html2canvas === 'undefined') {
console.warn('html2canvas未加载,将动态加载...');
this.loadHtml2Canvas();
}
}
/**
* 将HTML元素转换为图片
* @param {HTMLElement} element - 要转换的HTML元素
* @param {Object} options - 转换选项
* @returns {Promise<string>} - 返回图片的DataURL
*/
async toImage(element, options = {}) {
try {
// 确保html2canvas已加载
if (typeof html2canvas === 'undefined') {
await this.loadHtml2Canvas();
}
const mergedOptions = { ...this.options, ...options };
const canvas = await html2canvas(element, mergedOptions);
return canvas.toDataURL('image/png');
} catch (error) {
console.error('HTML转图片失败:', error);
throw error;
}
}
/**
* 将HTML元素转换为JPEG图片
* @param {HTMLElement} element - 要转换的HTML元素
* @param {number} quality - JPEG质量 (0-1)
* @param {Object} options - 转换选项
* @returns {Promise<string>} - 返回图片的DataURL
*/
async toJPEG(element, quality = 0.92, options = {}) {
try {
if (typeof html2canvas === 'undefined') {
await this.loadHtml2Canvas();
}
const mergedOptions = { ...this.options, ...options };
const canvas = await html2canvas(element, mergedOptions);
return canvas.toDataURL('image/jpeg', quality);
} catch (error) {
console.error('HTML转JPEG失败:', error);
throw error;
}
}
/**
* 下载图片
* @param {string} dataURL - 图片的DataURL
* @param {string} filename - 文件名
*/
downloadImage(dataURL, filename = 'image.png') {
const link = document.createElement('a');
link.download = filename;
link.href = dataURL;
link.click();
}
/**
* 将图片DataURL转换为Blob对象
* @param {string} dataURL - 图片的DataURL
* @returns {Promise<Blob>}
*/
dataURLToBlob(dataURL) {
return new Promise((resolve) => {
const byteString = atob(dataURL.split(',')[1]);
const mimeString = dataURL.split(',')[0].split(':')[1].split(';')[0];
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
resolve(new Blob([ab], { type: mimeString }));
});
}
/**
* 获取图片的尺寸信息
* @param {string} dataURL - 图片的DataURL
* @returns {Promise<{width: number, height: number}>}
*/
getImageDimensions(dataURL) {
return new Promise((resolve) => {
const img = new Image();
img.onload = () => {
resolve({
width: img.width,
height: img.height
});
};
img.src = dataURL;
});
}
/**
* 批量转换多个元素
* @param {HTMLElement[]} elements - 要转换的元素数组
* @param {Object} options - 转换选项
* @returns {Promise<string[]>} - 返回图片DataURL数组
*/
async batchConvert(elements, options = {}) {
const results = [];
for (let i = 0; i < elements.length; i++) {
try {
const dataURL = await this.toImage(elements[i], options);
results.push(dataURL);
console.log(`第 ${i + 1} 个元素转换完成`);
} catch (error) {
console.error(`第 ${i + 1} 个元素转换失败:`, error);
results.push(null);
}
}
return results;
}
}
/**
* 便捷函数:快速转换并下载
* @param {HTMLElement} element - 要转换的HTML元素
* @param {string} filename - 文件名
* @param {Object} options - 转换选项
*/
async function convertAndDownload(element, filename = 'screenshot.png', options = {}) {
const converter = new HTMLToImage(options);
try {
const dataURL = await converter.toImage(element, options);
converter.downloadImage(dataURL, filename);
console.log('图片下载成功');
return Promise.resolve(); // 返回成功的Promise
} catch (error) {
console.error('转换下载失败:', error);
return Promise.reject(error); // 返回失败的Promise
}
}
/**
* 便捷函数:获取图片DataURL
* @param {HTMLElement} element - 要转换的HTML元素
* @param {Object} options - 转换选项
* @returns {Promise<string>}
*/
async function getImageDataURL(element, options = {}) {
const converter = new HTMLToImage(options);
return await converter.toImage(element, options);
}
// 导出到全局作用域
if (typeof window !== 'undefined') {
window.HTMLToImage = HTMLToImage;
window.convertAndDownload = convertAndDownload;
window.getImageDataURL = getImageDataURL;
}

20
static/js/html2canvas.min.js vendored Normal file

File diff suppressed because one or more lines are too long

303
static/js/index.js Normal file
View File

@@ -0,0 +1,303 @@
let currentOffset = 0;
const limit = 50;
let currentView = 'groups';
let currentGroupId = null;
// 页面加载时初始化
document.addEventListener('DOMContentLoaded', function () {
loadStatistics();
loadGroupMessages();
loadMessages();
});
// 加载统计信息
async function loadStatistics() {
try {
const response = await fetch('api/statistics');
const data = await response.json();
if (data) {
const stats = data;
document.getElementById('userCount').textContent = stats.user_count;
document.getElementById('groupCount').textContent = stats.group_count;
document.getElementById('messageCount').textContent = stats.message_count;
document.getElementById('fileCount').textContent = stats.file_count;
}
} catch (error) {
console.error('加载统计信息失败:', error);
}
}
// 加载按群组分组的消息统计
async function loadGroupMessages() {
try {
const response = await fetch('api/groups');
const data = await response.json();
const groupList = document.getElementById('groupList');
if (data.success) {
const groups = data.groups || [];
groupList.innerHTML = '';
if (groups.length === 0) {
groupList.innerHTML = '<li>暂无群组</li>';
return;
} else {
currentGroupId = groups[0].id;
}
groups.forEach(group => {
const li = document.createElement('li');
li.className = 'group-item';
li.setAttribute('data-group-id', group.id);
li.onclick = () => selectGroup(group.id);
const groupName = document.createElement('div');
groupName.className = 'group-name';
groupName.textContent = group.name || group.id;
const groupInfo = document.createElement('div');
groupInfo.className = 'group-info';
groupInfo.innerHTML = `
<span>创建者: ${group.owner || '未知'}</span>
`;
li.appendChild(groupName);
li.appendChild(groupInfo);
groupList.appendChild(li);
});
// 默认选择第一个群组
if (currentView === 'groups' && groups.length > 0) {
selectGroup(groups[0].id);
}
} else {
groupList.innerHTML = '<li>加载失败</li>';
}
} catch (error) {
console.error('加载群组消息失败:', error);
}
}
// 选择群组
function selectGroup(groupId) {
currentGroupId = groupId;
currentOffset = 0;
// 更新选中状态
document.querySelectorAll('.group-item').forEach(item => {
item.classList.remove('active');
});
// 找到对应的群组项并添加选中状态
document.querySelectorAll('.group-item').forEach(item => {
// 使用data-group-id属性来准确匹配群组
if (item.getAttribute('data-group-id') === groupId) {
item.classList.add('active');
// 更新群组信息
document.getElementById('currentGroup').textContent = item.querySelector('.group-name').textContent;
document.getElementById('messageCountDisplay').textContent = '消息数量: 加载中...';
document.getElementById('latestTime').textContent = '最新消息: 加载中...';
}
});
// 加载该群组的消息
loadMessages();
// 加载统计信息
loadStatistics();
}
// 加载更多消息
async function loadMoreMessages() {
await loadMessages();
}
// 关闭聊天记录模态框
function closeChatRecordModal() {
document.getElementById('chatRecordModal').style.display = 'none';
}
// 显示聊天记录模态框
function showChatRecordModal(chatrecordData) {
const modal = document.getElementById('chatRecordModal');
const title = document.getElementById('modalTitle');
const content = document.getElementById('chatRecordContent');
// 设置模态框标题
if (chatrecordData.chatrecord && chatrecordData.chatrecord.title) {
title.textContent = chatrecordData.chatrecord.title;
} else {
title.textContent = '聊天记录';
}
// 渲染聊天记录内容
renderChatRecordContent(chatrecordData, content);
modal.style.display = 'block';
}
// 渲染聊天记录内容
function renderChatRecordContent(chatrecordData, contentElement) {
try {
if (!chatrecordData.chatrecord || !chatrecordData.chatrecord.item) {
contentElement.innerHTML = '<div class="error">聊天记录数据格式错误</div>';
return;
}
const chatItems = chatrecordData.chatrecord.item;
if (!Array.isArray(chatItems) || chatItems.length === 0) {
contentElement.innerHTML = '<div class="error">暂无聊天记录内容</div>';
return;
}
let html = '';
chatItems.forEach(item => {
// 处理不同类型的聊天记录项
let contentHtml = '';
if (item.type === 'ChatRecordText') {
// 文本消息
try {
const contentData = JSON.parse(item.content);
contentHtml = contentData.content || item.content || '';
} catch (e) {
contentHtml = item.content || '';
}
} else if (item.type === 'ChatRecordImage') {
// 图片消息
contentHtml = '<div class="chat-record-image">[图片消息]</div>';
} else {
// 其他类型消息
contentHtml = `[${item.type}] ${item.content || ''}`;
}
html += `
<div class="chat-record-item">
<div class="chat-record-sender">${item.from_chatroom ? '群聊' : '私聊'}</div>
<div class="chat-record-text">${contentHtml}</div>
<div class="chat-record-time">${new Date(item.msgtime * 1000).toLocaleString()}</div>
</div>
`;
});
contentElement.innerHTML = html;
} catch (error) {
console.error('渲染聊天记录失败:', error);
contentElement.innerHTML = '<div class="error">渲染聊天记录失败: ' + error.message + '</div>';
}
}
// 加载消息
async function loadMessages() {
try {
const chatMessages = document.getElementById('chatMessages');
if (!currentGroupId) {
chatMessages.innerHTML = '<div class="loading">暂无消息</div>';
return;
}
let url = `api/group_messages?limit=${limit}&offset=${currentOffset}&group_id=${currentGroupId}`;
const response = await fetch(url);
const data = await response.json();
if (data.success) {
const messages = data.messages || [];
if (messages.length === 0) {
if (currentOffset === 0) {
chatMessages.innerHTML = '<div class="loading">暂无消息</div>';
}
document.getElementById('messageCountDisplay').textContent = `消息数量: ${data.total || 0}`;
document.getElementById('latestTime').textContent = `最新消息: ${data.lastest_time || '暂无'}`;
return;
}
// 如果是第一次加载(offset=0),清空消息区域
if (currentOffset === 0) {
chatMessages.innerHTML = '';
}
// 将新消息插入到消息区域的开头(向上加载历史消息)
messages.forEach(message => {
const messageDiv = createMessageElement(message);
chatMessages.insertBefore(messageDiv, chatMessages.firstChild);
});
// 更新偏移量,用于下次加载更多
currentOffset += limit;
document.getElementById('messageCountDisplay').textContent = `消息数量: ${data.total || 0}`;
document.getElementById('latestTime').textContent = `最新消息: ${data.lastest_time || '暂无'}`;
} else {
chatMessages.innerHTML = '<div class="error">加载消息失败</div>';
}
} catch (error) {
console.error('加载消息失败:', error);
document.getElementById('chatMessages').innerHTML = '<div class="error">加载消息失败: ' + error.message + '</div>';
}
}
// 创建消息元素
function createMessageElement(message) {
const messageDiv = document.createElement('div');
messageDiv.className = 'message';
// 判断是否为自己的消息
if (message.is_own) {
messageDiv.classList.add('own');
}
const avatar = document.createElement('div');
avatar.className = 'avatar';
avatar.textContent = message.sender_name ? message.sender_name.charAt(0).toUpperCase() : 'U';
const contentDiv = document.createElement('div');
contentDiv.className = 'message-content';
const senderDiv = document.createElement('div');
senderDiv.className = 'message-sender';
senderDiv.textContent = message.sender_name || '未知用户';
const textDiv = document.createElement('div');
textDiv.className = 'message-text';
// 处理消息内容
if (message.content) {
if (message.type === 'chatrecord' && message.chatrecord_data) {
const chatrecordBtn = document.createElement('button');
chatrecordBtn.className = 'chatrecord-btn';
chatrecordBtn.textContent = message.display_content || '[聊天记录]';
chatrecordBtn.onclick = () => showChatRecordModal(message.chatrecord_data);
textDiv.appendChild(chatrecordBtn);
} else {
textDiv.textContent = message.display_content;
}
} else {
textDiv.textContent = '[空消息]';
}
const timeDiv = document.createElement('div');
timeDiv.className = 'message-time';
timeDiv.textContent = message.formatted_time;
contentDiv.appendChild(senderDiv);
contentDiv.appendChild(textDiv);
contentDiv.appendChild(timeDiv);
messageDiv.appendChild(avatar);
messageDiv.appendChild(contentDiv);
return messageDiv;
}
// 点击模态框外部关闭
window.onclick = function (event) {
const modal = document.getElementById('chatRecordModal');
if (event.target === modal) {
modal.style.display = 'none';
}
}

View File

@@ -0,0 +1,311 @@
/**
* 基础Markdown解析器
* 支持标题、粗体、斜体、列表、链接、图片、代码、引用等基础语法
*/
class MarkdownParser {
constructor() {
this.patterns = {
heading: /^(#{1,6})\s+(.+)$/gm,
bold: /\*\*(.*?)\*\*/g,
italic: /\*(.*?)\*/g,
inlineCode: /`(.*?)`/g,
image: /!\[(.*?)]\((.*?)\)/g,
base64Image: /!\[(.*?)]\((data:image\/[^;]+;base64,[^\)]+)\)/gi,
imageLink: /\[(.*?)]\((.*?\.(?:jpg|jpeg|png|gif|bmp|webp|svg))\s*(?:"(.*?)")?\)/gi,
link: /\[(.*?)]\((?!.*\.(?:jpg|jpeg|png|gif|bmp|webp|svg))(.*?)\)/g,
blockquote: /^>\s+(.+)$/gm,
unorderedList: /^\s*[-*+]\s+(.+)$/gm,
orderedList: /^\d+\.\s+(.+)$/gm,
codeBlock: /```.*?\n([\s\S]*?)```/g,
horizontalRule: /^---$/gm,
comment: /<!--([\s\S]*?)-->/g
};
}
/**
* 解析Markdown文本为HTML
* @param {string} markdown - Markdown文本
* @returns {string} - HTML文本
*/
parse(markdown) {
let html = markdown;
// 处理代码块(先处理,避免其他语法干扰)
html = html.replace(this.patterns.codeBlock, (match, code) => {
// 保留代码内部的换行符,只去除首尾空白
let codeLines = code.split('\n');
let result = '<pre>';
for (let i in codeLines) {
if (codeLines[i].trim() === '') {
continue;
} else {
result += `<code>${codeLines[i]}</code><br>`;
}
}
result += '</pre>';
return result;
});
// 处理块引用
html = html.replace(this.patterns.blockquote, (match, text) => {
return `<blockquote>${this.parseInline(text)}</blockquote>`;
});
// 处理水平分割线
html = html.replace(this.patterns.horizontalRule, '<hr>');
// 处理注释(保留HTML注释)
html = html.replace(this.patterns.comment, '<!--$1-->');
// 处理列表(先处理有序列表,再处理无序列表,避免冲突)
html = this.processLists(html);
// 处理段落(将连续文本包装为段落)
html = this.wrapParagraphs(html);
return html;
}
/**
* 解析行内元素
* @param {string} text - 文本内容
* @returns {string} - 解析后的HTML
*/
parseInline(text) {
let html = text;
// 处理粗体
html = html.replace(this.patterns.bold, '<strong>$1</strong>');
// 处理斜体
html = html.replace(this.patterns.italic, '<em>$1</em>');
// 处理行内代码
html = html.replace(this.patterns.inlineCode, '<code>$1</code>');
// 处理普通图片格式 ![alt](url)
html = html.replace(this.patterns.image, '<img width="100%" src="$2" alt="$1">');
// 处理base64图片格式 ![alt](data:image/...)
html = html.replace(this.patterns.base64Image, '<img width="100%" src="$2" alt="$1">');
// 处理图片链接格式 [alt](image.jpg "title")
html = html.replace(this.patterns.imageLink, (match, alt, src, title) => {
const titleAttr = title ? ` title="${title}"` : '';
return `<img width="100%" src="${src}" alt="${alt}"${titleAttr}>`;
});
// 处理链接
html = html.replace(this.patterns.link, '<a href="$2">$1</a>');
return html;
}
/**
* 处理所有列表,先识别列表类型再处理列表项
* @param {string} html - HTML文本
* @returns {string} - 处理后的HTML
*/
processLists(html) {
// 先识别并标记列表类型
const lines = html.split('\n');
let result = '';
let currentListType = '';
let listItems = [];
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.match(/^\d+\.\s/)) {
// 有序列表项
if (currentListType !== 'ol') {
// 结束前一个列表
if (listItems.length > 0) {
result += this.wrapListItems(listItems, currentListType);
listItems = [];
}
currentListType = 'ol';
}
const content = line.replace(/^\d+\.\s+/, '');
listItems.push(`<li>${this.parseInline(content)}</li>`);
} else if (line.match(/^[-*+]\s/)) {
// 无序列表项
if (currentListType !== 'ul') {
// 结束前一个列表
if (listItems.length > 0) {
result += this.wrapListItems(listItems, currentListType);
listItems = [];
}
currentListType = 'ul';
}
const content = line.replace(/^[-*+]\s+/, '');
listItems.push(`<li>${this.parseInline(content)}</li>`);
} else {
// 非列表项
if (listItems.length > 0) {
result += this.wrapListItems(listItems, currentListType);
listItems = [];
currentListType = '';
}
result += lines[i] + '\n';
}
}
// 处理最后一个列表
if (listItems.length > 0) {
result += this.wrapListItems(listItems, currentListType);
}
return result;
}
/**
* 包装列表项
* @param {Array} listItems - 列表项数组
* @param {string} listType - 列表类型(ul或ol)
* @returns {string} - 包装后的HTML列表
*/
wrapListItems(listItems, listType) {
if (listItems.length === 0) return '';
const listTag = listType === 'ol' ? 'ol' : 'ul';
return `<${listTag}>\n${listItems.join('\n')}\n</${listTag}>\n`;
}
/**
* 包装段落,保留Markdown原有换行
* @param {string} html - HTML文本
* @returns {string} - 包装后的HTML
*/
wrapParagraphs(html) {
const lines = html.split('\n');
let result = '';
let currentParagraph = '';
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const trimmedLine = line.trim();
if (!trimmedLine) {
// 空行,结束当前段落
if (currentParagraph) {
// 检查当前段落是否已经是块级元素
if (!currentParagraph.match(/^<(h[1-6]|blockquote|ul|ol|li|pre|hr)/)) {
result += `<p>${this.parseInline(currentParagraph)}</p>`;
} else {
result += currentParagraph;
}
currentParagraph = '';
}
result += '\n';
} else if (trimmedLine.match(/^<(h[1-6]|blockquote|ul|ol|li|pre|hr)/)) {
// 已经是块级元素,直接添加
if (currentParagraph) {
if (!currentParagraph.match(/^<(h[1-6]|blockquote|ul|ol|li|pre|hr)/)) {
result += `<p>${this.parseInline(currentParagraph)}</p>`;
} else {
result += currentParagraph;
}
currentParagraph = '';
}
result += line + '\n';
} else {
// 保留原有换行,不合并为一行
if (currentParagraph) {
currentParagraph += '\n' + line;
} else {
currentParagraph = line;
}
}
}
// 处理最后一个段落
if (currentParagraph) {
if (!currentParagraph.match(/^<(h[1-6]|blockquote|ul|ol|li|pre|hr)/)) {
result += `<p>${this.parseInline(currentParagraph)}</p>`;
} else {
result += currentParagraph;
}
}
return result;
}
/**
* HTML转义,支持保留<br>标签
* @param {string} text - 原始文本
* @returns {string} - 转义后的文本
*/
escapeHTML(text) {
// 首先转义所有HTML特殊字符
const escapedText = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
// 然后恢复<br>标签的功能
return escapedText
.replace(/&lt;br\s*\/?&gt;/gi, '<br>')
.replace(/&lt;br\s*\/?&gt;/gi, '<br>')
.replace(/\\n/g, '<br>'); // 也支持\n换行符
}
/**
* 专门解析表格(与MergeTableParser配合使用)
* @param {string} markdown - Markdown表格文本
* @returns {string} - HTML表格
*/
parseTable(markdown) {
// 使用MergeTableParser处理表格
if (typeof MergeTableParser !== 'undefined') {
const tableParser = new MergeTableParser();
return tableParser.parseMarkdownTable(markdown);
}
return markdown;
}
/**
* 完整解析Markdown,包含表格处理
* @param {string} markdown - 完整Markdown文本
* @returns {string} - 完整HTML
*/
parseFull(markdown) {
let html = markdown;
// 先处理标题,避免表格干扰
html = html.replace(this.patterns.heading, (match, hashes, text) => {
const level = hashes.length;
return `<h${level}>${this.parseInline(text)}</h${level}>`;
});
// 再提取并处理表格
const tableRegex = /(\|.*?\|\s*\n)+/g;
html = html.replace(tableRegex, (match) => {
// 检查是否是有效的表格格式
const lines = match.trim().split('\n');
if (lines.length >= 2 && lines.every(line => line.trim().startsWith('|') && line.trim().endsWith('|'))) {
return this.parseTable(match);
}
return match;
});
// 然后处理其他Markdown语法
return this.parse(html);
}
}
// 导出为全局变量
if (typeof window !== 'undefined') {
window.MarkdownParser = MarkdownParser;
}
// 使用示例
if (typeof module !== 'undefined' && module.exports) {
module.exports = MarkdownParser;
}

View File

@@ -0,0 +1,273 @@
/**
* 支持合并单元格的Markdown表格解析器
* 语法说明:
* ^n# - 向上合并n个单元格
* >n# - 向左合并n个单元格
* ^n>m# - 同时向上合并n个单元格,向左合并m个单元格
*/
class MergeTableParser {
constructor() {
this.patterns = {
mergeUp: /\^(\d+)#/, // ^2#
mergeLeft: />(\d+)#/, // >3#
mergeBoth: /\^(\d+)>(\d+)#/, // ^2>3#
};
}
/**
* 解析Markdown表格并转换为HTML表格
* @param {string} markdown - Markdown表格文本
* @returns {string} - HTML表格
*/
parseMarkdownTable(markdown) {
const lines = markdown.trim().split('\n');
const tableData = this.parseTableLines(lines);
return this.generateHTMLTable(tableData);
}
/**
* 解析表格行数据
* @param {string[]} lines - 表格行数组
* @returns {Object} - 表格数据对象
*/
parseTableLines(lines) {
const rows = [];
let headers = [];
let separatorIndex = -1;
// 解析表头和分隔符
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('|') && line.endsWith('|')) {
const cells = line.slice(1, -1).split('|').map(cell => cell.trim());
if (line.includes('---') || line.includes('===')) {
separatorIndex = i;
continue;
}
if (separatorIndex === -1) {
headers = cells;
} else {
rows.push(cells);
}
}
}
return { headers, rows, separatorIndex };
}
/**
* 生成HTML表格
* @param {Object} tableData - 表格数据
* @returns {string} - HTML表格字符串
*/
generateHTMLTable(tableData) {
const { headers, rows } = tableData;
const skipMap = new Map(); // 用于标记需要跳过的单元格
let html = '<table border="1" style="border-collapse: collapse; width: 100%;">\n';
// 生成表头(支持合并单元格)
if (headers.length > 0) {
html += ' <thead>\n <tr>\n';
// 处理表头合并单元格
headers.forEach((header, colIndex) => {
// 检查当前单元格是否应该被跳过
const key = `-1,${colIndex}`; // 表头行索引为-1
if (skipMap.has(key)) {
return;
}
const mergeInfo = this.parseMergeSyntax(header);
let cellHtml = '';
if (mergeInfo.rowspan > 1 || mergeInfo.colspan > 1) {
cellHtml = ` <th rowspan="${mergeInfo.rowspan}" colspan="${mergeInfo.colspan}">${this.escapeHTML(mergeInfo.content)}</th>\n`;
// 标记被合并的表头单元格
this.markMergedCells(-1, colIndex, mergeInfo, skipMap);
} else {
cellHtml = ` <th>${this.escapeHTML(header)}</th>\n`;
}
html += cellHtml;
});
html += ' </tr>\n </thead>\n';
}
// 生成表格主体
html += ' <tbody>\n';
// 第一遍:标记所有需要合并的单元格
rows.forEach((row, rowIndex) => {
row.forEach((cell, colIndex) => {
const mergeInfo = this.parseMergeSyntax(cell);
if (mergeInfo.rowspan > 1 || mergeInfo.colspan > 1) {
this.markMergedCells(rowIndex, colIndex, mergeInfo, skipMap);
}
});
});
// 第二遍:生成HTML,跳过被合并的单元格
rows.forEach((row, rowIndex) => {
html += ' <tr>\n';
let colOffset = 0; // 列偏移量,用于处理被跳过的单元格
row.forEach((cell, colIndex) => {
// 检查当前单元格是否应该被跳过
const key = `${rowIndex},${colIndex}`;
if (skipMap.has(key)) {
colOffset++;
return;
}
const mergeInfo = this.parseMergeSyntax(cell);
let cellHtml = '';
if (mergeInfo.rowspan > 1 || mergeInfo.colspan > 1) {
cellHtml = ` <td rowspan="${mergeInfo.rowspan}" colspan="${mergeInfo.colspan}">${this.escapeHTML(mergeInfo.content)}</td>\n`;
} else {
cellHtml = ` <td>${this.escapeHTML(cell)}</td>\n`;
}
html += cellHtml;
});
html += ' </tr>\n';
});
html += ' </tbody>\n</table>';
return html;
}
/**
* 解析合并语法
* @param {string} cell - 单元格内容
* @returns {Object} - 合并信息
*/
parseMergeSyntax(cell) {
const result = {
content: cell,
rowspan: 1,
colspan: 1,
shouldSkip: false
};
// 检查合并语法
const bothMatch = cell.match(this.patterns.mergeBoth);
const upMatch = cell.match(this.patterns.mergeUp);
const leftMatch = cell.match(this.patterns.mergeLeft);
if (bothMatch) {
result.rowspan = parseInt(bothMatch[1]) + 1;
result.colspan = parseInt(bothMatch[2]) + 1;
result.content = cell.replace(this.patterns.mergeBoth, '').trim();
} else if (upMatch) {
result.rowspan = parseInt(upMatch[1]) + 1;
result.content = cell.replace(this.patterns.mergeUp, '').trim();
} else if (leftMatch) {
result.colspan = parseInt(leftMatch[1]) + 1;
result.content = cell.replace(this.patterns.mergeLeft, '').trim();
}
return result;
}
/**
* 标记被合并的单元格
* @param {number} rowIndex - 行索引
* @param {number} colIndex - 列索引
* @param {Object} mergeInfo - 合并信息
* @param {Map} skipMap - 跳过映射
*/
markMergedCells(rowIndex, colIndex, mergeInfo, skipMap) {
for (let r = 0; r < mergeInfo.rowspan; r++) {
for (let c = 0; c < mergeInfo.colspan; c++) {
if (r === 0 && c === 0) continue; // 跳过主单元格
// 处理表头合并(行索引为-1)
const targetRow = rowIndex === -1 ? -1 : rowIndex + r;
const key = `${targetRow},${colIndex + c}`;
skipMap.set(key, true);
}
}
}
/**
* HTML转义,支持保留<br>标签
* @param {string} text - 原始文本
* @returns {string} - 转义后的文本
*/
escapeHTML(text) {
// 首先转义所有HTML特殊字符
const escapedText = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
// 然后恢复<br>标签的功能
return escapedText
.replace(/&lt;br\s*\/?&gt;/gi, '<br>')
.replace(/&lt;br\s*\/?&gt;/gi, '<br>')
.replace(/\\n/g, '<br>'); // 也支持\n换行符
}
/**
* 将HTML表格转换回Markdown格式
* @param {string} html - HTML表格
* @returns {string} - Markdown表格
*/
htmlToMarkdown(html) {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const table = doc.querySelector('table');
if (!table) return '';
let markdown = '';
const rows = table.querySelectorAll('tr');
rows.forEach((row, rowIndex) => {
const cells = row.querySelectorAll('th, td');
let rowMarkdown = '|';
cells.forEach(cell => {
const rowspan = parseInt(cell.getAttribute('rowspan') || '1');
const colspan = parseInt(cell.getAttribute('colspan') || '1');
let content = cell.textContent.trim();
// 添加合并语法
if (rowspan > 1) {
content += ` ^${rowspan - 1}`;
}
if (colspan > 1) {
content += ` >${colspan - 1}`;
}
rowMarkdown += ` ${content} |`;
});
markdown += rowMarkdown + '\n';
// 添加分隔符行(仅在第一行后)
if (rowIndex === 0) {
markdown += '|' + cells.map(() => '---').join('|') + '|\n';
}
});
return markdown;
}
}
// 导出为全局变量
if (typeof window !== 'undefined') {
window.MergeTableParser = MergeTableParser;
}
// 使用示例
if (typeof module !== 'undefined' && module.exports) {
module.exports = MergeTableParser;
}

1015
static/js/qa.js Normal file

File diff suppressed because it is too large Load Diff

191
static/js/weekly_report.js Normal file
View File

@@ -0,0 +1,191 @@
togglePreview = function (mode) {
const previewBtn = document.getElementById('preview-toggle');
const sourceBtn = document.getElementById('source-toggle');
const reportContent = document.getElementById('report-content');
const markdownSource = document.getElementById('markdown-source');
const sourceContent = document.getElementById('source-content');
if (mode === 'preview') {
previewBtn.classList.add('active');
sourceBtn.classList.remove('active');
reportContent.style.display = 'block';
markdownSource.style.display = 'none';
} else {
previewBtn.classList.remove('active');
sourceBtn.classList.add('active');
reportContent.style.display = 'none';
markdownSource.style.display = 'block';
// 显示原始Markdown源代码
const markdown = reportContent.getAttribute('data-markdown');
sourceContent.textContent = markdown;
}
};
// 设置默认周次为当前周
function getCurrentWeek() {
const now = new Date();
const startOfYear = new Date(now.getFullYear(), 0, 1);
const days = Math.floor((now - startOfYear) / (24 * 60 * 60 * 1000));
const weekNumber = Math.ceil((days + 1) / 7);
return `${now.getFullYear()}-W${weekNumber.toString().padStart(2, '0')}`;
}
// 页面加载时设置默认周次
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('week').value = getCurrentWeek();
});
function showLoading() {
document.getElementById('loading').style.display = 'block';
document.getElementById('report-container').style.display = 'none';
document.getElementById('error').style.display = 'none';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
}
function showError(message) {
document.getElementById('error').style.display = 'block';
document.getElementById('error').textContent = message;
}
function generateCurrentWeekReport() {
document.getElementById('week').value = getCurrentWeek();
generateReport();
}
function generateReport() {
const week = document.getElementById('week').value;
if (!week) {
showError('请选择周次');
return;
}
// 转换格式:YYYY-WWW 到 YYYY-WW
const weekFormatted = week.replace('W', '');
showLoading();
fetch(`api/reports/weekly?week=${weekFormatted}`)
.then(response => response.json())
.then(data => {
hideLoading();
if (data.success) {
// 保存原始Markdown内容到data属性
document.getElementById('report-content').setAttribute('data-markdown', data.report);
// 使用专业的Markdown解析器将Markdown转换为HTML并显示
const htmlContent = parseMarkdownWithTables(data.report);
document.getElementById('report-content').innerHTML = htmlContent;
// 重置为预览模式
togglePreview('preview');
document.getElementById('report-container').style.display = 'block';
// 显示统计数据
if (data.statistics) {
displayStatistics(data.statistics);
document.getElementById('statistics').style.display = 'block';
// 显示分类图表
if (data.statistics.category_breakdown) {
displayCategoryChart(data.statistics.category_breakdown);
document.getElementById('category-chart').style.display = 'block';
}
}
} else {
showError('生成周报失败:' + data.error);
}
})
.catch(error => {
hideLoading();
showError('网络错误:' + error.message);
});
}
function displayStatistics(stats) {
const statGrid = document.getElementById('stat-grid');
statGrid.innerHTML = '';
const statistics = [
{label: '本周消息量', value: stats.week_message_count, unit: '条'},
{label: '上周消息量', value: stats.last_week_message_count, unit: '条'},
{label: '消息变化率', value: stats.message_change_rate.toFixed(1), unit: '%'},
{label: '本周活跃用户', value: stats.week_active_users, unit: '人'},
{label: '群组数量', value: stats.group_count, unit: '个'},
{label: '成员总数', value: stats.member_count, unit: '人'},
{label: '问答记录数', value: stats.qa_count, unit: '条'}
];
statistics.forEach(stat => {
const statItem = document.createElement('div');
statItem.className = 'stat-item';
statItem.innerHTML = `
<div class="stat-value">${stat.value}${stat.unit}</div>
<div class="stat-label">${stat.label}</div>
`;
statGrid.appendChild(statItem);
});
}
function displayCategoryChart(categories) {
const categoryItems = document.getElementById('category-items');
categoryItems.innerHTML = '';
Object.entries(categories).forEach(([category, percentage]) => {
const categoryItem = document.createElement('div');
categoryItem.className = 'category-item';
categoryItem.innerHTML = `
<span style="min-width: 120px;">${category}</span>
<div class="category-bar" style="width: ${percentage * 2}px;"></div>
<span style="min-width: 40px; text-align: right;">${percentage}%</span>
`;
categoryItems.appendChild(categoryItem);
});
}
function exportReport() {
const reportContent = document.getElementById('report-content').getAttribute('data-markdown');
if (!reportContent) {
showError('请先生成周报');
return;
}
const blob = new Blob([reportContent], {type: 'text/markdown'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `运营周报_${document.getElementById('week').value}.md`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// 页面加载时自动生成本周周报
window.addEventListener('load', function () {
generateCurrentWeekReport();
});
// 支持回车键生成报告
document.getElementById('week').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
generateReport();
}
});
// 使用专业的Markdown解析器解析Markdown文本,支持表格
function parseMarkdownWithTables(markdown) {
if (typeof MarkdownParser !== 'undefined' && typeof MergeTableParser !== 'undefined') {
const parser = new MarkdownParser();
return parser.parseFull(markdown);
} else {
// 回退到简单的markdown渲染
return markdownToHtml(markdown);
}
}

View File

@@ -0,0 +1,284 @@
// 周报生成器 v3版本 JavaScript
togglePreview = function (mode) {
const previewBtn = document.getElementById('preview-toggle');
const sourceBtn = document.getElementById('source-toggle');
const reportContent = document.getElementById('report-content');
const markdownSource = document.getElementById('markdown-source');
const sourceContent = document.getElementById('source-content');
if (mode === 'preview') {
previewBtn.classList.add('active');
sourceBtn.classList.remove('active');
reportContent.style.display = 'block';
markdownSource.style.display = 'none';
} else {
previewBtn.classList.remove('active');
sourceBtn.classList.add('active');
reportContent.style.display = 'none';
markdownSource.style.display = 'block';
// 显示原始Markdown源代码
const markdown = reportContent.getAttribute('data-markdown');
sourceContent.textContent = markdown;
}
};
// 页面加载时获取可用的周次列表
document.addEventListener('DOMContentLoaded', function () {
loadAvailableWeeks();
});
// 加载可用的周次列表
function loadAvailableWeeks() {
fetch('/v3/api/weekly_report/weeks')
.then(response => response.json())
.then(data => {
if (data.success) {
const weekSelect = document.getElementById('week');
weekSelect.innerHTML = '<option value="">请选择周次...</option>';
data.data.weeks.forEach(week => {
const option = document.createElement('option');
option.value = week.week;
option.textContent = week.display;
weekSelect.appendChild(option);
});
// 设置默认选择为当前周
const currentDate = new Date();
const year = currentDate.getFullYear();
const weekNumber = getWeekNumber(currentDate);
const currentWeek = `${year}-${weekNumber.toString().padStart(2, '0')}`;
weekSelect.value = currentWeek;
} else {
console.error('获取周次列表失败:', data.error);
}
})
.catch(error => {
console.error('网络错误:', error);
});
}
// 获取周数
function getWeekNumber(date) {
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
const pastDaysOfYear = (date - firstDayOfYear) / 86400000;
return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
}
function showLoading(message = '正在生成周报,请稍候...') {
document.getElementById('loading').style.display = 'block';
document.getElementById('loading-details').textContent = message;
document.getElementById('report-container').style.display = 'none';
document.getElementById('error').style.display = 'none';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
document.getElementById('loading-details').textContent = '';
}
function showError(message) {
document.getElementById('error').style.display = 'block';
document.getElementById('error').textContent = message;
}
function generateCurrentWeekReport() {
const currentDate = new Date();
const year = currentDate.getFullYear();
const weekNumber = getWeekNumber(currentDate);
const currentWeek = `${year}-${weekNumber.toString().padStart(2, '0')}`;
document.getElementById('week').value = currentWeek;
generateReport();
}
function generateReport() {
const week = document.getElementById('week').value;
const useDeepseek = document.getElementById('use-deepseek').checked;
if (!week) {
showError('请选择周次');
return;
}
showLoading(useDeepseek ? '正在生成周报(使用DeepSeek AI增强)...' : '正在生成周报...');
fetch('/v3/api/weekly_report/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
week: week,
use_deepseek: useDeepseek
})
})
.then(response => response.json())
.then(data => {
hideLoading();
if (data.success) {
// 保存原始Markdown内容到data属性
document.getElementById('report-content').setAttribute('data-markdown', data.data.report);
// 使用专业的Markdown解析器将Markdown转换为HTML并显示
const htmlContent = parseMarkdownWithTables(data.data.report);
document.getElementById('report-content').innerHTML = htmlContent;
// 重置为预览模式
togglePreview('preview');
document.getElementById('report-container').style.display = 'block';
// 启用图片导出按钮
updateImageExportButtonState();
// 显示统计数据
if (data.data.statistics) {
// 显示分类图表
if (data.data.statistics.category_breakdown) {
displayCategoryChart(data.data.statistics.category_breakdown);
document.getElementById('category-chart').style.display = 'block';
}
}
} else {
showError('生成周报失败:' + data.error);
}
})
.catch(error => {
hideLoading();
showError('网络错误:' + error.message);
});
}
function displayCategoryChart(categories) {
const categoryItems = document.getElementById('category-items');
categoryItems.innerHTML = '';
Object.entries(categories).forEach(([category, percentage]) => {
const categoryItem = document.createElement('div');
categoryItem.className = 'category-item';
categoryItem.innerHTML = `
<span style="min-width: 120px;">${category}</span>
<div class="category-bar" style="width: ${percentage * 2}px;"></div>
<span style="min-width: 40px; text-align: right;">${percentage}%</span>
`;
categoryItems.appendChild(categoryItem);
});
}
function exportReport() {
const reportContent = document.getElementById('report-content').getAttribute('data-markdown');
if (!reportContent) {
showError('请先生成周报');
return;
}
const week = document.getElementById('week').value;
const blob = new Blob([reportContent], {type: 'text/markdown'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `运营周报_v3_${week}.md`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
/**
* 导出报告为图片
*/
async function exportReportAsImage() {
const exportBtn = document.getElementById('image-export-btn');
const reportContent = document.getElementById('report-content');
if (!reportContent || reportContent.innerHTML.trim() === '') {
alert('请先生成周报内容');
return;
}
if (typeof convertAndDownload === 'undefined') {
alert('图片导出功能未加载,请刷新页面重试');
return;
}
try {
// 显示加载中状态
const originalText = exportBtn.textContent;
exportBtn.disabled = true;
exportBtn.textContent = '导出中...';
// 获取当前周数 - 修复选择器
const week = document.getElementById('week').value || '当前';
const filename = `运营周报_v3_${week}.png`;
console.log('开始导出图片...');
console.log('目标元素:', reportContent);
console.log('文件名:', filename);
await convertAndDownload(reportContent, filename, {
scale: 2,
backgroundColor: '#ffffff',
useCORS: true,
allowTaint: false
});
console.log('图片导出成功');
alert('图片导出成功!');
} catch (error) {
console.error('图片导出失败:', error);
alert(`图片导出失败: ${error.message || error}`);
} finally {
// 恢复按钮状态
exportBtn.disabled = false;
exportBtn.textContent = '导出图片';
}
}
// 启用/禁用图片导出按钮
function updateImageExportButtonState() {
const reportContent = document.getElementById('report-content');
const imageExportBtn = document.getElementById('image-export-btn');
if (reportContent && reportContent.innerHTML.trim()) {
imageExportBtn.disabled = false;
imageExportBtn.classList.remove('disabled');
} else {
imageExportBtn.disabled = true;
imageExportBtn.classList.add('disabled');
}
}
// 支持回车键生成报告
document.getElementById('week').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
generateReport();
}
});
// 使用专业的Markdown解析器解析Markdown文本,支持表格
function parseMarkdownWithTables(markdown) {
if (typeof MarkdownParser !== 'undefined' && typeof MergeTableParser !== 'undefined') {
const parser = new MarkdownParser();
return parser.parseFull(markdown);
} else {
// 回退到简单的markdown渲染
return markdownToHtml(markdown);
}
}
// 简单的Markdown转HTML函数(备用)
function markdownToHtml(markdown) {
return markdown
.replace(/\n/g, '<br>')
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.*?)\*/g, '<em>$1</em>')
.replace(/^#\s+(.*)$/gm, '<h1>$1</h1>')
.replace(/^##\s+(.*)$/gm, '<h2>$1</h2>')
.replace(/^###\s+(.*)$/gm, '<h3>$1</h3>')
.replace(/`(.*?)`/g, '<code>$1</code>');
}