XNSim/XNSimPortal/components/help-component.js
2025-07-08 13:45:48 +08:00

311 lines
10 KiB
JavaScript

class HelpComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.render();
this.setupEventListeners();
}
render() {
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
height: 100%;
overflow: auto;
padding: 16px;
box-sizing: border-box;
}
.help-container {
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
padding: 16px;
height: 100%;
box-sizing: border-box;
display: flex;
}
.help-sidebar {
width: 240px;
border-right: 1px solid #e0e0e0;
padding-right: 16px;
overflow-y: auto;
}
.help-content {
flex: 1;
padding-left: 24px;
overflow-y: auto;
}
.search-box {
display: flex;
margin-bottom: 16px;
position: relative;
}
.search-input {
width: 100%;
padding: 8px 12px;
border: 1px solid #d9d9d9;
border-radius: 4px;
font-size: 14px;
outline: none;
transition: all 0.3s;
}
.search-input:focus {
border-color: #7986E7;
box-shadow: 0 0 0 2px rgba(121, 134, 231, 0.2);
}
.help-category {
margin-bottom: 16px;
}
.category-title {
font-size: 16px;
font-weight: bold;
color: #333;
margin-bottom: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: space-between;
}
.category-title::after {
content: '';
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #666;
transition: transform 0.3s;
}
.category-title.expanded::after {
transform: rotate(180deg);
}
.help-items {
margin-left: 8px;
border-left: 2px solid #f0f0f0;
padding-left: 12px;
display: none;
}
.help-items.expanded {
display: block;
}
.help-item {
padding: 6px 0;
font-size: 14px;
color: #666;
cursor: pointer;
transition: color 0.3s;
}
.help-item:hover {
color: #7986E7;
}
.help-item.active {
color: #8B6DB3;
font-weight: 500;
}
.content-title {
font-size: 24px;
font-weight: bold;
color: #333;
margin-bottom: 16px;
padding-bottom: 8px;
border-bottom: 1px solid #e0e0e0;
}
.content-body {
font-size: 15px;
line-height: 1.6;
color: #333;
}
.content-section {
margin-bottom: 24px;
}
.section-title {
font-size: 18px;
font-weight: bold;
color: #333;
margin-bottom: 12px;
}
.section-content {
font-size: 15px;
line-height: 1.6;
color: #333;
}
.code-block {
background-color: #f5f5f5;
padding: 12px;
border-radius: 4px;
font-family: monospace;
overflow-x: auto;
margin: 12px 0;
}
.note {
background-color: #f0f7ff;
border-left: 4px solid #1890ff;
padding: 12px;
margin: 12px 0;
border-radius: 0 4px 4px 0;
}
.warning {
background-color: #fff7e6;
border-left: 4px solid #faad14;
padding: 12px;
margin: 12px 0;
border-radius: 0 4px 4px 0;
}
.help-footer {
margin-top: 24px;
padding-top: 16px;
border-top: 1px solid #e0e0e0;
display: flex;
justify-content: space-between;
color: #666;
font-size: 14px;
}
.feedback-link {
color: #7986E7;
text-decoration: none;
}
.feedback-link:hover {
text-decoration: underline;
}
</style>
<div class="help-container">
<div class="help-sidebar">
<div class="search-box">
<input type="text" class="search-input" placeholder="搜索帮助文档..." />
</div>
<div class="help-category">
<div class="category-title expanded">入门指南</div>
<div class="help-items expanded">
<div class="help-item active">系统概述</div>
<div class="help-item">快速开始</div>
<div class="help-item">基本概念</div>
<div class="help-item">用户界面</div>
</div>
</div>
<div class="help-category">
<div class="category-title">功能指南</div>
<div class="help-items">
<div class="help-item">创建模型</div>
<div class="help-item">运行仿真</div>
<div class="help-item">数据分析</div>
<div class="help-item">监控与调试</div>
<div class="help-item">参数配置</div>
</div>
</div>
<div class="help-category">
<div class="category-title">高级功能</div>
<div class="help-items">
<div class="help-item">API接口</div>
<div class="help-item">自定义扩展</div>
<div class="help-item">脚本编程</div>
<div class="help-item">性能优化</div>
</div>
</div>
<div class="help-category">
<div class="category-title">常见问题</div>
<div class="help-items">
<div class="help-item">账户与权限</div>
<div class="help-item">连接问题</div>
<div class="help-item">数据导入导出</div>
<div class="help-item">错误诊断</div>
</div>
</div>
</div>
<div class="help-content">
<div class="content-title">系统概述</div>
<div class="content-body">
<div class="content-section">
<div class="section-content">
这里显示系统概述
</div>
</div>
</div>
<div class="help-footer">
<div>最后更新: 2023-10-15</div>
<a href="#" class="feedback-link">提交反馈</a>
</div>
</div>
</div>
`;
}
setupEventListeners() {
// 设置分类展开/折叠功能
const categoryTitles = this.shadowRoot.querySelectorAll('.category-title');
categoryTitles.forEach(title => {
title.addEventListener('click', () => {
title.classList.toggle('expanded');
const items = title.nextElementSibling;
items.classList.toggle('expanded');
});
});
// 设置帮助项点击事件
const helpItems = this.shadowRoot.querySelectorAll('.help-item');
helpItems.forEach(item => {
item.addEventListener('click', () => {
// 移除所有活动状态
helpItems.forEach(i => i.classList.remove('active'));
// 添加活动状态到当前项
item.classList.add('active');
// 加载对应的帮助内容(实际项目中应该调用加载内容的方法)
this.loadHelpContent(item.textContent);
});
});
// 设置搜索功能
const searchInput = this.shadowRoot.querySelector('.search-input');
searchInput.addEventListener('input', () => {
this.searchHelp(searchInput.value);
});
}
loadHelpContent(topic) {
console.log(`加载帮助内容: ${topic}`);
// 在此处添加实际加载帮助内容的逻辑
}
searchHelp(keyword) {
console.log(`搜索帮助: ${keyword}`);
// 在此处添加实际搜索帮助内容的逻辑
}
}
customElements.define('help-component', HelpComponent);