(container)
| 155 | } |
| 156 | |
| 157 | function attachTableOperationsToContainer(container) { |
| 158 | if (container.hasAttribute('data-operations-attached')) return; |
| 159 | container.setAttribute('data-operations-attached', 'true'); |
| 160 | |
| 161 | const table = container.querySelector('.nsn-table'); |
| 162 | const toolbar = container.querySelector('.nsn-table-toolbar'); |
| 163 | |
| 164 | if (!table || !toolbar) return; |
| 165 | |
| 166 | let currentCell = null; |
| 167 | |
| 168 | // 鼠标进入显示工具栏 |
| 169 | container.addEventListener('mouseenter', (e) => { |
| 170 | // 确保不是从工具栏内部进入 |
| 171 | if (!e.relatedTarget || !toolbar.contains(e.relatedTarget)) { |
| 172 | toolbar.style.display = 'flex'; |
| 173 | container.style.border = '1px solid #409eff'; |
| 174 | } |
| 175 | }); |
| 176 | |
| 177 | // 鼠标离开隐藏工具栏 |
| 178 | container.addEventListener('mouseleave', (e) => { |
| 179 | // 确保不是进入工具栏 |
| 180 | if (!e.relatedTarget || !toolbar.contains(e.relatedTarget)) { |
| 181 | toolbar.style.display = 'none'; |
| 182 | container.style.border = '1px solid transparent'; |
| 183 | } |
| 184 | }); |
| 185 | |
| 186 | // 工具栏的鼠标事件处理 |
| 187 | toolbar.addEventListener('mouseenter', () => { |
| 188 | toolbar.style.display = 'flex'; |
| 189 | container.style.border = '1px solid #409eff'; |
| 190 | }); |
| 191 | |
| 192 | toolbar.addEventListener('mouseleave', () => { |
| 193 | toolbar.style.display = 'none'; |
| 194 | container.style.border = '1px solid transparent'; |
| 195 | }); |
| 196 | |
| 197 | // 点击单元格记录当前位置 |
| 198 | table.addEventListener('click', (e) => { |
| 199 | const cell = e.target.closest('td, th'); |
| 200 | if (cell) { |
| 201 | currentCell = cell; |
| 202 | // 高亮当前行列 |
| 203 | highlightRowCol(table, cell); |
| 204 | } |
| 205 | }); |
| 206 | |
| 207 | // 工具栏按钮事件 |
| 208 | toolbar.addEventListener('click', (e) => { |
| 209 | e.preventDefault(); |
| 210 | e.stopPropagation(); |
| 211 | |
| 212 | const action = e.target.getAttribute('data-action'); |
| 213 | if (!action || !currentCell) return; |
| 214 |
no test coverage detected