2 lines
6.8 KiB
JavaScript
2 lines
6.8 KiB
JavaScript
import{p as t,q as e,s as o,v as a,o as s,c as i,w as n,l,t as r,x as u,y as c,h as d,k as f,z as h,A as p,r as b,a as g,b as m,e as y,f as _,B as C,F as v,C as S,d as B,D as w,u as x,E as k,g as T,G as U}from"./index.c8b9a6e8.js";import{_ as I}from"./u-icon.14facb7e.js";import{_ as P}from"./plugin-vue_export-helper.21dcd24c.js";const $=(e,o=!1,a)=>new Promise(((s,i)=>{let n=t();a&&(n=t().in(a)),n[o?"selectAll":"select"](e).boundingClientRect((function(t){return o&&Array.isArray(t)&&t.length||!o&&t?s(t):void i("找不到元素")})).exec()}));function z(t,s="navigateTo"){const i=t.query?`${t.path}?${function(t){let e="";for(const o of Object.keys(t)){const s=t[o],i=encodeURIComponent(o)+"=";if(!N(s))if(console.log(encodeURIComponent(o),a(s)),a(s)){for(const t of Object.keys(s))if(!N(s[t])){e+=encodeURIComponent(o+"["+t+"]")+"="+encodeURIComponent(s[t])+"&"}}else e+=i+encodeURIComponent(s)+"&"}return e.slice(0,-1)}(t.query)}`:t.path;"navigateTo"==s&&e({url:i}),"reLaunch"==s&&o({url:i})}const N=t=>null==t&&void 0===t;var R=P({name:"u-badge",props:{type:{type:String,default:"error"},size:{type:String,default:"default"},isDot:{type:Boolean,default:!1},count:{type:[Number,String]},overflowCount:{type:Number,default:99},showZero:{type:Boolean,default:!1},offset:{type:Array,default:()=>[20,20]},absolute:{type:Boolean,default:!0},fontSize:{type:[String,Number],default:"24"},color:{type:String,default:"#ffffff"},bgColor:{type:String,default:""},isCenter:{type:Boolean,default:!1}},computed:{boxStyle(){let t={};return this.isCenter?(t.top=0,t.right=0,t.transform="translateY(-50%) translateX(50%)"):(t.top=this.offset[0]+"rpx",t.right=this.offset[1]+"rpx",t.transform="translateY(0) translateX(0)"),"mini"==this.size&&(t.transform=t.transform+" scale(0.8)"),t},showText(){return this.isDot?"":this.count>this.overflowCount?`${this.overflowCount}+`:this.count},show(){return 0!=this.count||0!=this.showZero}}},[["render",function(t,e,o,a,h,p){const b=f;return p.show?(s(),i(b,{key:0,class:u(["u-badge",[o.isDot?"u-badge-dot":"","mini"==o.size?"u-badge-mini":"",o.type?"u-badge--bg--"+o.type:""]]),style:c([{top:o.offset[0]+"rpx",right:o.offset[1]+"rpx",fontSize:o.fontSize+"rpx",position:o.absolute?"absolute":"static",color:o.color,backgroundColor:o.bgColor},p.boxStyle])},{default:n((()=>[l(r(p.showText),1)])),_:1},8,["class","style"])):d("v-if",!0)}],["__scopeId","data-v-11d03f21"]]);var L=P({emits:["update:modelValue","input","change"],props:{value:{type:[String,Number],default:0},modelValue:{type:[String,Number],default:0},show:{type:Boolean,default:!0},bgColor:{type:String,default:"#ffffff"},height:{type:[String,Number],default:100},iconSize:{type:[String,Number],default:40},midButtonSize:{type:[String,Number],default:90},activeColor:{type:String,default:"#303133"},inactiveColor:{type:String,default:"#606266"},midButton:{type:Boolean,default:!1},list:{type:Array,default:()=>[]},beforeSwitch:{type:Function,default:null},borderTop:{type:Boolean,default:!0},hideTabBar:{type:Boolean,default:!0}},data:()=>({midButtonLeft:"50%",pageUrl:""}),created(){this.hideTabBar&&h();let t=p();this.pageUrl=t[t.length-1].route},computed:{valueCom(){return this.modelValue},elIconPath(){return t=>{let e=this.list[t].pagePath;return e?e==this.pageUrl||e=="/"+this.pageUrl?this.list[t].selectedIconPath:this.list[t].iconPath:t==this.valueCom?this.list[t].selectedIconPath:this.list[t].iconPath}},elColor(){return t=>{let e=this.list[t].pagePath;return e?e==this.pageUrl||e=="/"+this.pageUrl?this.activeColor:this.inactiveColor:t==this.valueCom?this.activeColor:this.inactiveColor}}},mounted(){this.midButton&&this.getMidButtonLeft()},methods:{async clickHandler(t){if(this.beforeSwitch&&"function"==typeof this.beforeSwitch){let e=this.beforeSwitch.bind(this.$u.$parent.call(this))(t);e&&"function"==typeof e.then?await e.then((e=>{this.switchTab(t)})).catch((t=>{})):!0===e&&this.switchTab(t)}else this.switchTab(t)},switchTab(t){let e=this.list[t].pagePath;if(e){if(e==this.pageUrl||e=="/"+this.pageUrl)return;this.$emit("change",t)}else this.$emit("change",t),this.$emit("input",t),this.$emit("update:modelValue",t)},getOffsetRight:(t,e)=>e?-20:t>9?-40:-30,getMidButtonLeft(){let t=this.$u.sys().windowWidth;this.midButtonLeft=t/2+"px"}}},[["render",function(t,e,o,a,h,p){const B=b(g("u-icon"),I),w=b(g("u-badge"),R),x=f,k=S;return o.show?(s(),i(x,{key:0,class:"u-tabbar",onTouchmove:e[0]||(e[0]=C((()=>{}),["stop","prevent"]))},{default:n((()=>[m(x,{class:u(["u-tabbar__content safe-area-inset-bottom",{"u-border-top":o.borderTop}]),style:c({height:t.$u.addUnit(o.height),backgroundColor:o.bgColor})},{default:n((()=>[(s(!0),y(v,null,_(o.list,((t,e)=>(s(),i(x,{class:u(["u-tabbar__content__item",{"u-tabbar__content__circle":o.midButton&&t.midButton}]),key:e,onClick:C((t=>p.clickHandler(e)),["stop"]),style:c({backgroundColor:o.bgColor})},{default:n((()=>[m(x,{class:u([o.midButton&&t.midButton?"u-tabbar__content__circle__button":"u-tabbar__content__item__button"])},{default:n((()=>[m(B,{size:o.midButton&&t.midButton?o.midButtonSize:o.iconSize,name:p.elIconPath(e),"img-mode":"scaleToFill",color:p.elColor(e),"custom-prefix":t.customIcon?"custom-icon":"uicon"},null,8,["size","name","color","custom-prefix"]),t.count?(s(),i(w,{key:0,count:t.count,"is-dot":t.isDot,offset:[-2,p.getOffsetRight(t.count,t.isDot)]},null,8,["count","is-dot","offset"])):d("v-if",!0)])),_:2},1032,["class"]),m(x,{class:"u-tabbar__content__item__text",style:c({color:p.elColor(e)})},{default:n((()=>[m(k,{class:"u-line-1"},{default:n((()=>[l(r(t.text),1)])),_:2},1024)])),_:2},1032,["style"])])),_:2},1032,["class","onClick","style"])))),128)),o.midButton?(s(),i(x,{key:0,class:u(["u-tabbar__content__circle__border",{"u-border":o.borderTop}]),style:c({backgroundColor:o.bgColor,left:h.midButtonLeft})},null,8,["class","style"])):d("v-if",!0)])),_:1},8,["style","class"]),d(" 这里加上一个48rpx的高度,是为了增高有凸起按钮时的防塌陷高度(也即按钮凸出来部分的高度) "),m(x,{class:"u-fixed-placeholder safe-area-inset-bottom",style:c({height:`calc(${t.$u.addUnit(o.height)} + ${o.midButton?48:0}rpx)`})},null,8,["style"])])),_:1})):d("v-if",!0)}],["__scopeId","data-v-e0c09bf6"]]);const V=B({__name:"tabbar",setup(t){const e=w(),o=x(),a=k((()=>o.getTabbarConfig.map((t=>{const e=JSON.parse(t.link);return{iconPath:t.unselected,selectedIconPath:t.selected,text:t.name,link:e,pagePath:e.path}})))),n=k((()=>{const t=p(),e=t[t.length-1];return a.value.findIndex((t=>t.pagePath==="/"+e.route))>=0})),l=k((()=>({activeColor:o.getStyleConfig.selectedColor,inactiveColor:o.getStyleConfig.defaultColor}))),r=t=>{z(a.value[t].link,"reLaunch")};return(t,o)=>{const u=b(g("u-tabbar"),L);return T(n)?(s(),i(u,U({key:0,modelValue:e.value,"onUpdate:modelValue":o[0]||(o[0]=t=>e.value=t)},T(l),{list:T(a),onChange:r,"hide-tab-bar":!1}),null,16,["modelValue","list"])):d("v-if",!0)}}});export{V as _,R as a,$ as g,z as n};
|