@tarojs/components
Version:
1 lines • 10.8 kB
JavaScript
var __spreadArray=this&&this.__spreadArray||function(e,t,a){if(a||arguments.length===2)for(var r=0,o=t.length,n;r<o;r++){if(n||!(r in t)){if(!n)n=Array.prototype.slice.call(t,0,r);n[r]=t[r]}}return e.concat(n||Array.prototype.slice.call(t))};System.register(["./p-2b70c348.system.js","@tarojs/runtime","@tarojs/taro","./p-2ec68968.system.js","resolve-pathname","./p-010faa87.system.js"],(function(e){"use strict";var t,a,r,o,n,i,s,l,b,d,c,h,u;return{setters:[function(e){t=e.h;a=e.r;r=e.c;o=e.H;n=e.g},function(e){i=e.stripSuffix;s=e.stripBasename;l=e.addLeadingSlash;b=e.getCurrentPage},function(e){d=e.default},function(e){c=e.c},function(e){h=e.default},function(e){u=e.a}],execute:function(){var f=function(e){var t=e||"";var a;var r={path:null,query:null,fragment:null};a=t.indexOf("#");if(a>-1){r.fragment=t.substring(a+1);t=t.substring(0,a)}a=t.indexOf("?");if(a>-1){r.query=t.substring(a+1);t=t.substring(0,a)}r.path=t;return r};var g=function(e){var a=e.index,r=e.isSelected,o=r===void 0?false:r,n=e.textColor,i=e.iconPath,s=e.badgeText,l=e.showRedDot,b=l===void 0?false:l,h=e.pagePath,f=e.text,g=e.onSelect;var v=c("weui-tabbar__item",{"weui-bar__item_on":o});var p={position:"absolute",top:"-2px",right:"-13px"};var _={position:"absolute",top:"0",right:"-6px"};function m(){var e=d.getCurrentPages().shift();if(typeof(e===null||e===void 0?void 0:e.onTabItemTap)==="function"&&u(this)){e.onTabItemTap({index:a,pagePath:h,text:f})}g(a)}return t("a",{key:a,href:"javascript:;",class:v,onClick:m},t("span",{style:{display:"inline-block",position:"relative"}},t("img",{src:i,alt:"",class:"weui-tabbar__icon"}),!!s&&t("span",{class:"weui-badge taro-tabbar-badge",style:p},s),b&&t("span",{class:"weui-badge weui-badge_dot",style:_})),t("p",{class:"weui-tabbar__label",style:{color:n}},f))};var v='.weui-tabbar{z-index:500;background-color:#f7f7fa;-ms-flex-align:center;align-items:center;width:100%;display:-ms-flexbox;display:flex;position:absolute;bottom:0}.weui-tabbar:before{content:" ";color:#c0bfc4;-webkit-transform-origin:0 0;transform-origin:0 0;border-top:1px solid #c0bfc4;height:1px;position:absolute;top:0;left:0;right:0;-webkit-transform:scaleY(.5);transform:scaleY(.5)}.weui-tabbar__item{padding:5px 0;padding-bottom:constant(safe-area-inset-bottom);padding-bottom:env(safe-area-inset-bottom);color:#999;text-align:center;-webkit-tap-highlight-color:transparent;-ms-flex:1;flex:1;font-size:0;display:block}.weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon,.weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon>i,.weui-tabbar__item.weui-bar__item_on .weui-tabbar__label{color:#09bb07}.weui-tabbar__icon{width:27px;height:27px;display:inline-block}.weui-tabbar__icon img{width:100%;height:100%}i.weui-tabbar__icon,.weui-tabbar__icon>i{color:#999;font-size:24px}.weui-tabbar__label{text-align:center;color:#999;font-size:10px;line-height:1.8}.weui-badge{color:#fff;text-align:center;vertical-align:middle;background-color:#f43530;border-radius:18px;min-width:8px;padding:.15em .4em;font-size:12px;line-height:1.2;display:inline-block}.weui-badge_dot{min-width:0;padding:.4em}html,body{height:100%}:root{--taro-tabbar-height:50px}#app{height:100%}.taro-tabbar__border-white:before{border-top-color:#fff!important}.taro-tabbar__container{-ms-flex-direction:column;flex-direction:column;height:100%;display:-ms-flexbox;display:flex;overflow:hidden}.taro-tabbar__panel{-webkit-overflow-scrolling:auto;-ms-flex:1;flex:1;position:relative;overflow:auto}.taro-tabbar__tabbar{height:var(--taro-tabbar-height);width:100%;-webkit-transition:bottom .2s,top .2s;transition:bottom .2s,top .2s;position:relative}.taro-tabbar__tabbar-top{top:0}.taro-tabbar__tabbar-bottom{margin-bottom:constant(safe-area-inset-bottom);margin-bottom:env(safe-area-inset-bottom);bottom:0}.taro-tabbar__tabbar-hide{display:none}.taro-tabbar__tabbar-slideout{-ms-flex:0 0;flex:0 0;top:-52px}.taro-tabbar__panel+.taro-tabbar__tabbar-slideout{top:auto;bottom:-52px}';var p=0;var _=1;var m=2;var T="taro-tabbar__tabbar";var w="taro-tabbar__tabbar-hide";var x="taro-tabbar__tabbar-slideout";var B=e("taro_tabbar",function(){function e(e){var t=this;a(this,e);this.onLongPress=r(this,"longpress",7);this.homePage="";this.customRoutes=[];this.tabbarPos="bottom";this.getOriginUrl=function(e){var a=t.customRoutes.filter((function(t){var a=t[1];var r=f(a).path;var o=f(e).path;return r===o}));return i(a.length?a[0][0]:e,".html")};this.getSelectedIndex=function(e){var a=-1;t.list.forEach((function(t,r){var o=t.pagePath;var n=f(e).path;var i=f(o).path;if(n===i){a=r}}));return a};this.switchTab=function(e){t.selectedIndex=e;d.switchTab({url:t.list[e].pagePath})};this.switchTabHandler=function(e){var a=e.url,r=e.successHandler,o=e.errorHandler;var n=t.getOriginUrl(t.getCurrentUrl()||t.homePage);var i=h(a,n);var s=t.getSelectedIndex(i);if(s>-1){t.switchTab(s);r({errMsg:"switchTab:ok"})}else{o({errMsg:'switchTab:fail page "'.concat(i,'" is not found')})}};this.routerChangeHandler=function(e){var a;var r=(a=e===null||e===void 0?void 0:e.toLocation)===null||a===void 0?void 0:a.path;var o;if(typeof r==="string"){var n=t.conf.basename||"/";o=s(l(r||t.homePage),n)||"/"}else{o=t.getCurrentUrl()}t.selectedIndex=t.getSelectedIndex(t.getOriginUrl(o))};this.setTabBarBadgeHandler=function(e){var a=e.index,r=e.text,o=e.successHandler,n=e.errorHandler;var i=__spreadArray([],t.list,true);if(a in i){i[a].showRedDot=false;i[a].badgeText=r;o({errMsg:"setTabBarBadge:ok"})}else{n({errMsg:"setTabBarBadge:fail tabbar item not found"})}t.list=i};this.removeTabBarBadgeHandler=function(e){var a=e.index,r=e.successHandler,o=e.errorHandler;var n=__spreadArray([],t.list,true);if(a in n){n[a].badgeText=null;n[a].badgeText=null;r({errMsg:"removeTabBarBadge:ok"})}else{o({errMsg:"removeTabBarBadge:fail tabbar item not found"})}t.list=n};this.showTabBarRedDotHandler=function(e){var a=e.index,r=e.successHandler,o=e.errorHandler;var n=__spreadArray([],t.list,true);if(a in n){n[a].badgeText=null;n[a].showRedDot=true;r({errMsg:"showTabBarRedDot:ok"})}else{o({errMsg:"showTabBarRedDot:fail tabbar item not found"})}t.list=n};this.hideTabBarRedDotHandler=function(e){var a=e.index,r=e.successHandler,o=e.errorHandler;var n=__spreadArray([],t.list,true);if(a in n){n[a].showRedDot=false;r({errMsg:"hideTabBarRedDot:ok"})}else{o({errMsg:"hideTabBarRedDot:fail tabbar item not found"})}t.list=n};this.showTabBarHandler=function(e){var a=e.successHandler;t.status=p;a({errMsg:"showTabBar:ok"})};this.hideTabBarHandler=function(e){var a=e.animation,r=e.successHandler;t.status=a?m:_;r({errMsg:"hideTabBar:ok"})};this.setTabBarStyleHandler=function(e){var a=e.color,r=e.selectedColor,o=e.backgroundColor,n=e.borderStyle,i=e.successHandler;if(o)t.backgroundColor=o;if(n)t.borderStyle=n;if(a)t.color=a;if(r)t.selectedColor=r;i({errMsg:"setTabBarStyle:ok"})};this.setTabBarItemHandler=function(e){var a=e.index,r=e.iconPath,o=e.selectedIconPath,n=e.text,i=e.successHandler,s=e.errorHandler;var l=__spreadArray([],t.list,true);if(a in l){if(r)l[a].iconPath=r;if(o)l[a].selectedIconPath=o;if(n)l[a].text=n;i({errMsg:"setTabBarItem:ok"})}else{s({errMsg:"setTabBarItem:fail tabbar item not found"})}t.list=l};this.conf=undefined;this.list=undefined;this.borderStyle=undefined;this.backgroundColor=undefined;this.color=undefined;this.selectedColor=undefined;this.selectedIndex=-1;this.status=p}e.prototype.componentWillLoad=function(){var e,t;var a=((e=this.conf)===null||e===void 0?void 0:e.list)||[];var r=((t=this.conf)===null||t===void 0?void 0:t.customRoutes)||{};if(Object.prototype.toString.call(a)!=="[object Array]"||a.length<2||a.length>5){throw new Error("tabBar 配置错误")}this.homePage=l(this.conf.homePage);var o=function(e){var t;var a=r[e];e=l(e);if(typeof a==="string"){n.customRoutes.push([e,l(a)])}else if((a===null||a===void 0?void 0:a.length)>0){(t=n.customRoutes).push.apply(t,a.map((function(t){return[e,l(t)]})))}};var n=this;for(var i in r){o(i)}a.forEach((function(e){if(e.pagePath.indexOf("/")!==0){e.pagePath="/"+e.pagePath}}));this.list=a;this.borderStyle=this.conf.borderStyle;this.backgroundColor=this.conf.backgroundColor;this.color=this.conf.color;this.selectedColor=this.conf.selectedColor};e.prototype.getCurrentUrl=function(){var e=b(this.conf.mode,this.conf.basename);return decodeURI(e==="/"?this.homePage:e)};e.prototype.bindEvent=function(){d.eventCenter.on("__taroRouterChange",this.routerChangeHandler);d.eventCenter.on("__taroSwitchTab",this.switchTabHandler);d.eventCenter.on("__taroSetTabBarBadge",this.setTabBarBadgeHandler);d.eventCenter.on("__taroRemoveTabBarBadge",this.removeTabBarBadgeHandler);d.eventCenter.on("__taroShowTabBarRedDotHandler",this.showTabBarRedDotHandler);d.eventCenter.on("__taroHideTabBarRedDotHandler",this.hideTabBarRedDotHandler);d.eventCenter.on("__taroShowTabBar",this.showTabBarHandler);d.eventCenter.on("__taroHideTabBar",this.hideTabBarHandler);d.eventCenter.on("__taroSetTabBarStyle",this.setTabBarStyleHandler);d.eventCenter.on("__taroSetTabBarItem",this.setTabBarItemHandler)};e.prototype.removeEvent=function(){d.eventCenter.off("__taroRouterChange",this.routerChangeHandler);d.eventCenter.off("__taroSwitchTab",this.switchTabHandler);d.eventCenter.off("__taroSetTabBarBadge",this.setTabBarBadgeHandler);d.eventCenter.off("__taroRemoveTabBarBadge",this.removeTabBarBadgeHandler);d.eventCenter.off("__taroShowTabBarRedDotHandler",this.showTabBarRedDotHandler);d.eventCenter.off("__taroHideTabBarRedDotHandler",this.hideTabBarRedDotHandler);d.eventCenter.off("__taroShowTabBar",this.showTabBarHandler);d.eventCenter.off("__taroHideTabBar",this.hideTabBarHandler);d.eventCenter.off("__taroSetTabBarStyle",this.setTabBarStyleHandler);d.eventCenter.off("__taroSetTabBarItem",this.setTabBarItemHandler)};e.prototype.componentDidLoad=function(){this.tabbarPos=this.tabbar.nextElementSibling?"top":"bottom";this.bindEvent();this.routerChangeHandler()};e.prototype.disconnectedCallback=function(){this.removeEvent()};e.prototype.render=function(){var e,a;var r=this;var n=this.tabbarPos,i=n===void 0?"bottom":n;var s=this.status;var l=c("weui-tabbar",(e={},e["taro-tabbar__border-".concat(this.borderStyle||"black")]=true,e));var b=this.selectedIndex===-1||s===_;var d=s===m;return t(o,{class:c(T,"".concat(T,"-").concat(i),(a={},a[w]=b,a[x]=d,a))},t("div",{class:l,style:{backgroundColor:this.backgroundColor||"",height:"inherit"}},this.list.map((function(e,a){var o=r.selectedIndex===a;var n;var i;if(o){n=r.selectedColor||"";i=e.selectedIconPath}else{n=r.color||"";i=e.iconPath}return t(g,{index:a,onSelect:r.switchTab.bind(r),isSelected:o,textColor:n,iconPath:i,pagePath:e.pagePath,text:e.text,badgeText:e.badgeText,showRedDot:e.showRedDot})}))))};Object.defineProperty(e.prototype,"tabbar",{get:function(){return n(this)},enumerable:false,configurable:true});return e}());B.style=v}}}));