主要改动: 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 目录 - 无需为新示例项目修改配置
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
import { html } from 'htm/preact';
|
|
import { useState } from 'preact/hooks';
|
|
import { TableCell } from '~/components/TableCell.js';
|
|
|
|
const styles = {
|
|
td: {
|
|
padding: '10px 12px',
|
|
borderBottom: '1px solid var(--border-color)',
|
|
color: 'var(--text-primary)',
|
|
textAlign: 'center'
|
|
},
|
|
iconButton: (isRowHovered, isButtonHovered) => ({
|
|
width: '28px',
|
|
height: '28px',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
background: isButtonHovered ? 'var(--primary)' : 'var(--bg-elevated)',
|
|
color: isButtonHovered ? '#fff' : 'var(--primary)',
|
|
border: '1px solid var(--border-color)',
|
|
borderRadius: 'var(--radius-sm)',
|
|
cursor: 'pointer',
|
|
fontSize: '14px',
|
|
transition: 'all 0.2s ease',
|
|
opacity: isRowHovered ? 1 : 0,
|
|
pointerEvents: isRowHovered ? 'auto' : 'none'
|
|
})
|
|
};
|
|
|
|
export function TableRow({ row, columns, onViewDetail, onShowPopover, onHidePopover }) {
|
|
const [isRowHovered, setIsRowHovered] = useState(false);
|
|
const [isButtonHovered, setIsButtonHovered] = useState(false);
|
|
|
|
return html`
|
|
<tr
|
|
onMouseEnter=${(e) => {
|
|
e.currentTarget.style.background = 'var(--bg-hover)';
|
|
setIsRowHovered(true);
|
|
}}
|
|
onMouseLeave=${(e) => {
|
|
e.currentTarget.style.background = 'transparent';
|
|
setIsRowHovered(false);
|
|
}}
|
|
>
|
|
${columns.map(col => html`
|
|
<${TableCell}
|
|
key=${col}
|
|
value=${row[col]}
|
|
column=${col}
|
|
isTruncated=${row[col + '_truncated']}
|
|
onShowPopover=${onShowPopover}
|
|
onHidePopover=${onHidePopover}
|
|
/>
|
|
`)}
|
|
<td style=${styles.td}>
|
|
<button
|
|
style=${styles.iconButton(isRowHovered, isButtonHovered)}
|
|
onClick=${() => onViewDetail(row._seq)}
|
|
onMouseEnter=${() => setIsButtonHovered(true)}
|
|
onMouseLeave=${() => setIsButtonHovered(false)}
|
|
title="查看详情"
|
|
>
|
|
👁
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
}
|