You've already forked iFlow-Settings-Editor-GUI
优化 保存机制,在编辑、创建和删除时自动保存配置
This commit is contained in:
97
src/App.vue
97
src/App.vue
@@ -24,16 +24,6 @@
|
|||||||
<div class="header-left">
|
<div class="header-left">
|
||||||
<span class="header-title">iFlow 设置编辑器</span>
|
<span class="header-title">iFlow 设置编辑器</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="header-actions">
|
|
||||||
<button class="btn btn-secondary" @click="reloadSettings">
|
|
||||||
<Refresh size="14" />
|
|
||||||
重新加载
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-primary" @click="saveSettings">
|
|
||||||
<Save size="14" />
|
|
||||||
保存更改
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="main">
|
<main class="main">
|
||||||
@@ -204,7 +194,6 @@
|
|||||||
<div class="footer-status-dot"></div>
|
<div class="footer-status-dot"></div>
|
||||||
<span>配置: {{ currentApiProfile || 'default' }}</span>
|
<span>配置: {{ currentApiProfile || 'default' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<span :class="{ 'footer-modified': modified }">{{ modified ? '● 已修改' : '✓ 未修改' }}</span>
|
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<!-- Input Dialog -->
|
<!-- Input Dialog -->
|
||||||
@@ -567,141 +556,74 @@ const closeApiCreateDialog = () => {
|
|||||||
|
|
||||||
|
|
||||||
// Save API create
|
// Save API create
|
||||||
|
|
||||||
const saveApiCreate = async () => {
|
const saveApiCreate = async () => {
|
||||||
|
|
||||||
const name = creatingApiData.value.name.trim()
|
const name = creatingApiData.value.name.trim()
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
|
||||||
await showMessage({ type: 'warning', title: '错误', message: '请输入配置名称' })
|
await showMessage({ type: 'warning', title: '错误', message: '请输入配置名称' })
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const result = await window.electronAPI.createApiProfile(name)
|
const result = await window.electronAPI.createApiProfile(name)
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
|
||||||
// 创建成功后,更新配置数据
|
// 创建成功后,更新配置数据
|
||||||
|
|
||||||
const profileData = {
|
const profileData = {
|
||||||
|
|
||||||
selectedAuthType: creatingApiData.value.selectedAuthType,
|
selectedAuthType: creatingApiData.value.selectedAuthType,
|
||||||
|
|
||||||
apiKey: creatingApiData.value.apiKey,
|
apiKey: creatingApiData.value.apiKey,
|
||||||
|
|
||||||
baseUrl: creatingApiData.value.baseUrl,
|
baseUrl: creatingApiData.value.baseUrl,
|
||||||
|
|
||||||
modelName: creatingApiData.value.modelName,
|
modelName: creatingApiData.value.modelName,
|
||||||
|
|
||||||
searchApiKey: creatingApiData.value.searchApiKey,
|
searchApiKey: creatingApiData.value.searchApiKey,
|
||||||
|
|
||||||
cna: creatingApiData.value.cna
|
cna: creatingApiData.value.cna
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 保存配置数据
|
// 保存配置数据
|
||||||
|
|
||||||
const loadResult = await window.electronAPI.loadSettings()
|
const loadResult = await window.electronAPI.loadSettings()
|
||||||
|
|
||||||
if (loadResult.success) {
|
if (loadResult.success) {
|
||||||
|
|
||||||
const data = loadResult.data
|
const data = loadResult.data
|
||||||
|
|
||||||
if (!data.apiProfiles) data.apiProfiles = {}
|
if (!data.apiProfiles) data.apiProfiles = {}
|
||||||
|
|
||||||
data.apiProfiles[name] = profileData
|
data.apiProfiles[name] = profileData
|
||||||
|
await window.electronAPI.saveSettings(data)
|
||||||
await window.electronAPI.saveSettings(data)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
showApiCreateDialog.value = false
|
||||||
showApiCreateDialog.value = false
|
await loadApiProfiles()
|
||||||
|
await showMessage({ type: 'info', title: '创建成功', message: `配置 "${name}" 已创建` })
|
||||||
await loadApiProfiles()
|
}
|
||||||
|
|
||||||
await showMessage({ type: 'info', title: '创建成功', message: `配置 "${name}" 已创建` })
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
await showMessage({ type: 'error', title: '创建失败', message: result.error })
|
await showMessage({ type: 'error', title: '创建失败', message: result.error })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete API profile
|
// Delete API profile
|
||||||
|
|
||||||
const deleteApiProfile = async (name) => {
|
const deleteApiProfile = async (name) => {
|
||||||
|
|
||||||
const profileName = name || currentApiProfile.value
|
const profileName = name || currentApiProfile.value
|
||||||
|
|
||||||
if (profileName === 'default') {
|
if (profileName === 'default') {
|
||||||
|
|
||||||
await showMessage({ type: 'warning', title: '无法删除', message: '不能删除默认配置' })
|
await showMessage({ type: 'warning', title: '无法删除', message: '不能删除默认配置' })
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const confirmed = await new Promise(resolve => {
|
const confirmed = await new Promise(resolve => {
|
||||||
|
|
||||||
showInputDialog.value = {
|
showInputDialog.value = {
|
||||||
|
|
||||||
show: true,
|
show: true,
|
||||||
|
|
||||||
title: '删除配置',
|
title: '删除配置',
|
||||||
|
|
||||||
placeholder: `确定要删除配置 "${profileName}" 吗?`,
|
placeholder: `确定要删除配置 "${profileName}" 吗?`,
|
||||||
|
|
||||||
callback: resolve,
|
callback: resolve,
|
||||||
|
|
||||||
isConfirm: true
|
isConfirm: true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!confirmed) return
|
if (!confirmed) return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const result = await window.electronAPI.deleteApiProfile(profileName)
|
const result = await window.electronAPI.deleteApiProfile(profileName)
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
|
||||||
const data = JSON.parse(JSON.stringify(result.data))
|
const data = JSON.parse(JSON.stringify(result.data))
|
||||||
|
|
||||||
if (!data.checkpointing) data.checkpointing = { enabled: true }
|
if (!data.checkpointing) data.checkpointing = { enabled: true }
|
||||||
|
|
||||||
if (!data.mcpServers) data.mcpServers = {}
|
if (!data.mcpServers) data.mcpServers = {}
|
||||||
|
|
||||||
settings.value = data
|
settings.value = data
|
||||||
|
|
||||||
originalSettings.value = JSON.parse(JSON.stringify(data))
|
originalSettings.value = JSON.parse(JSON.stringify(data))
|
||||||
|
|
||||||
modified.value = false
|
modified.value = false
|
||||||
|
|
||||||
await loadApiProfiles()
|
await loadApiProfiles()
|
||||||
|
|
||||||
await showMessage({ type: 'info', title: '删除成功', message: `配置已删除` })
|
await showMessage({ type: 'info', title: '删除成功', message: `配置已删除` })
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
await showMessage({ type: 'error', title: '删除失败', message: result.error })
|
await showMessage({ type: 'error', title: '删除失败', message: result.error })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename API profile
|
// Rename API profile
|
||||||
@@ -842,7 +764,7 @@ const closeApiEditDialog = () => {
|
|||||||
|
|
||||||
|
|
||||||
// Save API edit
|
// Save API edit
|
||||||
const saveApiEdit = () => {
|
const saveApiEdit = async () => {
|
||||||
if (!settings.value.apiProfiles) {
|
if (!settings.value.apiProfiles) {
|
||||||
settings.value.apiProfiles = {}
|
settings.value.apiProfiles = {}
|
||||||
}
|
}
|
||||||
@@ -861,6 +783,13 @@ const saveApiEdit = () => {
|
|||||||
settings.value.apiProfiles[editingApiProfileName.value].cna = editingApiData.value.cna
|
settings.value.apiProfiles[editingApiProfileName.value].cna = editingApiData.value.cna
|
||||||
|
|
||||||
showApiEditDialog.value = false
|
showApiEditDialog.value = false
|
||||||
|
|
||||||
|
// 自动保存到文件
|
||||||
|
const result = await window.electronAPI.saveSettings(settings.value)
|
||||||
|
if (result.success) {
|
||||||
|
originalSettings.value = JSON.parse(JSON.stringify(settings.value))
|
||||||
|
modified.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user