You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
4.6 KiB
1 line
4.6 KiB
10 months ago
|
"use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/classNames")),_styleToCssString=_interopRequireDefault(require("../helpers/styleToCssString")),_checkIPhoneX=require("../helpers/checkIPhoneX");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(t,e){var n=[],r=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){i=!0,a=t}finally{try{r||null==s.return||s.return()}finally{if(i)throw a}}return n}function _arrayWithHoles(t){if(Array.isArray(t))return t}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(n,!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var findActiveByIndex=function(e,n,t){return t.filter(function(t){return t.index===e&&t.name===n})[0]},findActiveByPosition=function(e,n,t){return t.filter(function(t){return e<t.top+t.height-n&&e>=t.top-n})[0]};(0,_baseComponent.default)({relations:{"../index-item/index":{type:"child",observer:function(){this.callDebounceFn(this.updated)}}},properties:{prefixCls:{type:String,value:"wux-index"},height:{type:[String,Number],value:300,observer:"updateStyle"},showIndicator:{type:Boolean,value:!0},parentOffsetTop:{type:Number,value:0}},data:{scrollTop:0,sections:[],moving:!1,current:0,currentName:"",extStyle:""},computed:{classes:["prefixCls",function(t){return{wrap:(0,_classNames.default)(t),nav:"".concat(t,"__nav"),navRow:"".concat(t,"__nav-row"),navItem:"".concat(t,"__nav-item"),indicator:"".concat(t,"__indicator")}}]},methods:{updateStyle:function(t){var e=0<arguments.length&&void 0!==t?t:this.data.height,n=(0,_styleToCssString.default)({height:e});n!==this.data.extStyle&&this.setData({extStyle:n})},updated:function(){var t=this.getRelationNodes("../index-item/index");0<t.length&&(t.forEach(function(t,e){t.updated(e)}),setTimeout(this.getNavPoints.bind(this))),this.data.sections.length!==t.length&&this.setData({sections:t.map(function(t){return t.data})})},setActive:function(t,e){if(t!==this.data.current||e!==this.data.currentName){var n=findActiveByIndex(t,e,this.data.sections);void 0!==n&&this.setData({current:t,currentName:e,scrollTop:n.top-this.data.parentOffsetTop}),this.vibrateShort(),this.triggerEvent("change",{index:t,name:e})}},onTouchStart:function(t){if(!this.data.moving){var e=t.target.dataset,n=e.index,r=e.name;this.setActive(n,r),this.setData({moving:!0})}},onTouchMove:function(t){var e=this.getTargetFromPoint(t.changedTouches[0].pageY);if(void 0!==e){var n=e.dataset,r=n.index,i=n.name;this.setActive(r,i)}},onTouchEnd:function(t){var e=this;this.data.moving&&setTimeout(function(){return e.setData({moving:!1})},300)},onScroll:function(t){var a=this;if(!this.data.moving){if(!this.checkActiveIndex){var e=this.useThrottleFn(function(t,e){var n=findActiveByPosition(e.detail.scrollTop,t.parentOffsetTop,t.sections);if(void 0!==n){var r=n.index,i=n.name;r===t.current&&i===t.currentName||(a.setData({current:r,currentName:i}),a.triggerEvent("change",{index:r,name:i}))}},50,{trailing:!0,leading:!0}).run;this.checkActiveIndex=e}this.checkActiveIndex.call(this,this.data,t)}},getNavPoints:function(){var e=this,t=".".concat(this.data.pr
|