This commit is contained in:
aaron 2026-02-03 16:55:29 +08:00
parent dbd3a6322c
commit af799e8ee3
3 changed files with 299 additions and 5 deletions

View File

@ -201,6 +201,83 @@ html, body {
color: var(--text-primary);
}
/* Message Actions */
.message-actions {
display: flex;
gap: 8px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--border);
}
.action-btn {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
background: transparent;
border: 1px solid var(--border-bright);
border-radius: 2px;
color: var(--text-secondary);
font-size: 12px;
cursor: pointer;
transition: all 0.2s;
}
.action-btn:hover {
background: var(--accent-dim);
border-color: var(--accent);
color: var(--accent);
}
.action-btn svg {
flex-shrink: 0;
}
/* Share Image Container (hidden, used for rendering) */
.share-image-container {
position: fixed;
left: -9999px;
top: 0;
width: 800px;
background: var(--bg-secondary);
padding: 40px;
border: 1px solid var(--border);
}
.share-image-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 24px;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
}
.share-image-logo {
font-size: 18px;
font-weight: 500;
color: var(--text-primary);
letter-spacing: 0.5px;
}
.share-image-content {
color: var(--text-primary);
font-size: 14px;
line-height: 1.8;
border-left: 2px solid var(--accent);
padding-left: 20px;
}
.share-image-footer {
margin-top: 24px;
padding-top: 16px;
border-top: 1px solid var(--border);
text-align: center;
font-size: 12px;
color: var(--text-tertiary);
}
/* Markdown Styles */
.markdown h1,
.markdown h2,
@ -549,3 +626,79 @@ html, body {
transform: translateX(-50%) translateY(-10px);
}
}
/* Image Modal */
.image-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.95);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
padding: 20px;
animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.image-modal-content {
position: relative;
max-width: 90%;
max-height: 90%;
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.modal-close-btn {
position: absolute;
top: -50px;
right: 0;
width: 40px;
height: 40px;
background: transparent;
border: 1px solid var(--border-bright);
border-radius: 2px;
color: var(--text-primary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
}
.modal-close-btn:hover {
background: var(--accent-dim);
border-color: var(--accent);
color: var(--accent);
}
.modal-image {
max-width: 100%;
max-height: calc(90vh - 80px);
border: 1px solid var(--border);
border-radius: 2px;
box-shadow: 0 8px 32px rgba(0, 255, 65, 0.1);
}
.modal-hint {
color: var(--text-secondary);
font-size: 13px;
text-align: center;
padding: 8px 16px;
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 2px;
}

View File

@ -53,11 +53,32 @@
:class="['message', msg.role]">
<div class="message-content">
<div v-if="msg.role === 'user'" class="text">{{ msg.content }}</div>
<div v-else class="text markdown" v-html="renderMarkdown(msg.content)"></div>
<div v-else>
<div class="text markdown" v-html="renderMarkdown(msg.content)"></div>
<!-- Chart Display -->
<div v-if="msg.metadata && msg.metadata.type === 'chart'" class="chart-box">
<div :id="'chart-' + index" class="chart"></div>
<!-- Action Buttons for AI Messages -->
<div class="message-actions">
<button class="action-btn" @click.stop="copyMessage(msg.content)" title="复制内容">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
<span>复制</span>
</button>
<button class="action-btn" @click.stop="generateShareImage(msg.content, index)" title="生成分享图">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
<span>分享图</span>
</button>
</div>
<!-- Chart Display -->
<div v-if="msg.metadata && msg.metadata.type === 'chart'" class="chart-box">
<div :id="'chart-' + index" class="chart"></div>
</div>
</div>
</div>
</div>
@ -107,6 +128,20 @@
</div>
</div>
</div>
<!-- Image Modal -->
<div v-if="showImageModal" class="image-modal" @click="closeImageModal">
<div class="image-modal-content" @click.stop>
<button class="modal-close-btn" @click="closeImageModal" title="关闭">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
<img :src="modalImageUrl" alt="分享图" class="modal-image">
<p class="modal-hint">长按图片可保存到相册</p>
</div>
</div>
</div>
<!-- Vue 3 -->
@ -115,6 +150,9 @@
<!-- Lightweight Charts -->
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
<!-- html2canvas for generating share images -->
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<!-- App Script -->
<script src="/static/js/app.js"></script>
</body>

View File

@ -8,7 +8,9 @@ createApp({
userInput: '',
loading: false,
sessionId: null,
charts: {}
charts: {},
showImageModal: false,
modalImageUrl: ''
};
},
mounted() {
@ -256,6 +258,107 @@ createApp({
setTimeout(() => {
document.body.removeChild(notification);
}, 2000);
},
copyMessage(content) {
// 移除HTML标签只保留纯文本
const tempDiv = document.createElement('div');
tempDiv.innerHTML = marked.parse(content);
const plainText = tempDiv.textContent || tempDiv.innerText;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(plainText).then(() => {
this.showNotification('已复制内容');
}).catch(err => {
console.error('复制失败:', err);
this.fallbackCopy(plainText);
});
} else {
this.fallbackCopy(plainText);
}
},
async generateShareImage(content, index) {
try {
this.showNotification('正在生成分享图...');
// 创建临时容器
const container = document.createElement('div');
container.className = 'share-image-container';
container.style.left = '-9999px';
// 构建分享图内容
container.innerHTML = `
<div class="share-image-header">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z" fill="#00ff41"/>
</svg>
<div class="share-image-logo">龙哥的 AI 金融智能体</div>
</div>
<div class="share-image-content">${marked.parse(content)}</div>
<div class="share-image-footer">
AI 智能分析生成 | 仅供参考不构成投资建议
</div>
`;
document.body.appendChild(container);
// 等待渲染
await new Promise(resolve => setTimeout(resolve, 100));
// 生成图片
const canvas = await html2canvas(container, {
backgroundColor: '#0a0a0a',
scale: 2,
logging: false,
useCORS: true
});
// 移除临时容器
document.body.removeChild(container);
// 显示图片在模态框中
this.modalImageUrl = canvas.toDataURL('image/png');
this.showImageModal = true;
this.showNotification('长按图片可保存');
} catch (error) {
console.error('生成分享图失败:', error);
this.showNotification('生成失败,请重试');
}
},
closeImageModal() {
this.showImageModal = false;
this.modalImageUrl = '';
},
showNotification(text) {
const notification = document.createElement('div');
notification.textContent = text;
notification.style.cssText = `
position: fixed;
bottom: 80px;
left: 50%;
transform: translateX(-50%);
background: #00ff41;
color: #000000;
padding: 8px 16px;
border-radius: 2px;
font-size: 13px;
font-weight: 500;
z-index: 10000;
animation: fadeInOut 2s ease;
`;
document.body.appendChild(notification);
setTimeout(() => {
if (document.body.contains(notification)) {
document.body.removeChild(notification);
}
}, 2000);
}
},