2 lines
4.1 KiB
JavaScript
2 lines
4.1 KiB
JavaScript
var e=Object.assign;import{u as t}from"./useTimeout.4ab89dd3.js";import{a as s,d as i,i as n,h as a,aV as o,aj as r,c as l,cz as u,j as c,g as d,bK as f}from"./index.8a947221.js";import{u as p}from"./useExpose.4645fd96.js";import{C as m}from"./CheckOutlined.af985792.js";import{D as g}from"./DoubleRightOutlined.9ab318aa.js";const{t:h}=s(),y={value:{type:Boolean,default:!1},isSlot:{type:Boolean,default:!1},text:{type:[String],default:h("component.verify.dragText")},successText:{type:[String],default:h("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:{}}},v=e(e({},y),{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}});var x=i({name:"BaseDargVerify",props:y,emits:["success","update:value","change","start","move","end"],setup(s,{emit:i,slots:h}){const y=n({isMoving:!1,isPassing:!1,moveDistance:0,toLeft:!1,startTime:0,endTime:0}),v=a(null),x=a(null),w=a(null),b=a(null);o((()=>y.isPassing),(e=>{if(e){const{startTime:t,endTime:s}=y;i("success",{isPassing:e,time:((s-t)/1e3).toFixed(1)}),i("update:value",e),i("change",e)}})),r((()=>{y.isPassing=!!s.value}));const S=l((()=>{const{height:t,actionStyle:i}=s,n=`${parseInt(t)}px`;return e({left:0,width:n,height:n},i)})),T=l((()=>{const{height:t,width:i,circle:n,wrapStyle:a}=s,o=parseInt(t),r=`${parseInt(i)}px`;return e({width:r,height:`${o}px`,lineHeight:`${o}px`,borderRadius:n?o/2+"px":0},a)})),D=l((()=>{const{height:t,circle:i,barStyle:n}=s,a=parseInt(t);return e({height:`${a}px`,borderRadius:i?a/2+"px 0 0 "+a/2+"px":0},n)})),j=l((()=>{const{height:t,width:i,contentStyle:n}=s,a=`${parseInt(t)}px`,o=`${parseInt(i)}px`;return e({height:a,width:o},n)}));function M(e){return e.pageX||e.touches[0].pageX}function I(e){if(y.isPassing)return;const t=c(b);t&&(i("start",e),y.moveDistance=M(e)-parseInt(t.style.left.replace("px",""),10),y.startTime=(new Date).getTime(),y.isMoving=!0)}function P(e){const t=parseInt(e.style.width),{width:i}=s,n=parseInt(i);return{offset:n-t-6,widthNum:n,actionWidth:t}}function $(e){const{isMoving:t,moveDistance:n}=y;if(t){const t=c(b),a=c(x);if(!t||!a)return;const{offset:o,widthNum:r,actionWidth:l}=P(t),u=M(e)-n;i("move",{event:e,moveDistance:n,moveX:u}),u>0&&u<=o?(t.style.left=`${u}px`,a.style.width=`${u+l/2}px`):u>o&&(t.style.left=r-l+"px",a.style.width=r-l/2+"px",s.isSlot||O())}}function N(e){const{isMoving:t,isPassing:n,moveDistance:a}=y;if(t&&!n){i("end",e);const t=c(b),n=c(x);if(!t||!n)return;const o=M(e)-a,{offset:r,widthNum:l,actionWidth:u}=P(t);o<r?s.isSlot?setTimeout((()=>{if(s.value){const e=c(w);e&&(e.style.width=`${parseInt(n.style.width)}px`)}else L()}),0):L():(t.style.left=l-u+"px",n.style.width=l-u/2+"px",O()),y.isMoving=!1}}function O(){s.isSlot?L():(y.endTime=(new Date).getTime(),y.isPassing=!0,y.isMoving=!1)}function L(){y.isMoving=!1,y.isPassing=!1,y.moveDistance=0,y.toLeft=!1,y.startTime=0,y.endTime=0;const e=c(b),s=c(x),i=c(w);e&&s&&i&&(y.toLeft=!0,t((()=>{y.toLeft=!1,e.style.left="0",s.style.width="0"}),300),i.style.width=c(j).width)}return u({el:document,name:"mouseup",listener:()=>{y.isMoving&&L()}}),p({resume:L}),()=>d("div",{class:"darg-verify",ref:v,style:c(T),onMousemove:$,onTouchmove:$,onMouseleave:N,onMouseup:N,onTouchend:N},[(()=>{const e=["darg-verify-bar"];return y.toLeft&&e.push("to-left"),d("div",{class:e,ref:x,style:c(D)},null)})(),(()=>{const e=["darg-verify-content"],{isPassing:t}=y,{text:i,successText:n}=s;return t&&e.push("success"),d("div",{class:e,ref:w,style:c(j)},[f(h,"text",t)||(t?n:i)])})(),(()=>{const e=["darg-verify-action"],{toLeft:t,isPassing:s}=y;return t&&e.push("to-left"),d("div",{class:e,onMousedown:I,onTouchstart:I,style:c(S),ref:b},[f(h,"actionIcon",s)||d(s?m:g,{class:"darg-verify-action__icon"},null)])})()])}}),w=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:x});export{x as B,w as D,v as r};
|