index-vq5DTpTl.js 6.5 KB

1
  1. var J=Object.defineProperty,K=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable;var k=(e,r,d)=>r in e?J(e,r,{enumerable:!0,configurable:!0,writable:!0,value:d}):e[r]=d,v=(e,r)=>{for(var d in r||(r={}))U.call(r,d)&&k(e,d,r[d]);if(C)for(var d of C(r))tt.call(r,d)&&k(e,d,r[d]);return e},F=(e,r)=>K(e,Q(r));import{e as V,aF as et,s as A,aY as X,bS as W,aC as Z}from"./entry/index-BaQQ7BQ_.js";import{d as H,r as Y,f as E,c as b,w as q,h as nt,u,k as h,ab as st}from"./vue-CF9JqwIh.js";import{a_ as at,aa as it}from"./antd-ILpsl5AZ.js";const{t:j}=V(),z={value:{type:Boolean,default:!1},isSlot:{type:Boolean,default:!1},text:{type:[String],default:j("component.verify.dragText")},successText:{type:[String],default:j("component.verify.successText")},height:{type:[Number,String],default:40},width:{type:[Number,String],default:220},circle:{type:Boolean,default:!1},wrapStyle:{type:Object,default:()=>({})},contentStyle:{type:Object,default:()=>({})},barStyle:{type:Object,default:()=>({})},actionStyle:{type:Object,default:()=>({})}},ot=F(v({},z),{src:{type:String},imgWidth:{type:Number,default:260},imgWrapStyle:{type:Object,default:()=>({})},minDegree:{type:Number,default:90},maxDegree:{type:Number,default:270},diffDegree:{type:Number,default:20}}),G=H({name:"BaseDargVerify",props:z,emits:["success","update:value","change","start","move","end"],setup(e,{emit:r,slots:d,expose:P}){const n=Y({isMoving:!1,isPassing:!1,moveDistance:0,toLeft:!1,startTime:0,endTime:0}),s=E(null),w=E(null),D=E(null),x=E(null);et({el:document,name:"mouseup",listener:()=>{n.isMoving&&y()}});const O=b(()=>{const{height:t,actionStyle:i}=e,c=`${parseInt(t)}px`;return v({left:0,width:c,height:c},i)}),N=b(()=>{const{height:t,width:i,circle:c,wrapStyle:a}=e,l=parseInt(t),m=`${parseInt(i)}px`;return v({width:m,height:`${l}px`,lineHeight:`${l}px`,borderRadius:c?l/2+"px":0},a)}),I=b(()=>{const{height:t,circle:i,barStyle:c}=e,a=parseInt(t);return v({height:`${a}px`,borderRadius:i?a/2+"px 0 0 "+a/2+"px":0},c)}),_=b(()=>{const{height:t,width:i,contentStyle:c}=e,a=`${parseInt(t)}px`,l=`${parseInt(i)}px`;return v({height:a,width:l},c)});q(()=>n.isPassing,t=>{if(t){const{startTime:i,endTime:c}=n,a=(c-i)/1e3;r("success",{isPassing:t,time:a.toFixed(1)}),r("update:value",t),r("change",t)}}),nt(()=>{n.isPassing=!!e.value});function R(t){return t.pageX||t.touches[0].pageX}function M(t){if(n.isPassing)return;const i=u(x);i&&(r("start",t),n.moveDistance=R(t)-parseInt(i.style.left.replace("px",""),10),n.startTime=new Date().getTime(),n.isMoving=!0)}function o(t){const i=parseInt(t.style.width),{width:c}=e,a=parseInt(c);return{offset:a-i-6,widthNum:a,actionWidth:i}}function f(t){const{isMoving:i,moveDistance:c}=n;if(i){const a=u(x),l=u(w);if(!a||!l)return;const{offset:m,widthNum:S,actionWidth:$}=o(a),p=R(t)-c;r("move",{event:t,moveDistance:c,moveX:p}),p>0&&p<=m?(a.style.left=`${p}px`,l.style.width=`${p+$/2}px`):p>m&&(a.style.left=`${S-$}px`,l.style.width=`${S-$/2}px`,e.isSlot||T())}}function g(t){const{isMoving:i,isPassing:c,moveDistance:a}=n;if(i&&!c){r("end",t);const l=u(x),m=u(w);if(!l||!m)return;const S=R(t)-a,{offset:$,widthNum:p,actionWidth:B}=o(l);S<$?e.isSlot?setTimeout(()=>{if(!e.value)y();else{const L=u(D);L&&(L.style.width=`${parseInt(m.style.width)}px`)}},0):y():(l.style.left=`${p-B}px`,m.style.width=`${p-B/2}px`,T()),n.isMoving=!1}}function T(){if(e.isSlot){y();return}n.endTime=new Date().getTime(),n.isPassing=!0,n.isMoving=!1}function y(){n.isMoving=!1,n.isPassing=!1,n.moveDistance=0,n.toLeft=!1,n.startTime=0,n.endTime=0;const t=u(x),i=u(w),c=u(D);!t||!i||!c||(n.toLeft=!0,A(()=>{n.toLeft=!1,t.style.left="0",i.style.width="0"},300),c.style.width=u(_).width)}return P({resume:y}),()=>{const t=()=>{const a=["darg-verify-bar"];return n.toLeft&&a.push("to-left"),h("div",{class:a,ref:w,style:u(I)},null)},i=()=>{const a=["darg-verify-content"],{isPassing:l}=n,{text:m,successText:S}=e;return l&&a.push("success"),h("div",{class:a,ref:D,style:u(_)},[X(d,"text",l)||(l?S:m)])},c=()=>{const a=["darg-verify-action"],{toLeft:l,isPassing:m}=n;return l&&a.push("to-left"),h("div",{class:a,onMousedown:M,onTouchstart:M,style:u(O),ref:x},[X(d,"actionIcon",m)||(m?h(at,{class:"darg-verify-action__icon"},null):h(it,{class:"darg-verify-action__icon"},null))])};return h("div",{class:"darg-verify",ref:s,style:u(N),onMousemove:f,onTouchmove:f,onMouseleave:g,onMouseup:g,onTouchend:g},[t(),i(),c()])}}}),rt=H({name:"ImgRotateDragVerify",inheritAttrs:!1,props:ot,emits:["success","change","update:value"],setup(e,{emit:r,attrs:d,expose:P}){const n=E(null),s=Y({showTip:!1,isPassing:!1,imgStyle:{},randomRotate:0,currentRotate:0,toOrigin:!1,startTime:0,endTime:0,draged:!1}),{t:w}=V();q(()=>s.isPassing,o=>{if(o){const{startTime:f,endTime:g}=s,T=(g-f)/1e3;r("success",{isPassing:o,time:T.toFixed(1)}),r("change",o),r("update:value",o)}});const D=b(()=>{const{imgWrapStyle:o,imgWidth:f}=e;return v({width:`${f}px`,height:`${f}px`},o)}),x=b(()=>{const{minDegree:o,maxDegree:f}=e;return o===f?Math.floor(1+Math.random()*1)/10+1:1});function O(){s.startTime=new Date().getTime()}function N(o){s.draged=!0;const{imgWidth:f,height:g,maxDegree:T}=e,{moveX:y}=o,t=Math.ceil(y/(f-parseInt(g))*T*u(x));s.currentRotate=t,s.imgStyle=W("transform",`rotateZ(${s.randomRotate-t}deg)`)}function I(){const{minDegree:o,maxDegree:f}=e,g=Math.floor(o+Math.random()*(f-o));s.randomRotate=g,s.imgStyle=W("transform",`rotateZ(${g}deg)`)}function _(){const{randomRotate:o,currentRotate:f}=s,{diffDegree:g}=e;Math.abs(o-f)>=(g||20)?(s.imgStyle=W("transform",`rotateZ(${o}deg)`),s.toOrigin=!0,A(()=>{s.toOrigin=!1,s.showTip=!0},300)):R(),s.showTip=!0}function R(){s.isPassing=!0,s.endTime=new Date().getTime()}function M(){s.showTip=!1;const o=u(n);o&&(s.isPassing=!1,o.resume(),I())}return P({resume:M}),()=>{const{src:o}=e,{toOrigin:f,isPassing:g,startTime:T,endTime:y}=s,t=[];f&&t.push("to-origin");const i=(y-T)/1e3;return h("div",{class:"ir-dv"},[h("div",{class:"ir-dv-img__wrap",style:u(D)},[h("img",{src:o,onLoad:I,width:parseInt(e.width),class:t,style:s.imgStyle,onClick:()=>{M()},alt:"verify"},null),s.showTip&&h("span",{class:["ir-dv-img__tip",s.isPassing?"success":"error"]},[s.isPassing?w("component.verify.time",{time:i.toFixed(1)}):w("component.verify.error")]),!s.showTip&&!s.draged&&h("span",{class:["ir-dv-img__tip","normal"]},[w("component.verify.redoTip")])]),h(G,st({class:"ir-dv-drag__bar",onMove:N,onEnd:_,onStart:O,ref:n},v(v({},d),e),{value:g,isSlot:!0}),null)])}}}),dt=Z(G),gt=Z(rt);export{dt as B,gt as R};