fix: clean JS confirm via delPhoto function
This commit is contained in:
parent
dda5e1ffd7
commit
291c3a97de
@ -65,30 +65,38 @@ function navPhoto(id,dir){
|
||||
document.getElementById('next-'+id).style.display=d.idx===d.photos.length-1?'none':'';
|
||||
}
|
||||
function showImport(){
|
||||
document.getElementById('modal-body').innerHTML='<h3 style="margin-bottom:12px">批量导入</h3><div class="form-hint" style="margin-bottom:12px">选择按姓名分目录的照片根目录</div><form method="post" action="/ui/face-gallery/import" enctype="multipart/form-data"><label class="full" style="margin-bottom:12px;display:block"><span>选择照片目录</span><input type="file" name="photos" webkitdirectory multiple required /></label><div class="actions"><button class="btn" type="submit">导入</button></div></form>';
|
||||
document.getElementById('modal-body').innerHTML='<h3>批量导入</h3><div class="form-hint" style="margin-bottom:12px">选择按姓名分目录的照片根目录</div><form method="post" action="/ui/face-gallery/import" enctype="multipart/form-data"><label class="full" style="margin-bottom:12px;display:block"><span>选择照片目录</span><input type="file" name="photos" webkitdirectory multiple required /></label><div class="actions"><button class="btn" type="submit">导入</button></div></form>';
|
||||
document.getElementById('modal').style.display='flex';
|
||||
}
|
||||
function showAdd(){
|
||||
document.getElementById('modal-body').innerHTML='<h3 style="margin-bottom:12px">新增人员</h3><form method="post" action="/ui/face-gallery/add" enctype="multipart/form-data"><div class="field-grid"><label><span>姓名</span><input type="text" name="name" required /></label><label><span>照片</span><input type="file" name="photo" accept="image/*" required /></label></div><div class="actions" style="margin-top:12px"><button class="btn" type="submit">新增</button></div></form>';
|
||||
document.getElementById('modal-body').innerHTML='<h3>新增人员</h3><form method="post" action="/ui/face-gallery/add" enctype="multipart/form-data"><div class="field-grid"><label><span>姓名</span><input type="text" name="name" required /></label><label><span>照片</span><input type="file" name="photo" accept="image/*" required /></label></div><div class="actions"><button class="btn" type="submit">新增</button></div></form>';
|
||||
document.getElementById('modal').style.display='flex';
|
||||
}
|
||||
function showEdit(id,name,photos){
|
||||
var h='<h3 style="margin-bottom:8px">编辑人员</h3>';
|
||||
var h='<h3>编辑人员</h3>';
|
||||
h+='<form method="post" action="/ui/face-gallery/rename" style="margin-bottom:12px;display:flex;gap:8px;align-items:flex-end">';
|
||||
h+='<input type="hidden" name="id" value="'+id+'"><label style="flex:1;margin:0"><span class="small muted" style="display:block;margin-bottom:4px">姓名</span><input type="text" name="name" value="'+esc(name)+'" required /></label>';
|
||||
h+='<button class="btn" type="submit" style="margin-bottom:1px">保存</button></form>';
|
||||
h+='<input type="hidden" name="id" value="'+id+'"><label style="flex:1"><span class="small muted">姓名</span><input type="text" name="name" value="'+esc(name)+'" required /></label>';
|
||||
h+='<button class="btn" type="submit">保存</button></form>';
|
||||
h+='<div style="display:flex;flex-wrap:wrap;gap:8px;margin-bottom:12px">';
|
||||
photos.forEach(function(p){
|
||||
h+='<div style="position:relative;width:80px;height:100px"><img src="'+p.p+'" style="width:100%;height:100%;object-fit:cover;border-radius:4px">';
|
||||
h+='<form method="post" action="/ui/face-gallery/delete-photo" onsubmit="return confirm(\"确认删除这张照片?\")" style="position:absolute;top:2px;right:2px"><input type="hidden" name="id" value="'+p.id+'"><span class="btn-icon ghost" style="font-size:10px;color:red;background:rgba(0,0,0,0.5)" onclick="this.closest(\'form\').submit()">×</span></form></div>';
|
||||
h+='<span class="btn-icon ghost" style="position:absolute;top:2px;right:2px;font-size:10px;color:red;background:rgba(0,0,0,0.5)" onclick="delPhoto('+p.id+')">×</span>';
|
||||
h+='</div>';
|
||||
});
|
||||
h+='</div>';
|
||||
h+='<form method="post" action="/ui/face-gallery/add-photo" enctype="multipart/form-data" style="display:flex;gap:8px;align-items:flex-end">';
|
||||
h+='<input type="hidden" name="id" value="'+id+'"><label style="flex:1;margin:0"><span class="small muted" style="display:block;margin-bottom:4px">添加照片</span><input type="file" name="photo" accept="image/*" /></label>';
|
||||
h+='<button class="btn ghost" type="submit" style="margin-bottom:1px">上传</button></form>';
|
||||
h+='<input type="hidden" name="id" value="'+id+'"><label style="flex:1"><span class="small muted">添加照片</span><input type="file" name="photo" accept="image/*" /></label>';
|
||||
h+='<button class="btn ghost" type="submit">上传</button></form>';
|
||||
document.getElementById('modal-body').innerHTML=h;
|
||||
document.getElementById('modal').style.display='flex';
|
||||
}
|
||||
function delPhoto(id){
|
||||
if(!confirm('确认删除这张照片?'))return;
|
||||
var f=document.createElement('form');
|
||||
f.method='post';f.action='/ui/face-gallery/delete-photo';
|
||||
var i=document.createElement('input');i.type='hidden';i.name='id';i.value=id;f.appendChild(i);
|
||||
document.body.appendChild(f);f.submit();
|
||||
}
|
||||
function closeModal(){document.getElementById('modal').style.display='none';}
|
||||
document.addEventListener('click',function(e){var b=e.target.closest('.edit-btn');if(b){showEdit(b.dataset.id,b.dataset.name,JSON.parse(b.dataset.photos));}});
|
||||
function esc(s){return(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user