Pārlūkot izejas kodu

fix(box/auth): 修复纸盒编辑器与退出登录的 5 个问题

- 素材(图标/形状)支持修改颜色,并同步重绘 2D/3D 预览
- 3D 结构补位面(扣底/平口箱等)继承对应面纸的底色与纹理,底面不再露出白边
- 盒体闭合时隐藏插舌,避免插舌穿出正面板(平摊视图仍可见)
- 盒型卡片改为两列等宽栅格,长名称省略,面板不再横向滚动
- 退出登录增加二次确认弹窗(菜单入口与页头入口),并补充英文文案
wenhongquan 1 mēnesi atpakaļ
vecāks
revīzija
23c9416dc2
6 mainītis faili ar 137 papildinājumiem un 28 dzēšanām
  1. 26 0
      assets/css/auth.css
  2. 4 4
      assets/css/box.css
  3. 29 2
      assets/js/auth.js
  4. 53 9
      assets/js/box.js
  5. 23 13
      assets/js/box3d.js
  6. 2 0
      assets/js/i18n-en.js

+ 26 - 0
assets/css/auth.css

@@ -154,6 +154,32 @@
   color: var(--muted-2, #a79d8d);
 }
 
+.pl-auth-actions {
+  display: flex;
+  gap: 10px;
+  margin-top: 18px;
+}
+
+.pl-auth-actions .pl-auth-submit {
+  flex: 1;
+  width: auto;
+  margin-top: 0;
+}
+
+.pl-auth-cancel {
+  flex: 1;
+  height: 44px;
+  border-radius: 10px;
+  border: 1px solid var(--line-2, #d5cbb9);
+  background: var(--paper-2, #faf6ec);
+  color: var(--ink-2, #2c271f);
+  font-size: 13px;
+  font-weight: 600;
+  transition: background 0.2s;
+}
+
+.pl-auth-cancel:hover { background: var(--paper, #f6f2e9); }
+
 .pl-auth-entry {
   position: relative;
   display: inline-flex;

+ 4 - 4
assets/css/box.css

@@ -188,18 +188,18 @@ html, body { height: 100%; }
 .bx-chips button:hover { border-color: var(--bx-orange); color: var(--bx-orange); }
 .bx-chips button.on { background: var(--bx-orange); border-color: var(--bx-orange); color: #fff; }
 
-.bx-box-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
+.bx-box-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
 .bx-box-card {
   position: relative; border: 1.5px solid #eee; background: #fff; border-radius: 10px;
-  padding: 8px; cursor: pointer; text-align: left;
+  padding: 8px; cursor: pointer; text-align: left; min-width: 0;
 }
 .bx-box-card:hover { border-color: #ffc79b; }
 .bx-box-card.on { border-color: var(--bx-orange); }
 .bx-box-card .thumb { display: block; height: 74px; border-radius: 7px; background: #f7f7f7; overflow: hidden; }
 .bx-box-card .thumb svg { width: 100%; height: 100%; }
 .bx-box-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; }
-.bx-box-card .meta b { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
-.bx-box-card .meta .no { font-size: 10.5px; color: #b0aaa0; }
+.bx-box-card .meta b { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+.bx-box-card .meta .no { flex: none; margin-left: 4px; font-size: 10.5px; color: #b0aaa0; }
 .bx-box-card .flag {
   position: absolute; left: 8px; top: 8px; background: rgba(40,36,30,.62); color: #fff;
   font-size: 9.5px; border-radius: 4px; padding: 2px 5px; font-style: normal;

+ 29 - 2
assets/js/auth.js

@@ -476,6 +476,33 @@
     notify('已退出登录');
   }
 
+  function confirmLogout() {
+    if (document.getElementById('plLogoutConfirm')) return;
+    const mask = document.createElement('div');
+    mask.id = 'plLogoutConfirm';
+    mask.className = 'pl-auth-mask';
+    mask.innerHTML =
+      '<div class="pl-auth-card" role="dialog" aria-modal="true" aria-labelledby="plLogoutTitle">' +
+        '<button class="pl-auth-close" type="button" aria-label="关闭">✕</button>' +
+        '<div class="pl-auth-brand">袋研社 <em>POUCHLAB</em></div>' +
+        '<h2 id="plLogoutTitle">退出登录</h2>' +
+        '<p class="pl-auth-sub">退出后需重新登录才能查看设计、订单进度与下载记录,确定要退出吗?</p>' +
+        '<div class="pl-auth-actions">' +
+          '<button class="pl-auth-cancel" type="button">取消</button>' +
+          '<button class="pl-auth-submit" type="button">确认退出</button>' +
+        '</div>' +
+      '</div>';
+    const closeDlg = function () { mask.remove(); };
+    mask.querySelector('.pl-auth-close').addEventListener('click', closeDlg);
+    mask.querySelector('.pl-auth-cancel').addEventListener('click', closeDlg);
+    mask.addEventListener('click', function (e) { if (e.target === mask) closeDlg(); });
+    mask.querySelector('.pl-auth-submit').addEventListener('click', function () {
+      closeDlg();
+      logout();
+    });
+    document.body.appendChild(mask);
+  }
+
   function requireAuth(cb) {
     if (user) {
       if (user.needsBindEmail) openBind();
@@ -522,7 +549,7 @@
     entry.querySelector('.pl-auth-logout').addEventListener('click', function (e) {
       e.stopPropagation();
       menu.hidden = true;
-      logout();
+      confirmLogout();
     });
     document.addEventListener('click', function () { menu.hidden = true; });
     renderEntry(entry);
@@ -535,7 +562,7 @@
         trigger.addEventListener('click', function (e) { e.preventDefault(); });
       }
       trigger.addEventListener('click', function () {
-        if (user) { logout(); } else { open(); }
+        if (user) { confirmLogout(); } else { open(); }
       });
       const sync = function () {
         trigger.textContent = displayName();

+ 53 - 9
assets/js/box.js

@@ -378,16 +378,24 @@
 
     if (type === 'rsc') {
       [[xF, W, 'top', true], [xR, D2, null, false], [xB, W, null, false], [xL, D2, null, false]].forEach(function (f) {
-        panels.push(rect(f[0], -half, f[1], half, f[2], 'flap'));
-        panels.push(rect(f[0], H, f[1], half, f[3] ? 'bottom' : null, 'flap'));
+        const top = rect(f[0], -half, f[1], half, f[2], 'flap');
+        if (!f[2]) top.paint = 'top';
+        panels.push(top);
+        const bottom = rect(f[0], H, f[1], half, f[3] ? 'bottom' : null, 'flap');
+        if (!f[3]) bottom.paint = 'bottom';
+        panels.push(bottom);
       });
     } else if (type === 'carton') {
       panels.push(big(xF, 0, 'top', -1));
-      panels.push(big(xB, 0, null, -1));
+      const topBack = big(xB, 0, null, -1);
+      topBack.paint = 'top';
+      panels.push(topBack);
       panels.push(dust(xR, 0, -1));
       panels.push(dust(xL, 0, -1));
       panels.push(big(xF, H, 'bottom', 1));
-      panels.push(big(xB, H, null, 1));
+      const bottomBack = big(xB, H, null, 1);
+      bottomBack.paint = 'bottom';
+      panels.push(bottomBack);
       panels.push(dust(xR, H, 1));
       panels.push(dust(xL, H, 1));
     } else if (type === 'mailer') {
@@ -434,9 +442,15 @@
           [xF, H], [xF + c2, H + d1], [xF + W * 0.32, H + d1], [xF + W * 0.32, H + d1 - 4],
           [xF + W * 0.68, H + d1 - 4], [xF + W * 0.68, H + d1], [xF + W - c2, H + d1], [xF + W, H]
         ], 'bottom', 'flap'));
-        panels.push(poly([[xB, H], [xB + c2, H + d2], [xB + W - c2, H + d2], [xB + W, H]], null, 'flap'));
-        panels.push(poly([[xR, H], [xR + D2, H], [xR + D2 / 2, H + half + 3]], null, 'dust'));
-        panels.push(poly([[xL, H], [xL + D2, H], [xL + D2 / 2, H + half + 3]], null, 'dust'));
+        const bottomBack = poly([[xB, H], [xB + c2, H + d2], [xB + W - c2, H + d2], [xB + W, H]], null, 'flap');
+        bottomBack.paint = 'bottom';
+        panels.push(bottomBack);
+        const bottomR = poly([[xR, H], [xR + D2, H], [xR + D2 / 2, H + half + 3]], null, 'dust');
+        bottomR.paint = 'bottom';
+        panels.push(bottomR);
+        const bottomL = poly([[xL, H], [xL + D2, H], [xL + D2 / 2, H + half + 3]], null, 'dust');
+        bottomL.paint = 'bottom';
+        panels.push(bottomL);
       } else {
         // tuck 反向插锁:下盖挂前板
         panels.push(poly([[xF, H], [xF + ch, H + lidD], [xF + W - ch, H + lidD], [xF + W, H]], 'bottom', 'flap'));
@@ -828,6 +842,14 @@
     return '';
   }
 
+  function assetFillSrc(item, color) {
+    if (item.draw) return LB.shapeDataUrl(item.draw, color, 160);
+    if (item.svgDef) return 'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">' + item.svgDef.replace(/currentColor/g, color) + '</svg>');
+    const id = String(item.assetId || '').replace(/^icon:/, '');
+    const svg = id ? LB.assetSvg(id, color) : null;
+    return svg ? 'data:image/svg+xml;utf8,' + encodeURIComponent(svg) : null;
+  }
+
   function addAssetToFace(item) {
     const face = curFace();
     face.items = face.items || [];
@@ -990,7 +1012,7 @@
     if (t.asset && LB.ICONS[t.asset.id]) {
       face.items.push({
         id: 'i' + Date.now().toString(36) + Math.random().toString(36).slice(2, 5),
-        type: 'asset', assetId: t.asset.id, src: 'data:image/svg+xml;utf8,' + encodeURIComponent(LB.assetSvg(t.asset.id, '#c2451f')), x: 50, y: 68, w: 26
+        type: 'asset', assetId: t.asset.id, src: 'data:image/svg+xml;utf8,' + encodeURIComponent(LB.assetSvg(t.asset.id, '#c2451f')), color: '#c2451f', x: 50, y: 68, w: 26
       });
     }
     UI.message.success('模板「' + t.name + '」已套用到' + faceName(t.face));
@@ -1056,7 +1078,7 @@
     let src;
     if (a.svgDef) src = 'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">' + a.svgDef.replace(/currentColor/g, '#17140f') + '</svg>');
     else src = LB.shapeDataUrl(a.draw, '#17140f', 160);
-    addAssetToFace({ type: 'asset', assetId: a.id, name: a.name, src: src });
+    addAssetToFace({ type: 'asset', assetId: a.id, name: a.name, src: src, color: '#17140f', svgDef: a.svgDef || null, draw: a.draw || null });
   }
 
   /* ---- 文字面板 ---- */
@@ -1649,8 +1671,30 @@
         )
       ));
     } else {
+      const colorable = item.type === 'asset' && !!assetFillSrc(item, '#17140f');
       rows.push(h('div', { className: 'bx-props-sec' },
         h('img', { className: 'bx-item-preview', src: item.src, alt: '' }),
+        colorable && h('div', { className: 'p-field' }, h('label', null, '颜色'), h(A.ColorPicker, {
+          key: 'ac-' + item.id,
+          defaultValue: item.color || '#17140f',
+          showText: true,
+          onChange: function (c) {
+            const hex = c.toHexString();
+            const next = assetFillSrc(item, hex);
+            if (!next) return;
+            item.color = hex;
+            item.src = next;
+            save(true); renderDieline(); render3d(); renderMini();
+          },
+          onChangeComplete: function (c) {
+            const hex = c.toHexString();
+            const next = assetFillSrc(item, hex);
+            if (!next) return;
+            item.color = hex;
+            item.src = next;
+            commit();
+          }
+        })),
         h('div', { className: 'p-field' }, h('label', null, '宽度 ' + (item.w == null ? 60 : item.w) + '%'), h(A.Slider, { value: item.w == null ? 60 : item.w, min: 8, max: 100, onChange: function (v) { item.w = v; renderDieline(); render3d(); renderMini(); }, onAfterChange: function () { commit(); } }))
       ));
     }

+ 23 - 13
assets/js/box3d.js

@@ -210,7 +210,7 @@
             ctx.fillText(line, x, y + (i - (lines.length - 1) / 2) * lh);
           });
           ctx.restore();
-        } else if (it.type === 'image' && it.src) {
+        } else if ((it.type === 'image' || it.type === 'asset') && it.src) {
           const img = getCachedImage(it.src, function () { refreshTextures(); });
           if (img) {
             const iw = ((it.w == null ? 70 : it.w) / 100) * cw;
@@ -261,7 +261,7 @@
       return null;
     }
 
-    function drawFaceTo(entry, face) {
+    function drawFaceTo(entry, face, fillOnly) {
       const sideData = (state.faces[state.side || 'outer'] || {});
       const data = sideData[face] || {};
       const ctx = entry.ctx;
@@ -279,11 +279,12 @@
           }
         }
       }
-      drawFaceArt(ctx, cw, ch, data, cw / Math.max(1, size.w));
+      // 结构副面(如扣底/平口箱的补位摇盖)只刷底色与纹理,不重复印图案
+      if (!fillOnly) drawFaceArt(ctx, cw, ch, data, cw / Math.max(1, size.w));
     }
 
-    function getFaceTexture(face, size) {
-      const key = (state.side || 'outer') + '|' + face;
+    function getFaceTexture(face, size, fillOnly) {
+      const key = (state.side || 'outer') + '|' + face + (fillOnly ? '|fill' : '');
       let entry = faceTexCache[key];
       if (!entry) {
         const cw = opts.mini ? 360 : 760;
@@ -310,10 +311,10 @@
         }
       });
       meshes.forEach(function (mesh) {
-        const face = mesh.userData.face;
+        const face = mesh.userData.face || mesh.userData.paint;
         if (!face || !mesh.material) return;
-        const entry = getFaceTexture(face, mesh.userData.faceSize || { w: 1, h: 1 });
-        drawFaceTo(entry, face);
+        const entry = getFaceTexture(face, mesh.userData.faceSize || { w: 1, h: 1 }, mesh.userData.fillOnly);
+        drawFaceTo(entry, face, mesh.userData.fillOnly);
         entry.texture.needsUpdate = true;
         if (mesh.material.map !== entry.texture) {
           mesh.material.map = entry.texture;
@@ -322,9 +323,9 @@
       });
     }
 
-    function makeMaterial(face, size, inner) {
-      const entry = getFaceTexture(face, size);
-      drawFaceTo(entry, face);
+    function makeMaterial(face, size, inner, fillOnly) {
+      const entry = getFaceTexture(face, size, fillOnly);
+      drawFaceTo(entry, face, fillOnly);
       entry.texture.needsUpdate = true;
       return new THREE.MeshStandardMaterial({
         map: entry.texture,
@@ -348,11 +349,15 @@
 
     function makePanelMesh(p, box) {
       const geom = planeGeometry(box, p.poly);
-      const mat = p.face ? makeMaterial(p.face, { w: box.w, h: box.h }, state.side === 'inner') : cardboardMaterial();
+      const face = p.face || p.paint || null;
+      const fillOnly = !p.face && !!p.paint;
+      const mat = face ? makeMaterial(face, { w: box.w, h: box.h }, state.side === 'inner', fillOnly) : cardboardMaterial();
       const mesh = new THREE.Mesh(geom, mat);
       mesh.position.z = panelLayer(p);
       mesh.userData.face = p.face || null;
-      mesh.userData.faceSize = p.face ? { w: box.w, h: box.h } : null;
+      mesh.userData.paint = p.paint || null;
+      mesh.userData.fillOnly = fillOnly;
+      mesh.userData.faceSize = face ? { w: box.w, h: box.h } : null;
       mesh.add(new THREE.LineSegments(
         new THREE.EdgesGeometry(geom),
         new THREE.LineBasicMaterial({ color: 0x17140f, transparent: true, opacity: 0.24 })
@@ -639,6 +644,11 @@
       hinges.forEach(function (g) {
         g.setRotationFromAxisAngle(g.userData.axis, g.userData.angle * (1 - foldT));
       });
+      // 盒体闭合时插舌应插入盒内,简化折纸模型无法表达穿插,直接隐藏
+      const showTuck = foldT > 0.35;
+      meshes.forEach(function (m) {
+        if (m.userData.kind === 'tuck') m.visible = showTuck;
+      });
       components.forEach(function (c) {
         if (c.isMain) return;
         c.group.position.lerpVectors(c.assembled, c.home, foldT);

+ 2 - 0
assets/js/i18n-en.js

@@ -717,6 +717,8 @@ window.PLI18N_EN = window.PLI18N_EN || { dict: {}, rules: [] };
     '订单详情': 'Order details',
     '登录': 'Sign in',
     '退出登录': 'Sign out',
+    '确认退出': 'Sign out',
+    '退出后需重新登录才能查看设计、订单进度与下载记录,确定要退出吗?': 'You will need to sign in again to view designs, order progress and download records. Sign out now?',
     '登录已失效,请重新登录': 'Session expired, please sign in again',
     '登录后可查看订单的支付状态、生产进度与物流信息': 'Sign in to view payment status, production progress and tracking.',
     '手机号登录': 'Sign in with phone',