powerCtrl.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. app.controller('powerCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "Restangular", "api_user_data", "api_configure_data", "api_conversation", function($rootScope, $scope, $state, $timeout, $interval, SweetAlert, $modal, Restangular, api_user_data, api_configure_data, api_conversation) {
  2. var loginUser = $rootScope.user;
  3. $scope.xinzeng=false;
  4. $scope.shanchu=false;
  5. $scope.bianji=false;
  6. $scope.fenpeiquanxian=false;
  7. // $scope.role={};
  8. // $scope.role.flag=1;
  9. for(var i=0;i<loginUser.menu.length;i++){
  10. if(loginUser.menu[i].link=="quanxianguanli_xinzeng"){
  11. $scope.xinzeng=true
  12. }
  13. if(loginUser.menu[i].link=="quanxianguanli_shanchu"){
  14. $scope.shanchu=true
  15. }
  16. if(loginUser.menu[i].link=="quanxianguanli_bianji"){
  17. $scope.bianji=true
  18. }
  19. if(loginUser.menu[i].link=="quanxianguanli_fenpeiquanxian"){
  20. $scope.fenpeiquanxian=true
  21. }
  22. }
  23. //user tree
  24. var apple_selected, tree, treedata_avm, treedata_geography;
  25. var i = 0;
  26. $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
  27. $(window).resize(function() {
  28. $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
  29. });
  30. $rootScope.isMask = false;
  31. //角色仪表权限
  32. function dashboardaborad(branch) {
  33. $scope.dashboard_tree = angular.copy($scope.dashboard_data);
  34. angular.forEach($scope.dashboard_tree, function(index, i) {
  35. if (branch.dashboard && branch.dashboard.length > 0) {
  36. angular.forEach(branch.dashboard, function(item) {
  37. if (index.id == item.id) {
  38. $scope.dashboard_tree[i].checks = true;
  39. }
  40. })
  41. }
  42. })
  43. }
  44. //角色树
  45. $scope.my_tree = {};
  46. $scope.my_power = {};
  47. $scope.try_async_load = function() {
  48. $scope.my_data = [];
  49. $scope.doing_async = true;
  50. api_user_data.fetchDataList('role', { "idx": 0, "sum": 1000 }).then(function(response) {
  51. if (response.status == 200) {
  52. var data = response.list;
  53. var objects = [];
  54. for (var i = 0; i < data.length; i++) {
  55. var object = {};
  56. object.id = data[i].id;
  57. if (data[i].parent && data[i].parent.id != 0) {
  58. object.parent = data[i].parent.id;
  59. }
  60. angular.extend(object, data[i]);
  61. object.label = object.role;
  62. if (loginUser.id == 1) {
  63. objects.push(object);
  64. } else {
  65. if (object.rolecode != "system_menus") {
  66. objects.push(object);
  67. }
  68. }
  69. }
  70. $scope.my_data = convertParentToChildList(objects);
  71. $scope.tree_data = angular.copy($scope.my_data);
  72. if ($scope.my_data.length > 0) {
  73. $scope.doing_async = false;
  74. }
  75. } else {
  76. SweetAlert.swal({
  77. title: "系统错误!",
  78. text: "请刷新重试!",
  79. type: "error"
  80. });
  81. }
  82. });
  83. };
  84. function convertListToTree(data, treeMap) {
  85. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  86. var root = null; //Initially set our loop to null
  87. //loop over data
  88. for (var i = 0; i < data.length; i++) {
  89. var datum = data[i];
  90. //each node will have children, so let's give it a "children" poperty
  91. datum.children = [];
  92. //add an entry for this node to the map so that any future children can
  93. //lookup the parent
  94. idToNodeMap[datum.id] = datum;
  95. //Does this node have a parent?
  96. // console.log("datum="+JSON.stringify(datum))
  97. if (typeof datum.parent === "undefined" || datum.parent === null) {
  98. //Doesn't look like it, so this node is the root of the tree
  99. root = datum;
  100. treeMap[datum.id] = root;
  101. } else {
  102. //This node has a parent, so let's look it up using the id
  103. parentNode = idToNodeMap[datum.parent.id];
  104. //We don't need this property, so let's delete it.
  105. // delete datum.parent;
  106. //Let's add the current node as a child of the parent node.
  107. parentNode.children.push(datum);
  108. }
  109. }
  110. return root;
  111. }
  112. function convertParentToChildList(data) {
  113. var treeMap = {};
  114. var list = [];
  115. convertListToTree(data, treeMap);
  116. angular.forEach(treeMap, function(item) {
  117. list.push(item);
  118. });
  119. return list;
  120. }
  121. $scope.try_async_load();
  122. //end power
  123. //普通用户菜单权限
  124. $scope.try_async_powerload = function(items) {
  125. if (items) {
  126. $scope.getbranchs = items.menu;
  127. }
  128. // $scope.my_power = [];
  129. var objects = [];
  130. var selected = [];
  131. api_user_data.roleMenu(items.id).then(function(response) {
  132. console.log(response);
  133. // api_configure_data.fetchDataList('menu', { "idx": 0, "sum": 1000 }).then(function(response) {
  134. if (response.status == 200) {
  135. // //旧的树
  136. // var data = response.data;
  137. // var objects = [];
  138. // for (var i = 0; i < data.length; i++) {
  139. // var object = {};
  140. // object.id = data[i].id;
  141. // if (data[i].parent && data[i].parent.id != 0) {
  142. // object.parent = data[i].parent.id;
  143. // }
  144. // angular.extend(object, data[i]);
  145. // object.label = object.title;
  146. // objects.push(object);
  147. // }
  148. // selected = angular.copy($scope.tile);
  149. // $scope.my_power = angular.copy($scope.tree_power);
  150. // if (data.length > 0) {
  151. // angular.forEach(selected, function(index, i) {
  152. // angular.forEach(objects, function(item) {
  153. // if (index.id == item.id) {
  154. // selected[i].checks = true;
  155. // }
  156. // })
  157. // })
  158. // $scope.my_power = convertParentToChildList(selected);
  159. // } else {
  160. // $scope.my_power = convertParentToChildList($scope.tile);
  161. // }
  162. // if ($scope.my_power.length > 0) {
  163. // $scope.doing_asyncpower = false;
  164. // }
  165. // 新的树
  166. $scope.allPower_select=[];
  167. var data=response.data;
  168. for(var i=0;i<$scope.allPower.length;i++){
  169. $scope.allPower[i].biaoshi=false
  170. }
  171. $scope.allPower_select=$scope.allPower;
  172. for(var i=0;i<$scope.allPower_select.length;i++){
  173. for(var j=0;j<data.length;j++){
  174. if($scope.allPower_select[i].id==data[j].id){
  175. $scope.allPower_select[i].biaoshi=true
  176. }
  177. }
  178. }
  179. var objects = [];
  180. for (var i = 0; i < $scope.allPower_select.length; i++) {
  181. var object = {};
  182. object.id = $scope.allPower_select[i].id;
  183. if ($scope.allPower_select[i].parent && $scope.allPower_select[i].parent.id != 0) {
  184. object.parent = $scope.allPower_select[i].parent.id;
  185. }
  186. angular.extend(object, $scope.allPower_select[i]);
  187. object.label = object.title;
  188. objects.push(object);
  189. }
  190. $scope.tile = objects;
  191. $scope.my_power = convertParentToChildList(objects);
  192. $scope.tree_power = angular.copy($scope.my_power);
  193. if ($scope.my_data.length > 0) {
  194. $scope.doing_asyncpower = false;
  195. }
  196. } else {
  197. SweetAlert.swal({
  198. title: "系统错误!",
  199. text: "请刷新重试!",
  200. type: "error"
  201. });
  202. }
  203. });
  204. };
  205. $scope.dianjiceshi=function(){
  206. console.log($scope.my_power);
  207. console.log($scope.allPower_select);
  208. }
  209. //普通用户底菜单权限
  210. $scope.allPower=[];
  211. $scope.my_power = [];
  212. $scope.tile = [];
  213. $scope.try_async_powerloadlow = function() {
  214. var objects = [];
  215. api_user_data.pageMenuByCode("system_menus").then(function(response) {
  216. if (response.status == 200) {
  217. var data = response.data;
  218. $scope.allPower= response.data;
  219. var objects = [];
  220. for (var i = 0; i < data.length; i++) {
  221. data[i]["biaoshi"]=false;
  222. var object = {};
  223. object.id = data[i].id;
  224. if (data[i].parent && data[i].parent.id != 0) {
  225. object.parent = data[i].parent.id;
  226. }
  227. angular.extend(object, data[i]);
  228. object.label = object.title;
  229. objects.push(object);
  230. }
  231. $scope.tile = objects;
  232. $scope.my_power = convertParentToChildList(objects);
  233. $scope.tree_power = angular.copy($scope.my_power);
  234. if ($scope.my_data.length > 0) {
  235. $scope.doing_asyncpower = false;
  236. }
  237. console.log($scope.my_power)
  238. } else {
  239. SweetAlert.swal({
  240. title: "系统错误!",
  241. text: "请刷新重试!",
  242. type: "error"
  243. });
  244. }
  245. });
  246. };
  247. // $scope.jry_AllPower=[];
  248. // $scope.getJry_AllPower=function(){
  249. // api_user_data.pageMenuByCode("system_menus").then(function(res) {
  250. // console.log(res.data);
  251. // $scope.jry_AllPower=res.data
  252. // })
  253. // }
  254. // $scope.getJry_AllPower()
  255. //管理员 底菜单
  256. $scope.try_async_powerloadadmin = function() {
  257. var objects = [];
  258. // api_conversation.pageMenuByCode("system_menus").then(function(response) {
  259. api_user_data.getMenu({}).then(function(response) {
  260. if (response.status == 200) {
  261. var data = response.data;
  262. var objects = [];
  263. for (var i = 0; i < data.length; i++) {
  264. var object = {};
  265. object.id = data[i].id;
  266. if (data[i].parent && data[i].parent.id != 0) {
  267. object.parent = data[i].parent.id;
  268. }
  269. angular.extend(object, data[i]);
  270. object.label = object.title;
  271. objects.push(object);
  272. }
  273. $scope.tile = objects;
  274. $scope.my_power = convertParentToChildList(objects);
  275. $scope.tree_power = angular.copy($scope.my_power);
  276. if ($scope.tree_power.length > 0) {
  277. $scope.doing_asyncpower = false;
  278. }
  279. } else {
  280. SweetAlert.swal({
  281. title: "系统错误!",
  282. text: "请刷新重试!",
  283. type: "error"
  284. });
  285. }
  286. });
  287. };
  288. //点击角色
  289. $scope.role = {};
  290. // $scope.role.flag=1;
  291. $scope.chaoguan=true;//超级管理员禁止修改判断
  292. $scope.flagSwitch=true;
  293. $scope.change = true;
  294. $scope.my_tree_handler = function(branch) {
  295. console.log(branch);
  296. if(branch.flag==0){
  297. $scope.flagSwitch=true
  298. }else{
  299. $scope.flagSwitch=false
  300. }
  301. if(branch.label=="超级管理员"){
  302. $scope.chaoguan=false
  303. }else{
  304. $scope.chaoguan=true
  305. }
  306. $scope.role = branch;
  307. for (var i = 0; i < $scope.roledetail.length; i++) {
  308. if ($scope.role.model == $scope.roledetail[i].name) {
  309. $scope.role.model = { 'id': $scope.roledetail[i].id, 'name': $scope.roledetail[i].name }
  310. }
  311. }
  312. $scope.formlist = branch.dashboard;
  313. dashboardaborad($scope.role);
  314. $scope.try_async_powerload(branch);
  315. $scope.change = false;
  316. }
  317. // if (loginUser.id == 1) {
  318. // $scope.try_async_powerloadadmin();
  319. // } else {
  320. $scope.try_async_powerloadlow();
  321. // }
  322. // $scope.try_async_powerloadadmin();
  323. // console.log(loginUser);
  324. //start remove
  325. $scope.getbranchs = {};
  326. $scope.formbranch = function(branchData) {
  327. $scope.getbranchs = branchData;
  328. }
  329. //change right
  330. $scope.selectAllBiaoshi=true;
  331. // 全选/反选
  332. $scope.allSelect=function(){
  333. if($scope.selectAllBiaoshi){
  334. for(var i=0;i<$scope.my_power.length;i++){
  335. $scope.my_power[i].biaoshi=true;
  336. if($scope.my_power[i].children){
  337. for(var j=0;j<$scope.my_power[i].children.length;j++){
  338. $scope.my_power[i].children[j].biaoshi=true
  339. if($scope.my_power[i].children[j].children){
  340. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  341. $scope.my_power[i].children[j].children[k].biaoshi=true
  342. if($scope.my_power[i].children[j].children[k].children){
  343. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  344. $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. $scope.selectAllBiaoshi=false;
  353. }else{
  354. for(var i=0;i<$scope.my_power.length;i++){
  355. $scope.my_power[i].biaoshi=false;
  356. if($scope.my_power[i].children){
  357. for(var j=0;j<$scope.my_power[i].children.length;j++){
  358. $scope.my_power[i].children[j].biaoshi=false
  359. if($scope.my_power[i].children[j].children){
  360. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  361. $scope.my_power[i].children[j].children[k].biaoshi=false
  362. if($scope.my_power[i].children[j].children[k].children){
  363. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  364. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. $scope.selectAllBiaoshi=true;
  373. }
  374. }
  375. // 点击选项
  376. $scope.changeCheckBox1=function(data){
  377. console.log($scope.my_power);
  378. for(var i=0;i<$scope.my_power.length;i++){
  379. if(data.id === $scope.my_power[i].id){
  380. if(!$scope.my_power[i].biaoshi){
  381. if($scope.my_power[i].children){
  382. for(var j=0;j<$scope.my_power[i].children.length;j++){
  383. $scope.my_power[i].children[j].biaoshi=false
  384. if($scope.my_power[i].children[j].children){
  385. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  386. $scope.my_power[i].children[j].children[k].biaoshi=false
  387. if($scope.my_power[i].children[j].children[k].children){
  388. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  389. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }else{
  397. if($scope.my_power[i].children){
  398. for(var j=0;j<$scope.my_power[i].children.length;j++){
  399. $scope.my_power[i].children[j].biaoshi=true
  400. if($scope.my_power[i].children[j].children){
  401. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  402. $scope.my_power[i].children[j].children[k].biaoshi=true
  403. if($scope.my_power[i].children[j].children[k].children){
  404. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  405. $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. }
  416. $scope.changeCheckBox2=function(){
  417. for(var i=0;i<$scope.my_power.length;i++){
  418. if($scope.my_power[i].children){
  419. for(var j=0;j<$scope.my_power[i].children.length;j++){
  420. if(!$scope.my_power[i].children[j].biaoshi){
  421. if($scope.my_power[i].children[j].children){
  422. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  423. $scope.my_power[i].children[j].children[k].biaoshi=false
  424. if($scope.my_power[i].children[j].children[k].children){
  425. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  426. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  427. }
  428. }
  429. }
  430. }
  431. }else{
  432. $scope.my_power[i].biaoshi=true
  433. }
  434. }
  435. }
  436. }
  437. }
  438. $scope.changeCheckBox3=function(){
  439. for(var i=0;i<$scope.my_power.length;i++){
  440. if($scope.my_power[i].children){
  441. for(var j=0;j<$scope.my_power[i].children.length;j++){
  442. if($scope.my_power[i].children[j].children){
  443. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  444. if(!$scope.my_power[i].children[j].children[k].biaoshi){
  445. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  446. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  447. }
  448. }else{
  449. $scope.my_power[i].biaoshi=true;
  450. $scope.my_power[i].children[j].biaoshi=true;
  451. }
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }
  458. $scope.changeCheckBox4=function(){
  459. for(var i=0;i<$scope.my_power.length;i++){
  460. if($scope.my_power[i].children){
  461. for(var j=0;j<$scope.my_power[i].children.length;j++){
  462. if($scope.my_power[i].children[j].children){
  463. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  464. if($scope.my_power[i].children[j].children[k].children){
  465. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  466. if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
  467. $scope.my_power[i].biaoshi=true;
  468. $scope.my_power[i].children[j].biaoshi=true;
  469. $scope.my_power[i].children[j].children[k].biaoshi=true;
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. //修改权限
  480. $scope.changeData = function() {
  481. if($scope.role.id){
  482. var menu = [];
  483. $rootScope.isMask = true;
  484. // 旧的树
  485. // angular.forEach($scope.getbranchs, function(it) {
  486. // menu.push({ "id": it.id });
  487. // })
  488. // 新的树
  489. for(var i=0;i<$scope.my_power.length;i++){
  490. if($scope.my_power[i].biaoshi){
  491. menu.push({ "id": $scope.my_power[i].id });
  492. }
  493. if($scope.my_power[i].children){
  494. for(var j=0;j<$scope.my_power[i].children.length;j++){
  495. if($scope.my_power[i].children[j].biaoshi){
  496. menu.push({ "id": $scope.my_power[i].children[j].id });
  497. }
  498. if($scope.my_power[i].children[j].children){
  499. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  500. if($scope.my_power[i].children[j].children[k].biaoshi){
  501. menu.push({ "id": $scope.my_power[i].children[j].children[k].id });
  502. }
  503. if($scope.my_power[i].children[j].children[k].children){
  504. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  505. if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
  506. menu.push({ "id": $scope.my_power[i].children[j].children[k].children[l].id });
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. var branch = { 'menu': menu };
  516. angular.extend(branch, { 'id': $scope.role.id, 'role': $scope.role.role,'flag':$scope.role.flag, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype,'remark': $scope.role.remark })
  517. // var modelData = {role: branch};
  518. api_user_data.addData('role', { 'role': branch }).then(function(response) {
  519. if (response && response.status == 200) {
  520. $scope.role={};
  521. SweetAlert.swal({
  522. title: "提交成功!",
  523. type: "success",
  524. confirmButtonColor: "#007AFF"
  525. }, function() {
  526. $rootScope.isMask = false;
  527. $scope.try_async_load();
  528. });
  529. } else {
  530. SweetAlert.swal({
  531. title: "系统错误",
  532. text: "系统错误,请稍后重试!",
  533. type: "error",
  534. confirmButtonColor: "#DD6B55"
  535. }, function() {
  536. $rootScope.isMask = false;
  537. });
  538. }
  539. })
  540. }else{
  541. SweetAlert.swal({
  542. title: "操作失败",
  543. text: "请选择需要修改的角色!",
  544. type: "error",
  545. })
  546. }
  547. // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
  548. }
  549. //新增角色
  550. // $scope.addData = function() {
  551. // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data' });
  552. // }
  553. //change menu
  554. // $scope.choiceMenu = [];
  555. // $scope.showHandler = function(branch) {
  556. // $scope.choiceMenu = branch;
  557. // }
  558. // $scope.changeMenu = function() {
  559. // // if ($scope.choiceMenu && $scope.choiceMenu != null) {
  560. // // }
  561. // api_configure_data.fetchDataById('menu', $scope.choiceMenu.id).then(function(response) {
  562. // if (response.status == 200) {
  563. // if (response.data.link != null) {
  564. // response.data.type = "link";
  565. // } else if (response.data.service) {
  566. // response.data.type = "service";
  567. // } else if (response.data.event) {
  568. // response.data.type = "event";
  569. // }
  570. // response.data['menu'] = { parent: response.data.parent };
  571. // var modelData = { model: response.data }
  572. // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data', model: JSON.stringify(modelData) });
  573. // }
  574. // })
  575. // }
  576. //remove menu
  577. $scope.removeData = function() {
  578. var modalInstance = $modal.open({
  579. templateUrl: 'assets/views/delete.html',
  580. controller: function($scope, scope, $modalInstance) {
  581. $scope.rmvList = [];
  582. angular.forEach(scope.getbranchs, function(item) {
  583. $scope.rmvList.push(item.id);
  584. })
  585. $scope.ok = function() {
  586. $modalInstance.close($scope.rmvList);
  587. };
  588. $scope.cancel = function() {
  589. $modalInstance.dismiss('cancel');
  590. };
  591. },
  592. size: 'sm',
  593. resolve: {
  594. scope: function() {
  595. return $scope;
  596. }
  597. }
  598. });
  599. modalInstance.result.then(function(selectedItem) {
  600. if (selectedItem) {
  601. if (selectedItem.length > 0) {
  602. api_configure_data.rmvData('menu', selectedItem).then(function(response) {
  603. if (response.data) {
  604. SweetAlert.swal({
  605. title: "删除成功!",
  606. type: "success",
  607. confirmButtonColor: "#007AFF"
  608. }, function() {
  609. if (loginUser.id == 1) {
  610. $scope.try_async_powerloadadmin();
  611. } else {
  612. $scope.try_async_powerload();
  613. }
  614. });
  615. } else {
  616. SweetAlert.swal({
  617. title: "操作异常!",
  618. text: "系统异常,请稍后重试,或者联系管理员!",
  619. type: "error"
  620. });
  621. }
  622. })
  623. }
  624. }
  625. })
  626. }
  627. //add role
  628. $scope.addRole = function() {
  629. var modalInstance = $modal.open({
  630. templateUrl: 'assets/views/system/tpl/addpower.html',
  631. controller: function($scope, scope, $modalInstance, api_user_data) {
  632. $scope.role={
  633. "role":"",
  634. "remark":"",
  635. "flag":0
  636. }
  637. $scope.addSwitch=true;
  638. $scope.addSwitchChange=function(data){
  639. console.log(data);
  640. if(data==true){
  641. $scope.role.flag=0
  642. }else{
  643. $scope.role.flag=1
  644. }
  645. }
  646. $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }, { 'id': 4, 'name': '发布流程' }, { 'id': 5, 'name': '知识库模块' }, { 'id': 6, 'name': '资产模块' }, { 'id': 7, 'name': '系统管理模块' }]
  647. $scope.cancel = function() {
  648. $modalInstance.dismiss('cancel');
  649. };
  650. $scope.ok = function(role) {
  651. if(role.role&&role.remark){
  652. if (role.role) {
  653. var roledisable = false;
  654. for (var i = 0; i < scope.my_data.length; i++) {
  655. if (scope.my_data[i].role == role.role) {
  656. roledisable = true;
  657. break;
  658. }
  659. }
  660. if (!roledisable) {
  661. angular.extend(role, { 'roletype': '0' });
  662. if (role.model) {
  663. role.model = role.model.name;
  664. }
  665. var fildata = { loginUser: loginUser, role };
  666. $modalInstance.close(fildata);
  667. } else {
  668. SweetAlert.swal({
  669. title: "新增失败!",
  670. text: "该角色已存在",
  671. type: "error"
  672. })
  673. }
  674. } else {
  675. SweetAlert.swal({
  676. title: "新增失败!",
  677. text: "请填写角色名",
  678. type: "error"
  679. })
  680. }
  681. }else{
  682. SweetAlert.swal({
  683. title: "新增失败!",
  684. text: "请填写必填项",
  685. type: "error"
  686. })
  687. }
  688. }
  689. },
  690. resolve: {
  691. scope: function() {
  692. return $scope;
  693. }
  694. }
  695. });
  696. modalInstance.result.then(function(selectedItem) {
  697. if (selectedItem) {
  698. api_user_data.addData('role', selectedItem).then(function(response) {
  699. if (response) {
  700. if (response.status == 200) {
  701. SweetAlert.swal({
  702. title: "新增成功!",
  703. type: "success"
  704. }, function() {
  705. $scope.try_async_load();
  706. })
  707. } else {
  708. SweetAlert.swal({
  709. title: "新增失败!",
  710. type: "error"
  711. })
  712. }
  713. // $modalInstance.close();
  714. }
  715. })
  716. }
  717. })
  718. }
  719. // $scope.addRole = function(role) {
  720. // // $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
  721. // angular.extend(role, { 'roletype': '0' });
  722. // if (role.model) {
  723. // role.model = role.model.name;
  724. // }
  725. // var fildata = { loginUser: loginUser, role };
  726. // // var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } };
  727. // api_user_data.addData('role', fildata).then(function(response) {
  728. // if (response) {
  729. // if (response.status == 200) {
  730. // SweetAlert.swal({
  731. // title: "新增成功!",
  732. // type: "success"
  733. // }, function() {
  734. // $scope.try_async_load();
  735. // // $scope.refreshData('expand-right', defaultFilterData);
  736. // })
  737. // } else {
  738. // SweetAlert.swal({
  739. // title: "新增失败!",
  740. // type: "error"
  741. // })
  742. // }
  743. // // $modalInstance.close();
  744. // }
  745. // })
  746. // }
  747. //角色详情
  748. $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
  749. //change role
  750. $scope.changeIfEnableEdit=function(data){
  751. console.log(data);
  752. if(data){
  753. $scope.role.flag=0;
  754. $scope.flagSwitch=true
  755. }else{
  756. $scope.role.flag=1;
  757. $scope.flagSwitch=false
  758. }
  759. }
  760. $scope.changerole = function(role) {
  761. if($scope.role.id){
  762. if($scope.role.role&&$scope.role.remark){
  763. var model = "";
  764. if ($scope.role.model) {
  765. model = $scope.role.model.name
  766. }
  767. var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id,'menu':$scope.role.menu,'flag':$scope.role.flag, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } };
  768. api_user_data.addData('role', fildata).then(function(response) {
  769. if (response) {
  770. if (response.status == 200) {
  771. $scope.role={};
  772. SweetAlert.swal({
  773. title: "修改成功!",
  774. type: "success"
  775. }, function() {
  776. $scope.try_async_load();
  777. // $scope.refreshData('expand-right', defaultFilterData);
  778. })
  779. } else {
  780. SweetAlert.swal({
  781. title: "修改失败!",
  782. type: "error"
  783. })
  784. }
  785. // $modalInstance.close();
  786. }
  787. })
  788. }else{
  789. SweetAlert.swal({
  790. title: "修改失败!",
  791. text:"请填写必填项",
  792. type: "error"
  793. })
  794. }
  795. }else{
  796. SweetAlert.swal({
  797. title: "操作失败!",
  798. text:"请选择需要修改的角色",
  799. type: "error"
  800. })
  801. }
  802. }
  803. // })
  804. // }
  805. //change role
  806. $scope.changeRole = function() {
  807. var modalInstance = $modal.open({
  808. templateUrl: 'assets/views/system/tpl/addpower.html',
  809. controller: function($scope, scope, $modalInstance, api_user_data) {
  810. $scope.role = scope.role;
  811. $scope.cancel = function() {
  812. $modalInstance.dismiss('cancel');
  813. };
  814. $scope.ok = function(item) {
  815. var fildata = { loginUser: loginUser, 'role': { 'id': item.id, 'role': item.role, 'roletype': item.roletype } };
  816. $modalInstance.close(fildata);
  817. }
  818. },
  819. resolve: {
  820. scope: function() {
  821. return $scope;
  822. }
  823. }
  824. });
  825. modalInstance.result.then(function(selectedItem) {
  826. if (selectedItem) {
  827. api_user_data.addData('role', selectedItem).then(function(response) {
  828. if (response) {
  829. if (response.status == 200) {
  830. SweetAlert.swal({
  831. title: "修改成功!",
  832. type: "success"
  833. }, function() {
  834. $scope.try_async_load();
  835. // $scope.refreshData('expand-right', defaultFilterData);
  836. })
  837. } else {
  838. SweetAlert.swal({
  839. title: "修改失败!",
  840. type: "error"
  841. })
  842. }
  843. // $modalInstance.close();
  844. }
  845. })
  846. }
  847. })
  848. }
  849. //remove role
  850. $scope.removeRole = function() {
  851. if ($scope.role && $scope.role.roletype == 0) {
  852. var modalInstance = $modal.open({
  853. templateUrl: 'assets/views/delete.html',
  854. controller: function($scope, scope, $modalInstance) {
  855. var rmvList = [];
  856. // angular.forEach(scope.getbranchs, function(item) {
  857. // $scope.rmvList.push(item.id);
  858. // })
  859. rmvList.push(scope.role.id);
  860. $scope.ok = function() {
  861. $modalInstance.close(rmvList);
  862. };
  863. $scope.cancel = function() {
  864. $modalInstance.dismiss('cancel');
  865. };
  866. $scope.title = '角色删除';
  867. $scope.connect = '是否删除该角色'
  868. },
  869. size: 'sm',
  870. resolve: {
  871. scope: function() {
  872. return $scope;
  873. }
  874. }
  875. });
  876. modalInstance.result.then(function(selectedItem) {
  877. if (selectedItem) {
  878. if (selectedItem.length > 0) {
  879. api_user_data.rmvData('role', selectedItem).then(function(response) {
  880. if (response.data) {
  881. $scope.role={};
  882. SweetAlert.swal({
  883. title: "删除成功!",
  884. type: "success",
  885. confirmButtonColor: "#007AFF"
  886. }, function() {
  887. $scope.try_async_load();
  888. });
  889. } else {
  890. SweetAlert.swal({
  891. title: "操作异常!",
  892. text: "系统异常,请稍后重试,或者联系管理员!",
  893. type: "error"
  894. });
  895. }
  896. })
  897. }
  898. }
  899. })
  900. } else {
  901. SweetAlert.swal({
  902. title: "操作错误!",
  903. text: "该角色不能删除!",
  904. type: "error"
  905. });
  906. }
  907. }
  908. //仪表盘
  909. //查看仪表盘权限
  910. $scope.doing_asyncdash = true;
  911. $scope.dashboard_tree = [];
  912. // $scope.try_async_dashboard = function() {
  913. // api_user_data.fetchDataList("dashboard", { "idx": 0, "sum": 1000 }).then(function(response) {
  914. // if (response.status == 200) {
  915. // var data = response.list;
  916. // var objects = [];
  917. // for (var i = 0; i < data.length; i++) {
  918. // var object = {};
  919. // object.id = data[i].id;
  920. // object.label = data[i].name;
  921. // objects.push(object);
  922. // }
  923. // $scope.dashboard_tree = objects;
  924. // $scope.dashboard_data = angular.copy($scope.dashboard_tree);
  925. // if ($scope.dashboard_data.length > 0) {
  926. // $scope.doing_asyncdash = false;
  927. // }
  928. // } else {
  929. // SweetAlert.swal({
  930. // title: "系统错误!",
  931. // text: "请刷新重试!",
  932. // type: "error"
  933. // });
  934. // }
  935. // });
  936. // }
  937. // $scope.try_async_dashboard();
  938. $scope.formlist = {};
  939. $scope.formdashboard = function(branchData) {
  940. // $scope.formlist = {};
  941. $scope.formlist = branchData;
  942. }
  943. //修改仪表盘权限
  944. // var dashboard = [];
  945. $scope.changeDashboard = function() {
  946. var firldata = {};
  947. var dashboard = [];
  948. $rootScope.isMask = true;
  949. angular.forEach($scope.formlist, function(item) {
  950. dashboard.push({ 'id': item.id, 'name': item.label });
  951. })
  952. firldata = { 'dashboard': dashboard, 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'menu': $scope.role.menu }
  953. api_user_data.addData('role', { 'role': firldata }).then(function(response) {
  954. if (response && response.status == 200) {
  955. $scope.try_async_load();
  956. SweetAlert.swal({
  957. title: "提交成功!",
  958. type: "success",
  959. confirmButtonColor: "#007AFF"
  960. }, function() {
  961. $rootScope.isMask = false;
  962. // $scope.formlist = {}
  963. });
  964. } else {
  965. SweetAlert.swal({
  966. title: "系统错误",
  967. text: "系统错误,请稍后重试!",
  968. type: "error",
  969. confirmButtonColor: "#DD6B55"
  970. }, function() {
  971. $rootScope.isMask = false;
  972. });
  973. }
  974. })
  975. }
  976. }]);