controllers.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. (function () {
  2. 'use strict';
  3. angular.module('ylmis').controller("homeCtrl", function ($scope, $rootScope, $state, $http, AuthUser, $alert, $interval, $loading, $modal ,$bsRouterState) {
  4. $scope.User = { name: AuthUser.getUser().UserName, roleName:AuthUser.getUser().RoleName };
  5. $scope.panels = [];
  6. $scope.roleName = '';
  7. $scope.roleList = [];
  8. ////站点ID
  9. $scope.menudatas = {
  10. getMenuUrl: '../../api/systemsetting/Menu/GetMenu',
  11. toggle: true
  12. };
  13. $scope.now = new Date();
  14. $scope.weekes = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  15. $scope.week = $scope.weekes[$scope.now.getDay()];
  16. var timer = $interval(function () {
  17. $scope.now = new Date();
  18. }, 1000);
  19. $scope.$on("menudatas.toggle", function (event, data) {
  20. $scope.menudatas.toggle = data;
  21. });
  22. //$scope.$watch('roleList.selectedId', function (newVal, oldVal) {
  23. // if (newVal != undefined && newVal != '') {
  24. // //修改选择角色
  25. // $scope.User.curRoleId = newVal;
  26. // AuthUser.setUser($scope.User);
  27. // $bsRouterState.tabs.length=0;
  28. // $scope.getMenuList(newVal);
  29. // $scope.getUserDataScope();
  30. // }
  31. //});
  32. $scope.getMenuList = function () {
  33. $scope.menuList = [];
  34. $scope.panels.length = 0;
  35. $http({
  36. method: 'post', url: $scope.menudatas.getMenuUrl, data: {}
  37. }).then(function (result) {
  38. if (result.data.IsSuccess) {
  39. $scope.menuList = result.data.Data;
  40. //$state.get('home');若路由不存在,返回null
  41. //$state.is('home');若路由不存在,返回undifined;
  42. if ($scope.menuList.length > 0) {
  43. $scope.panels = $scope.buildMenuTree($scope.menuList, 'mainMenu');
  44. $scope.initActive($scope.panels);
  45. }
  46. $bsRouterState.buildTabRoute($scope.menuList);
  47. } else {
  48. $alert({
  49. title: '错误:',
  50. content: result.data.Message,
  51. placement: 'centre',
  52. type: 'info',
  53. show: true,
  54. duration: 3
  55. });
  56. }
  57. });
  58. };
  59. //begin菜单树方法
  60. {
  61. //构建菜单树
  62. $scope.buildMenuTree = function (menuList, parentId) {
  63. var returnVal = [];
  64. angular.forEach(menuList, function (menu) {
  65. if (menu.IsVisible != 1) {
  66. return true;
  67. }
  68. var pmenu = {
  69. id: menu.MenuId,
  70. title: menu.Title,
  71. icon: menu.Icon,
  72. name: menu.Url,
  73. url: menu.Url,
  74. cNodes: [], //子节点
  75. childShow: 0, //子节点是否显示,0不显示,1显示
  76. parentIds: parentId
  77. };
  78. //遍历插入子节点
  79. pmenu.cNodes = $scope.buildMenuTree(menu.Childrens, parentId + '.' + pmenu.id);
  80. returnVal.push(pmenu);
  81. });
  82. return returnVal;
  83. };
  84. //点击菜单事件
  85. $scope.menutoggle = function (node) {
  86. var childShow = node.cNodes.length > 0 ? (node.childShow > 0 ? 0 : 1) : 1;
  87. var codes = node.parentIds.split('.');
  88. codes.push(node.id);
  89. $scope.resetActive($scope.panels, codes);
  90. node.childShow = childShow;
  91. //$bsRouterState.$showTab(node.name, {});
  92. };
  93. //重置菜单选中项
  94. $scope.resetActive = function (list, codes) {
  95. angular.forEach(list, function (node, index) {
  96. var index = $.inArray(node.id, codes);
  97. node.childShow = index >= 0 ? 1 : 0;
  98. if (node.cNodes != null && node.cNodes.length > 0) {
  99. $scope.resetActive(node.cNodes, codes);
  100. }
  101. });
  102. };
  103. //刷新页面时默认打开菜单
  104. $scope.initActive = function (menuList) {
  105. //当前路由name
  106. var statename = $state.current.name;
  107. angular.forEach(menuList, function (value, index) {
  108. var p_realState = $scope.sliceStateName(value.name);
  109. if (p_realState == statename) {
  110. $scope.menutoggle(value);
  111. }
  112. $scope.initActive(value.cNodes);
  113. });
  114. };
  115. }
  116. //end
  117. var editPasswordCtrl = function ($scope, $http, AuthUser) {
  118. $scope.userinfovm = AuthUser.getUser();
  119. $scope.pwd = {
  120. pwd_default: '',
  121. pwd_confirm: ''
  122. };
  123. $scope.submitUser = function (isflag) {
  124. if (isflag) {
  125. if ($scope.pwd.pwd_default != $scope.pwd.pwd_confirm) {
  126. $scope.showMsg('失败', "两次输入的密码不一致!");
  127. return;
  128. }
  129. //$scope.uservm.userpwd = $scope.pwd.pwd_default;
  130. //var data = $desData.GetToken( $scope.pwd.pwd_default);
  131. $loading.show();
  132. $http({
  133. method: "post",
  134. url: "../../api/systemsetting/User/UpdatePwd",
  135. data: {
  136. newPassword: $.md5($scope.pwd.pwd_default)
  137. }
  138. }).then(function (result) {
  139. $loading.hide();
  140. if (result.data.IsSuccess) {
  141. $scope.showMsg('成功', '修改成功');
  142. $scope.$hide();
  143. } else {
  144. $scope.showMsg('失败', result.data.Message);
  145. }
  146. }), function (resp) {
  147. $scope.showMsg('错误', '服务器错误');
  148. }
  149. }
  150. }
  151. };
  152. editPasswordCtrl.$inject = ['$scope', '$http','AuthUser'];
  153. //定义模态框
  154. var passwordModal = $modal({
  155. resolve: {
  156. load: ['$ocLazyLoad', function ($ocLazyLoad) {
  157. //return [$ocLazyLoad.load('../main/user/edituser.css')];
  158. }]
  159. },
  160. scope: $scope,
  161. controller: editPasswordCtrl,
  162. templateUrl: '../main/home/editPwd.html',
  163. show: false,
  164. animation: 'am-fade-and-slide-top'
  165. });
  166. $scope.updatePwd = function (id) {
  167. passwordModal.$promise.then(passwordModal.show);
  168. };
  169. $scope.logout = function () {
  170. if (confirm('是否退出登录?')) {
  171. //$http.get("../../api/home/logout").then(function (req) {
  172. // if (req.data.success) {
  173. // AuthUser.clearUser();
  174. // $bsRouterState.tabs.length = 0;
  175. // $state.go("login");
  176. // //window.open("../public/index.html", "_self");
  177. // } else {
  178. // $alert({
  179. // title: '错误:',
  180. // content: '退出失败,请重试:' + req.data.msg,
  181. // placement: 'top',
  182. // type: 'info',
  183. // show: true,
  184. // duration: 3
  185. // });
  186. // }
  187. //}, function (err) {
  188. // $alert({
  189. // title: '错误:',
  190. // content: '退出失败,请重试:' + err,
  191. // placement: 'top',
  192. // type: 'info',
  193. // show: true,
  194. // duration: 3
  195. // });
  196. //});
  197. AuthUser.clearUser();
  198. $bsRouterState.tabs.length = 0;
  199. if (angular.isDefined($rootScope.refreshTokenInterval)) {
  200. $interval.cancel($rootScope.refreshTokenInterval);
  201. $rootScope.refreshTokenInterval = undefined;
  202. }
  203. $state.go("login");
  204. }
  205. };
  206. $scope.showMsg = function (title, content) {
  207. $alert({
  208. title: title + ':',
  209. content: content,
  210. placement: 'top',
  211. type: 'info',
  212. show: true,
  213. duration: 3
  214. });
  215. };
  216. $scope.sliceStateName = function (statename) {
  217. if (statename == null) return null;
  218. var index = statename.indexOf('(');
  219. if (index >= 0) {
  220. return statename.slice(0, index);
  221. }
  222. return statename;
  223. };
  224. $scope.getMenuList();
  225. $bsRouterState.$showTab($bsRouterState.defaults.initTabName, {});
  226. ////Set Waves
  227. //Waves.attach('.menu .list a', ['waves-block']);
  228. //Waves.init();
  229. });
  230. })();