Files
srdb/webui/static/js/components/ManifestModal.js
bourdon 30c3e74bd2 feat: 完善 WebUI basePath 支持并简化示例代码
主要改动:

1. WebUI basePath 逻辑完善
   - NewWebUI 支持可变参数 basePath
   - 新增 path() 辅助方法统一路径处理
   - handleTableAPI 正确处理 basePath 前缀
   - handleIndex 根据 basePath 替换占位符

2. 简化示例代码
   - 删除反向代理实现(111行)
   - 直接使用带 basePath 的 WebUI
   - 代码量减少 33%,架构更清晰

3. 前端优化
   - 新增 api.js 统一 API 服务层
   - 所有组件使用统一的 API 调用
   - 支持通过 window.API_BASE 配置 basePath

4. 修复 .gitignore
   - 使用通用模式支持 commands 目录
   - 无需为新示例项目修改配置
2025-10-14 22:23:30 +08:00

119 lines
3.3 KiB
JavaScript

import { html } from 'htm/preact';
import { useEffect } from 'preact/hooks';
import { ManifestView } from '~/components/ManifestView.js';
const styles = {
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: 'rgba(0, 0, 0, 0.6)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 1000,
padding: '20px'
},
modal: {
background: 'var(--bg-elevated)',
borderRadius: 'var(--radius-lg)',
boxShadow: 'var(--shadow-xl)',
width: '90vw',
maxWidth: '1200px',
maxHeight: '85vh',
display: 'flex',
flexDirection: 'column',
overflow: 'hidden'
},
header: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '20px 24px',
borderBottom: '1px solid var(--border-color)'
},
title: {
fontSize: '20px',
fontWeight: 600,
color: 'var(--text-primary)',
margin: 0
},
closeButton: {
width: '32px',
height: '32px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'transparent',
border: 'none',
borderRadius: 'var(--radius-sm)',
cursor: 'pointer',
fontSize: '20px',
color: 'var(--text-secondary)',
transition: 'var(--transition)'
},
content: {
flex: 1,
overflowY: 'auto',
padding: '20px 24px'
}
};
export function ManifestModal({ tableName, onClose }) {
// ESC 键关闭
useEffect(() => {
const handleEscape = (e) => {
if (e.key === 'Escape') {
onClose();
}
};
document.addEventListener('keydown', handleEscape);
return () => document.removeEventListener('keydown', handleEscape);
}, [onClose]);
// 阻止背景滚动
useEffect(() => {
document.body.style.overflow = 'hidden';
return () => {
document.body.style.overflow = '';
};
}, []);
const handleOverlayClick = (e) => {
if (e.target === e.currentTarget) {
onClose();
}
};
return html`
<div style=${styles.overlay} onClick=${handleOverlayClick}>
<div style=${styles.modal}>
<div style=${styles.header}>
<h2 style=${styles.title}>Manifest - ${tableName}</h2>
<button
style=${styles.closeButton}
onClick=${onClose}
onMouseEnter=${(e) => {
e.target.style.background = 'var(--bg-hover)';
e.target.style.color = 'var(--text-primary)';
}}
onMouseLeave=${(e) => {
e.target.style.background = 'transparent';
e.target.style.color = 'var(--text-secondary)';
}}
title="关闭"
>
</button>
</div>
<div style=${styles.content}>
<${ManifestView} tableName=${tableName} />
</div>
</div>
</div>
`;
}