新建任务可选空闲模型;任务文件面板点外部自动关闭

This commit is contained in:
2026-09-01 12:49:14 +08:00
parent 9ebf4ada91
commit 24b09281f5
5 changed files with 51 additions and 10 deletions
+6
View File
@@ -258,6 +258,12 @@ body {
padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none;
}
.modal input:focus { border-color: #2a5299; }
.modal select {
width: 100%; border: 1px solid #dde; border-radius: 8px;
padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none;
background: #fff; color: #334; appearance: auto;
}
.modal select:focus { border-color: #2a5299; }
.modal-close-btn {
position: absolute; right: 10px; top: 10px;
background: none; border: none; cursor: pointer; color: #99a;
+3 -2
View File
@@ -39,7 +39,7 @@
</button>
<span class="chat-title" id="chat-title"></span>
<div class="header-right">
<button class="icon-btn" onclick="ui.toggleFiles()" title="文件">
<button class="icon-btn" onclick="ui.toggleFiles(event)" title="文件">
<svg viewBox="0 0 24 24"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>
</button>
</div>
@@ -90,6 +90,7 @@
</button>
<h3>新建任务会话</h3>
<input type="text" id="new-title" placeholder="任务标题(留空自动取首条消息)" style="width:100%">
<select id="new-model" style="width:100%"><option value="">自动分配(使用任一空闲模型)</option></select>
<button class="primary-btn" onclick="ui.createSession()" style="width:100%">创建</button>
</div>
</div>
@@ -113,6 +114,6 @@
<div class="toast hidden" id="toast"></div>
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
<script src="/js/app.js?v=20260901a"></script>
<script src="/js/app.js?v=20260901b"></script>
</body>
</html>
+27 -3
View File
@@ -401,12 +401,26 @@ async function loadFiles() {
// ---------- 主逻辑 ----------
const ui = {
downloadFile(name) { return downloadFile(name); },
openCreate() { $('create-modal').classList.remove('hidden'); $('new-title').focus(); },
async openCreate() {
// 每次打开时刷新一次空闲模型列表
const sel = $('new-model');
try {
const rows = await req('GET', '/api/models');
const free = rows.filter(m => !m.is_busy);
sel.innerHTML = free.length
? '<option value="">自动分配(使用任一空闲模型)</option>' + free.map(m =>
'<option value="' + esc(m.id) + '">' + esc(m.display_name || m.id) + '</option>').join('')
: '<option value="">暂无空闲模型(将排队等待)</option>';
} catch (_) { /* 保留默认选项 */ }
$('create-modal').classList.remove('hidden');
$('new-title').focus();
},
closeCreate() { $('create-modal').classList.add('hidden'); },
async createSession() {
try {
const title = $('new-title').value.trim();
const s = await req('POST', '/api/sessions', { title });
const model_id = $('new-model') ? $('new-model').value : '';
const s = await req('POST', '/api/sessions', { title, model_id });
this.closeCreate();
$('new-title').value = '';
await loadSessions();
@@ -472,7 +486,9 @@ const ui = {
scrollBottom();
} catch (e) { toast('发送失败:' + e.message); }
},
toggleFiles() {
toggleFiles(ev) {
// 阻断冒泡,避免开启面板的同一次点击被「点外部自动关闭」监听器立刻关掉
if (ev) ev.stopPropagation();
state.filePanelOpen = !state.filePanelOpen;
$('files-panel').classList.toggle('hidden', !state.filePanelOpen);
if (state.filePanelOpen) loadFiles();
@@ -513,6 +529,14 @@ const ui = {
logout() { location.href = '/logout'; },
};
// 文件面板展开时,点击面板以外的区域自动关闭
document.addEventListener('click', e => {
if (!state.filePanelOpen) return;
if ($('files-panel').contains(e.target)) return;
state.filePanelOpen = false;
$('files-panel').classList.add('hidden');
});
// ---------- 登录态:显示当前用户;未启用认证(/api/me 404)则隐藏退出按钮 ----------
async function initAuth() {
try {