u-empty.ce873022.js
9.1 KB
import{d as e,m as t,a as s,o as i,c as a,w as r,g as l,t as o,j as n,n as d,h as u,k as p,r as c,b as h,f as b,i as m,e as g,F as y,G as f,C as _,ab as w,J as S}from"./index-09ea2a64.js";import{_ as v}from"./_plugin-vue_export-helper.1b428a4d.js";import{_ as x}from"./u-icon.282abda9.js";const $=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,c,h,b){const m=p;return e.show&&(0!==Number(e.value)||e.showZero||e.isDot)?(i(),a(m,{key:0,class:n([[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),b.badgeStyle])},{default:r((()=>[l(o(e.isDot?"":b.showValue),1)])),_:1},8,["class","style"])):u("",!0)}],["__scopeId","data-v-53f4f32b"]]);const C=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 i=t-(this.tabsRect.width-e.rect.width)/2-(s-this.tabsRect.right)/2+this.tabsRect.left/2;i=Math.min(i,this.scrollViewWidth-this.tabsRect.width),this.scrollLeft=Math.max(0,i)},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,S,v){const x=p,C=c(h("u-badge"),$),N=_,k=w;return i(),a(N,{class:"u-tabs"},{default:r((()=>[b(N,{class:"u-tabs__wrapper"},{default:r((()=>[m(e.$slots,"left",{},void 0,!0),b(N,{class:"u-tabs__wrapper__scroll-view-wrapper"},{default:r((()=>[b(k,{"scroll-x":e.scrollable,"scroll-left":S.scrollLeft,"scroll-with-animation":"",class:"u-tabs__wrapper__scroll-view","show-scrollbar":!1,ref:"u-tabs__wrapper__scroll-view"},{default:r((()=>[b(N,{class:"u-tabs__wrapper__nav",ref:"u-tabs__wrapper__nav"},{default:r((()=>[(i(!0),g(y,null,f(e.list,((t,s)=>(i(),a(N,{class:n(["u-tabs__wrapper__nav__item",[`u-tabs__wrapper__nav__item-${s}`,t.disabled&&"u-tabs__wrapper__nav__item--disabled"]]),key:s,onClick:e=>v.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((()=>[b(x,{class:n([[t.disabled&&"u-tabs__wrapper__nav__item__text--disabled"],"u-tabs__wrapper__nav__item__text"]),style:d([v.textStyle(s)])},{default:r((()=>[l(o(t[e.keyName]),1)])),_:2},1032,["class","style"]),b(C,{show:!(!t.badge||!(t.badge.show||t.badge.isDot||t.badge.value)),isDot:t.badge&&t.badge.isDot||v.propsBadge.isDot,value:t.badge&&t.badge.value||v.propsBadge.value,max:t.badge&&t.badge.max||v.propsBadge.max,type:t.badge&&t.badge.type||v.propsBadge.type,showZero:t.badge&&t.badge.showZero||v.propsBadge.showZero,bgColor:t.badge&&t.badge.bgColor||v.propsBadge.bgColor,color:t.badge&&t.badge.color||v.propsBadge.color,shape:t.badge&&t.badge.shape||v.propsBadge.shape,numberType:t.badge&&t.badge.numberType||v.propsBadge.numberType,inverted:t.badge&&t.badge.inverted||v.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)),b(N,{class:"u-tabs__wrapper__nav__line",ref:"u-tabs__wrapper__nav__line",style:d([{width:e.$u.addUnit(e.lineWidth),transform:`translate(${S.lineOffsetLeft}px)`,transitionDuration:`${S.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}),m(e.$slots,"right",{},void 0,!0)])),_:3})])),_:3})}],["__scopeId","data-v-6704b9c8"]]);const N=v({name:"u-empty",mixins:[t,s,{props:{icon:{type:String,default:e.empty.icon},text:{type:String,default:e.empty.text},textColor:{type:String,default:e.empty.textColor},textSize:{type:[String,Number],default:e.empty.textSize},iconColor:{type:String,default:e.empty.iconColor},iconSize:{type:[String,Number],default:e.empty.iconSize},mode:{type:String,default:e.empty.mode},width:{type:[String,Number],default:e.empty.width},height:{type:[String,Number],default:e.empty.height},show:{type:Boolean,default:e.empty.show},marginTop:{type:[String,Number],default:e.empty.marginTop}}}],data:()=>({icons:{car:"购物车为空",page:"页面不存在",search:"没有搜索结果",address:"没有收货地址",wifi:"没有WiFi",order:"订单为空",coupon:"没有优惠券",favor:"暂无收藏",permission:"无权限",history:"无历史记录",news:"无新闻列表",message:"消息列表为空",list:"列表为空",data:"数据为空",comment:"暂无评论"}}),computed:{emptyStyle(){const e={};return e.marginTop=uni.$u.addUnit(this.marginTop),uni.$u.deepMerge(uni.$u.addStyle(this.customStyle),e)},textStyle(){const e={};return e.color=this.textColor,e.fontSize=uni.$u.addUnit(this.textSize),e},isSrc(){return this.icon.indexOf("/")>=0}}},[["render",function(e,t,s,n,g,y){const f=c(h("u-icon"),x),w=S,v=p,$=_;return e.show?(i(),a($,{key:0,class:"u-empty",style:d([y.emptyStyle])},{default:r((()=>[y.isSrc?(i(),a(w,{key:1,style:d({width:e.$u.addUnit(e.width),height:e.$u.addUnit(e.height)}),src:e.icon,mode:"widthFix"},null,8,["style","src"])):(i(),a(f,{key:0,name:"message"===e.mode?"chat":`empty-${e.mode}`,size:e.iconSize,color:e.iconColor,"margin-top":"14"},null,8,["name","size","color"])),b(v,{class:"u-empty__text",style:d([y.textStyle])},{default:r((()=>[l(o(e.text?e.text:g.icons[e.mode]),1)])),_:1},8,["style"]),e.$slots.default||e.$slots.$default?(i(),a($,{key:2,class:"u-empty__wrap"},{default:r((()=>[m(e.$slots,"default",{},void 0,!0)])),_:3})):u("",!0)])),_:3},8,["style"])):u("",!0)}],["__scopeId","data-v-44b75afc"]]);export{C as _,N as a};