feat(cafe24): 옵션/품목 팝업에 모바일 스와이프 코드 복사 버튼

첫 줄 `// 상품명`, 이어서 품목마다 `"품목코드": "/web/... 썸네일 경로",`
형식으로 클립보드에 복사한다. 썸네일은 행에 보이는 이미지 기준이며
도메인·CDN 주소는 떼고 /web/ 부터 남긴다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 10:54:00 +09:00
parent f1384d3a9a
commit ef6313ec9f
3 changed files with 46 additions and 2 deletions
+2
View File
@@ -12,6 +12,8 @@
- 정보 패널(`routes_product_info.py`, `_side.html`)에서 상품명·판매가·공급가·소비자가, 대표이미지, 옵션(생성/이름·썸네일·표시방식 수정/삭제)·품목(자체코드·추가금액·진열·판매) 수정.
- 대표이미지는 `POST /admin/products/{no}/images` 에 base64 data URI + `image_upload_type=A`.
NNEditor 업로드 경로를 PUT `detail_image` 에 넣는 방식은 적용 안 됨.
- 옵션/품목 팝업(단일 옵션 화면) 「모바일 스와이프 코드 복사」: `// 상품명` + `"품목코드": "/web/…썸네일 경로",` 줄들을 클립보드로
(`cafe24-options.js` `swipeCode` — 행에 지금 보이는 썸네일 기준, 도메인/CDN 은 떼고 `/web/` 부터).
- 권한키 `cafe24`(연결/해제는 admin 전용).
## 규칙
@@ -125,7 +125,7 @@
{% endblock %}
{% block scripts %}
<script src="/static/cafe24-options.js?v=20260928c"></script>
<script src="/static/cafe24-options.js?v=20261020a"></script>
<script>
(function () {
var pane = document.getElementById("cf24-editor-pane");
+43 -1
View File
@@ -68,7 +68,8 @@
openBtn.addEventListener("click", function () {
var nameEl = document.getElementById("cf24-name-text");
modal.open((nameEl ? nameEl.textContent : "") + " (상품번호 " + no + ")");
state.productName = nameEl ? nameEl.textContent.trim() : "";
modal.open(state.productName + " (상품번호 " + no + ")");
myGen = modal.gen;
load();
});
@@ -233,6 +234,34 @@
return state.imageBase ? state.imageBase + (path.charAt(0) === "/" ? "" : "/") + path : "";
}
// 이미지 주소 → 쇼핑몰 기준 경로("/web/product/…"). 도메인·CDN 주소(이중 주소 포함)는 뗀다.
function shopPath(url) {
url = String(url || "").trim();
var at = url.lastIndexOf("/web/");
if (at >= 0) return url.slice(at);
return url.indexOf("web/") === 0 ? "/" + url : url;
}
// 모바일 스와이프(product-swiper.js)에 붙여 넣을 품목코드 → 썸네일 경로 목록.
// 썸네일은 행에 **지금 보이는** 이미지(버튼 → 연결 → 품목 이미지, 깨진 후보는 건너뛴 결과)다.
// // 상품명
// "P00000CM000A": "/web/product/extra/202503/….jpg",
function swipeCode(tbody) {
var lines = ["// " + (state.productName || ("상품번호 " + no))];
var count = 0;
var missing = 0;
tbody.querySelectorAll("tr").forEach(function (tr) {
var code = tr.dataset.code;
if (!code) return; // 아직 품목코드 없는 행(새 행·생성 대기)
var img = tr.querySelector("img.cf24-opt-thumb");
var path = img ? shopPath(img.getAttribute("src")) : "";
if (!path) missing++;
lines.push(' "' + code + '": "' + path + '",');
count++;
});
return { text: lines.join("\n"), count: count, missing: missing };
}
// 후보(버튼 이미지 → 연결 이미지 → 품목 image) 중 첫 번째를 보여주고, 깨지면 다음
// 후보로 넘어간다(cf24ThumbFallback). 전부 실패하면 "없음".
var THUMB_EMPTY = '<div class="cf24-opt-thumb-empty">없음</div>';
@@ -367,6 +396,7 @@
' <label class="cf24-side-field cf24-u-optname"><span>옵션명</span><input type="text" name="option_name" value="' + esc(group.option_name) + '" placeholder="예: 구성" /></label>' +
' <label class="cf24-side-field cf24-side-field-type"><span>표시방식</span>' + typeSelect(group.option_display_type || DEFAULT_TYPE, "option_display_type") + "</label>" +
' <span class="cf24-u-head-actions">' +
(isNew ? "" : ' <button type="button" class="erp-btn erp-btn-outline" id="cf24-u-swipe" title="품목코드와 썸네일 경로를 모바일 스와이프(product-swiper.js) 형식으로 복사합니다">모바일 스와이프 코드 복사</button>') +
' <button type="button" class="erp-btn erp-btn-outline" id="cf24-u-import">옵션값 불러오기</button>' +
' <button type="button" class="erp-btn erp-btn-outline" id="cf24-u-add">+ 행 추가</button>' +
" </span>" +
@@ -416,6 +446,18 @@
tr.querySelector('[name="option_text"]').focus();
});
body.querySelector("#cf24-u-import").addEventListener("click", function () { openImport(isNew, tbody, msg); });
var swipeBtn = body.querySelector("#cf24-u-swipe");
if (swipeBtn) swipeBtn.addEventListener("click", function () {
var out = swipeCode(tbody);
if (!out.count) { window.erpAlert("품목코드가 있는 행이 없습니다."); return; }
copyText(out.text, function () {
var old = swipeBtn.textContent;
swipeBtn.textContent = "복사됨";
setTimeout(function () { swipeBtn.textContent = old; }, 1200);
msg.textContent = "스와이프 코드 " + out.count + "개 품목 복사" +
(out.missing ? " — 썸네일 없는 품목 " + out.missing + "개는 경로가 비어 있습니다" : "");
});
});
body.querySelector("#cf24-u-save").addEventListener("click", function () { saveUnified(isNew, tbody, msg); });
var del = body.querySelector("#cf24-opt-delete");
if (del) del.addEventListener("click", deleteOptions);