u-tabs-swiper.js 6.4 KB

12345678910
  1. (global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["uview-ui/components/u-tabs-swiper/u-tabs-swiper"],{"02c4":function(t,e,n){"use strict";n.r(e);var i=n("aa7e"),r=n("6c32");for(var o in r)"default"!==o&&function(t){n.d(e,t,(function(){return r[t]}))}(o);n("5bcc");var a,u=n("f0c5"),s=Object(u["a"])(r["default"],i["b"],i["c"],!1,null,"60797506",null,!1,i["a"],a);e["default"]=s.exports},"5bcc":function(t,e,n){"use strict";var i=n("eda2"),r=n.n(i);r.a},"6c32":function(t,e,n){"use strict";n.r(e);var i=n("d56b"),r=n.n(i);for(var o in i)"default"!==o&&function(t){n.d(e,t,(function(){return i[t]}))}(o);e["default"]=r.a},aa7e:function(t,e,n){"use strict";var i;n.d(e,"b",(function(){return r})),n.d(e,"c",(function(){return o})),n.d(e,"a",(function(){return i}));var r=function(){var t=this,e=t.$createElement,n=(t._self._c,t.__map(t.getTabs,(function(e,n){var i=t.__get_orig(e),r=t.__get_style([t.tabItemStyle(n)]);return{$orig:i,s0:r}}))),i=t.showBar?t.__get_style([t.tabBarStyle]):null;t.$mp.data=Object.assign({},{$root:{l0:n,s1:i}})},o=[]},d56b:function(t,e,n){"use strict";(function(t){Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var i=o(n("a34a")),r=o(n("acd7"));function o(t){return t&&t.__esModule?t:{default:t}}function a(t,e,n,i,r,o,a){try{var u=t[o](a),s=u.value}catch(c){return void n(c)}u.done?e(s):Promise.resolve(s).then(i,r)}function u(t){return function(){var e=this,n=arguments;return new Promise((function(i,r){var o=t.apply(e,n);function u(t){a(o,i,r,u,s,"next",t)}function s(t){a(o,i,r,u,s,"throw",t)}u(void 0)}))}}var s=r.default,c=t.getSystemInfoSync(),l=c.windowWidth,f="UEl_",h={name:"u-tabs-swiper",props:{isScroll:{type:Boolean,default:!0},list:{type:Array,default:function(){return[]}},current:{type:[Number,String],default:0},height:{type:[Number,String],default:80},fontSize:{type:[Number,String],default:30},swiperWidth:{type:[String,Number],default:750},activeColor:{type:String,default:"#2979ff"},inactiveColor:{type:String,default:"#303133"},barWidth:{type:[Number,String],default:40},barHeight:{type:[Number,String],default:6},gutter:{type:[Number,String],default:40},zIndex:{type:[Number,String],default:1},bgColor:{type:String,default:"#ffffff"},autoCenterMode:{type:String,default:"window"},name:{type:String,default:"name"},bold:{type:Boolean,default:!0},activeItemStyle:{type:Object,default:function(){return{}}},showBar:{type:Boolean,default:!0},barStyle:{type:Object,default:function(){return{}}}},data:function(){return{scrollLeft:0,tabQueryInfo:[],windowWidth:0,animationFinishCurrent:this.current,componentsWidth:0,line3AddDx:0,line3Dx:0,preId:f,sW:0,tabsInfo:[],colorGradientArr:[],colorStep:100}},computed:{getCurrent:function(){var t=Number(this.current);return t>this.getTabs.length-1?this.getTabs.length-1:t<0?0:t},getTabs:function(){return this.list},scrollBarLeft:function(){return Number(this.line3Dx)+Number(this.line3AddDx)},barWidthPx:function(){return t.upx2px(this.barWidth)},tabItemStyle:function(){var t=this;return function(e){var n={height:t.height+"rpx",lineHeight:t.height+"rpx",padding:"0 ".concat(t.gutter/2,"rpx"),color:t.tabsInfo.length>0?t.tabsInfo[e]?t.tabsInfo[e].color:t.activeColor:t.inactiveColor,fontSize:t.fontSize+"rpx",zIndex:t.zIndex+2,fontWeight:e==t.getCurrent&&t.bold?"bold":"normal"};return e==t.getCurrent&&(n=Object.assign(n,t.activeItemStyle)),n}},tabBarStyle:function(){var t={width:this.barWidthPx+"px",height:this.barHeight+"rpx",borderRadius:"100px",backgroundColor:this.activeColor,left:this.scrollBarLeft+"px"};return Object.assign(t,this.barStyle)}},watch:{current:function(t,e){this.change(t),this.setFinishCurrent(t)},list:function(){var t=this;this.$nextTick((function(){t.init()}))}},mounted:function(){this.init()},methods:{init:function(){var t=this;return u(i.default.mark((function e(){return i.default.wrap((function(e){while(1)switch(e.prev=e.next){case 0:return t.countPx(),e.next=3,t.getTabsInfo();case 3:t.countLine3Dx(),t.getQuery((function(){t.setScrollViewToCenter()})),t.colorGradientArr=s.colorGradient(t.inactiveColor,t.activeColor,t.colorStep);case 6:case"end":return e.stop()}}),e)})))()},getTabsInfo:function(){var e=this;return new Promise((function(n,i){for(var r=t.createSelectorQuery().in(e),o=0;o<e.list.length;o++)r.select("."+f+o).boundingClientRect();r.exec((function(t){for(var i=[],r=0;r<t.length;r++)t[r].color=e.inactiveColor,r==e.getCurrent&&(t[r].color=e.activeColor),i.push(t[r]);e.tabsInfo=i,n()}))}))},countLine3Dx:function(){var t=this.tabsInfo[this.animationFinishCurrent];t&&(this.line3Dx=t.left+t.width/2-this.barWidthPx/2-this.tabsInfo[0].left)},countPx:function(){this.sW=t.upx2px(Number(this.swiperWidth))},emit:function(t){this.$emit("change",t)},change:function(){this.setScrollViewToCenter()},getQuery:function(e){var n=this;try{var i=t.createSelectorQuery().in(this).select(".u-tabs");i.fields({size:!0},(function(t){t?(n.componentsWidth=t.width,e&&"function"===typeof e&&e(t)):n.getQuery(e)})).exec()}catch(r){this.componentsWidth=l}},setScrollViewToCenter:function(){var t;if(t=this.tabsInfo[this.animationFinishCurrent],t){var e,n=t.left+t.width/2;e="window"===this.autoCenterMode?l:this.componentsWidth,this.scrollLeft=n-e/2}},setDx:function(t){var e=t>0?this.animationFinishCurrent+1:this.animationFinishCurrent-1;e=e<=0?0:e,e=e>=this.list.length?this.list.length-1:e;this.tabsInfo[e];var n=this.tabsInfo[this.animationFinishCurrent],i=n.left+n.width/2,r=this.tabsInfo[e],o=r.left+r.width/2,a=Math.abs(o-i);this.line3AddDx=t/this.sW*a,this.setTabColor(this.animationFinishCurrent,e,t)},setTabColor:function(t,e,n){var i=Math.abs(Math.ceil(n/this.sW*100)),r=this.colorGradientArr.length;i=i>=r?r-1:i<=0?0:i,this.tabsInfo[e].color=this.colorGradientArr[i],this.tabsInfo[t].color=this.colorGradientArr[r-1-i]},setFinishCurrent:function(t){var e=this;this.tabsInfo.map((function(n,i){return n.color=t==i?e.activeColor:e.inactiveColor,n})),this.line3AddDx=0,this.animationFinishCurrent=t,this.countLine3Dx()}}};e.default=h}).call(this,n("543d")["default"])},eda2:function(t,e,n){}}]);
  2. ;(global["webpackJsonp"] = global["webpackJsonp"] || []).push([
  3. 'uview-ui/components/u-tabs-swiper/u-tabs-swiper-create-component',
  4. {
  5. 'uview-ui/components/u-tabs-swiper/u-tabs-swiper-create-component':(function(module, exports, __webpack_require__){
  6. __webpack_require__('543d')['createComponent'](__webpack_require__("02c4"))
  7. })
  8. },
  9. [['uview-ui/components/u-tabs-swiper/u-tabs-swiper-create-component']]
  10. ]);