roleList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. (function ($ang_role) {
  2. 'use strict';
  3. $ang_role.module('devself.common', []).controller("roleListController", function ($scope, $state, $http, $rootScope, $alert, $modal, AuthUser, $ocLazyLoad, $filter, $loading, $bsRouterState) {
  4. $scope.title = "人员角色权限";
  5. $scope.roleLists = []; //角色信息
  6. $scope.roleLists_dir = new Array(); //包含数据范围的角色信息
  7. $scope.roleName = "";
  8. $scope.roleConfigList = [];
  9. $state.params = $bsRouterState.$params($scope);
  10. //分页参数设置
  11. $scope.finddata = {
  12. pageindex: 1,
  13. pagesize: 10,
  14. ptotal: 0,
  15. lx: ''
  16. };
  17. $scope.selectPage = function (page) {
  18. if ($scope.finddata.ptotal > 0) {
  19. $scope.getRoleList($state.params.appid);
  20. }
  21. }
  22. //查询按钮
  23. $scope.selectpage = function () {
  24. $scope.finddata.pageindex = 1;
  25. $scope.finddata.ptotal = 0;
  26. $scope.getRoleList($state.params.appid);
  27. }
  28. $scope.getRoleConfigList = function () {
  29. $http({
  30. method: 'get',
  31. url: '../../api/dictionary/getDictionaryListByDicTypeKey',
  32. params: {
  33. dicTypeKey: 'roleConfig'
  34. }
  35. }).then(function (result) {
  36. $scope.roleConfigList = result.data;
  37. }, function (resp) {
  38. });
  39. };
  40. $scope.getRoleConfigList();
  41. $scope.getRoleList = function (id) {
  42. $loading.show();
  43. $scope.roleLists_dir = new Array();
  44. $http({
  45. url: "../../api/userrole/GetRoleList",
  46. method: 'GET',
  47. params: {
  48. appid: id,
  49. rolename: $scope.roleName,
  50. pageindex: $scope.finddata.pageindex,
  51. pagesize: $scope.finddata.pagesize,
  52. userId: AuthUser.getUser().Id
  53. }
  54. })
  55. .then(function (rq) {
  56. $scope.roleLists = rq.data.item.list;
  57. for (var i = 0; i < $scope.roleLists.length; i++) {
  58. //判断是否含有dictionaryId
  59. if ($scope.roleLists[i].dictionaryid == null || $scope.roleLists[i].dictionaryid == "") {
  60. // $scope.roleLists_dir.push($scope.roleLists[i]);
  61. } else {
  62. $scope.getDictionaryByID(i, $scope.roleLists[i].dictionaryid);
  63. }
  64. }
  65. $scope.finddata.ptotal = rq.data.item.total;
  66. $loading.hide();
  67. }, function (rq) {
  68. alert("获取失败");
  69. $loading.hide();
  70. });
  71. }
  72. $scope.getDictionaryByID = function (index, id) {
  73. $http({
  74. url: "../../api/dictionary/getDictionaryByID",
  75. method: 'GET',
  76. params: {
  77. id: id
  78. }
  79. }).then(function (res) {
  80. //合并role和dictionary信息
  81. $scope.roleLists[index] = Object.assign(res.data.item, $scope.roleLists[index]);
  82. }, function (res) {
  83. console.log(res);
  84. });
  85. }
  86. $scope.getRoleList($state.params.appid);
  87. //删除一条角色信息记录
  88. $scope.deleteRole = function (RoleId) {
  89. if (!confirm("确认删除?")) {
  90. return;
  91. }
  92. $http({
  93. url: "../../api/userrole/deleteRole",
  94. method: 'GET',
  95. params: {
  96. roleId: RoleId
  97. }
  98. }).then(function (res) {
  99. $scope.showalert(res.data.msg);
  100. $scope.getRoleList($state.params.appid);
  101. }, function (res) {
  102. console.log(res);
  103. });
  104. };
  105. //提示信息
  106. $scope.showalert = function (data) {
  107. $alert({title: '提示:', content: data, placement: 'top', type: 'info', show: true, duration: 3});
  108. };
  109. //弹窗的更改
  110. var MyEditModalController = function ($scope, $http) {
  111. $scope.params = myModal.params;
  112. $scope.loadRoleMenu = function () {
  113. $http.get("../../api/userrole/getRoleMenu", {params: {'id': $scope.params.roleId}}).then(function (result) {
  114. $scope.content = result.data.item;
  115. $scope.content2 = result.data.extdata.array;
  116. //循环遍历所有的Menulist与返回结果的content的值进行比对,然后设置MenuList的isChecked=true
  117. angular.forEach($scope.content2, function (val, key) {
  118. var data = $filter('filter')($scope.menuLists, function (value) {
  119. return value.menuid == val
  120. });
  121. if (data.length > 0) {
  122. data[0].isChecked = true;
  123. }
  124. });
  125. $scope.PmenuLists = [];
  126. $scope.getPmenuLists($scope.PmenuLists, null);
  127. }, function () {
  128. alert("服务器错误");
  129. });
  130. }
  131. //加载所有的菜单记录
  132. $scope.getMenuList = function () {
  133. $http({
  134. method: 'get',
  135. url: "../../api/userrole/getMenuList",
  136. params: {
  137. appid: $state.params.appid,
  138. }
  139. }).then(function (res) {
  140. $scope.menuLists = res.data.item;
  141. if ($scope.params.title == "角色编辑") {
  142. $scope.loadRoleMenu();
  143. }
  144. //先显示父级节点
  145. $scope.PmenuLists = [];
  146. $scope.getPmenuLists($scope.PmenuLists, null);
  147. }, function (res) {
  148. alert("获取失败");
  149. });
  150. };
  151. $scope.getMenuList();
  152. //使用递归将所有节点的内容填好
  153. $scope.getPmenuLists = function (dataList, MenuId) {
  154. angular.forEach($scope.menuLists, function (data) {
  155. if (data.parentmenuid == MenuId) {
  156. var childList = [];
  157. $scope.getPmenuLists(childList, data.menuid);
  158. dataList.push({
  159. myMenu: data,
  160. isChecked: data.isChecked,
  161. childMenu: childList,
  162. changeShow: false,
  163. changeClass: 'glyphicon-chevron-right'
  164. });
  165. }
  166. });
  167. };
  168. //根据父节点来显示对应的子节点
  169. $scope.getMenuByPMenuID = function (item) {
  170. //改变样式
  171. item.changeClass = item.changeClass == 'glyphicon-chevron-down' ? 'glyphicon-chevron-right' : 'glyphicon-chevron-down';
  172. //改变child的显示
  173. angular.forEach(item.childMenu, function (data) {
  174. data.changeShow = data.changeShow == true ? false : true;
  175. });
  176. };
  177. //父节点的过滤
  178. $scope.menufilter = function (value) {
  179. return !value.parentmenuid;
  180. }
  181. //checkbox的判断
  182. $scope.chkchildren = function (item) {
  183. //angular.forEach($scope.menuLists, function (val) {
  184. // if (val.MenuId == item.myMenu.MenuId) {
  185. // val.isChecked = item.isChecked;
  186. // }
  187. //});
  188. if (angular.isDefined(item.childMenu)) {
  189. angular.forEach(item.childMenu, function (val, key) {
  190. val.isChecked = item.isChecked;
  191. $scope.chkchildren(val);
  192. });
  193. }
  194. $scope.chkparent(item);
  195. };
  196. $scope.chkparent = function (item) {
  197. $scope.tempMenu = "";
  198. $scope.getPmenu = function (dataList, menuId) {
  199. var flag = true;
  200. angular.forEach(dataList, function (val) {
  201. if (flag) {
  202. if (menuId == val.myMenu.menuid) {
  203. //找到父级
  204. $scope.tempMenu = val;
  205. //选择一个全部勾选父节点
  206. if (item.isChecked) {
  207. val.isChecked = item.isChecked;
  208. } else {
  209. $scope.Amt = 0;
  210. var flag2 = true;
  211. angular.forEach(val.childMenu, function (val_child) {
  212. if (flag2) {
  213. if (val_child.isChecked == item.isChecked) {
  214. $scope.Amt = $scope.Amt + 1;
  215. }
  216. flag = false;
  217. }
  218. })
  219. if (val.childMenu.length == $scope.Amt) {
  220. val.isChecked = item.isChecked;
  221. }
  222. }
  223. flag = false;
  224. }
  225. $scope.getPmenu(val.childMenu, menuId);
  226. }
  227. });
  228. }
  229. if (item.myMenu.parentmenuid != null) {
  230. $scope.getPmenu($scope.PmenuLists, item.myMenu.parentmenuid);
  231. var grandChk = $scope.tempMenu;
  232. $scope.chkparent(grandChk);
  233. }
  234. };
  235. //保存
  236. $scope.saveRole = function (isflag) {
  237. if (isflag) {
  238. //遍历所有的isChecked的属性,用,去拼接;
  239. var menuIdArr = [];
  240. $scope.GetPmenuChecked = function (dataList) {
  241. angular.forEach(dataList, function (data) {
  242. if (data.isChecked) {
  243. this.push(data.myMenu.menuid);
  244. }
  245. $scope.GetPmenuChecked(data.childMenu);
  246. }, menuIdArr);
  247. }
  248. $scope.GetPmenuChecked($scope.PmenuLists);
  249. //angular.forEach($scope.menuLists, function (data) {
  250. // if (data.isChecked) {
  251. // this.push(data.MenuId);
  252. // }
  253. //}, menuIdArr);
  254. if (menuIdArr.length <= 0) {
  255. $scope.showalert("请分配菜单权限");
  256. return false;
  257. }
  258. $http({
  259. method: "post",
  260. url: "../../api/userrole/SaveRoleList",
  261. data: {
  262. "applicationId": $state.params.appid,
  263. "roleId": $scope.content.roleid || '',
  264. "roleName": $scope.content.rolename,
  265. "description": $scope.content.description,
  266. "groupby": $scope.content.groupby,
  267. "orderby": $scope.content.orderby,
  268. "dictionaryid": $scope.content.dictionaryid,
  269. "menuIds": menuIdArr.join(','),
  270. }
  271. }).then(function (result) {
  272. //alert(result.data);
  273. $scope.$hide();
  274. $scope.getRoleList($state.params.appid);
  275. $scope.showalert(result.data.msg);
  276. }), function (resp) {
  277. alert("服务器错误");
  278. }
  279. }
  280. }
  281. }
  282. MyEditModalController.$inject = ['$scope', '$http'];
  283. //新增或者编辑角色 模拟框
  284. var myModal = $modal({
  285. scope: $scope,
  286. resolve: {
  287. load: ['$ocLazyLoad', function ($ocLazyLoad) {
  288. $ocLazyLoad.load('../js/template/modal_userselect.css');
  289. return true;
  290. }]
  291. },
  292. templateUrl: '../js/setting/userRole/editRoleModal.html',
  293. controller: MyEditModalController,
  294. show: false,
  295. animation: 'am-fade-and-slide-top'
  296. });
  297. //打开新增角色模拟框
  298. $scope.savemodal = function () {
  299. myModal.content = {};
  300. myModal.params = {
  301. title: "角色新增",
  302. content: {},
  303. content2: {}
  304. }
  305. myModal.$promise.then(myModal.show);
  306. }
  307. //打开角色编辑模拟框
  308. $scope.editmodal = function (id) {
  309. myModal.params = {
  310. title: "角色编辑",
  311. content: {},
  312. content2: {},
  313. roleId: id
  314. }
  315. myModal.$promise.then(myModal.show);
  316. }
  317. //添加人员管理弹出模块
  318. var myModal2 = $modal({
  319. resolve: {
  320. load: ['$ocLazyLoad', function ($ocLazyLoad) {
  321. $rootScope.aid = "100";
  322. return $ocLazyLoad.load('../js/setting/userRole/UserManageList.js');
  323. }]
  324. },
  325. scope: $scope,
  326. title: '人员列表',
  327. controller: 'UserManageListController',
  328. templateUrl: '../js/setting/userRole/UserManageList.html',
  329. show: false,
  330. animation: 'am-fade-and-slide-top'
  331. });
  332. $scope.showModal2 = function (e) {
  333. $rootScope.role = {
  334. roleName: e.rolename,
  335. roleId: e.roleid
  336. }
  337. myModal2.$promise.then(myModal2.show);
  338. };
  339. $scope.hideModal2 = function () {
  340. myModal2.$promise.then(myModal2.hide);
  341. }
  342. });
  343. })(angular);