Skip to content

Commit ef14526

Browse files
committed
优化:选择目录
1 parent 227b88b commit ef14526

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

model_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ async def select_directory() -> str:
3030
"""使用文件对话框选择目录"""
3131
root = tk.Tk()
3232
root.withdraw() # 隐藏主窗口
33+
root.attributes('-topmost', True) # 确保对话框在最前面
3334
path = filedialog.askdirectory()
35+
root.destroy() # 完全清理 Tk 实例
3436
return path if path else ""
3537

3638
class ModelManager:

templates/index.html

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
</button>
6464
<button class="btn btn-outline-primary" id="scanModels">扫描模型</button>
6565
</div>
66-
<div class="form-text">请选择包含 Stable Diffusion 模型的目录</div>
6766
</div>
6867
</div>
6968
</div>
@@ -182,13 +181,32 @@
182181
const response = await fetch(`${API_BASE}/config`);
183182
const config = await response.json();
184183
if (config.models_path) {
185-
document.querySelector('.form-text').textContent = `当前目录: ${config.models_path}`;
184+
pathInput.value = config.models_path;
186185
}
187186
} catch (err) {
188187
showError('加载配置失败');
189188
}
190189
}
191190

191+
// 选择目录
192+
selectPathBtn.addEventListener('click', async () => {
193+
try {
194+
const response = await fetch(`${API_BASE}/select_directory`, {
195+
method: 'POST'
196+
});
197+
198+
if (response.ok) {
199+
const data = await response.json();
200+
if (data.path) {
201+
pathInput.value = data.path;
202+
await saveSelectedPath(data.path);
203+
}
204+
}
205+
} catch (err) {
206+
showError('选择目录失败');
207+
}
208+
});
209+
192210
// 选择并保存路径
193211
async function saveSelectedPath(path) {
194212
try {
@@ -210,25 +228,6 @@
210228
}
211229
}
212230

213-
// 选择目录
214-
selectPathBtn.addEventListener('click', async () => {
215-
try {
216-
const response = await fetch(`${API_BASE}/select_directory`, {
217-
method: 'POST'
218-
});
219-
220-
if (response.ok) {
221-
const data = await response.json();
222-
if (data.path) {
223-
pathInput.value = data.path;
224-
await saveSelectedPath(data.path);
225-
}
226-
}
227-
} catch (err) {
228-
showError('选择目录失败');
229-
}
230-
});
231-
232231
// 扫描模型
233232
scanModelsBtn.addEventListener('click', async () => {
234233
try {

0 commit comments

Comments
 (0)