feat(performance): 일자별 표 열 너비 자동/수동 옵션
실적 설정 "보기 설정"에 표 열 너비 [자동(글자 길이)]·[수동 조절] 추가(쿠키 perf_colw). 수동이면 매출 실적·광고비 일자별 표 머리글 오른쪽 경계를 끌어 열 너비를 바꾸고, 바꾼 너비는 localStorage(perf_colw_sales/ads)에 유지. 경계 두 번 클릭 = 그 열만 자동, 설정 [조절한 너비 초기화]로 전부 되돌림. 그룹 접기·펴기 애니메이션과 연동. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -252,6 +252,93 @@
|
||||
// ════════════════════════════════════════════════════
|
||||
// 대시보드
|
||||
// ════════════════════════════════════════════════════
|
||||
// 일자별 표 열 너비 수동 조절(2026-10-27) — 실적 설정 "보기 설정"에서 수동(쿠키 perf_colw=manual)이면 서버가 표에 perf-colw-manual.
|
||||
// 처음엔 자동 너비(글자 길이)를 재 두고 table-layout:fixed 로 고정, 머리글 오른쪽 경계(.perf-colw-grip)를 끌면 그 열만 그 너비로.
|
||||
// 바꾼 너비는 이 브라우저 localStorage(perf_colw_sales / perf_colw_ads, 열 = th data-col)에 계속 유지, 경계를 두 번 누르면 그 열만 자동 너비로.
|
||||
// 그룹 접기·펴기 애니메이션은 apply(접는 열)/animate/settle 로 열 너비를 0 ↔ 원래 너비로 함께 움직인다.
|
||||
const COLW_MIN = 36;
|
||||
function initColWidths(root) {
|
||||
const table = root.querySelector("table.perf-colw-manual");
|
||||
const row = table && table.tHead && table.tHead.rows[0];
|
||||
if (!row) return null;
|
||||
const KEY = "perf_colw_" + (table.dataset.colwKey || "sales");
|
||||
const heads = Array.prototype.slice.call(row.cells);
|
||||
const auto = {};
|
||||
let saved = {};
|
||||
try { saved = JSON.parse(localStorage.getItem(KEY) || "{}") || {}; } catch (_) { saved = {}; }
|
||||
function store() {
|
||||
try { localStorage.setItem(KEY, JSON.stringify(saved)); } catch (_) { /* 기억만 못 함 */ }
|
||||
}
|
||||
function widthOf(th) { const c = th.dataset.col; return saved[c] || auto[c] || 80; }
|
||||
function apply(zero) { // zero = 너비 0 으로 둘 열(접는 중·펴기 직전)
|
||||
let sum = 0;
|
||||
heads.forEach(function (th) {
|
||||
const w = zero && zero.indexOf(th) >= 0 ? 0 : widthOf(th);
|
||||
th.style.width = w + "px";
|
||||
if (!th.classList.contains("is-gfolded")) sum += w;
|
||||
});
|
||||
table.style.width = sum + "px";
|
||||
table.classList.add("is-colw-fixed");
|
||||
}
|
||||
function measure() { // 자동 너비 다시 재기(접혀 안 보이는 열은 앞서 잰 값 그대로)
|
||||
table.classList.remove("is-colw-fixed", "is-colw-anim");
|
||||
heads.forEach(function (th) { th.style.width = ""; });
|
||||
table.style.width = "";
|
||||
heads.forEach(function (th) {
|
||||
const w = th.getBoundingClientRect().width;
|
||||
if (w > 0) auto[th.dataset.col] = Math.ceil(w);
|
||||
});
|
||||
apply();
|
||||
}
|
||||
heads.forEach(function (th) {
|
||||
const g = document.createElement("span");
|
||||
g.className = "perf-colw-grip";
|
||||
g.setAttribute("aria-hidden", "true");
|
||||
th.appendChild(g);
|
||||
});
|
||||
measure();
|
||||
if (document.fonts && document.fonts.status !== "loaded") document.fonts.ready.then(measure); // 글꼴 늦게 오면 자동 너비 다시
|
||||
|
||||
let drag = null;
|
||||
row.addEventListener("pointerdown", function (e) {
|
||||
const g = e.target.closest(".perf-colw-grip");
|
||||
if (!g || e.button !== 0) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
drag = { th: g.parentElement, grip: g, x: e.clientX, w: widthOf(g.parentElement) };
|
||||
try { g.setPointerCapture(e.pointerId); } catch (_) { /* 캡처 못 해도 끌기는 됨 */ }
|
||||
g.classList.add("is-active");
|
||||
document.body.classList.add("perf-colw-dragging");
|
||||
});
|
||||
row.addEventListener("pointermove", function (e) {
|
||||
if (!drag) return;
|
||||
saved[drag.th.dataset.col] = Math.max(COLW_MIN, Math.round(drag.w + e.clientX - drag.x));
|
||||
apply();
|
||||
});
|
||||
function end() {
|
||||
if (!drag) return;
|
||||
drag.grip.classList.remove("is-active");
|
||||
document.body.classList.remove("perf-colw-dragging");
|
||||
drag = null;
|
||||
store();
|
||||
}
|
||||
row.addEventListener("pointerup", end);
|
||||
row.addEventListener("pointercancel", end);
|
||||
row.addEventListener("click", function (e) { if (e.target.closest(".perf-colw-grip")) e.stopPropagation(); });
|
||||
row.addEventListener("dblclick", function (e) {
|
||||
const g = e.target.closest(".perf-colw-grip");
|
||||
if (!g) return;
|
||||
delete saved[g.parentElement.dataset.col];
|
||||
store();
|
||||
apply();
|
||||
});
|
||||
return {
|
||||
apply: apply,
|
||||
animate: function (zero) { table.classList.add("is-colw-anim"); apply(zero); },
|
||||
settle: function () { table.classList.remove("is-colw-anim"); apply(); },
|
||||
};
|
||||
}
|
||||
|
||||
function initDashboard(root) {
|
||||
const data = JSON.parse((document.getElementById("perf-data") || {}).textContent || "{}");
|
||||
const METRIC_NAMES = { gross: "총매출", commission: "수수료", net: "수수료 차감 매출" };
|
||||
@@ -285,8 +372,10 @@
|
||||
const groupRun = {}; // 그룹 → 애니메이션 번호(빠르게 두 번 누르면 앞 애니메이션의 마무리를 버린다)
|
||||
let collapsed = [];
|
||||
try { collapsed = JSON.parse(localStorage.getItem(GROUP_KEY) || "[]") || []; } catch (_) { collapsed = []; }
|
||||
const colw = initColWidths(root); // 열 너비 수동 조절(보기 설정) — 그룹을 접기 전에 자동 너비를 잰다
|
||||
function setGroup(code, fold, animate) {
|
||||
const cells = Array.prototype.slice.call(root.querySelectorAll('[data-group-child="' + code + '"]'));
|
||||
const heads = cells.filter(function (n) { return n.tagName === "TH"; });
|
||||
root.querySelectorAll('[data-group-toggle="' + code + '"]').forEach(function (b) {
|
||||
b.setAttribute("aria-expanded", fold ? "false" : "true");
|
||||
b.setAttribute("aria-label", (b.getAttribute("aria-label") || "").replace(/ (접기|펴기)$/, "") + (fold ? " 펴기" : " 접기"));
|
||||
@@ -298,6 +387,7 @@
|
||||
if (groupRun[code] !== run) return;
|
||||
cells.forEach(function (n) { n.classList.remove("is-ganim", "is-gshut"); n.classList.toggle("is-gfolded", fold); });
|
||||
boxes.forEach(function (b) { b.style.maxWidth = ""; });
|
||||
if (colw) colw.settle();
|
||||
};
|
||||
if (!animate || REDUCE_MOTION || !boxes.length) { settle(); return; }
|
||||
if (fold) {
|
||||
@@ -306,12 +396,15 @@
|
||||
void root.offsetWidth; // 지금 너비에서 출발
|
||||
cells.forEach(function (n) { n.classList.add("is-gshut"); });
|
||||
boxes.forEach(function (b) { b.style.maxWidth = "0px"; });
|
||||
if (colw) colw.animate(heads); // 수동 너비 표 — 열 너비도 0 으로
|
||||
} else {
|
||||
cells.forEach(function (n) { n.classList.remove("is-gfolded", "is-ganim"); n.classList.add("is-gshut"); });
|
||||
boxes.forEach(function (b) { b.style.maxWidth = "0px"; });
|
||||
if (colw) colw.apply(heads);
|
||||
void root.offsetWidth; // 0 에서 출발
|
||||
cells.forEach(function (n) { n.classList.add("is-ganim"); n.classList.remove("is-gshut"); });
|
||||
boxes.forEach(function (b) { b.style.maxWidth = b.scrollWidth + "px"; });
|
||||
if (colw) colw.animate(); // 수동 너비 표 — 열 너비도 원래대로
|
||||
}
|
||||
setTimeout(settle, GROUP_MS + 30);
|
||||
}
|
||||
@@ -1199,6 +1292,31 @@
|
||||
if (ex) ex.textContent = "예: 2,475,300원 → " + UNIT_EX[u];
|
||||
});
|
||||
});
|
||||
// 보기 설정 — 표 열 너비 자동/수동(2026-10-27, 쿠키 perf_colw 1년). 수동으로 바꾼 너비는 표 화면 localStorage 에 있고 [초기화]가 지운다
|
||||
const COLW_HELP = {
|
||||
auto: "열 너비가 글자 길이에 맞춰 자동으로 정해집니다.",
|
||||
manual: "매출 실적·광고비 표 머리글의 오른쪽 경계를 끌어 너비를 바꿉니다(두 번 누르면 그 열만 자동 너비). 바꾼 너비는 계속 유지됩니다.",
|
||||
};
|
||||
const colwReset = document.getElementById("perf-colw-reset");
|
||||
root.querySelectorAll("#perf-view-opts [data-colw]").forEach(function (b) {
|
||||
b.addEventListener("click", function () {
|
||||
const v = b.dataset.colw;
|
||||
document.cookie = "perf_colw=" + v + "; path=/performance; max-age=31536000; SameSite=Lax";
|
||||
root.querySelectorAll("#perf-view-opts [data-colw]").forEach(function (x) {
|
||||
x.classList.toggle("is-active", x === b);
|
||||
x.setAttribute("aria-checked", x === b ? "true" : "false");
|
||||
});
|
||||
const help = document.getElementById("perf-colw-help");
|
||||
if (help) help.textContent = COLW_HELP[v];
|
||||
if (colwReset) colwReset.hidden = v !== "manual";
|
||||
});
|
||||
});
|
||||
if (colwReset) colwReset.addEventListener("click", async function () {
|
||||
if (!(await confirmMsg("매출 실적·광고비 표에서 조절한 열 너비를 모두 지우고 자동 너비로 되돌릴까요?"))) return;
|
||||
try { localStorage.removeItem("perf_colw_sales"); localStorage.removeItem("perf_colw_ads"); } catch (_) { /* 저장소 없음 */ }
|
||||
colwReset.textContent = "초기화했습니다";
|
||||
setTimeout(function () { colwReset.textContent = "조절한 너비 초기화"; }, 1800);
|
||||
});
|
||||
initAutoSyncSettings(root);
|
||||
|
||||
// 사용 / 매출 집계 토글 — 바로 저장, 실패하면 되돌림
|
||||
|
||||
Reference in New Issue
Block a user