Files
wechat_wc/dist/pages/diy/stickerEdit/index.js
T
broccoli b19a56003f 添加登录和后端校验
完成后端设计(未在本仓库体现),通过安全的手段完成了登录鉴权
2026-08-06 16:27:36 +08:00

1 line
8.1 KiB
JavaScript

"use strict";(wx["webpackJsonp"]=wx["webpackJsonp"]||[]).push([[339],{9519:function(e,s,t){var n=t(7842),i=t(9379),a=t(5544),c=t(118),r=t(758),l=t.n(r),o=t(6540),d=t(8594),u=t(9703),h=t(9201),v=t(5414),f=t(4848),m=function(e,s,t){return Math.min(Math.max(e,s),t)};function x(){var e=(0,u.wR)(),s=e.resolvedTheme,t=(0,h.c)();(0,v.l)(s);var n=(0,o.useState)(""),r=(0,a.A)(n,2),x=r[0],g=r[1],S=(0,o.useState)(""),j=(0,a.A)(S,2),w=j[0],N=j[1],p=(0,o.useState)(null),T=(0,a.A)(p,2),k=T[0],b=T[1],y=(0,o.useState)(0),A=(0,a.A)(y,2),E=A[0],Y=A[1],M=(0,o.useState)(0),C=(0,a.A)(M,2),I=C[0],R=C[1],P=(0,o.useState)(0),q=(0,a.A)(P,2),D=q[0],F=q[1],Q=(0,o.useState)(!1),B=(0,a.A)(Q,2),J=B[0],O=B[1],X=(0,o.useState)(!1),_=(0,a.A)(X,2),z=_[0],H=_[1],G=((0,o.useRef)(null),(0,o.useRef)(null)),K=(0,o.useRef)(null),L=(0,o.useRef)({width:0,height:0}),U=(0,o.useCallback)(function(e){z||l().nextTick(function(){var s=l().createSelectorQuery();s.select("#editCanvas").fields({node:!0,size:!0}).exec(function(s){var t,n,i,a=null===s||void 0===s||null===(t=s[0])||void 0===t?void 0:t.node;if(a){var c=a.getContext("2d"),r=(null===(n=s[0])||void 0===n?void 0:n.width)||300,o=(null===(i=s[0])||void 0===i?void 0:i.height)||400;r<=0&&(r=300),o<=0&&(o=400);var d=l().getSystemInfoSync().pixelRatio||1;a.width=Math.round(r*d),a.height=Math.round(o*d),c.scale(d,d),K.current=a,G.current=c,L.current={width:r,height:o},H(!0),V(c,r,o,e)}else setTimeout(function(){return U(e)},300)})})},[z]);(0,o.useEffect)(function(){var e,s,t=null===(e=l().getCurrentInstance().router)||void 0===e?void 0:e.params,n=null===t||void 0===t?void 0:t.designId,i=null===t||void 0===t?void 0:t.stickerId;g(n),N(i);var a,c,r,o=(0,d.p_)(),u=o.find(function(e){return e.id===n}),h=null===u||void 0===u||null===(s=u.designData)||void 0===s||null===(s=s.stickers)||void 0===s?void 0:s.find(function(e){return e.id===i});h&&(b(h),Y((null===(a=h.edits)||void 0===a?void 0:a.brightness)||0),R((null===(c=h.edits)||void 0===c?void 0:c.hue)||0),F((null===(r=h.edits)||void 0===r?void 0:r.contrast)||0),U(h))},[U]);var V=function(e,s,t,n,i){if(e&&K.current){var a=K.current;if(s&&t){var c=n.width||200,r=n.height||200,o=a.createImage();o.onload=function(){var n,a,l;e.clearRect(0,0,s,t),e.save();var d=.9*Math.min(s/c,t/r,4),u=c*d,h=r*d,v=(s-u)/2,f=(t-h)/2,m=null!==(n=null===i||void 0===i?void 0:i.brightness)&&void 0!==n?n:E,x=null!==(a=null===i||void 0===i?void 0:i.hue)&&void 0!==a?a:I,g=null!==(l=null===i||void 0===i?void 0:i.contrast)&&void 0!==l?l:D;e.filter=0!==m||0!==x||0!==g?"brightness(".concat(100+m,"%) hue-rotate(").concat(x,"deg) contrast(").concat(100+g,"%)"):"none",e.drawImage(o,v,f,u,h),e.restore()},o.onerror=function(e){console.error("Canvas load image error:",e,n.src),l().showToast({title:"\u56fe\u7247\u52a0\u8f7d\u5931\u8d25",icon:"none"})},n.src&&(o.src=n.src)}}},W=function(){if(k&&G.current&&K.current){var e=L.current,s=e.width,t=e.height;V(G.current,s,t,k,{brightness:E,hue:I,contrast:D})}};(0,o.useEffect)(function(){W()},[E,I,D]);var Z=function(){k&&x&&(O(!0),l().canvasToTempFilePath({canvas:K.current,quality:.92,success:function(e){var s,t=e.tempFilePath,n=(0,d.p_)(),a=n.findIndex(function(e){return e.id===x});if(-1!==a){var c=(null===(s=n[a].designData)||void 0===s?void 0:s.stickers)||[],r=c.findIndex(function(e){return e.id===w});-1!==r?(c[r]=(0,i.A)((0,i.A)({},c[r]),{},{src:t,edits:{brightness:E,hue:I,contrast:D}}),(0,d.i5)(x,{designData:(0,i.A)((0,i.A)({},n[a].designData),{},{stickers:c})}),l().showToast({title:"\u4fdd\u5b58\u6210\u529f",icon:"success"}),l().navigateBack()):O(!1)}else O(!1)},fail:function(){O(!1),l().showToast({title:"\u4fdd\u5b58\u5931\u8d25",icon:"none"})}}))},$=function(){k&&(l().cropImage?l().cropImage({src:k.src,cropScale:"1:1",success:function(e){var s=(0,i.A)((0,i.A)({},k),{},{src:e.tempFilePath});b(s),setTimeout(function(){return W()},200)}}):l().showToast({title:"\u5f53\u524d\u5fae\u4fe1\u7248\u672c\u4e0d\u652f\u6301\u88c1\u526a",icon:"none"}))},ee="https://your-api-domain.com",se=function(){k&&(O(!0),l().uploadFile({url:"".concat(ee,"/api/sketch"),filePath:k.src,name:"image",success:function(e){try{var s=JSON.parse(e.data);if(!s.url)throw new Error("no url");var t=(0,i.A)((0,i.A)({},k),{},{src:s.url,edits:(0,i.A)((0,i.A)({},k.edits),{},{sketchSrc:s.url})});b(t),setTimeout(function(){return W()},200),l().showToast({title:"\u7ebf\u7a3f\u751f\u6210\u6210\u529f",icon:"success"})}catch(e){te()}},fail:function(){te()}}))},te=function(){k&&G.current?(l().showToast({title:"\u4f7f\u7528\u672c\u5730\u7ebf\u7a3f",icon:"none"}),Y(20),F(80),R(0),O(!1)):O(!1)},ne="".concat((E+100)/200*100,"%"),ie="".concat((I+180)/360*100,"%"),ae="".concat((D+100)/200*100,"%");return(0,f.jsx)(c.Ss,{className:"theme-".concat(s),children:(0,f.jsxs)(c.Ss,{className:"sticker-edit-page",children:[(0,f.jsxs)(c.Ss,{className:"edit-header",style:{paddingTop:"".concat(t.headerPaddingTop,"px")},children:[(0,f.jsx)(c.EY,{className:"edit-back",onTap:function(){return l().navigateBack()},children:"\u2190"}),(0,f.jsx)(c.EY,{className:"edit-title",children:"\u7f16\u8f91\u8d34\u7eb8"}),(0,f.jsx)(c.EY,{className:"edit-save",onTap:Z,children:"\u4fdd\u5b58"})]}),(0,f.jsx)(c.Ss,{className:"edit-canvas-wrap",children:(0,f.jsx)(c.Hl,{id:"editCanvas",type:"2d",className:"edit-canvas",style:{width:"100%",height:"400px"}})}),(0,f.jsxs)(c.Ss,{className:"edit-tools dashed-card mt-20",children:[(0,f.jsxs)(c.Ss,{className:"edit-row",children:[(0,f.jsx)(c.EY,{className:"edit-label",children:"\u5feb\u901f\u64cd\u4f5c"}),(0,f.jsxs)(c.Ss,{className:"edit-quick-actions",children:[(0,f.jsx)(c.Ss,{className:"quick-btn",onTap:$,children:(0,f.jsx)(c.EY,{children:"\u88c1\u526a"})}),(0,f.jsx)(c.Ss,{className:"quick-btn",onTap:se,children:(0,f.jsx)(c.EY,{children:"\u8f6c\u7ebf\u7a3f"})})]})]}),(0,f.jsxs)(c.Ss,{className:"edit-row slider-row",onTouchMove:function(e){var s=e.changedTouches[0].clientX,t=l().createSelectorQuery().in(e.currentTarget);t.select(".slider-track").boundingClientRect(function(e){if(e){var t=m((s-e.left)/e.width,0,1),n=1*Math.round((200*t-100)/1);Y(m(n,-100,100))}}).exec()},children:[(0,f.jsx)(c.EY,{className:"edit-label",children:"\u4eae\u5ea6"}),(0,f.jsxs)(c.Ss,{className:"slider-wrap",children:[(0,f.jsxs)(c.Ss,{className:"slider-track",children:[(0,f.jsx)(c.Ss,{className:"slider-fill",style:{width:ne}}),(0,f.jsx)(c.Ss,{className:"slider-thumb",style:{left:ne}})]}),(0,f.jsx)(c.EY,{className:"slider-value",children:E>0?"+".concat(E):E})]})]}),(0,f.jsxs)(c.Ss,{className:"edit-row slider-row",onTouchMove:function(e){var s=e.changedTouches[0].clientX,t=l().createSelectorQuery().in(e.currentTarget);t.select(".slider-track").boundingClientRect(function(e){if(e){var t=m((s-e.left)/e.width,0,1),n=1*Math.round((360*t-180)/1);R(m(n,-180,180))}}).exec()},children:[(0,f.jsx)(c.EY,{className:"edit-label",children:"\u8272\u76f8"}),(0,f.jsxs)(c.Ss,{className:"slider-wrap",children:[(0,f.jsxs)(c.Ss,{className:"slider-track",children:[(0,f.jsx)(c.Ss,{className:"slider-fill",style:{width:ie}}),(0,f.jsx)(c.Ss,{className:"slider-thumb",style:{left:ie}})]}),(0,f.jsx)(c.EY,{className:"slider-value",children:I>0?"+".concat(I):I})]})]}),(0,f.jsxs)(c.Ss,{className:"edit-row slider-row",onTouchMove:function(e){var s=e.changedTouches[0].clientX,t=l().createSelectorQuery().in(e.currentTarget);t.select(".slider-track").boundingClientRect(function(e){if(e){var t=m((s-e.left)/e.width,0,1),n=1*Math.round((200*t-100)/1);F(m(n,-100,100))}}).exec()},children:[(0,f.jsx)(c.EY,{className:"edit-label",children:"\u5bf9\u6bd4\u5ea6"}),(0,f.jsxs)(c.Ss,{className:"slider-wrap",children:[(0,f.jsxs)(c.Ss,{className:"slider-track",children:[(0,f.jsx)(c.Ss,{className:"slider-fill",style:{width:ae}}),(0,f.jsx)(c.Ss,{className:"slider-thumb",style:{left:ae}})]}),(0,f.jsx)(c.EY,{className:"slider-value",children:D>0?"+".concat(D):D})]})]})]}),(0,f.jsx)(c.Ss,{style:{flex:1}}),J&&(0,f.jsx)(c.Ss,{className:"edit-loading",children:(0,f.jsx)(c.EY,{className:"edit-loading-text",children:"\u5904\u7406\u4e2d\u2026"})})]})})}var g={navigationStyle:"custom",navigationBarTitleText:"\u7f16\u8f91\u8d34\u7eb8"};Page((0,n.createPageConfig)(x,"pages/diy/stickerEdit/index",{root:{cn:[]}},g||{}))}},function(e){var s=function(s){return e(e.s=s)};e.O(0,[907,96,76],function(){return s(9519)});e.O()}]);