powerCtrl.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  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(!$scope.my_power[i].biaoshi){
  380. if($scope.my_power[i].children){
  381. for(var j=0;j<$scope.my_power[i].children.length;j++){
  382. $scope.my_power[i].children[j].biaoshi=false
  383. if($scope.my_power[i].children[j].children){
  384. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  385. $scope.my_power[i].children[j].children[k].biaoshi=false
  386. if($scope.my_power[i].children[j].children[k].children){
  387. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  388. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }else{
  396. if($scope.my_power[i].children){
  397. for(var j=0;j<$scope.my_power[i].children.length;j++){
  398. $scope.my_power[i].children[j].biaoshi=true
  399. if($scope.my_power[i].children[j].children){
  400. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  401. $scope.my_power[i].children[j].children[k].biaoshi=true
  402. if($scope.my_power[i].children[j].children[k].children){
  403. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  404. $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. $scope.changeCheckBox2=function(){
  415. for(var i=0;i<$scope.my_power.length;i++){
  416. if($scope.my_power[i].children){
  417. for(var j=0;j<$scope.my_power[i].children.length;j++){
  418. if(!$scope.my_power[i].children[j].biaoshi){
  419. if($scope.my_power[i].children[j].children){
  420. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  421. $scope.my_power[i].children[j].children[k].biaoshi=false
  422. if($scope.my_power[i].children[j].children[k].children){
  423. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  424. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  425. }
  426. }
  427. }
  428. }
  429. }else{
  430. $scope.my_power[i].biaoshi=true
  431. }
  432. }
  433. }
  434. }
  435. }
  436. $scope.changeCheckBox3=function(){
  437. for(var i=0;i<$scope.my_power.length;i++){
  438. if($scope.my_power[i].children){
  439. for(var j=0;j<$scope.my_power[i].children.length;j++){
  440. if($scope.my_power[i].children[j].children){
  441. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  442. if(!$scope.my_power[i].children[j].children[k].biaoshi){
  443. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  444. $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
  445. }
  446. }else{
  447. $scope.my_power[i].biaoshi=true;
  448. $scope.my_power[i].children[j].biaoshi=true;
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. }
  456. $scope.changeCheckBox4=function(){
  457. for(var i=0;i<$scope.my_power.length;i++){
  458. if($scope.my_power[i].children){
  459. for(var j=0;j<$scope.my_power[i].children.length;j++){
  460. if($scope.my_power[i].children[j].children){
  461. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  462. if($scope.my_power[i].children[j].children[k].children){
  463. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  464. if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
  465. $scope.my_power[i].biaoshi=true;
  466. $scope.my_power[i].children[j].biaoshi=true;
  467. $scope.my_power[i].children[j].children[k].biaoshi=true;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. //修改权限
  478. $scope.changeData = function() {
  479. if($scope.role.id){
  480. var menu = [];
  481. $rootScope.isMask = true;
  482. // 旧的树
  483. // angular.forEach($scope.getbranchs, function(it) {
  484. // menu.push({ "id": it.id });
  485. // })
  486. // 新的树
  487. for(var i=0;i<$scope.my_power.length;i++){
  488. if($scope.my_power[i].biaoshi){
  489. menu.push({ "id": $scope.my_power[i].id });
  490. }
  491. if($scope.my_power[i].children){
  492. for(var j=0;j<$scope.my_power[i].children.length;j++){
  493. if($scope.my_power[i].children[j].biaoshi){
  494. menu.push({ "id": $scope.my_power[i].children[j].id });
  495. }
  496. if($scope.my_power[i].children[j].children){
  497. for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
  498. if($scope.my_power[i].children[j].children[k].biaoshi){
  499. menu.push({ "id": $scope.my_power[i].children[j].children[k].id });
  500. }
  501. if($scope.my_power[i].children[j].children[k].children){
  502. for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
  503. if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
  504. menu.push({ "id": $scope.my_power[i].children[j].children[k].children[l].id });
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. var branch = { 'menu': menu };
  514. 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 })
  515. // var modelData = {role: branch};
  516. api_user_data.addData('role', { 'role': branch }).then(function(response) {
  517. if (response && response.status == 200) {
  518. $scope.role={};
  519. SweetAlert.swal({
  520. title: "提交成功!",
  521. type: "success",
  522. confirmButtonColor: "#007AFF"
  523. }, function() {
  524. $rootScope.isMask = false;
  525. $scope.try_async_load();
  526. });
  527. } else {
  528. SweetAlert.swal({
  529. title: "系统错误",
  530. text: "系统错误,请稍后重试!",
  531. type: "error",
  532. confirmButtonColor: "#DD6B55"
  533. }, function() {
  534. $rootScope.isMask = false;
  535. });
  536. }
  537. })
  538. }else{
  539. SweetAlert.swal({
  540. title: "操作失败",
  541. text: "请选择需要修改的角色!",
  542. type: "error",
  543. })
  544. }
  545. // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
  546. }
  547. //新增角色
  548. // $scope.addData = function() {
  549. // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data' });
  550. // }
  551. //change menu
  552. // $scope.choiceMenu = [];
  553. // $scope.showHandler = function(branch) {
  554. // $scope.choiceMenu = branch;
  555. // }
  556. // $scope.changeMenu = function() {
  557. // // if ($scope.choiceMenu && $scope.choiceMenu != null) {
  558. // // }
  559. // api_configure_data.fetchDataById('menu', $scope.choiceMenu.id).then(function(response) {
  560. // if (response.status == 200) {
  561. // if (response.data.link != null) {
  562. // response.data.type = "link";
  563. // } else if (response.data.service) {
  564. // response.data.type = "service";
  565. // } else if (response.data.event) {
  566. // response.data.type = "event";
  567. // }
  568. // response.data['menu'] = { parent: response.data.parent };
  569. // var modelData = { model: response.data }
  570. // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data', model: JSON.stringify(modelData) });
  571. // }
  572. // })
  573. // }
  574. //remove menu
  575. $scope.removeData = function() {
  576. var modalInstance = $modal.open({
  577. templateUrl: 'assets/views/delete.html',
  578. controller: function($scope, scope, $modalInstance) {
  579. $scope.rmvList = [];
  580. angular.forEach(scope.getbranchs, function(item) {
  581. $scope.rmvList.push(item.id);
  582. })
  583. $scope.ok = function() {
  584. $modalInstance.close($scope.rmvList);
  585. };
  586. $scope.cancel = function() {
  587. $modalInstance.dismiss('cancel');
  588. };
  589. },
  590. size: 'sm',
  591. resolve: {
  592. scope: function() {
  593. return $scope;
  594. }
  595. }
  596. });
  597. modalInstance.result.then(function(selectedItem) {
  598. if (selectedItem) {
  599. if (selectedItem.length > 0) {
  600. api_configure_data.rmvData('menu', selectedItem).then(function(response) {
  601. if (response.data) {
  602. SweetAlert.swal({
  603. title: "删除成功!",
  604. type: "success",
  605. confirmButtonColor: "#007AFF"
  606. }, function() {
  607. if (loginUser.id == 1) {
  608. $scope.try_async_powerloadadmin();
  609. } else {
  610. $scope.try_async_powerload();
  611. }
  612. });
  613. } else {
  614. SweetAlert.swal({
  615. title: "操作异常!",
  616. text: "系统异常,请稍后重试,或者联系管理员!",
  617. type: "error"
  618. });
  619. }
  620. })
  621. }
  622. }
  623. })
  624. }
  625. //add role
  626. $scope.addRole = function() {
  627. var modalInstance = $modal.open({
  628. templateUrl: 'assets/views/system/tpl/addpower.html',
  629. controller: function($scope, scope, $modalInstance, api_user_data) {
  630. $scope.role={
  631. "role":"",
  632. "remark":"",
  633. "flag":0
  634. }
  635. $scope.addSwitch=true;
  636. $scope.addSwitchChange=function(data){
  637. console.log(data);
  638. if(data==true){
  639. $scope.role.flag=0
  640. }else{
  641. $scope.role.flag=1
  642. }
  643. }
  644. $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }, { 'id': 4, 'name': '发布流程' }, { 'id': 5, 'name': '知识库模块' }, { 'id': 6, 'name': '资产模块' }, { 'id': 7, 'name': '系统管理模块' }]
  645. $scope.cancel = function() {
  646. $modalInstance.dismiss('cancel');
  647. };
  648. $scope.ok = function(role) {
  649. if(role.role&&role.remark){
  650. if (role.role) {
  651. var roledisable = false;
  652. for (var i = 0; i < scope.my_data.length; i++) {
  653. if (scope.my_data[i].role == role.role) {
  654. roledisable = true;
  655. break;
  656. }
  657. }
  658. if (!roledisable) {
  659. angular.extend(role, { 'roletype': '0' });
  660. if (role.model) {
  661. role.model = role.model.name;
  662. }
  663. var fildata = { loginUser: loginUser, role };
  664. $modalInstance.close(fildata);
  665. } else {
  666. SweetAlert.swal({
  667. title: "新增失败!",
  668. text: "该角色已存在",
  669. type: "error"
  670. })
  671. }
  672. } else {
  673. SweetAlert.swal({
  674. title: "新增失败!",
  675. text: "请填写角色名",
  676. type: "error"
  677. })
  678. }
  679. }else{
  680. SweetAlert.swal({
  681. title: "新增失败!",
  682. text: "请填写必填项",
  683. type: "error"
  684. })
  685. }
  686. }
  687. },
  688. resolve: {
  689. scope: function() {
  690. return $scope;
  691. }
  692. }
  693. });
  694. modalInstance.result.then(function(selectedItem) {
  695. if (selectedItem) {
  696. api_user_data.addData('role', selectedItem).then(function(response) {
  697. if (response) {
  698. if (response.status == 200) {
  699. SweetAlert.swal({
  700. title: "新增成功!",
  701. type: "success"
  702. }, function() {
  703. $scope.try_async_load();
  704. })
  705. } else {
  706. SweetAlert.swal({
  707. title: "新增失败!",
  708. type: "error"
  709. })
  710. }
  711. // $modalInstance.close();
  712. }
  713. })
  714. }
  715. })
  716. }
  717. // $scope.addRole = function(role) {
  718. // // $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
  719. // angular.extend(role, { 'roletype': '0' });
  720. // if (role.model) {
  721. // role.model = role.model.name;
  722. // }
  723. // var fildata = { loginUser: loginUser, role };
  724. // // var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } };
  725. // api_user_data.addData('role', fildata).then(function(response) {
  726. // if (response) {
  727. // if (response.status == 200) {
  728. // SweetAlert.swal({
  729. // title: "新增成功!",
  730. // type: "success"
  731. // }, function() {
  732. // $scope.try_async_load();
  733. // // $scope.refreshData('expand-right', defaultFilterData);
  734. // })
  735. // } else {
  736. // SweetAlert.swal({
  737. // title: "新增失败!",
  738. // type: "error"
  739. // })
  740. // }
  741. // // $modalInstance.close();
  742. // }
  743. // })
  744. // }
  745. //角色详情
  746. $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
  747. //change role
  748. $scope.changeIfEnableEdit=function(data){
  749. console.log(data);
  750. if(data){
  751. $scope.role.flag=0;
  752. $scope.flagSwitch=true
  753. }else{
  754. $scope.role.flag=1;
  755. $scope.flagSwitch=false
  756. }
  757. }
  758. $scope.changerole = function(role) {
  759. if($scope.role.id){
  760. if($scope.role.role&&$scope.role.remark){
  761. var model = "";
  762. if ($scope.role.model) {
  763. model = $scope.role.model.name
  764. }
  765. 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 } };
  766. api_user_data.addData('role', fildata).then(function(response) {
  767. if (response) {
  768. if (response.status == 200) {
  769. $scope.role={};
  770. SweetAlert.swal({
  771. title: "修改成功!",
  772. type: "success"
  773. }, function() {
  774. $scope.try_async_load();
  775. // $scope.refreshData('expand-right', defaultFilterData);
  776. })
  777. } else {
  778. SweetAlert.swal({
  779. title: "修改失败!",
  780. type: "error"
  781. })
  782. }
  783. // $modalInstance.close();
  784. }
  785. })
  786. }else{
  787. SweetAlert.swal({
  788. title: "修改失败!",
  789. text:"请填写必填项",
  790. type: "error"
  791. })
  792. }
  793. }else{
  794. SweetAlert.swal({
  795. title: "操作失败!",
  796. text:"请选择需要修改的角色",
  797. type: "error"
  798. })
  799. }
  800. }
  801. // })
  802. // }
  803. //change role
  804. $scope.changeRole = function() {
  805. var modalInstance = $modal.open({
  806. templateUrl: 'assets/views/system/tpl/addpower.html',
  807. controller: function($scope, scope, $modalInstance, api_user_data) {
  808. $scope.role = scope.role;
  809. $scope.cancel = function() {
  810. $modalInstance.dismiss('cancel');
  811. };
  812. $scope.ok = function(item) {
  813. var fildata = { loginUser: loginUser, 'role': { 'id': item.id, 'role': item.role, 'roletype': item.roletype } };
  814. $modalInstance.close(fildata);
  815. }
  816. },
  817. resolve: {
  818. scope: function() {
  819. return $scope;
  820. }
  821. }
  822. });
  823. modalInstance.result.then(function(selectedItem) {
  824. if (selectedItem) {
  825. api_user_data.addData('role', selectedItem).then(function(response) {
  826. if (response) {
  827. if (response.status == 200) {
  828. SweetAlert.swal({
  829. title: "修改成功!",
  830. type: "success"
  831. }, function() {
  832. $scope.try_async_load();
  833. // $scope.refreshData('expand-right', defaultFilterData);
  834. })
  835. } else {
  836. SweetAlert.swal({
  837. title: "修改失败!",
  838. type: "error"
  839. })
  840. }
  841. // $modalInstance.close();
  842. }
  843. })
  844. }
  845. })
  846. }
  847. //remove role
  848. $scope.removeRole = function() {
  849. if ($scope.role && $scope.role.roletype == 0) {
  850. var modalInstance = $modal.open({
  851. templateUrl: 'assets/views/delete.html',
  852. controller: function($scope, scope, $modalInstance) {
  853. var rmvList = [];
  854. // angular.forEach(scope.getbranchs, function(item) {
  855. // $scope.rmvList.push(item.id);
  856. // })
  857. rmvList.push(scope.role.id);
  858. $scope.ok = function() {
  859. $modalInstance.close(rmvList);
  860. };
  861. $scope.cancel = function() {
  862. $modalInstance.dismiss('cancel');
  863. };
  864. $scope.title = '角色删除';
  865. $scope.connect = '是否删除该角色'
  866. },
  867. size: 'sm',
  868. resolve: {
  869. scope: function() {
  870. return $scope;
  871. }
  872. }
  873. });
  874. modalInstance.result.then(function(selectedItem) {
  875. if (selectedItem) {
  876. if (selectedItem.length > 0) {
  877. api_user_data.rmvData('role', selectedItem).then(function(response) {
  878. if (response.data) {
  879. $scope.role={};
  880. SweetAlert.swal({
  881. title: "删除成功!",
  882. type: "success",
  883. confirmButtonColor: "#007AFF"
  884. }, function() {
  885. $scope.try_async_load();
  886. });
  887. } else {
  888. SweetAlert.swal({
  889. title: "操作异常!",
  890. text: "系统异常,请稍后重试,或者联系管理员!",
  891. type: "error"
  892. });
  893. }
  894. })
  895. }
  896. }
  897. })
  898. } else {
  899. SweetAlert.swal({
  900. title: "操作错误!",
  901. text: "该角色不能删除!",
  902. type: "error"
  903. });
  904. }
  905. }
  906. //仪表盘
  907. //查看仪表盘权限
  908. $scope.doing_asyncdash = true;
  909. $scope.dashboard_tree = [];
  910. // $scope.try_async_dashboard = function() {
  911. // api_user_data.fetchDataList("dashboard", { "idx": 0, "sum": 1000 }).then(function(response) {
  912. // if (response.status == 200) {
  913. // var data = response.list;
  914. // var objects = [];
  915. // for (var i = 0; i < data.length; i++) {
  916. // var object = {};
  917. // object.id = data[i].id;
  918. // object.label = data[i].name;
  919. // objects.push(object);
  920. // }
  921. // $scope.dashboard_tree = objects;
  922. // $scope.dashboard_data = angular.copy($scope.dashboard_tree);
  923. // if ($scope.dashboard_data.length > 0) {
  924. // $scope.doing_asyncdash = false;
  925. // }
  926. // } else {
  927. // SweetAlert.swal({
  928. // title: "系统错误!",
  929. // text: "请刷新重试!",
  930. // type: "error"
  931. // });
  932. // }
  933. // });
  934. // }
  935. // $scope.try_async_dashboard();
  936. $scope.formlist = {};
  937. $scope.formdashboard = function(branchData) {
  938. // $scope.formlist = {};
  939. $scope.formlist = branchData;
  940. }
  941. //修改仪表盘权限
  942. // var dashboard = [];
  943. $scope.changeDashboard = function() {
  944. var firldata = {};
  945. var dashboard = [];
  946. $rootScope.isMask = true;
  947. angular.forEach($scope.formlist, function(item) {
  948. dashboard.push({ 'id': item.id, 'name': item.label });
  949. })
  950. firldata = { 'dashboard': dashboard, 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'menu': $scope.role.menu }
  951. api_user_data.addData('role', { 'role': firldata }).then(function(response) {
  952. if (response && response.status == 200) {
  953. $scope.try_async_load();
  954. SweetAlert.swal({
  955. title: "提交成功!",
  956. type: "success",
  957. confirmButtonColor: "#007AFF"
  958. }, function() {
  959. $rootScope.isMask = false;
  960. // $scope.formlist = {}
  961. });
  962. } else {
  963. SweetAlert.swal({
  964. title: "系统错误",
  965. text: "系统错误,请稍后重试!",
  966. type: "error",
  967. confirmButtonColor: "#DD6B55"
  968. }, function() {
  969. $rootScope.isMask = false;
  970. });
  971. }
  972. })
  973. }
  974. }]);