feat(라이브커머스): 라이브 커머스 모듈 추가
말레이시아 라이브 방송의 호스트 정보와 방송 스케줄을 관리하는 새 모듈. 호스트 설정(이름·연락처·주소·계좌·틱톡)은 ERP 관리자만 다루고, 스케줄표에서 등록된 호스트를 골라 날짜·시간·장소·판매금액(RM)·결과 이미지를 저장한다. 권한키 live, DB live_db(LIVE_DB_URL), 미설정이면 설정 필요 안내만 표시한다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/* 라이브 커머스(2026-11-04) — 스케줄표·호스트 설정 */
|
||||
.erp-page:has(> .lv) { box-sizing: border-box; } /* 공용 .erp-page 는 폭 100% + 안쪽 여백이라 그대로면 화면보다 넓어진다 */
|
||||
.lv { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
|
||||
.lv *, .lv-dlg *, .lv-dlg *::before, .lv-dlg *::after { box-sizing: border-box; }
|
||||
.lv-dlg [hidden] { display: none !important; }
|
||||
.lv-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.lv-gap { flex: 1 1 auto; }
|
||||
.lv-month { margin: 0 6px; font-size: 18px; font-weight: 600; white-space: nowrap; }
|
||||
.lv-note { margin: 0; padding: 10px 14px; border-radius: 8px; background: #eef6ff; color: #0b4a8b; border: 1px solid #cfe3fb; font-size: 13px; }
|
||||
|
||||
.lv-table td { vertical-align: middle; overflow-wrap: anywhere; }
|
||||
.lv-table th { white-space: nowrap; }
|
||||
.lv-table tr.lv-off td { color: var(--color-midtone-gray, #666); }
|
||||
.lv-r { text-align: right; }
|
||||
.lv-table th.lv-r { text-align: right; }
|
||||
.lv-num { font-variant-numeric: tabular-nums; }
|
||||
.lv-nowrap { white-space: nowrap; }
|
||||
.lv-sub { margin: 0; font-size: 12px; color: var(--color-midtone-gray, #666); }
|
||||
.lv-actions { white-space: nowrap; text-align: right; }
|
||||
.lv-thumbs { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.lv-thumbs img { display: block; width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--color-subtle-ash, #e5e5e5); }
|
||||
|
||||
/* 공용 .erp-table 은 640px 아래에서 제목 줄을 숨기고 카드로 바뀐다 — 칸 이름을 칸마다 보여 준다 */
|
||||
@media (max-width: 640px) {
|
||||
.lv-table td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 400; color: var(--color-midtone-gray, #666); text-align: left; }
|
||||
.lv-table td.lv-r { text-align: left; }
|
||||
}
|
||||
|
||||
.lv-dlg { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--color-subtle-ash, #e5e5e5); border-radius: 12px; }
|
||||
.lv-dlg::backdrop { background: rgba(0, 0, 0, .35); }
|
||||
.lv-dlg form { display: flex; flex-direction: column; gap: 12px; padding: 20px 22px; }
|
||||
.lv-dlg h3 { margin: 0; font-size: 17px; font-weight: 600; }
|
||||
.lv-field { display: flex; flex: 1 1 0; flex-direction: column; gap: 4px; min-width: 0; font-size: 13px; font-weight: 500; }
|
||||
.lv-field .erp-input, .lv-field .erp-select { width: 100%; min-width: 0; font-weight: 400; }
|
||||
.lv-field textarea { resize: vertical; }
|
||||
.lv-row { display: flex; flex-wrap: wrap; gap: 10px; }
|
||||
.lv-row .lv-field { flex-basis: 140px; }
|
||||
.lv-check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
|
||||
.lv-saved { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 13px; }
|
||||
.lv-saved li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.lv-saved a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.lv-msg { margin: 0; padding: 9px 12px; border-radius: 8px; background: #fbe9e6; color: #a1261b; border: 1px solid #efc6bf; font-size: 13px; }
|
||||
.lv-foot { display: flex; justify-content: flex-end; gap: 8px; }
|
||||
@@ -0,0 +1,105 @@
|
||||
/* 라이브 커머스(2026-11-04) — 스케줄표·호스트 설정 공용: 추가·고치기 창, 저장·지우기(fetch → JSON {ok, message}, 틀려도 입력한 값이 창에 남음). */
|
||||
(function () {
|
||||
"use strict";
|
||||
const dlg = document.getElementById("lv-dlg");
|
||||
const form = document.getElementById("lv-form");
|
||||
if (!dlg || !form) return;
|
||||
const title = dlg.querySelector("#lv-dlg-title");
|
||||
const msg = form.querySelector("[data-msg]");
|
||||
const saved = form.querySelector("[data-saved]");
|
||||
const hostSelect = form.querySelector('select[name="host_id"]');
|
||||
const fileInput = form.querySelector('input[type="file"]');
|
||||
|
||||
function say(text) {
|
||||
msg.textContent = text || "";
|
||||
msg.hidden = !text;
|
||||
}
|
||||
|
||||
async function post(url, body) {
|
||||
try {
|
||||
const res = await fetch(url, { method: "POST", body: body, headers: { Accept: "application/json" } });
|
||||
const data = await res.json().catch(function () { return {}; });
|
||||
return { ok: res.ok && data.ok !== false, message: data.message || data.detail || "HTTP " + res.status };
|
||||
} catch (_) {
|
||||
return { ok: false, message: "서버에 연결하지 못했습니다. 입력한 값은 그대로 있으니 다시 저장해 보세요." };
|
||||
}
|
||||
}
|
||||
|
||||
// 사용 안 함 호스트는 그 호스트로 이미 등록된 방송을 고칠 때만 보인다
|
||||
function showHosts(current) {
|
||||
if (!hostSelect) return;
|
||||
Array.from(hostSelect.options).forEach(function (opt) {
|
||||
const off = opt.dataset.inactive === "1" && opt.value !== String(current || "");
|
||||
opt.hidden = off;
|
||||
opt.disabled = off;
|
||||
});
|
||||
}
|
||||
|
||||
function showSaved(images) {
|
||||
if (!saved) return;
|
||||
saved.textContent = "";
|
||||
(images || []).forEach(function (im) {
|
||||
const li = document.createElement("li");
|
||||
const link = document.createElement("a");
|
||||
link.href = "/live/images/" + im.id;
|
||||
link.target = "_blank";
|
||||
link.rel = "noopener";
|
||||
link.textContent = im.filename || "이미지 " + im.id;
|
||||
const del = document.createElement("button");
|
||||
del.type = "button";
|
||||
del.className = "erp-btn erp-btn-outline erp-btn-sm";
|
||||
del.dataset.post = "/live/images/" + im.id + "/delete";
|
||||
del.dataset.confirm = (im.filename || "이 이미지") + " 를 지울까요?";
|
||||
del.textContent = "지우기";
|
||||
li.append(link, del);
|
||||
saved.appendChild(li);
|
||||
});
|
||||
saved.hidden = !saved.children.length;
|
||||
}
|
||||
|
||||
function open(row) {
|
||||
form.reset();
|
||||
say("");
|
||||
title.textContent = row ? title.dataset.edit : title.dataset.add;
|
||||
Array.from(form.elements).forEach(function (el) {
|
||||
if (!row || !el.name || !(el.name in row)) return;
|
||||
if (el.type === "checkbox") el.checked = !!row[el.name];
|
||||
else if (el.type !== "file") el.value = row[el.name];
|
||||
});
|
||||
if (!row) form.elements.id.value = "";
|
||||
showHosts(row && row.host_id);
|
||||
if (row && hostSelect) hostSelect.value = String(row.host_id); // 위에서 보이게 한 뒤 다시 고름
|
||||
showSaved(row && row.images);
|
||||
dlg.showModal();
|
||||
}
|
||||
|
||||
const addBtn = document.getElementById("lv-add");
|
||||
if (addBtn) addBtn.addEventListener("click", function () { open(null); });
|
||||
dlg.addEventListener("click", function (e) {
|
||||
if (e.target.closest("[data-close]")) dlg.close();
|
||||
});
|
||||
|
||||
document.addEventListener("click", async function (e) {
|
||||
const edit = e.target.closest("[data-edit]");
|
||||
if (edit && edit.tagName === "BUTTON") { open(JSON.parse(edit.dataset.edit)); return; }
|
||||
const btn = e.target.closest("button[data-post]");
|
||||
if (!btn) return;
|
||||
if (!(await window.erpConfirm(btn.dataset.confirm))) return;
|
||||
const r = await post(btn.dataset.post);
|
||||
if (r.ok) { location.reload(); return; }
|
||||
if (dlg.open) say(r.message); else window.erpAlert(r.message);
|
||||
});
|
||||
|
||||
form.addEventListener("submit", async function (e) {
|
||||
e.preventDefault();
|
||||
const save = form.querySelector('button[type="submit"]');
|
||||
const body = new FormData(form);
|
||||
if (fileInput && !fileInput.files.length) body.delete("images");
|
||||
save.disabled = true;
|
||||
say("");
|
||||
const r = await post(form.getAttribute("action"), body);
|
||||
if (r.ok) { location.reload(); return; }
|
||||
save.disabled = false;
|
||||
say(r.message);
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user