1 |
- "use strict";var _baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames2=_interopRequireDefault(require("../helpers/libs/classNames")),_warning=_interopRequireDefault(require("../helpers/libs/warning")),_styleToCssString=_interopRequireDefault(require("../helpers/libs/styleToCssString")),_useNativeAPI=require("../helpers/hooks/useNativeAPI"),_useDOM=require("../helpers/hooks/useDOM");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}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 ownKeys(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,e){var r;if(t)return"string"==typeof t?_arrayLikeToArray(t,e):"Map"===(r="Object"===(r=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(t,e):void 0}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function _iterableToArrayLimit(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,a,s=[],u=!0,c=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(s.push(n.value),s.length!==e);u=!0);}catch(t){c=!0,i=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw i}}return s}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,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 r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}var findActiveByIndex=function(e,r,t){return t.filter(function(t){return t.index===e&&t.name===r})[0]},findActiveByPosition=function(e,r,t){return t.filter(function(t){return e<t.top+t.height-r&&e>=t.top-r})[0]};(0,_baseComponent.default)({useExport:!0,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},indicatorPosition:{type:String,value:"center"},parentOffsetTop:{type:Number,value:0}},data:{colHight:0,points:[],scrollTop:0,children:[],moving:!1,current:0,currentName:"",currentBrief:"",extStyle:"",indicatorStyle:""},computed:{classes:["prefixCls, indicatorPosition",function(t,e){return{wrap:(0,_classNames2.default)(t),nav:"".concat(t,"__nav"),navRow:"".concat(t,"__nav-row"),navCol:"".concat(t,"__nav-col"),navItem:"".concat(t,"__nav-item"),indicator:(0,_classNames2.default)("".concat(t,"__indicator"),_defineProperty({},"".concat(t,"__indicator--").concat(e),e))}}]},methods:{updateStyle:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.data.height,t=(0,_styleToCssString.default)({height:t});t!==this.data.extStyle&&this.setData({extStyle:t})},updated:function(){var t=this.getRelationsByName("../index-item/index");0<t.length&&(t.forEach(function(t,e){t.updated(e)}),setTimeout(this.getNavPoints.bind(this))),this.updateChildren()},setActive:function(t,e){var r,n,i,o;t===this.data.current&&e===this.data.currentName||(n=void 0!==(r=findActiveByIndex(t,e,this.data.children))?r.brief:e.charAt(0),void 0!==r&&(i=(o=this.data).colHight,o="right"===o.indicatorPosition?(0,_styleToCssString.default)({top:t*i+i/2}):"",this.setData({current:t,currentName:e,currentBrief:n,scrollTop:r.top-this.data.parentOffsetTop,indicatorStyle:o})),(0,_useNativeAPI.vibrateShort)(),this.triggerEvent("change",{index:t,name:e,brief:n}))},onTouchStart:function(t){var e;this.data.moving||(e=(t=t.target.dataset).index,t=t.name,this.setActive(e,t),this.setData({moving:!0}))},onTouchMove:function(t){var e,t=this.getTargetFromPoint(t.changedTouches[0].pageY);void 0!==t&&(e=(t=t.dataset).index,t=t.name,this.setActive(e,t))},onTouchEnd:function(){var t=this;this.data.moving&&setTimeout(function(){return t.setData({moving:!1})},300)},onScroll:function(t){this.data.moving||this.checkActiveIndex.call(this,this.data,t)},getNavPoints:function(){var r=this,t=".".concat(this.data.prefixCls,"__nav-col"),e=".".concat(this.data.prefixCls,"__nav-item");(0,_useDOM.useRectAll)([t,e],this).then(function(t){var t=_slicedToArray(t,2),e=t[0],t=t[1];(e.length||t.length)&&r.setData({colHight:e[0].height,points:t.map(function(t){return _objectSpread(_objectSpread({},t),{},{offsets:[t.top,t.top+t.height]})})})})},getTargetFromPoint:function(t){for(var e,r=this.data.points,n=r.length-1;0<=n;n--){var i=_slicedToArray(r[n].offsets,2),o=i[0],i=i[1];if(n===r.length-1&&i<t||0===n&&t<o||o<=t&&t<=i){e=r[n];break}}return e},getInternalHooks:function(t){return"INDEX_HOOK_MARK"===t?{updateChildren:this.updateChildren.bind(this)}:((0,_warning.default)(!1,"`getInternalHooks` is internal usage of the <index />. Should not call directly."),null)},expose:function(){var r=this;return{scrollTo:function(e){var t=r.data.children,t=("number"==typeof e?t.filter(function(t){return t.index===e}):t.filter(function(t){return t.name===e}))[0];t&&(r.setData({moving:!0}),r.setActive(t.index,t.name),setTimeout(function(){return r.setData({moving:!1})},300))},getInternalHooks:this.getInternalHooks.bind(this)}}},created:function(){var i=this,t=this.useThrottleFn(function(t,e){var r,n,e=findActiveByPosition(e.detail.scrollTop,t.parentOffsetTop,t.children);void 0!==e&&(r=e.index,n=e.name,e=e.brief,r===t.current&&n===t.currentName||(i.setData({current:r,currentName:n,currentBrief:e}),i.triggerEvent("change",{index:r,name:n,brief:e})))},50,{trailing:!0,leading:!0}).run,t=(this.checkActiveIndex=t,this.useThrottleFn(function(){var t=i.getRelationsByName("../index-item/index").map(function(t){return{name:(t=t.data).name,index:t.index,top:t.top,height:t.height,brief:t.brief}});i.setData({children:t})},50,{trailing:!0,leading:!0}).run);this.updateChildren=t},ready:function(){this.updateStyle(),this.getNavPoints(),this.updateChildren()}});
|