등록 화면: 작품 수정(사진 재배치·삭제·추가, 항목 편집, 저장/배포) + 배포 시 재빌드
This commit is contained in:
1 parent
f2ae889795
commit
a6835e943a
4 files changed
+372
-15
No files matched your search
+183
-14
@@ -87,13 +87,16 @@
|
||||
.summary{font-size:14px;color:var(--muted);margin-bottom:14px}
|
||||
.summary b{color:var(--ink);font-weight:500}
|
||||
a.live{color:var(--sage)}
|
||||
.work-card{display:grid;grid-template-columns:88px 1fr;gap:12px;align-items:center;text-decoration:none;
|
||||
color:var(--ink);padding:10px 0;border-bottom:1px solid var(--line);position:relative}
|
||||
.work-card img{width:88px;aspect-ratio:4/5;object-fit:cover;background:var(--line);display:block}
|
||||
.work-card{display:block;position:relative;padding:10px 0;border-bottom:1px solid var(--line)}
|
||||
.work-open{display:grid;grid-template-columns:88px 1fr;gap:12px;align-items:center;
|
||||
text-decoration:none;color:var(--ink);padding-right:64px}
|
||||
.work-open img{width:88px;aspect-ratio:4/5;object-fit:cover;background:var(--line);display:block}
|
||||
.work-meta{display:grid;gap:3px;min-width:0}
|
||||
.work-meta strong{font-weight:500;font-size:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.work-meta span{font-size:12px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.work-meta .price{color:var(--ink);font-size:13px}
|
||||
.edit-btn{position:absolute;right:0;bottom:12px;border:1px solid var(--line);background:var(--white);
|
||||
color:var(--ink);font-size:13px;padding:8px 12px;cursor:pointer}
|
||||
.new-badge{position:absolute;right:0;top:10px;background:var(--sage);color:#fff;
|
||||
font-size:10px;letter-spacing:.08em;padding:3px 6px}
|
||||
</style>
|
||||
@@ -208,6 +211,58 @@
|
||||
<a class="btn ghost" id="open-live" href="#" target="_blank" rel="noopener" hidden>사이트에서 보기</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ⑥ 고치기 -->
|
||||
<section id="s-edit" hidden>
|
||||
<p class="label">EDIT</p>
|
||||
<h1 id="edit-head">작품 고치기</h1>
|
||||
<p class="note" id="edit-slug"></p>
|
||||
|
||||
<p class="label">사진</p>
|
||||
<div class="thumbs" id="edit-thumbs"></div>
|
||||
<div class="row2">
|
||||
<button class="btn ghost" id="edit-shoot">사진 찍어 추가</button>
|
||||
<a class="btn ghost" id="edit-open" href="#" target="_blank" rel="noopener">페이지 열기</a>
|
||||
</div>
|
||||
<button class="btn ghost btn-sm" id="edit-album-btn" style="width:100%;margin-top:8px">앨범에서 추가</button>
|
||||
<input type="file" id="edit-cam" accept="image/*" capture="environment" hidden>
|
||||
<input type="file" id="edit-album" accept="image/*" multiple hidden>
|
||||
<div class="status" id="edit-up"></div>
|
||||
|
||||
<div style="margin-top:18px">
|
||||
<label class="field"><span>제목</span><input type="text" id="e-title"></label>
|
||||
<label class="field"><span>부제</span><input type="text" id="e-subtitle"></label>
|
||||
<label class="field"><span>본문</span><textarea id="e-body" style="min-height:220px"></textarea></label>
|
||||
<label class="field"><span>사진 설명(alt)</span><input type="text" id="e-alt"></label>
|
||||
|
||||
<label class="field"><span>규격</span><input type="text" id="e-size"></label>
|
||||
<div class="chips" data-for="e-size"></div>
|
||||
<label class="field"><span>소재</span><input type="text" id="e-material"></label>
|
||||
<div class="chips" data-for="e-material"></div>
|
||||
<label class="field"><span>세탁</span><input type="text" id="e-care"></label>
|
||||
<div class="chips" data-for="e-care"></div>
|
||||
|
||||
<div class="row2">
|
||||
<label class="field"><span>가격(원)</span><input type="number" id="e-price" inputmode="numeric"></label>
|
||||
<label class="field"><span>날짜</span><input type="date" id="e-date"></label>
|
||||
</div>
|
||||
<label class="field"><span>가격 옵션 안내</span><input type="text" id="e-pricenote"></label>
|
||||
<label class="field"><span>네이버 링크</span><input type="url" id="e-naver"></label>
|
||||
<label class="field" style="display:flex;gap:10px;align-items:center">
|
||||
<input type="checkbox" id="e-featured" style="width:20px;height:20px"><span style="margin:0">첫 페이지 대표작으로</span>
|
||||
</label>
|
||||
<label class="field" style="display:flex;gap:10px;align-items:center">
|
||||
<input type="checkbox" id="e-soldout" style="width:20px;height:20px"><span style="margin:0">품절 표시</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button class="btn sage" id="e-save">저장하고 사이트에 올리기</button>
|
||||
<div style="height:10px"></div>
|
||||
<button class="btn ghost" id="e-save-only">저장만</button>
|
||||
<div style="height:10px"></div>
|
||||
<button class="btn ghost" id="e-cancel">목록으로</button>
|
||||
<div class="status" id="e-status"></div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<div class="bar" id="bar">
|
||||
@@ -240,6 +295,7 @@ const STEPS = {
|
||||
write:{el:'#s-write', n:'2/4 내용', prev:'photos', next:'specs'},
|
||||
specs:{el:'#s-specs', n:'3/4 항목', prev:'write', next:'done'},
|
||||
done:{el:'#s-done', n:'4/4 저장', prev:'specs', next:null},
|
||||
edit:{el:'#s-edit', n:'고치기', prev:null, next:null},
|
||||
};
|
||||
function go(step){
|
||||
S.step = step;
|
||||
@@ -247,7 +303,7 @@ function go(step){
|
||||
$(STEPS[step].el).hidden = false;
|
||||
$('#steps').textContent = STEPS[step].n;
|
||||
const cfg = STEPS[step];
|
||||
$('#bar').style.display = step==='home' ? 'none' : 'grid';
|
||||
$('#bar').style.display = (step==='home' || step==='edit') ? 'none' : 'grid';
|
||||
$('#back').style.visibility = cfg.prev ? 'visible' : 'hidden';
|
||||
const next = $('#next');
|
||||
next.textContent = step==='specs' ? '확인' : '다음';
|
||||
@@ -277,16 +333,21 @@ async function loadHome(){
|
||||
? rows.length + '점 · 최근에 만든 순서입니다. 눌러서 확인하세요.'
|
||||
: '아직 등록한 작품이 없습니다.';
|
||||
$('#home-list').innerHTML = rows.map(p => `
|
||||
<a class="work-card" href="/p/${p.slug}.html" target="_blank" rel="noopener">
|
||||
${p.image ? `<img src="/${p.image}" alt="" loading="lazy">` : '<span></span>'}
|
||||
<div class="work-meta">
|
||||
<strong>${p.title}</strong>
|
||||
<span>${p.subtitle || ''}</span>
|
||||
<span class="price">${p.price ? Number(p.price).toLocaleString('ko-KR') + '원' : '가격 문의'}${p.sold_out ? ' · 판매 완료' : ''}</span>
|
||||
</div>
|
||||
<div class="work-card">
|
||||
<a class="work-open" href="/p/${p.slug}.html" target="_blank" rel="noopener">
|
||||
${p.image ? `<img src="/${p.image}" alt="" loading="lazy">` : '<span></span>'}
|
||||
<div class="work-meta">
|
||||
<strong>${p.title}</strong>
|
||||
<span>${p.subtitle || ''}</span>
|
||||
<span class="price">${p.price ? Number(p.price).toLocaleString('ko-KR') + '원' : '가격 문의'}${p.sold_out ? ' · 판매 완료' : ''}</span>
|
||||
</div>
|
||||
</a>
|
||||
<button class="edit-btn" data-slug="${p.slug}">수정</button>
|
||||
${S.lastSlug === p.slug ? '<span class="new-badge">방금 등록</span>'
|
||||
: (p.live === false ? '<span class="new-badge" style="background:var(--clay)">미발행</span>' : '')}
|
||||
</a>`).join('') || '<p class="note">아직 없습니다.</p>';
|
||||
</div>`).join('') || '<p class="note">아직 없습니다.</p>';
|
||||
|
||||
document.querySelectorAll('.edit-btn').forEach(b => b.onclick = () => openEdit(b.dataset.slug));
|
||||
|
||||
const pending = rows.filter(p => p.live === false).length;
|
||||
const button = $('#deploy-all');
|
||||
@@ -404,8 +465,9 @@ async function loadPresets(){
|
||||
const d = await api('/api/presets');
|
||||
S.presets = d.presets;
|
||||
document.querySelectorAll('.chips[data-for]').forEach(box=>{
|
||||
const key = box.dataset.for === 'f-size' ? 'size'
|
||||
: box.dataset.for === 'f-material' ? 'material' : 'care';
|
||||
const target = box.dataset.for;
|
||||
const key = target.endsWith('size') ? 'size'
|
||||
: target.endsWith('material') ? 'material' : 'care';
|
||||
box.innerHTML = (d.presets[key]||[]).map(v=>`<button class="chip">${v}</button>`).join('');
|
||||
box.querySelectorAll('.chip').forEach(ch=>ch.onclick=()=>{
|
||||
box.querySelectorAll('.chip').forEach(c=>c.setAttribute('aria-pressed','false'));
|
||||
@@ -500,6 +562,113 @@ $('#deploy-all').onclick = async () => {
|
||||
await run(false);
|
||||
};
|
||||
|
||||
/* ---------- 고치기 ---------- */
|
||||
async function openEdit(slug){
|
||||
$('#e-status').textContent = ''; $('#edit-up').textContent = '';
|
||||
try{
|
||||
const d = await api('/api/product?slug=' + encodeURIComponent(slug));
|
||||
const p = d.product, f = p.fields || {};
|
||||
const gallery = Array.isArray(f.gallery)
|
||||
? f.gallery
|
||||
: String(f.gallery || '').split('\n').map(s => s.trim()).filter(Boolean);
|
||||
S.edit = { slug, images: [f.image, ...gallery].filter(Boolean).map(path => ({ path })) };
|
||||
$('#edit-head').textContent = f.title || '작품 고치기';
|
||||
$('#edit-slug').textContent = slug;
|
||||
$('#edit-open').href = '/p/' + slug + '.html';
|
||||
$('#e-title').value = f.title || '';
|
||||
$('#e-subtitle').value = f.subtitle || '';
|
||||
$('#e-body').value = p.body || '';
|
||||
$('#e-alt').value = f.image_alt || '';
|
||||
$('#e-size').value = f.size || '';
|
||||
$('#e-material').value = f.material || '';
|
||||
$('#e-care').value = f.care || '';
|
||||
$('#e-price').value = f.price || '';
|
||||
$('#e-pricenote').value = f.price_note || '';
|
||||
$('#e-date').value = String(f.date || '').slice(0,10);
|
||||
$('#e-naver').value = f.naver_url || '';
|
||||
$('#e-featured').checked = !!f.featured;
|
||||
$('#e-soldout').checked = !!f.sold_out;
|
||||
renderEditThumbs();
|
||||
go('edit');
|
||||
}catch(e){ toast(e.message); }
|
||||
}
|
||||
|
||||
function renderEditThumbs(){
|
||||
const box = $('#edit-thumbs');
|
||||
const imgs = (S.edit && S.edit.images) || [];
|
||||
if (!imgs.length){ box.innerHTML = '<p class="note" style="grid-column:1/-1">사진이 없습니다. 한 장은 있어야 합니다.</p>'; return; }
|
||||
box.innerHTML = imgs.map((p,i)=>`
|
||||
<div class="thumb">
|
||||
<img src="${p.uid ? '/media-inbox/' + p.uid + '.jpg' : '/' + p.path}" alt="">
|
||||
${i===0?'<span class="badge">대표</span>':''}
|
||||
<div class="tools">
|
||||
${i>0?`<button data-mvn="${i}:-1" aria-label="앞으로">←</button>`:''}
|
||||
${i<imgs.length-1?`<button data-mvn="${i}:1" aria-label="뒤로">→</button>`:''}
|
||||
<button class="del" data-deln="${i}" aria-label="삭제">×</button>
|
||||
</div>
|
||||
</div>`).join('');
|
||||
box.querySelectorAll('[data-deln]').forEach(b=>b.onclick=()=>{
|
||||
S.edit.images.splice(+b.dataset.deln,1); renderEditThumbs();
|
||||
});
|
||||
box.querySelectorAll('[data-mvn]').forEach(b=>b.onclick=()=>{
|
||||
const [i,dv] = b.dataset.mvn.split(':').map(Number);
|
||||
const j = i + dv; if (j < 0 || j >= S.edit.images.length) return;
|
||||
[S.edit.images[i], S.edit.images[j]] = [S.edit.images[j], S.edit.images[i]];
|
||||
renderEditThumbs();
|
||||
});
|
||||
}
|
||||
|
||||
$('#edit-shoot').onclick = () => $('#edit-cam').click();
|
||||
$('#edit-album-btn').onclick = () => $('#edit-album').click();
|
||||
$('#edit-cam').onchange = e => uploadEditFiles(e.target.files);
|
||||
$('#edit-album').onchange = e => uploadEditFiles(e.target.files);
|
||||
|
||||
async function uploadEditFiles(files){
|
||||
const list = Array.from(files || []);
|
||||
if (!list.length) return;
|
||||
for (let i=0;i<list.length;i++){
|
||||
$('#edit-up').innerHTML = `<span class="spin"></span> 사진 올리는 중 ${i+1}/${list.length}`;
|
||||
try{
|
||||
const res = await fetch('/api/photo?name=' + encodeURIComponent(list[i].name || 'photo.jpg'),
|
||||
{method:'POST', headers:{'Content-Type':'application/octet-stream'}, body:list[i]});
|
||||
const d = await res.json();
|
||||
if (!res.ok || d.ok === false) throw new Error(d.error || '업로드 실패');
|
||||
S.edit.images.push({ uid: d.uid });
|
||||
}catch(e){ $('#edit-up').innerHTML = `<span class="status err">${e.message}</span>`; return; }
|
||||
}
|
||||
$('#edit-up').textContent = '';
|
||||
$('#edit-cam').value = ''; $('#edit-album').value = '';
|
||||
renderEditThumbs();
|
||||
}
|
||||
|
||||
async function saveEdit(deploy){
|
||||
const s = $('#e-status');
|
||||
if (!$('#e-title').value.trim()){ s.innerHTML = '<span class="err">제목을 넣어 주세요</span>'; return; }
|
||||
if (!S.edit || !S.edit.images.length){ s.innerHTML = '<span class="err">사진이 최소 한 장 필요합니다</span>'; return; }
|
||||
['#e-save','#e-save-only'].forEach(x=>$(x).disabled=true);
|
||||
s.innerHTML = '<span class="spin"></span> 저장 중… (사진 정리 → 빌드 → 커밋' + (deploy?' → 배포':'') + ')';
|
||||
try{
|
||||
const d = await api('/api/update', {
|
||||
slug: S.edit.slug, images: S.edit.images,
|
||||
title: $('#e-title').value.trim(), subtitle: $('#e-subtitle').value.trim(),
|
||||
body: $('#e-body').value, image_alt: $('#e-alt').value.trim(),
|
||||
size: $('#e-size').value.trim(), material: $('#e-material').value.trim(),
|
||||
care: $('#e-care').value.trim(), price: $('#e-price').value, price_note: $('#e-pricenote').value.trim(),
|
||||
date: $('#e-date').value, naver_url: $('#e-naver').value.trim(),
|
||||
featured: $('#e-featured').checked, sold_out: $('#e-soldout').checked, deploy
|
||||
});
|
||||
s.innerHTML = `고쳤습니다 — 커밋 ${String(d.commit).slice(0,34)}<br>` +
|
||||
(d.deployed ? '사이트에 올렸습니다. ' : '저장만 했습니다. ') +
|
||||
`<a class="live" href="${d.url}" target="_blank">페이지 열기</a>`;
|
||||
toast('수정 완료');
|
||||
S.lastSlug = d.slug;
|
||||
}catch(e){ s.innerHTML = `<span class="status err">${e.message}</span>`; }
|
||||
finally{ ['#e-save','#e-save-only'].forEach(x=>$(x).disabled=false); }
|
||||
}
|
||||
$('#e-save').onclick = () => saveEdit(true);
|
||||
$('#e-save-only').onclick = () => saveEdit(false);
|
||||
$('#e-cancel').onclick = () => go('home');
|
||||
|
||||
/* ---------- 시작 ---------- */
|
||||
go('home'); loadPresets();
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user