UNPKG

@tarojs/components

Version:
1 lines 9.61 kB
var __spreadArray=this&&this.__spreadArray||function(e,t){for(var r=0,a=t.length,o=e.length;r<a;r++,o++)e[o]=t[r];return e};System.register(["./p-b2d01686.system.js","@tarojs/taro","./p-5f4d0d5b.system.js"],(function(e){"use strict";var t,r,a,o,n,i,s;return{setters:[function(e){t=e.h;r=e.r;a=e.c;o=e.H;n=e.g},function(e){i=e.default},function(e){s=e.c}],execute:function(){var l=function(e){var t=e||"";var r;var a={path:null,query:null,fragment:null};r=t.indexOf("#");if(r>-1){a.fragment=t.substring(r+1);t=t.substring(0,r)}r=t.indexOf("?");if(r>-1){a.query=t.substring(r+1);t=t.substring(0,r)}a.path=t;return a};function d(e){return e.charAt(0)==="/"}function b(e,t){for(var r=t,a=r+1,o=e.length;a<o;r+=1,a+=1){e[r]=e[a]}e.pop()}function h(e,t){if(t===undefined)t="";var r=e&&e.split("/")||[];var a=t&&t.split("/")||[];var o=e&&d(e);var n=t&&d(t);var i=o||n;if(e&&d(e)){a=r}else if(r.length){a.pop();a=a.concat(r)}if(!a.length)return"/";var s;if(a.length){var l=a[a.length-1];s=l==="."||l===".."||l===""}else{s=false}var h=0;for(var c=a.length;c>=0;c--){var f=a[c];if(f==="."){b(a,c)}else if(f===".."){b(a,c);h++}else if(h){b(a,c);h--}}if(!i)for(;h--;h)a.unshift("..");if(i&&a[0]!==""&&(!a[0]||!d(a[0])))a.unshift("");var u=a.join("/");if(s&&u.substr(-1)!=="/")u+="/";return u}var c=function(e){var r=e.index,a=e.isSelected,o=a===void 0?false:a,n=e.textColor,i=e.iconPath,l=e.badgeText,d=e.showRedDot,b=d===void 0?false:d,h=e.text,c=e.onSelect;var f=s("weui-tabbar__item",{"weui-bar__item_on":o});var u={position:"absolute",top:"-2px",right:"-13px"};var v={position:"absolute",top:"0",right:"-6px"};function g(){c(r)}return t("a",{key:r,href:"javascript:;",class:f,onClick:g},t("span",{style:{display:"inline-block",position:"relative"}},t("img",{src:i,alt:"",class:"weui-tabbar__icon"}),!!l&&t("span",{class:"weui-badge taro-tabbar-badge",style:u},l),b&&t("span",{class:"weui-badge weui-badge_dot",style:v})),t("p",{class:"weui-tabbar__label",style:{color:n}},h))};var f="html,body{height:100%}#app{height:100%}.taro-tabbar__border-white::before{border-top-color:#fff !important}.taro-tabbar__container{display:-ms-flexbox;display:flex;overflow:hidden;-ms-flex-direction:column;flex-direction:column;height:100%}.taro-tabbar__panel{overflow:auto;position:relative;-ms-flex:1;flex:1;-webkit-overflow-scrolling:auto}.taro-tabbar__tabbar{position:relative;width:100%;height:50px;-webkit-transition:bottom 0.2s, top 0.2s;transition:bottom 0.2s, top 0.2s}.taro-tabbar__tabbar-top{top:0}.taro-tabbar__tabbar-bottom{bottom:0;margin-bottom:constant(safe-area-inset-bottom);margin-bottom:env(safe-area-inset-bottom)}.taro-tabbar__tabbar-hide{display:none}.taro-tabbar__tabbar-slideout{top:-52px;-ms-flex:0 0;flex:0 0}.taro-tabbar__panel+.taro-tabbar__tabbar-slideout{top:auto;bottom:-52px}";var u=function(e){return e[0]==="/"?e:"/"+e};var v=function(e,t){return new RegExp("^"+t+"(\\/|\\?|#|$)","i").test(e)};var g=function(e,t){return v(e,t)?e.substr(t.length):e};var _=0;var p=1;var m=2;var T="taro-tabbar__tabbar";var B="taro-tabbar__tabbar-hide";var H="taro-tabbar__tabbar-slideout";var x=e("taro_tabbar",function(){function e(e){var t=this;r(this,e);this.onLongPress=a(this,"longpress",7);this.homePage="";this.customRoutes=[];this.tabbarPos="bottom";this.selectedIndex=-1;this.status=_;this.getOriginUrl=function(e){var r=t.customRoutes.filter((function(t){var r=t[1];var a=l(r).path;var o=l(e).path;return a===o}));return r.length?r[0][0]:e};this.getSelectedIndex=function(e){var r=-1;t.list.forEach((function(t,a){var o=t.pagePath;var n=l(e).path;var i=l(o).path;if(n===i){r=a}}));return r};this.switchTab=function(e){t.selectedIndex=e;i.switchTab({url:t.list[e].pagePath})};this.switchTabHandler=function(e){var r=e.url,a=e.successHandler,o=e.errorHandler;var n=t.getOriginUrl(t.getCurrentUrl()||t.homePage);var i=h(r,n);var s=t.getSelectedIndex(i);if(s>-1){t.switchTab(s);a({errMsg:"switchTab:ok"})}else{o({errMsg:'switchTab:fail page "'+i+'" is not found'})}};this.routerChangeHandler=function(e){var r;var a=(r=e===null||e===void 0?void 0:e.toLocation)===null||r===void 0?void 0:r.path;var o;if(typeof a==="string"){var n=t.conf.basename||"/";o=g(u(a||t.homePage),n)||"/"}else{o=t.getCurrentUrl()}t.selectedIndex=t.getSelectedIndex(t.getOriginUrl(o))};this.setTabBarBadgeHandler=function(e){var r=e.index,a=e.text,o=e.successHandler,n=e.errorHandler;var i=__spreadArray([],t.list);if(r in i){i[r].showRedDot=false;i[r].badgeText=a;o({errMsg:"setTabBarBadge:ok"})}else{n({errMsg:"setTabBarBadge:fail tabbar item not found"})}t.list=i};this.removeTabBarBadgeHandler=function(e){var r=e.index,a=e.successHandler,o=e.errorHandler;var n=__spreadArray([],t.list);if(r in n){n[r].badgeText=null;n[r].badgeText=null;a({errMsg:"removeTabBarBadge:ok"})}else{o({errMsg:"removeTabBarBadge:fail tabbar item not found"})}t.list=n};this.showTabBarRedDotHandler=function(e){var r=e.index,a=e.successHandler,o=e.errorHandler;var n=__spreadArray([],t.list);if(r in n){n[r].badgeText=null;n[r].showRedDot=true;a({errMsg:"showTabBarRedDot:ok"})}else{o({errMsg:"showTabBarRedDot:fail tabbar item not found"})}t.list=n};this.hideTabBarRedDotHandler=function(e){var r=e.index,a=e.successHandler,o=e.errorHandler;var n=__spreadArray([],t.list);if(r in n){n[r].showRedDot=false;a({errMsg:"hideTabBarRedDot:ok"})}else{o({errMsg:"hideTabBarRedDot:fail tabbar item not found"})}t.list=n};this.showTabBarHandler=function(e){var r=e.successHandler;t.status=_;r({errMsg:"showTabBar:ok"})};this.hideTabBarHandler=function(e){var r=e.animation,a=e.successHandler;t.status=r?m:p;a({errMsg:"hideTabBar:ok"})};this.setTabBarStyleHandler=function(e){var r=e.color,a=e.selectedColor,o=e.backgroundColor,n=e.borderStyle,i=e.successHandler;if(o)t.backgroundColor=o;if(n)t.borderStyle=n;if(r)t.color=r;if(a)t.selectedColor=a;i({errMsg:"setTabBarStyle:ok"})};this.setTabBarItemHandler=function(e){var r=e.index,a=e.iconPath,o=e.selectedIconPath,n=e.text,i=e.successHandler,s=e.errorHandler;var l=__spreadArray([],t.list);if(r in l){if(a)l[r].iconPath=a;if(o)l[r].selectedIconPath=o;if(n)l[r].text=n;i({errMsg:"setTabBarItem:ok"})}else{s({errMsg:"setTabBarItem:fail tabbar item not found"})}t.list=l};var o=this.conf.list;var n=this.conf.customRoutes;if(Object.prototype.toString.call(o)!=="[object Array]"||o.length<2||o.length>5){throw new Error("tabBar 配置错误")}this.homePage=u(this.conf.homePage);var s=function(e){var t;var r=n[e];e=u(e);if(typeof r==="string"){d.customRoutes.push([e,u(r)])}else if((r===null||r===void 0?void 0:r.length)>0){(t=d.customRoutes).push.apply(t,r.map((function(t){return[e,u(t)]})))}};var d=this;for(var b in n){s(b)}o.forEach((function(e){if(e.pagePath.indexOf("/")!==0){e.pagePath="/"+e.pagePath}}));this.list=o;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=this.conf.mode;var t=this.conf.basename||"/";var r;if(e==="hash"){var a=window.location.href;var o=a.indexOf("#");r=o===-1?"":a.substring(o+1)}else{r=location.pathname}var n=u(g(r,t));return n==="/"?this.homePage:n};e.prototype.bindEvent=function(){i.eventCenter.on("__taroRouterChange",this.routerChangeHandler);i.eventCenter.on("__taroSwitchTab",this.switchTabHandler);i.eventCenter.on("__taroSetTabBarBadge",this.setTabBarBadgeHandler);i.eventCenter.on("__taroRemoveTabBarBadge",this.removeTabBarBadgeHandler);i.eventCenter.on("__taroShowTabBarRedDotHandler",this.showTabBarRedDotHandler);i.eventCenter.on("__taroHideTabBarRedDotHandler",this.hideTabBarRedDotHandler);i.eventCenter.on("__taroShowTabBar",this.showTabBarHandler);i.eventCenter.on("__taroHideTabBar",this.hideTabBarHandler);i.eventCenter.on("__taroSetTabBarStyle",this.setTabBarStyleHandler);i.eventCenter.on("__taroSetTabBarItem",this.setTabBarItemHandler)};e.prototype.removeEvent=function(){i.eventCenter.off("__taroRouterChange",this.routerChangeHandler);i.eventCenter.off("__taroSwitchTab",this.switchTabHandler);i.eventCenter.off("__taroSetTabBarBadge",this.setTabBarBadgeHandler);i.eventCenter.off("__taroRemoveTabBarBadge",this.removeTabBarBadgeHandler);i.eventCenter.off("__taroShowTabBarRedDotHandler",this.showTabBarRedDotHandler);i.eventCenter.off("__taroHideTabBarRedDotHandler",this.hideTabBarRedDotHandler);i.eventCenter.off("__taroShowTabBar",this.showTabBarHandler);i.eventCenter.off("__taroHideTabBar",this.hideTabBarHandler);i.eventCenter.off("__taroSetTabBarStyle",this.setTabBarStyleHandler);i.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,r;var a=this;var n=this.tabbarPos,i=n===void 0?"bottom":n;var l=this.status;var d=s("weui-tabbar",(e={},e["taro-tabbar__border-"+(this.borderStyle||"black")]=true,e));var b=this.selectedIndex===-1||l===p;var h=l===m;return t(o,{class:s(T,T+"-"+i,(r={},r[B]=b,r[H]=h,r))},t("div",{class:d,style:{backgroundColor:this.backgroundColor||"",height:"inherit"}},this.list.map((function(e,r){var o=a.selectedIndex===r;var n;var i;if(o){n=a.selectedColor||"";i=e.selectedIconPath}else{n=a.color||"";i=e.iconPath}return t(c,{index:r,onSelect:a.switchTab.bind(a),isSelected:o,textColor:n,iconPath:i,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}());x.style=f}}}));