2 lines
9.5 KiB
JavaScript
2 lines
9.5 KiB
JavaScript
|
import{U as e,V as t,W as s,p as a,q as l,h as i,i as r,w as n,j as d,S as o,E as u,F as c,G as p,H as b,n as _,J as f,K as h,M as m,t as g,ao as y,d as v,r as x,Y as w,o as k,b3 as C,l as S,k as $,v as B,m as j,$ as R,D as T,b4 as L,x as z,b5 as W}from"./index-849cf30e.js";import{_ as A,a as D}from"./u-tabbar.9997804a.js";import{_ as N}from"./_plugin-vue_export-helper.1b428a4d.js";import{_ as H}from"./u-empty.dadc8140.js";import{_ as O}from"./u-button.9fa3f2a0.js";import"./u-safe-bottom.2f6af56c.js";import"./u-icon.e3aa4770.js";import"./u-loading-icon.d012ecbf.js";const P=N({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,v,x,w){const k=m,C=a(l("u-badge"),A),S=g,$=y;return i(),r(S,{class:"u-tabs"},{default:n((()=>[d(S,{class:"u-tabs__wrapper"},{default:n((()=>[o(e.$slots,"left",{},void 0,!0),d(S,{class:"u-tabs__wrapper__scroll-view-wrapper"},{default:n((()=>[d($,{"scroll-x":e.scrollable,"scroll-left":x.scrollLeft,"scroll-with-animation":"",class:"u-tabs__wrapper__scroll-view","show-scrollbar":!1,ref:"u-tabs__wrapper__scroll-view"},{default:n((()=>[d(S,{class:"u-tabs__wrapper__nav",ref:"u-tabs__wrapper__nav"},{default:n((()=>[(i(!0),u(c,null,p(e.list,((t,s)=>(i(),r(S,{class:b(["u-tabs__wrapper__nav__item",[`u-tabs__wrapper__nav__item-${s}`,t.disabled&&"u-tabs__wrapper__nav__item--disabled"]]),key:s,onClick:e=>w.clickHandler(t,s),ref_for:!0,ref:`u-tabs__wrapper__nav__item-${s}`,style:_([e.$u
|