u-tabs.634de75c.js 7.0 KB
import{d as e,m as t,a as s,o as a,c as i,w as r,g as l,t as n,j as o,n as d,h as u,k as b,r as h,b as c,f as p,i as g,e as _,F as f,y as m,v as y,S as w}from"./index-7c219b35.js";import{_ as v}from"./_plugin-vue_export-helper.1b428a4d.js";const S=v({name:"u-badge",mixins:[t,{props:{isDot:{type:Boolean,default:e.badge.isDot},value:{type:[Number,String],default:e.badge.value},modelValue:{type:[Number,String],default:e.badge.modelValue},show:{type:Boolean,default:e.badge.show},max:{type:[Number,String],default:e.badge.max},type:{type:String,default:e.badge.type},showZero:{type:Boolean,default:e.badge.showZero},bgColor:{type:[String,null],default:e.badge.bgColor},color:{type:[String,null],default:e.badge.color},shape:{type:String,default:e.badge.shape},numberType:{type:String,default:e.badge.numberType},offset:{type:Array,default:e.badge.offset},inverted:{type:Boolean,default:e.badge.inverted},absolute:{type:Boolean,default:e.badge.absolute}}},s],computed:{boxStyle:()=>({}),badgeStyle(){const e={};if(this.color&&(e.color=this.color),this.bgColor&&!this.inverted&&(e.backgroundColor=this.bgColor),this.absolute&&(e.position="absolute",this.offset.length)){const t=this.offset[0],s=this.offset[1]||t;e.top=uni.$u.addUnit(t),e.right=uni.$u.addUnit(s)}return e},showValue(){switch(this.numberType){case"overflow":return Number(this.value)>Number(this.max)?this.max+"+":this.value;case"ellipsis":return Number(this.value)>Number(this.max)?"...":this.value;case"limit":return Number(this.value)>999?Number(this.value)>=9999?Math.floor(this.value/1e4*100)/100+"w":Math.floor(this.value/1e3*100)/100+"k":this.value;default:return Number(this.value)}}}},[["render",function(e,t,s,h,c,p){const g=b;return e.show&&(0!==Number(e.value)||e.showZero||e.isDot)?(a(),i(g,{key:0,class:o([[e.isDot?"u-badge--dot":"u-badge--not-dot",e.inverted&&"u-badge--inverted","horn"===e.shape&&"u-badge--horn",`u-badge--${e.type}${e.inverted?"--inverted":""}`],"u-badge"]),style:d([e.$u.addStyle(e.customStyle),p.badgeStyle])},{default:r((()=>[l(n(e.isDot?"":p.showValue),1)])),_:1},8,["class","style"])):u("",!0)}],["__scopeId","data-v-ca2c7ba1"]]);const x=v({name:"u-tabs",mixins:[t,s,{props:{duration:{type:Number,default:e.tabs.duration},list:{type:Array,default:e.tabs.list},lineColor:{type:String,default:e.tabs.lineColor},activeStyle:{type:[String,Object],default:e.tabs.activeStyle},inactiveStyle:{type:[String,Object],default:e.tabs.inactiveStyle},lineWidth:{type:[String,Number],default:e.tabs.lineWidth},lineHeight:{type:[String,Number],default:e.tabs.lineHeight},lineBgSize:{type:String,default:e.tabs.lineBgSize},itemStyle:{type:[String,Object],default:e.tabs.itemStyle},scrollable:{type:Boolean,default:e.tabs.scrollable},current:{type:[Number,String],default:e.tabs.current},keyName:{type:String,default:e.tabs.keyName}}}],data:()=>({firstTime:!0,scrollLeft:0,scrollViewWidth:0,lineOffsetLeft:0,tabsRect:{left:0},innerCurrent:0,moving:!1}),watch:{current:{immediate:!0,handler(e,t){e!==this.innerCurrent&&(this.innerCurrent=e,this.$nextTick((()=>{this.resize()})))}},list(){this.$nextTick((()=>{this.resize()}))}},computed:{textStyle(){return e=>{const t={},s=e===this.innerCurrent?uni.$u.addStyle(this.activeStyle):uni.$u.addStyle(this.inactiveStyle);return this.list[e].disabled&&(t.color="#c8c9cc"),uni.$u.deepMerge(s,t)}},propsBadge:()=>uni.$u.props.badge},async mounted(){this.init()},emits:["click","change"],methods:{setLineLeft(){const e=this.list[this.innerCurrent];if(!e)return;let t=this.list.slice(0,this.innerCurrent).reduce(((e,t)=>e+t.rect.width),0);const s=uni.$u.getPx(this.lineWidth);this.lineOffsetLeft=t+(e.rect.width-s)/2,this.firstTime&&setTimeout((()=>{this.firstTime=!1}),10)},animation(e,t=0){},clickHandler(e,t){this.$emit("click",{...e,index:t}),e.disabled||(this.innerCurrent=t,this.resize(),this.$emit("change",{...e,index:t}))},init(){uni.$u.sleep().then((()=>{this.resize()}))},setScrollLeft(){const e=this.list[this.innerCurrent],t=this.list.slice(0,this.innerCurrent).reduce(((e,t)=>e+t.rect.width),0),s=uni.$u.sys().windowWidth;let a=t-(this.tabsRect.width-e.rect.width)/2-(s-this.tabsRect.right)/2+this.tabsRect.left/2;a=Math.min(a,this.scrollViewWidth-this.tabsRect.width),this.scrollLeft=Math.max(0,a)},resize(){0!==this.list.length&&Promise.all([this.getTabsRect(),this.getAllItemRect()]).then((([e,t=[]])=>{this.tabsRect=e,this.scrollViewWidth=0,t.map(((e,t)=>{this.scrollViewWidth+=e.width,this.list[t].rect=e})),this.setLineLeft(),this.setScrollLeft()}))},getTabsRect(){return new Promise((e=>{this.queryRect("u-tabs__wrapper__scroll-view").then((t=>e(t)))}))},getAllItemRect(){return new Promise((e=>{const t=this.list.map(((e,t)=>this.queryRect(`u-tabs__wrapper__nav__item-${t}`,!0)));Promise.all(t).then((t=>e(t)))}))},queryRect(e,t){return new Promise((t=>{this.$uGetRect(`.${e}`).then((e=>{t(e)}))}))}}},[["render",function(e,t,s,u,v,x){const $=b,C=h(c("u-badge"),S),B=y,k=w;return a(),i(B,{class:"u-tabs"},{default:r((()=>[p(B,{class:"u-tabs__wrapper"},{default:r((()=>[g(e.$slots,"left",{},void 0,!0),p(B,{class:"u-tabs__wrapper__scroll-view-wrapper"},{default:r((()=>[p(k,{"scroll-x":e.scrollable,"scroll-left":v.scrollLeft,"scroll-with-animation":"",class:"u-tabs__wrapper__scroll-view","show-scrollbar":!1,ref:"u-tabs__wrapper__scroll-view"},{default:r((()=>[p(B,{class:"u-tabs__wrapper__nav",ref:"u-tabs__wrapper__nav"},{default:r((()=>[(a(!0),_(f,null,m(e.list,((t,s)=>(a(),i(B,{class:o(["u-tabs__wrapper__nav__item",[`u-tabs__wrapper__nav__item-${s}`,t.disabled&&"u-tabs__wrapper__nav__item--disabled"]]),key:s,onClick:e=>x.clickHandler(t,s),ref_for:!0,ref:`u-tabs__wrapper__nav__item-${s}`,style:d([e.$u.addStyle(e.itemStyle),{flex:e.scrollable?"":1}])},{default:r((()=>[p($,{class:o([[t.disabled&&"u-tabs__wrapper__nav__item__text--disabled"],"u-tabs__wrapper__nav__item__text"]),style:d([x.textStyle(s)])},{default:r((()=>[l(n(t[e.keyName]),1)])),_:2},1032,["class","style"]),p(C,{show:!(!t.badge||!(t.badge.show||t.badge.isDot||t.badge.value)),isDot:t.badge&&t.badge.isDot||x.propsBadge.isDot,value:t.badge&&t.badge.value||x.propsBadge.value,max:t.badge&&t.badge.max||x.propsBadge.max,type:t.badge&&t.badge.type||x.propsBadge.type,showZero:t.badge&&t.badge.showZero||x.propsBadge.showZero,bgColor:t.badge&&t.badge.bgColor||x.propsBadge.bgColor,color:t.badge&&t.badge.color||x.propsBadge.color,shape:t.badge&&t.badge.shape||x.propsBadge.shape,numberType:t.badge&&t.badge.numberType||x.propsBadge.numberType,inverted:t.badge&&t.badge.inverted||x.propsBadge.inverted,customStyle:"margin-left: 4px;"},null,8,["show","isDot","value","max","type","showZero","bgColor","color","shape","numberType","inverted"])])),_:2},1032,["onClick","style","class"])))),128)),p(B,{class:"u-tabs__wrapper__nav__line",ref:"u-tabs__wrapper__nav__line",style:d([{width:e.$u.addUnit(e.lineWidth),transform:`translate(${v.lineOffsetLeft}px)`,transitionDuration:`${v.firstTime?0:e.duration}ms`,height:e.$u.addUnit(e.lineHeight),background:e.lineColor,backgroundSize:e.lineBgSize}])},null,8,["style"])])),_:1},512)])),_:1},8,["scroll-x","scroll-left"])])),_:1}),g(e.$slots,"right",{},void 0,!0)])),_:3})])),_:3})}],["__scopeId","data-v-5c753c99"]]);export{x as _};