()
| 28 | } |
| 29 | |
| 30 | export async function showSaveConnectionModal() { |
| 31 | const connection = state.connections[state.selectedConnectionId]; |
| 32 | if (!connection) { |
| 33 | alert('请先选择一个连接'); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | if (connection.messages.length === 0) { |
| 38 | alert('此连接没有消息数据'); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if (connection.status === 'archived' || connection.savedId) { |
| 43 | alert('此连接已从数据库加载,无需再次保存'); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | const existing = await isConnectionSaved(connection.id); |
| 48 | const defaultName = formatDateTime(connection.createdAt); |
| 49 | |
| 50 | elements.presetModalTitle.textContent = '保存连接'; |
| 51 | elements.presetModalBody.innerHTML = ` |
| 52 | <div class="preset-form"> |
| 53 | <div class="form-group"> |
| 54 | <label class="form-label">连接名称</label> |
| 55 | <input type="text" id="connection-name-input" class="form-input" |
| 56 | placeholder="输入连接名称..." |
| 57 | value="${existing ? '(覆盖已保存的连接)' : defaultName}"> |
| 58 | </div> |
| 59 | <div class="form-group"> |
| 60 | <label class="form-label">连接信息</label> |
| 61 | <div class="connection-info-box"> |
| 62 | <div class="info-row"><strong>URL:</strong> <span class="info-url" title="${escapeHtml(connection.url)}">${escapeHtml(connection.url)}</span></div> |
| 63 | <div><strong>消息数量:</strong> ${connection.messages.length} 条</div> |
| 64 | <div><strong>状态:</strong> ${connection.status}</div> |
| 65 | <div><strong>创建时间:</strong> ${defaultName}</div> |
| 66 | </div> |
| 67 | </div> |
| 68 | </div> |
| 69 | `; |
| 70 | |
| 71 | elements.presetModalFooter.innerHTML = ` |
| 72 | <button class="modal-btn" id="connection-cancel-btn">取消</button> |
| 73 | <button class="modal-btn primary" id="connection-save-btn">保存</button> |
| 74 | `; |
| 75 | |
| 76 | elements.presetModal.style.display = 'flex'; |
| 77 | |
| 78 | const nameInput = document.getElementById('connection-name-input'); |
| 79 | const saveBtn = document.getElementById('connection-save-btn'); |
| 80 | const cancelBtn = document.getElementById('connection-cancel-btn'); |
| 81 | |
| 82 | cancelBtn.addEventListener('click', closeSaveConnectionModal); |
| 83 | |
| 84 | saveBtn.addEventListener('click', async () => { |
| 85 | if (!nameInput.value.trim()) { |
| 86 | alert('请输入连接名称'); |
| 87 | return; |
nothing calls this directly
no test coverage detected