tabbar.2bf8dc03.js 7.8 KB

1
  1. import{_ as e}from"./u-icon.086befcc.js";import{x as t,y as a,z as o,a as l,c as r,w as i,p as s,D as n,A as u,n as d,g as c,E as b,h,i as p,b as f,S as m,U as y,C as g,j as v,B as x,d as _,P as S,H as k,a0 as C,G as w,bd as I,be as $,T as D,e as B,t as N,M as P}from"./index-65a0752a.js";import{_ as A}from"./_plugin-vue_export-helper.1b428a4d.js";import{_ as H}from"./u-safe-bottom.ed5ce7c3.js";const j=A({name:"u-badge",mixins:[a,{props:{isDot:{type:Boolean,default:t.badge.isDot},value:{type:[Number,String],default:t.badge.value},modelValue:{type:[Number,String],default:t.badge.modelValue},show:{type:Boolean,default:t.badge.show},max:{type:[Number,String],default:t.badge.max},type:{type:String,default:t.badge.type},showZero:{type:Boolean,default:t.badge.showZero},bgColor:{type:[String,null],default:t.badge.bgColor},color:{type:[String,null],default:t.badge.color},shape:{type:String,default:t.badge.shape},numberType:{type:String,default:t.badge.numberType},offset:{type:Array,default:t.badge.offset},inverted:{type:Boolean,default:t.badge.inverted},absolute:{type:Boolean,default:t.badge.absolute}}},o],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],a=this.offset[1]||t;e.top=uni.$u.addUnit(t),e.right=uni.$u.addUnit(a)}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,a,o,h,p){const f=b;return e.show&&(0!==Number(e.value)||e.showZero||e.isDot)?(l(),r(f,{key:0,class:u([[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:i((()=>[s(n(e.isDot?"":p.showValue),1)])),_:1},8,["class","style"])):c("v-if",!0)}],["__scopeId","data-v-99cd5b85"]]);const O=A({name:"u-tabbar-item",mixins:[a,o,{props:{name:{type:[String,Number,null],default:t.tabbarItem.name},icon:{icon:String,default:t.tabbarItem.icon},badge:{type:[String,Number,null],default:t.tabbarItem.badge},dot:{type:Boolean,default:t.tabbarItem.dot},text:{type:String,default:t.tabbarItem.text},badgeStyle:{type:[Object,String],default:t.tabbarItem.badgeStyle}}}],data:()=>({isActive:!1,parentData:{value:null,activeColor:"",inactiveColor:""}}),options:{virtualHost:!0},created(){this.init()},methods:{init(){this.updateParentData(),this.parent||uni.$u.error("u-tabbar-item必须搭配u-tabbar组件使用");const e=this.parent.children.indexOf(this);this.isActive=(this.name||e)===this.parentData.value},updateParentData(){this.getParentData("u-tabbar")},updateFromParent(){this.init()},clickHandler(){this.$nextTick((()=>{const e=this.parent.children.indexOf(this),t=this.name||e;t!==this.parent.value&&this.parent.$emit("change",t),this.$emit("click",t)}))}}},[["render",function(t,a,o,u,c,x){const _=h(p("u-icon"),e),S=h(p("u-badge"),j),k=v,C=b;return l(),r(k,{class:"u-tabbar-item",style:d([t.$u.addStyle(t.customStyle)]),onClick:x.clickHandler},{default:i((()=>[f(k,{class:"u-tabbar-item__icon"},{default:i((()=>[t.icon?(l(),r(_,{key:0,name:t.icon,color:c.isActive?c.parentData.activeColor:c.parentData.inactiveColor,size:20},null,8,["name","color"])):(l(),m(y,{key:1},[c.isActive?g(t.$slots,"active-icon",{key:0},void 0,!0):g(t.$slots,"inactive-icon",{key:1},void 0,!0)],64)),f(S,{absolute:"",offset:[0,t.dot?"34rpx":t.badge>9?"14rpx":"20rpx"],customStyle:t.badgeStyle,isDot:t.dot,value:t.badge||(t.dot?1:null),show:t.dot||t.badge>0},null,8,["offset","customStyle","isDot","value","show"])])),_:3}),g(t.$slots,"text",{},(()=>[f(C,{class:"u-tabbar-item__text",style:d({color:c.isActive?c.parentData.activeColor:c.parentData.inactiveColor})},{default:i((()=>[s(n(t.text),1)])),_:1},8,["style"])]),!0)])),_:3},8,["style","onClick"])}],["__scopeId","data-v-b5faebd4"]]);const z=A({name:"u-tabbar",mixins:[a,o,{props:{value:{type:[String,Number,null],default:t.tabbar.value},safeAreaInsetBottom:{type:Boolean,default:t.tabbar.safeAreaInsetBottom},border:{type:Boolean,default:t.tabbar.border},zIndex:{type:[String,Number],default:t.tabbar.zIndex},activeColor:{type:String,default:t.tabbar.activeColor},inactiveColor:{type:String,default:t.tabbar.inactiveColor},fixed:{type:Boolean,default:t.tabbar.fixed},placeholder:{type:Boolean,default:t.tabbar.placeholder}}}],data:()=>({placeholderHeight:0}),computed:{tabbarStyle(){const e={zIndex:this.zIndex};return uni.$u.deepMerge(e,uni.$u.addStyle(this.customStyle))},updateChild(){return[this.value,this.activeColor,this.inactiveColor]},updatePlaceholder(){return[this.fixed,this.placeholder]}},watch:{updateChild(){this.updateChildren()},updatePlaceholder(){this.setPlaceholderHeight()}},created(){this.children=[]},mounted(){this.setPlaceholderHeight()},methods:{updateChildren(){this.children.length&&this.children.map((e=>e.updateFromParent()))},async setPlaceholderHeight(){this.fixed&&this.placeholder&&(await uni.$u.sleep(20),this.$uGetRect(".u-tabbar__content").then((({height:e=50})=>{this.placeholderHeight=e})))}}},[["render",function(e,t,a,o,s,n){const b=v,m=h(p("u-safe-bottom"),H);return l(),r(b,{class:"u-tabbar"},{default:i((()=>[f(b,{class:u(["u-tabbar__content",[e.border&&"u-border-top",e.fixed&&"u-tabbar--fixed"]]),ref:"u-tabbar__content",onTouchmove:x(e.noop,["stop","prevent"]),style:d([n.tabbarStyle])},{default:i((()=>[f(b,{class:"u-tabbar__content__item-wrapper"},{default:i((()=>[g(e.$slots,"default",{},void 0,!0)])),_:3}),e.safeAreaInsetBottom?(l(),r(m,{key:0})):c("v-if",!0)])),_:3},8,["onTouchmove","class","style"]),e.placeholder?(l(),r(b,{key:0,class:"u-tabbar__placeholder",style:d({height:s.placeholderHeight+"px"})},null,8,["style"])):c("v-if",!0)])),_:3})}],["__scopeId","data-v-b564ac71"]]),T=A(_({__name:"tabbar",props:{addon:{type:String,default:""}},setup(e,{expose:t}){const a=e;let o=a.addon;const s=S();!o&&s.addon&&(o=s.addon);const n=k({}),u=()=>{let e=S().tabbarList;if(1==e.length)Object.assign(n,e[0]);else for(let t=0;t<e.length;t++)if(e[t].key==o){Object.assign(n,e[t]);break}};u(),C((()=>a.addon),((e,t)=>{e&&t&&e!=t&&u()}),{immediate:!0}),a.addon||C((()=>S().tabbarList),((e,t)=>{e&&u()}),{deep:!0,immediate:!0});const b=w((()=>{let e=I().params,t=[];for(let a in e)t.push(a+"="+e[a]);return"/"+$()+(t.length>0?"?"+t.join("&"):"")})),g=e=>{-1!=e.indexOf("http")||-1!=e.indexOf("http")?window.location.href=e:P({url:e,mode:"reLaunch"})};return t({}),(e,t)=>{const a=h(p("u-tabbar-item"),O),o=h(p("u-tabbar"),z),s=v;return n&&Object.keys(n).length?(l(),m(y,{key:0},[f(o,{value:B(b),onChange:g,zIndex:"9999",fixed:!0,placeholder:!0,safeAreaInsetBottom:!0,"inactive-color":n.value.textColor,"active-color":n.value.textHoverColor},{default:i((()=>[(l(!0),m(y,null,D(n.value.list,(e=>(l(),m(y,null,[1==n.value.type?(l(),r(a,{key:0,class:"py-[5rpx]",style:d({"background-color":n.value.backgroundColor}),text:e.text,icon:B(N)(B(b)==e.link.url?e.iconSelectPath:e.iconPath),name:e.link.url},null,8,["style","text","icon","name"])):c("v-if",!0),2==n.value.type?(l(),r(a,{key:1,class:"py-[5rpx]",style:d({"background-color":n.value.backgroundColor}),icon:B(N)(B(b)==e.link.url?e.iconSelectPath:e.iconPath),name:e.link.url},null,8,["style","icon","name"])):c("v-if",!0),3==n.value.type?(l(),r(a,{key:2,class:"py-[5rpx]",style:d({"background-color":n.value.backgroundColor}),text:e.text,name:e.link.url},null,8,["style","text","name"])):c("v-if",!0)],64)))),256))])),_:1},8,["value","inactive-color","active-color"]),f(s,{class:"tab-bar-placeholder"})],64)):c("v-if",!0)}}}),[["__scopeId","data-v-a145d54c"]]);export{T as _};