index.js 5.2 KB

1
  1. "use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/libs/classNames")),_gestures=require("../helpers/shared/gestures");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function ownKeys(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _defineProperty(t,e,n){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"==_typeof(t)?t:String(t)}function _toPrimitive(t,e){if("object"!=_typeof(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);n=n.call(t,e||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}var defaults=_defineProperty(_defineProperty(_defineProperty(_defineProperty({prefixCls:"wux-gallery",classNames:"wux-animate--slideInRight",indicatorDots:!1,indicatorColor:"rgba(0, 0, 0, .3)",indicatorActiveColor:"#000000",autoplay:!1,interval:5e3,duration:500,circular:!1,vertical:!1,icon:"",showDelete:!0,allowScale:!0,current:0,urls:[]},"delete",function(){}),"cancel",function(){}),"onChange",function(){}),"onTap",function(){return!0}),MIN_RATIO=1,MAX_RATIO=1.2,defaultTouchOptions={scale:1,offset:[.5,3]},getImages=function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).map(function(t){return"object"!==_typeof(t)?{image:t,remark:"",touch:_objectSpread({},defaultTouchOptions)}:_objectSpread(_objectSpread({},t),{},{touch:_objectSpread({},defaultTouchOptions)})})};(0,_baseComponent.default)({useFunc:!0,data:defaults,computed:{classes:["prefixCls",function(t){return{swiper:"".concat(t,"__swiper"),item:"".concat(t,"__item"),img:"".concat(t,"__img"),remark:"".concat(t,"__remark"),opr:"".concat(t,"__opr"),del:"".concat(t,"__del"),icon:"".concat(t,"__icon")}}]},methods:{hide:function(){this.$$setData({in:!1}),"function"==typeof this.fns.cancel&&this.fns.cancel()},show:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=this.$$mergeOptionsAndBindMethods(Object.assign({},defaults,t,{images:getImages(t.urls)}));this.$$setData(_objectSpread({in:!0},t))},onTap:function(t){this.allowItemClick&&(t=t.currentTarget.dataset.index,!0===this.fns.onTap(t,this.data.urls))&&this.hide()},onTouchStart:function(t){if(this.allowItemClick=!0,!this.data.allowScale||1===(0,_gestures.getPointsNumber)(t)||this.touching)return!1;var e=(0,_gestures.getTouchPoints)(t),t=(0,_gestures.getTouchPoints)(t,1),e=(0,_gestures.getPointsDistance)(e,t);this.touching=!1,this.prevDistance=e,this.$$setData({transition:"none"})},onTouchMove:function(t){var e=this;if(!this.data.allowScale||1===(0,_gestures.getPointsNumber)(t)||this.isRendered)return!1;var n=(0,_gestures.getTouchPoints)(t),r=(0,_gestures.getTouchPoints)(t,1),n=(0,_gestures.getPointsDistance)(n,r),r=t.currentTarget.dataset,t=r.touch,r=r.index,i=n-this.prevDistance,i=t.scale+.005*i;if(r!==this.data.current)return!1;i<=t.offset[0]*MIN_RATIO?i=t.offset[0]*MIN_RATIO:i>=t.offset[1]*MAX_RATIO&&(i=t.offset[1]*MAX_RATIO);t=_defineProperty({},"images[".concat(r,"].touch.scale"),i);this.touching||(this.touching=!0),this.prevDistance=n,this.allowItemClick=!1,this.isRendered=!0,this.$$setData(t).then(function(){return e.isRendered=!1})},onTouchEnd:function(t){var e=this;if(!this.data.allowScale||!this.touching)return!1;var t=t.currentTarget.dataset,n=t.touch,t=t.index,r=n.scale,n=(r<=1?r=1:r>=n.offset[1]*MAX_RATIO&&(r=n.offset[1]),_defineProperty(_defineProperty({},"images[".concat(t,"].touch.scale"),r),"transition","transform .3s"));this.touching=!1,this.$$setData(n).then(function(){setTimeout(function(){return e.allowItemClick=!0},400)})},onDelete:function(t){"function"==typeof this.fns.delete&&!0===this.fns.delete(this.data.current,this.data.urls)&&this.hide()},onChange:function(t){this.$$setData({current:t.detail.current}),"function"==typeof this.fns.onChange&&this.fns.onChange.call(this,t)},slideTo:function(){var t=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,r=this.data,i=r.urls,r=r.circular,i=i.length-1;return e<0?e=r?i:0:i<e&&(e=r?0:i),0<n?this.$$requestAnimationFrame(function(){return t.$$setData({current:e})},n):this.$$setData({current:e})},slideNext:function(t){return this.slideTo(this.data.current+1,t)},slidePrev:function(t){return this.slideTo(this.data.current-1,t)}}});