feat(ui): 抽屉删除 — modal 加 checkbox + 滑动到位直接弹 modal
1) 删除会话 modal 加「同时删除任务文件夹」勾选框,默认勾选
- HTML 复用现有 .del-dir 样式,加 #confirm-check-wrap #confirm-check
- confirmModal(title, text, okText, danger, opts) 新增 opts.checkbox 支持
勾选状态通过 state._confirmChecked 传出(不破坏现有调用方签名)
- deleteSession 调 confirmModal 时传 checkbox,确认后用 _confirmChecked 决定 ?delete_dir=true/false
2) 移动端右滑到位直接弹删除 modal,不再露大红钮
- onUp 滑到 60+ 直接调 deleteSession(item.dataset.id)
- 起手已 swiped + 右滑回去(moved>=60 但 dx>0):视为滑回去,弹回原位
- 删除大红钮 .conv-del 相关 DOM/CSS 全部清理
3) 桌面端 .conv-del-inline 行为不变(hover/focus 露出,点击弹 modal)
This commit is contained in:
@@ -187,6 +187,7 @@
|
||||
<div class="modal">
|
||||
<h3 id="confirm-title">请确认</h3>
|
||||
<div class="modal-text" id="confirm-text"></div>
|
||||
<label class="del-dir hidden" id="confirm-check-wrap"><input type="checkbox" id="confirm-check"> <span id="confirm-check-label"></span></label>
|
||||
<div class="btn-row">
|
||||
<button class="ghost-btn" onclick="confirmClose(false)">取消</button>
|
||||
<button class="primary-btn" id="confirm-ok-btn" onclick="confirmClose(true)">确定</button>
|
||||
@@ -681,7 +682,6 @@
|
||||
'<span class="conv-title">' + esc(s.title || s.id) + '</span>' + drawerStatusDot(s) +
|
||||
'<button class="conv-del-inline" type="button" aria-label="删除会话" title="删除会话">×</button>' +
|
||||
'</button>' +
|
||||
'<button class="conv-del" type="button" aria-label="删除会话" title="删除会话">×</button>' +
|
||||
'</div>';
|
||||
}
|
||||
box.innerHTML = html;
|
||||
@@ -709,9 +709,11 @@
|
||||
// ---------- 会话打开 / 新建 / 状态栏(抽屉行 × 调 deleteSession; 默认含任务目录) ----------
|
||||
async function deleteSession(id) {
|
||||
if (!id) return;
|
||||
if (!await confirmModal('删除会话', '确定删除会话 ' + id + ' ?会话中的任务文件也会一起删除。', '删除', true)) return;
|
||||
if (!await confirmModal('删除会话', '确定删除会话 ' + id + ' ?', '删除', true,
|
||||
{ checkbox: { label: '同时删除任务文件夹', default: true } })) return;
|
||||
const delDir = state._confirmChecked ? 'true' : 'false';
|
||||
try {
|
||||
await req('DELETE', '/api/sessions/' + id + '?delete_dir=true');
|
||||
await req('DELETE', '/api/sessions/' + id + '?delete_dir=' + delDir);
|
||||
// 删的是当前打开的会话:回 welcome 视图并清状态
|
||||
if (state.sessionId === id) {
|
||||
closeStream();
|
||||
@@ -1443,7 +1445,7 @@
|
||||
searchTimer = setTimeout(loadSessionList, 250);
|
||||
});
|
||||
$('drawer-list').addEventListener('click', e => {
|
||||
if (e.target.closest('.conv-del, .conv-del-inline')) {
|
||||
if (e.target.closest('.conv-del-inline')) {
|
||||
const wrap = e.target.closest('.conv-wrap');
|
||||
const item = wrap && wrap.querySelector('.conv-item');
|
||||
if (item) { deleteSession(item.dataset.id); collapseAllSwiped(); }
|
||||
@@ -1512,11 +1514,22 @@
|
||||
g.item.style.transition = '';
|
||||
if (g.horiz) {
|
||||
if (moved >= THRESHOLD) {
|
||||
g.wrap.classList.add('swiped');
|
||||
g.item.style.transform = ''; // CSS 接管到 -60
|
||||
// 起手已是已滑开态 + 右滑回去:不应该触发删除,直接恢复原状
|
||||
if (g.wasSwiped && dx > 0) {
|
||||
// 保持 swiped 状态(因为这是从 -60 滑回 -30 不到 0 的情况)
|
||||
// 但本次手不是超阈值出去的,既然收回去就令弹回
|
||||
g.wrap.classList.remove('swiped');
|
||||
g.item.style.transform = '';
|
||||
} else {
|
||||
// 滑到位:不露 conv-del,直接弹删除确认 modal
|
||||
g.wrap.classList.remove('swiped');
|
||||
g.item.style.transform = '';
|
||||
deleteSession(g.item.dataset.id);
|
||||
}
|
||||
} else {
|
||||
// 未达阈值:弹回
|
||||
g.wrap.classList.remove('swiped');
|
||||
g.item.style.transform = ''; // CSS 接管回 0
|
||||
g.item.style.transform = '';
|
||||
}
|
||||
} else {
|
||||
// 未识别为横向:不动(交给 click 委派处理打开)
|
||||
@@ -1657,7 +1670,21 @@
|
||||
_dlgResolve = null;
|
||||
if (r) r(val);
|
||||
}
|
||||
function confirmModal(title, text, okText, danger) {
|
||||
// confirmModal(title, text, okText, danger, opts?)
|
||||
// opts.checkbox = {label, default=true} 可选:展示一个默认勾选状态可改的复选框
|
||||
// 确认/取消后在 state._confirmChecked 读出勾选状态(不破坏现有调用方签名)
|
||||
function confirmModal(title, text, okText, danger, opts) {
|
||||
state._confirmChecked = !!(opts && opts.checkbox); // 未传 opts 时 reset 为 false
|
||||
const wrap = $('confirm-check-wrap');
|
||||
if (opts && opts.checkbox) {
|
||||
$('confirm-check-label').textContent = opts.checkbox.label;
|
||||
$('confirm-check').checked = opts.checkbox.default !== false;
|
||||
state._confirmChecked = $('confirm-check').checked;
|
||||
wrap.classList.remove('hidden');
|
||||
} else {
|
||||
wrap.classList.add('hidden');
|
||||
}
|
||||
$('confirm-check').onchange = function () { state._confirmChecked = this.checked; };
|
||||
return new Promise(resolve => {
|
||||
_dlgResolve = resolve;
|
||||
$('confirm-title').textContent = title || '请确认';
|
||||
|
||||
Reference in New Issue
Block a user