Files
wechat_wc/dist/pages/diy/stickerEdit/index.js
T
lhmin0604andClaude 2e3676a470 fix(diy): 贴纸编辑页滑块组件化 + CSS filter 预览 + edits 参数化保存
修正工作流批次③(问题5):
- 三个滑块统一改用 TouchSlider 组件(id 选择器定位 + touchstart 缓存
  rect),删除原 .in(e.currentTarget) 坏实现与死代码
- 预览弃用 Canvas ctx.filter(开发者工具不支持),改 Image + CSS filter
  所见即所得;Canvas 导出链路整体移除
- 保存改为 edits 参数化持久化(src 不变;裁剪/线稿的 src 替换经
  pendingSrc 一并落库),不再依赖 canvasToTempFilePath
- DIY 工作台画布与预览弹层渲染端消费 edits(同一 CSS filter 逻辑),
  checkout 预览消费 edits 记入 R3 待办(routes/R2/README.md #6)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-12 19:29:03 +08:00

1 line
7.8 KiB
JavaScript

"use strict";(wx["webpackJsonp"]=wx["webpackJsonp"]||[]).push([[339],{9519:function(e,s,t){var a=t(7842),n=t(1212),c=t(467),i=t(9379),r=t(5544),l=t(118),d=t(758),o=t.n(d),u=t(6540),h=t(1457),m=t(6845),x=t(9703),f=t(9201),j=t(5414),g=t(9674),p=t(3053),v=t(9513),N=t(4848),S=function(e,s,t){return Math.min(Math.max(e,s),t)};function w(e){var s=e.id,t=e.value,a=e.min,n=e.max,c=e.onChange,i=e.format,r=(0,u.useRef)(null),d=function(e){o().createSelectorQuery().select("#".concat(s)).boundingClientRect(function(s){s&&s.width>0&&(r.current={left:s.left,width:s.width}),e&&e()}).exec()},h=function(e){var s=r.current;if(!s||!s.width)return t;var c=S((e-s.left)/s.width,0,1);return S(a+(n-a)*c,a,n)},m=function(e){var s=e.touches&&e.touches[0];s&&d(function(){return c(h(s.clientX))})},x=function(e){var s=e.touches&&e.touches[0];s&&(r.current?c(h(s.clientX)):d(function(){return c(h(s.clientX))}))},f="".concat((t-a)/(n-a)*100,"%");return(0,N.jsxs)(l.Ss,{className:"slider-wrap",children:[(0,N.jsxs)(l.Ss,{id:s,className:"slider-track",onTouchStart:m,onTouchMove:x,onTouchEnd:function(){},children:[(0,N.jsx)(l.Ss,{className:"slider-fill",style:{width:f}}),(0,N.jsx)(l.Ss,{className:"slider-thumb",style:{left:f}})]}),(0,N.jsx)(l.EY,{className:"slider-value",children:i?i(t):t})]})}function k(){var e=(0,x.wR)(),s=e.resolvedTheme,t=(0,f.c)();(0,j.l)(s);var a=(0,u.useState)(""),d=(0,r.A)(a,2),S=d[0],k=d[1],A=(0,u.useState)(""),b=(0,r.A)(A,2),E=b[0],T=b[1],Y=(0,u.useState)(null),y=(0,r.A)(Y,2),B=y[0],I=y[1],D=(0,u.useState)(!1),C=(0,r.A)(D,2),P=C[0],M=C[1],U=(0,u.useState)(null),q=(0,r.A)(U,2),F=q[0],R=q[1],X=(0,u.useState)(0),_=(0,r.A)(X,2),H=_[0],J=_[1],O=(0,u.useState)(0),Q=(0,r.A)(O,2),V=Q[0],W=Q[1],$=(0,u.useState)(0),z=(0,r.A)($,2),G=z[0],K=z[1],L=(0,u.useState)(!1),Z=(0,r.A)(L,2),ee=Z[0],se=Z[1];(0,u.useEffect)(function(){var e=o().getCurrentInstance().router,s=e?e.params:void 0,t=s?s.designId:"",a=s?s.stickerId:"";k(t),T(a);var n=(0,h.p_)(),c=n.find(function(e){return e.id===t}),i=c&&c.designData&&c.designData.stickers?c.designData.stickers.find(function(e){return e.id===a}):void 0;i?(I(i),J(i.edits&&i.edits.brightness||0),W(i.edits&&i.edits.hue||0),K(i.edits&&i.edits.contrast||0)):M(!0)},[]);var te=function(){if(B&&S){se(!0);var e=(0,h.p_)(),s=e.findIndex(function(e){return e.id===S});if(-1===s)return se(!1),void M(!0);var t=e[s],a=t.designData&&t.designData.stickers||[],n=a.findIndex(function(e){return e.id===E});if(-1===n)return se(!1),void M(!0);a[n]=(0,i.A)((0,i.A)((0,i.A)({},a[n]),F?{src:F}:{}),{},{edits:{brightness:H,hue:V,contrast:G}});var c=(0,i.A)((0,i.A)({},t.designData),{},{stickers:a});(0,h.i5)(S,{designData:c}),(0,m.i5)(S,{item:{productId:t.productId,productName:t.productName,unitPrice:t.unitPrice,count:t.count,designData:c}}).catch(function(){return o().showToast({title:"\u7f51\u7edc\u4e0d\u53ef\u7528\uff0c\u5df2\u6682\u5b58\u5230\u672c\u5730",icon:"none"})}),se(!1),o().showToast({title:"\u4fdd\u5b58\u6210\u529f",icon:"success"}),o().navigateBack()}},ae=function(){B&&(o().cropImage?o().cropImage({src:B.src,cropScale:"1:1",success:function(e){var s=(0,i.A)((0,i.A)({},B),{},{src:e.tempFilePath});I(s),R(e.tempFilePath)}}):o().showToast({title:"\u5f53\u524d\u5fae\u4fe1\u7248\u672c\u4e0d\u652f\u6301\u88c1\u526a",icon:"none"}))},ne=function(){var e=(0,c.A)((0,n.A)().m(function e(){var s;return(0,n.A)().w(function(e){while(1)switch(e.p=e.n){case 0:if(B){e.n=1;break}return e.a(2);case 1:return se(!0),e.p=2,e.n=3,(0,m.W$)(B.src);case 3:if(s=e.v,null===s||void 0===s||!s.imageUrl){e.n=4;break}I((0,i.A)((0,i.A)({},B),{},{src:s.imageUrl})),R(s.imageUrl),se(!1),o().showToast({title:"\u7ebf\u7a3f\u751f\u6210\u6210\u529f",icon:"success"}),e.n=5;break;case 4:throw new Error("no imageUrl");case 5:e.n=7;break;case 6:e.p=6,e.v,o().showToast({title:"\u4f7f\u7528\u672c\u5730\u7ebf\u7a3f",icon:"none"}),J(20),K(80),W(0),se(!1);case 7:return e.a(2)}},e,null,[[2,6]])}));return function(){return e.apply(this,arguments)}}(),ce=0===H&&0===V&&0===G?"none":"brightness(".concat(100+H,"%) hue-rotate(").concat(V,"deg) contrast(").concat(100+G,"%)");return P?(0,N.jsxs)(l.Ss,{className:"theme-".concat(s),children:[(0,N.jsx)(g.A,{}),(0,N.jsx)(p.A,{title:"\u7f16\u8f91\u8d34\u7eb8",targetSelector:".edit-header",showBack:!0}),(0,N.jsxs)(l.Ss,{className:"sticker-edit-page",children:[(0,N.jsxs)(l.Ss,{className:"edit-header",style:{paddingTop:"".concat(t.statusBarHeight+12,"px")},children:[(0,N.jsx)(l.EY,{className:"edit-back",onTap:function(){return o().navigateBack()},children:"\u2190"}),(0,N.jsx)(l.EY,{className:"edit-title",children:"\u7f16\u8f91\u8d34\u7eb8"}),(0,N.jsx)(l.EY,{className:"edit-save"})]}),(0,N.jsxs)(l.Ss,{className:"edit-empty surface-card mt-20",children:[(0,N.jsx)(l.EY,{className:"edit-empty-title",children:"\u672a\u627e\u5230\u8be5\u8d34\u7eb8"}),(0,N.jsx)(l.EY,{className:"edit-empty-desc",children:"\u8d34\u7eb8\u53ef\u80fd\u5df2\u88ab\u5220\u9664\uff0c\u8bf7\u8fd4\u56de\u5de5\u4f5c\u53f0\u91cd\u65b0\u6dfb\u52a0"}),(0,N.jsx)(l.Ss,{className:"btn-primary",onTap:function(){return o().navigateBack()},children:(0,N.jsx)(l.EY,{children:"\u8fd4\u56de\u5de5\u4f5c\u53f0"})})]})]})]}):(0,N.jsxs)(l.Ss,{className:"theme-".concat(s),children:[(0,N.jsx)(g.A,{}),(0,N.jsx)(p.A,{title:"\u7f16\u8f91\u8d34\u7eb8",targetSelector:".edit-header",showBack:!0}),(0,N.jsxs)(l.Ss,{className:"sticker-edit-page",children:[(0,N.jsxs)(l.Ss,{className:"edit-header",style:{paddingTop:"".concat(t.statusBarHeight+12,"px")},children:[(0,N.jsx)(l.EY,{className:"edit-back",onTap:function(){return o().navigateBack()},children:"\u2190"}),(0,N.jsx)(l.EY,{className:"edit-title",children:"\u7f16\u8f91\u8d34\u7eb8"}),(0,N.jsx)(l.EY,{className:"edit-save",onTap:te,children:"\u4fdd\u5b58"})]}),(0,N.jsx)(l.Ss,{className:"edit-canvas-wrap",children:(0,N.jsx)(l._V,{className:"edit-preview-img",src:B?B.src:"",mode:"aspectFit",style:{filter:ce}})}),(0,N.jsxs)(l.Ss,{className:"edit-tools surface-card mt-20",children:[(0,N.jsxs)(l.Ss,{className:"edit-row",children:[(0,N.jsx)(l.EY,{className:"edit-label",children:"\u5feb\u901f\u64cd\u4f5c"}),(0,N.jsxs)(l.Ss,{className:"edit-quick-actions",children:[(0,N.jsx)(l.Ss,{className:"quick-btn",onTap:ae,children:(0,N.jsx)(l.EY,{children:"\u88c1\u526a"})}),(0,N.jsx)(l.Ss,{className:"quick-btn",onTap:ne,children:(0,N.jsx)(l.EY,{children:"\u8f6c\u7ebf\u7a3f"})})]})]}),(0,N.jsxs)(l.Ss,{className:"edit-row slider-row",children:[(0,N.jsx)(l.EY,{className:"edit-label",children:"\u4eae\u5ea6"}),(0,N.jsx)(w,{id:"slider-brightness",value:H,min:-100,max:100,onChange:J,format:function(e){return e>0?"+".concat(e):"".concat(e)}})]}),(0,N.jsxs)(l.Ss,{className:"edit-row slider-row",children:[(0,N.jsx)(l.EY,{className:"edit-label",children:"\u8272\u76f8"}),(0,N.jsx)(w,{id:"slider-hue",value:V,min:-180,max:180,onChange:W,format:function(e){return e>0?"+".concat(e):"".concat(e)}})]}),(0,N.jsxs)(l.Ss,{className:"edit-row slider-row",children:[(0,N.jsx)(l.EY,{className:"edit-label",children:"\u5bf9\u6bd4\u5ea6"}),(0,N.jsx)(w,{id:"slider-contrast",value:G,min:-100,max:100,onChange:K,format:function(e){return e>0?"+".concat(e):"".concat(e)}})]})]}),(0,N.jsx)(l.Ss,{style:{flex:1}}),(0,N.jsxs)(v.A,{className:"edit-footer",children:[(0,N.jsx)(l.Ss,{className:"btn-secondary",onTap:function(){return o().navigateBack()},children:(0,N.jsx)(l.EY,{children:"\u53d6\u6d88"})}),(0,N.jsx)(l.Ss,{className:"btn-primary",onTap:te,children:(0,N.jsx)(l.EY,{children:"\u4fdd\u5b58"})})]}),(0,N.jsx)(l.Ss,{className:"safe-bottom-placeholder"}),ee&&(0,N.jsx)(l.Ss,{className:"edit-loading",children:(0,N.jsx)(l.EY,{className:"edit-loading-text",children:"\u5904\u7406\u4e2d\u2026"})})]})]})}var A={navigationStyle:"custom",enablePageMeta:!0,navigationBarTitleText:"\u7f16\u8f91\u8d34\u7eb8"};Page((0,a.createPageConfig)(k,"pages/diy/stickerEdit/index",{root:{cn:[]}},A||{}))}},function(e){var s=function(s){return e(e.s=s)};e.O(0,[907,96,76],function(){return s(9519)});e.O()}]);