uni-swipe-action.33021097.js
9.91 KB
import{o as t,c as e,w as o,b as n,W as s,j as i,F as a,k as r,J as h,K as l,d as c,t as u,q as d,i as p}from"./index-faed4152.js";import{_ as f}from"./_plugin-vue_export-helper.1b428a4d.js";let g={},m=null;m=function(){var t=navigator.userAgent,e=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"],o=!0;for(let n=0;n<e.length-1;n++)if(t.indexOf(e[n])>0){o=!1;break}return o}(),g={data:()=>({is_show:"none"}),watch:{show(t){this.is_show=this.show}},created(){this.swipeaction=this.getSwipeAction(),void 0!==this.swipeaction.children&&this.swipeaction.children.push(this)},mounted(){this.is_show=this.show},methods:{closeSwipe(t){this.autoClose&&this.swipeaction.closeOther(this)},change(t){this.$emit("change",t.open),this.is_show!==t.open&&(this.is_show=t.open)},appTouchStart(t){if(m)return;const{clientX:e}=t.changedTouches[0];this.clientX=e,this.timestamp=(new Date).getTime()},appTouchEnd(t,e,o,n){if(m)return;const{clientX:s}=t.changedTouches[0];let i=Math.abs(this.clientX-s),a=(new Date).getTime()-this.timestamp;i<40&&a<300&&this.$emit("click",{content:o,index:e,position:n})},onClickForPC(t,e,o){m&&this.$emit("click",{content:e,index:t,position:o})}}};var w=!1;function v(t,e){var o=t.instance,n=o.getDataset().disabled,s=o.getState();x(o,e),(n=("string"==typeof n?JSON.parse(n):n)||!1)||(o.requestAnimationFrame((function(){o.removeClass("ani"),e.callMethod("closeSwipe")})),s.x=s.left||0,function(t){var e=t.instance,o=e.getState();C(e);var n=t.touches[0];w&&_()&&(n=t);o.startX=n.clientX,o.startY=n.clientY}(t))}function b(t,e){var o=t.instance,n=o.getDataset().disabled,s=o.getState();(n=("string"==typeof n?JSON.parse(n):n)||!1)||(!function(t){var e=t.instance.getState(),o=t.touches[0];w&&_()&&(o=t);e.deltaX=o.clientX-e.startX,e.deltaY=o.clientY-e.startY,e.offsetY=Math.abs(e.deltaY),e.offsetX=Math.abs(e.deltaX),e.direction=e.direction||function(t,e){if(t>e&&t>10)return"horizontal";if(e>t&&e>10)return"vertical";return""}(e.offsetX,e.offsetY)}(t),"horizontal"===s.direction&&(t.preventDefault&&t.preventDefault(),y(s.x+s.deltaX,o)))}function S(t,e){var o=t.instance,n=o.getDataset().disabled,s=o.getState();(n=("string"==typeof n?JSON.parse(n):n)||!1)||function(t,e,o){var n=e.getState(),s=n.threshold;n.position;var i=n.isopen||"none",a=n.leftWidth,r=n.rightWidth;if(0===n.deltaX)return void T("none",e,o);T("none"===i&&r>0&&-t>s||"none"!==i&&r>0&&r+t<s?"right":"none"===i&&a>0&&t>s||"none"!==i&&a>0&&a-t<s?"left":"none",e,o)}(s.left,o,e)}function y(t,e,o){t=t||0;var n,s,i,a=e.getState(),r=a.leftWidth,h=a.rightWidth;a.left=(n=t,s=-h,i=r,Math.min(Math.max(n,s),i)),e.requestAnimationFrame((function(){e.setStyle({transform:"translateX("+a.left+"px)","-webkit-transform":"translateX("+a.left+"px)"})}))}function x(t,e){var o,n,s=t.getState(),i=e.selectComponent(".button-group--left"),a=e.selectComponent(".button-group--right");o=i.getBoundingClientRect(),n=a.getBoundingClientRect(),s.leftWidth=o.width||0,s.rightWidth=n.width||0,s.threshold=t.getDataset().threshold}function T(t,e,o){var n=e.getState(),s=n.leftWidth,i=n.rightWidth,a="";switch(n.isopen=n.isopen?n.isopen:"none",t){case"left":a=s;break;case"right":a=-i;break;default:a=0}n.isopen!==t&&(n.throttle=!0,o.callMethod("change",{open:t})),n.isopen=t,e.requestAnimationFrame((function(){e.addClass("ani"),y(a,e)}))}function C(t){var e=t.getState();e.direction="",e.deltaX=0,e.deltaY=0,e.offsetX=0,e.offsetY=0}function _(){for(var t=navigator.userAgent,e=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"],o=!0,n=0;n<e.length-1;n++)if(t.indexOf(e[n])>0){o=!1;break}return o}"object"==typeof window&&(w=!0);var X=!1;const k={showWatch:function(t,e,o,n){var s=n.getState();x(n,o),t&&"none"!==t?T(t,n,o):(s.left&&T("none",n,o),C(n))},touchstart:v,touchmove:b,touchend:S,mousedown:function(t,e){w&&_()&&(v(t,e),X=!0)},mousemove:function(t,e){w&&_()&&X&&b(t)},mouseup:function(t,e){w&&_()&&(S(t,e),X=!1)},mouseleave:function(t,e){w&&_()&&(X=!1)}},D=t=>{t.$wxs||(t.$wxs=[]),t.$wxs.push("wxsswipe"),t.mixins||(t.mixins=[]),t.mixins.push({beforeCreate(){this.wxsswipe=k}})},$={showWatch(t,e,o,n,s){var i=s.state;(o.$el||o.$vm&&o.$vm.$el)&&(this.getDom(n,o,s),t&&"none"!==t?this.openState(t,n,o,s):(i.left&&this.openState("none",n,o,s),this.resetTouchStatus(n,s)))},touchstart(t,e,o){let n=t.instance,s=n.getDataset().disabled,i=o.state;this.getDom(n,e,o),s=this.getDisabledType(s),s||(n.requestAnimationFrame((function(){n.removeClass("ani"),e.callMethod("closeSwipe")})),i.x=i.left||0,this.stopTouchStart(t,e,o))},touchmove(t,e,o){let n=t.instance;if(!n)return;let s=n.getDataset().disabled,i=o.state;if(s=this.getDisabledType(s),s)return;if(this.stopTouchMove(t,o),"horizontal"!==i.direction)return;t.preventDefault&&t.preventDefault();let a=i.x+i.deltaX;this.move(a,n,e,o)},touchend(t,e,o){let n=t.instance,s=n.getDataset().disabled,i=o.state;s=this.getDisabledType(s),s||this.moveDirection(i.left,n,e,o)},move(t,e,o,n){t=t||0;let s=n.state,i=s.leftWidth,a=s.rightWidth;s.left=this.range(t,-a,i),e.requestAnimationFrame((function(){e.setStyle({transform:"translateX("+s.left+"px)","-webkit-transform":"translateX("+s.left+"px)"})}))},getDom(t,e,o){var n=o.state,s=e.$el||e.$vm&&e.$vm.$el,i=s.querySelector(".button-group--left"),a=s.querySelector(".button-group--right");n.leftWidth=i.offsetWidth||0,n.rightWidth=a.offsetWidth||0,n.threshold=t.getDataset().threshold},getDisabledType:t=>("string"==typeof t?JSON.parse(t):t)||!1,range:(t,e,o)=>Math.min(Math.max(t,e),o),moveDirection(t,e,o,n){var s=n.state,i=s.threshold;s.position;var a=s.isopen||"none",r=s.leftWidth,h=s.rightWidth;0!==s.deltaX?"none"===a&&h>0&&-t>i||"none"!==a&&h>0&&h+t<i?this.openState("right",e,o,n):"none"===a&&r>0&&t>i||"none"!==a&&r>0&&r-t<i?this.openState("left",e,o,n):this.openState("none",e,o,n):this.openState("none",e,o,n)},openState(t,e,o,n){let s=n.state,i=s.leftWidth,a=s.rightWidth,r="";switch(s.isopen=s.isopen?s.isopen:"none",t){case"left":r=i;break;case"right":r=-a;break;default:r=0}s.isopen!==t&&(s.throttle=!0,o.callMethod("change",{open:t})),s.isopen=t,e.requestAnimationFrame((()=>{e.addClass("ani"),this.move(r,e,o,n)}))},getDirection:(t,e)=>t>e&&t>10?"horizontal":e>t&&e>10?"vertical":"",resetTouchStatus(t,e){let o=e.state;o.direction="",o.deltaX=0,o.deltaY=0,o.offsetX=0,o.offsetY=0},stopTouchStart(t,e,o){let n=t.instance,s=o.state;this.resetTouchStatus(n,o);var i=t.touches[0];s.startX=i.clientX,s.startY=i.clientY},stopTouchMove(t,e){t.instance;let o=e.state,n=t.touches[0];o.deltaX=n.clientX-o.startX,o.deltaY=n.clientY-o.startY,o.offsetY=Math.abs(o.deltaY),o.offsetX=Math.abs(o.deltaX),o.direction=o.direction||this.getDirection(o.offsetX,o.offsetY)}},W={mounted(t,e,o){this.state={}},methods:{showWatch(t,e,o,n){$.showWatch(t,e,o,n,this)},touchstart(t,e){$.touchstart(t,e,this)},touchmove(t,e){$.touchmove(t,e,this)},touchend(t,e){$.touchend(t,e,this)}}},F=t=>{t.$renderjs||(t.$renderjs=[]),t.$renderjs.push("renderswipe"),t.mixins||(t.mixins=[]),t.mixins.push({beforeCreate(){this.renderswipe=this},mounted(){this.$ownerInstance=this.$gcd(this,!0)}}),t.mixins.push(W)},Y={mixins:[g,{},{}],emits:["click","change"],props:{show:{type:String,default:"none"},disabled:{type:Boolean,default:!1},autoClose:{type:Boolean,default:!0},threshold:{type:Number,default:20},leftOptions:{type:Array,default:()=>[]},rightOptions:{type:Array,default:()=>[]}},unmounted(){this.__isUnmounted=!0,this.uninstall()},methods:{uninstall(){this.swipeaction&&this.swipeaction.children.forEach(((t,e)=>{t===this&&this.swipeaction.children.splice(e,1)}))},getSwipeAction(t="uniSwipeAction"){let e=this.$parent,o=e.$options.name;for(;o!==t;){if(e=e.$parent,!e)return!1;o=e.$options.name}return e}}};D(Y),F(Y);const A=f(Y,[["render",function(f,g,m,w,v,b){const S=d,y=p;return t(),e(y,{class:"uni-swipe"},{default:o((()=>[n(y,{class:"uni-swipe_box","change:prop":f.wxsswipe.showWatch,prop:f.is_show,"data-threshold":m.threshold,"data-disabled":m.disabled,onTouchstart:f.wxsswipe.touchstart,onTouchmove:f.wxsswipe.touchmove,onTouchend:f.wxsswipe.touchend},{default:o((()=>[n(y,{class:"uni-swipe_button-group button-group--left"},{default:o((()=>[s(f.$slots,"left",{},(()=>[(t(!0),i(a,null,r(m.leftOptions,((s,i)=>(t(),e(y,{key:i,style:h({backgroundColor:s.style&&s.style.backgroundColor?s.style.backgroundColor:"#C7C6CD"}),class:"uni-swipe_button button-hock",onTouchstart:f.appTouchStart,onTouchend:t=>f.appTouchEnd(t,i,s,"left"),onClick:l((t=>f.onClickForPC(i,s,"left")),["stop"])},{default:o((()=>[n(S,{class:"uni-swipe_button-text",style:h({color:s.style&&s.style.color?s.style.color:"#FFFFFF",fontSize:s.style&&s.style.fontSize?s.style.fontSize:"16px"})},{default:o((()=>[c(u(s.text),1)])),_:2},1032,["style"])])),_:2},1032,["style","onTouchstart","onTouchend","onClick"])))),128))]),!0)])),_:3}),n(y,{class:"uni-swipe_text--center"},{default:o((()=>[s(f.$slots,"default",{},void 0,!0)])),_:3}),n(y,{class:"uni-swipe_button-group button-group--right"},{default:o((()=>[s(f.$slots,"right",{},(()=>[(t(!0),i(a,null,r(m.rightOptions,((s,i)=>(t(),e(y,{key:i,style:h({backgroundColor:s.style&&s.style.backgroundColor?s.style.backgroundColor:"#C7C6CD"}),class:"uni-swipe_button button-hock",onTouchstart:f.appTouchStart,onTouchend:t=>f.appTouchEnd(t,i,s,"right"),onClick:l((t=>f.onClickForPC(i,s,"right")),["stop"])},{default:o((()=>[n(S,{class:"uni-swipe_button-text",style:h({color:s.style&&s.style.color?s.style.color:"#FFFFFF",fontSize:s.style&&s.style.fontSize?s.style.fontSize:"16px"})},{default:o((()=>[c(u(s.text),1)])),_:2},1032,["style"])])),_:2},1032,["style","onTouchstart","onTouchend","onClick"])))),128))]),!0)])),_:3})])),_:3},8,["change:prop","prop","data-threshold","data-disabled","onTouchstart","onTouchmove","onTouchend"])])),_:3})}],["__scopeId","data-v-ae2d0852"]]);const M=f({name:"uniSwipeAction",data:()=>({}),created(){this.children=[]},methods:{resize(){},closeAll(){this.children.forEach((t=>{t.is_show="none"}))},closeOther(t){this.openItem&&this.openItem!==t&&(this.openItem.is_show="none"),this.openItem=t}}},[["render",function(n,i,a,r,h,l){const c=p;return t(),e(c,null,{default:o((()=>[s(n.$slots,"default")])),_:3})}]]);export{A as _,M as a};