home-tabs.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. (function () {
  2. 'use strict';
  3. angular.module('ylmis').controller("homeTabsCtrl",function ($scope, $state, $http, AuthUser,$bsRouterState,$timeout,$window) {
  4. $scope.tabClear = function ($pane){
  5. $bsRouterState.$closeTab($pane);
  6. $timeout($scope.scrollBthHasShow,200);
  7. }
  8. $scope.tabs=$bsRouterState.tabs;
  9. //监视页数变化
  10. $scope.$watch("tabs.activeTab", function (newVal, oldVal) {
  11. if ($scope.tabs.activeTab != "") {
  12. $timeout(function () {
  13. var $tabPanel = $('div.nav-btn-panel');
  14. var $tab_ul = $tabPanel.find('.nav-btn-inline');
  15. var active = $tabPanel.find('.active')[0];
  16. if (active != undefined)
  17. $tab_ul.scrollLeft((active.offsetLeft > $tab_ul[0].offsetWidth ? active.offsetLeft : 0));
  18. }, 100);
  19. }
  20. });
  21. $scope.scrollLeft=function () {
  22. $timeout(function () {
  23. var $tabPanel=$('div.nav-btn-panel');
  24. var $tab_ul=$tabPanel.find('.nav-btn-inline');
  25. var left=$tab_ul.scrollLeft();
  26. left-=100;
  27. $tab_ul.scrollLeft(left);
  28. },200);
  29. };
  30. $scope.scrollRight=function () {
  31. $timeout(function () {
  32. var $tabPanel=$('div.nav-btn-panel');
  33. var $tab_ul=$tabPanel.find('.nav-btn-inline');
  34. var left=$tab_ul.scrollLeft();
  35. $tab_ul.scrollLeft(left+100);
  36. },200);
  37. };
  38. $scope.scrollBthHasShow=function () {
  39. var $tabPanel=$('div.nav-btn-panel');
  40. var $tab_btns=$tabPanel.find('.nav-btn');
  41. if($tabPanel.find('.nav-btn-inline')[0].scrollWidth>$tabPanel.find('.nav-tabs-body').width()){
  42. $tab_btns.show();
  43. } else {
  44. $tab_btns.hide();
  45. }
  46. };
  47. $window.addEventListener('message', function (e) {
  48. //console.log('message:'+e.data);
  49. if(e.data.method=='go'){
  50. $scope.$apply(function () {
  51. $bsRouterState.go(e.data.name,e.data.urlData,true);
  52. });
  53. }
  54. },false);
  55. /**
  56. * childData:{name:'xxxx',...}
  57. */
  58. $scope.$on("tabReloadData",function (event,data) {
  59. event.stopPropagation();
  60. $scope.$broadcast('tabChildReloadData', data);
  61. });
  62. }).directive('bsPaneUrl', function ($window, $animate, $sce,$bsCompiler,$alert) {
  63. return {
  64. require: ['^?ngModel', '^bsTabs'],
  65. scope: {panedata:'='},
  66. link: function postLink (scope, element, attrs, controllers) {
  67. //var ngModelCtrl = controllers[0];
  68. var bsTabsCtrl = controllers[1];
  69. //var bsTabsPanelScope=scope.$new();
  70. var $pane={};
  71. var paneOptions={};
  72. scope.showMsg = function (title, content, duration) {
  73. element.parents().find(".alert-info").remove();
  74. $alert({
  75. title: title + ':',
  76. content: content,
  77. placement: 'top',
  78. type: 'info',
  79. show: true,
  80. duration: duration || ((title == "失败" || title == "错误") ? 15 : 100)
  81. });
  82. };
  83. angular.extend(paneOptions,scope["panedata"]);
  84. var promise= $bsCompiler.compile(paneOptions);
  85. promise.then(function (data) {
  86. //scope.$tabScope=scope.$new();
  87. var paneEl=data.link(scope);
  88. paneEl.appendTo(element);
  89. //paneEl.css("min-height",$(window).height()-element.offset().top-50);
  90. });
  91. // Add base class
  92. element.addClass('tab-pane');
  93. // Observe title attribute for change
  94. attrs.$observe('title', function (newValue, oldValue) {
  95. scope.title = $sce.trustAsHtml(newValue);
  96. });
  97. // Save tab name into scope
  98. scope.name = attrs.name;
  99. // Add animation class
  100. if (bsTabsCtrl.$options.animation) {
  101. element.addClass(bsTabsCtrl.$options.animation);
  102. }
  103. attrs.$observe('disabled', function (newValue, oldValue) {
  104. scope.disabled = scope.$eval(newValue);
  105. });
  106. // Push pane to parent bsTabs controller
  107. bsTabsCtrl.$push(scope);
  108. // remove pane from tab controller when pane is destroyed
  109. scope.$on('$destroy', function () {
  110. bsTabsCtrl.$remove(scope);
  111. });
  112. function render () {
  113. var index = bsTabsCtrl.$panes.indexOf(scope);
  114. if(index>=0){
  115. $animate[bsTabsCtrl.$isActive(scope, index) ? 'addClass' : 'removeClass'](element, bsTabsCtrl.$options.activeClass);
  116. }
  117. if(bsTabsCtrl.$panes.$active==scope.name){
  118. if (scope.reloadData != undefined) {
  119. scope.reloadData();
  120. }
  121. }
  122. }
  123. bsTabsCtrl.$activePaneChangeListeners.push(function () {
  124. render();
  125. });
  126. render();
  127. }};
  128. }).directive('bsTabPaneHeigth',['$timeout',function ($timeout) {
  129. return {
  130. restrict: 'EAC',
  131. link: function postLink (scope, element, attrs, controllers) {
  132. if(scope.$last === true) {
  133. $timeout(function () {
  134. scope.scrollBthHasShow();
  135. /*
  136. var menuHeight = $(window).height()-155;
  137. var tabContentHeight = $(window).height()-105;
  138. angular.element('.main-tab-content').height(tabContentHeight);
  139. angular.element(".mainmenu").height(menuHeight);*/
  140. }, 200);
  141. }
  142. }
  143. }
  144. }]);
  145. })();