()
| 2129 | } |
| 2130 | |
| 2131 | async function showSaveConnectionModal() { |
| 2132 | const connection = state.connections[state.selectedConnectionId]; |
| 2133 | if (!connection) { |
| 2134 | alert('请先选择一个连接'); |
| 2135 | return; |
| 2136 | } |
| 2137 | |
| 2138 | if (connection.messages.length === 0) { |
| 2139 | alert('此连接没有消息数据'); |
| 2140 | return; |
| 2141 | } |
| 2142 | |
| 2143 | if (connection.status === 'archived' || connection.savedId) { |
| 2144 | alert('此连接已从数据库加载,无需再次保存'); |
| 2145 | return; |
| 2146 | } |
| 2147 | |
| 2148 | const existing = await isConnectionSaved(connection.id); |
| 2149 | const defaultName = formatDateTime(connection.createdAt); |
| 2150 | |
| 2151 | elements$1.presetModalTitle.textContent = '保存连接'; |
| 2152 | elements$1.presetModalBody.innerHTML = ` |
| 2153 | <div class="preset-form"> |
| 2154 | <div class="form-group"> |
| 2155 | <label class="form-label">连接名称</label> |
| 2156 | <input type="text" id="connection-name-input" class="form-input" |
| 2157 | placeholder="输入连接名称..." |
| 2158 | value="${existing ? '(覆盖已保存的连接)' : defaultName}"> |
| 2159 | </div> |
| 2160 | <div class="form-group"> |
| 2161 | <label class="form-label">连接信息</label> |
| 2162 | <div class="connection-info-box"> |
| 2163 | <div class="info-row"><strong>URL:</strong> <span class="info-url" title="${escapeHtml(connection.url)}">${escapeHtml(connection.url)}</span></div> |
| 2164 | <div><strong>消息数量:</strong> ${connection.messages.length} 条</div> |
| 2165 | <div><strong>状态:</strong> ${connection.status}</div> |
| 2166 | <div><strong>创建时间:</strong> ${defaultName}</div> |
| 2167 | </div> |
| 2168 | </div> |
| 2169 | </div> |
| 2170 | `; |
| 2171 | |
| 2172 | elements$1.presetModalFooter.innerHTML = ` |
| 2173 | <button class="modal-btn" id="connection-cancel-btn">取消</button> |
| 2174 | <button class="modal-btn primary" id="connection-save-btn">保存</button> |
| 2175 | `; |
| 2176 | |
| 2177 | elements$1.presetModal.style.display = 'flex'; |
| 2178 | |
| 2179 | const nameInput = document.getElementById('connection-name-input'); |
| 2180 | const saveBtn = document.getElementById('connection-save-btn'); |
| 2181 | const cancelBtn = document.getElementById('connection-cancel-btn'); |
| 2182 | |
| 2183 | cancelBtn.addEventListener('click', closeSaveConnectionModal); |
| 2184 | |
| 2185 | saveBtn.addEventListener('click', async () => { |
| 2186 | if (!nameInput.value.trim()) { |
| 2187 | alert('请输入连接名称'); |
| 2188 | return; |
nothing calls this directly
no test coverage detected