12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001 |
- 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) {
- var loginUser = $rootScope.user;
- $scope.xinzeng=false;
- $scope.shanchu=false;
- $scope.bianji=false;
- $scope.fenpeiquanxian=false;
- // $scope.role={};
- // $scope.role.flag=1;
- for(var i=0;i<loginUser.menu.length;i++){
- if(loginUser.menu[i].link=="quanxianguanli_xinzeng"){
- $scope.xinzeng=true
- }
- if(loginUser.menu[i].link=="quanxianguanli_shanchu"){
- $scope.shanchu=true
- }
- if(loginUser.menu[i].link=="quanxianguanli_bianji"){
- $scope.bianji=true
- }
- if(loginUser.menu[i].link=="quanxianguanli_fenpeiquanxian"){
- $scope.fenpeiquanxian=true
- }
- }
- //user tree
- var apple_selected, tree, treedata_avm, treedata_geography;
- var i = 0;
- $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
- $(window).resize(function() {
- $scope.bodyHeight = Math.max((window.innerHeight - 290), 500);
- });
- $rootScope.isMask = false;
- //角色仪表权限
- function dashboardaborad(branch) {
- $scope.dashboard_tree = angular.copy($scope.dashboard_data);
- angular.forEach($scope.dashboard_tree, function(index, i) {
- if (branch.dashboard && branch.dashboard.length > 0) {
- angular.forEach(branch.dashboard, function(item) {
- if (index.id == item.id) {
- $scope.dashboard_tree[i].checks = true;
- }
- })
- }
- })
- }
- //角色树
- $scope.my_tree = {};
- $scope.my_power = {};
- $scope.try_async_load = function() {
- $scope.my_data = [];
- $scope.doing_async = true;
- api_user_data.fetchDataList('role', { "idx": 0, "sum": 1000 }).then(function(response) {
- if (response.status == 200) {
- var data = response.list;
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (data[i].parent && data[i].parent.id != 0) {
- object.parent = data[i].parent.id;
- }
- angular.extend(object, data[i]);
- object.label = object.role;
- if (loginUser.id == 1) {
- objects.push(object);
- } else {
- if (object.rolecode != "system_menus") {
- objects.push(object);
- }
- }
- }
- $scope.my_data = convertParentToChildList(objects);
- $scope.tree_data = angular.copy($scope.my_data);
- if ($scope.my_data.length > 0) {
- $scope.doing_async = false;
- }
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- // console.log("datum="+JSON.stringify(datum))
- if (typeof datum.parent === "undefined" || datum.parent === null) {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- parentNode = idToNodeMap[datum.parent.id];
- //We don't need this property, so let's delete it.
- // delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function(item) {
- list.push(item);
- });
- return list;
- }
- $scope.try_async_load();
- //end power
- //普通用户菜单权限
- $scope.try_async_powerload = function(items) {
- if (items) {
- $scope.getbranchs = items.menu;
- }
- // $scope.my_power = [];
- var objects = [];
- var selected = [];
- api_user_data.roleMenu(items.id).then(function(response) {
- console.log(response);
- // api_configure_data.fetchDataList('menu', { "idx": 0, "sum": 1000 }).then(function(response) {
- if (response.status == 200) {
- // //旧的树
- // var data = response.data;
- // var objects = [];
- // for (var i = 0; i < data.length; i++) {
- // var object = {};
- // object.id = data[i].id;
- // if (data[i].parent && data[i].parent.id != 0) {
- // object.parent = data[i].parent.id;
- // }
- // angular.extend(object, data[i]);
- // object.label = object.title;
- // objects.push(object);
- // }
- // selected = angular.copy($scope.tile);
- // $scope.my_power = angular.copy($scope.tree_power);
- // if (data.length > 0) {
- // angular.forEach(selected, function(index, i) {
- // angular.forEach(objects, function(item) {
- // if (index.id == item.id) {
- // selected[i].checks = true;
- // }
- // })
- // })
- // $scope.my_power = convertParentToChildList(selected);
- // } else {
- // $scope.my_power = convertParentToChildList($scope.tile);
- // }
- // if ($scope.my_power.length > 0) {
- // $scope.doing_asyncpower = false;
- // }
- // 新的树
- $scope.allPower_select=[];
- var data=response.data;
- for(var i=0;i<$scope.allPower.length;i++){
- $scope.allPower[i].biaoshi=false
- }
- $scope.allPower_select=$scope.allPower;
- for(var i=0;i<$scope.allPower_select.length;i++){
- for(var j=0;j<data.length;j++){
- if($scope.allPower_select[i].id==data[j].id){
- $scope.allPower_select[i].biaoshi=true
- }
- }
- }
- var objects = [];
- for (var i = 0; i < $scope.allPower_select.length; i++) {
- var object = {};
- object.id = $scope.allPower_select[i].id;
- if ($scope.allPower_select[i].parent && $scope.allPower_select[i].parent.id != 0) {
- object.parent = $scope.allPower_select[i].parent.id;
- }
- angular.extend(object, $scope.allPower_select[i]);
- object.label = object.title;
- objects.push(object);
- }
- $scope.tile = objects;
- $scope.my_power = convertParentToChildList(objects);
- $scope.tree_power = angular.copy($scope.my_power);
- if ($scope.my_data.length > 0) {
- $scope.doing_asyncpower = false;
- }
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- $scope.dianjiceshi=function(){
- console.log($scope.my_power);
- console.log($scope.allPower_select);
- }
- //普通用户底菜单权限
- $scope.allPower=[];
- $scope.my_power = [];
- $scope.tile = [];
- $scope.try_async_powerloadlow = function() {
- var objects = [];
- api_user_data.pageMenuByCode("system_menus").then(function(response) {
- if (response.status == 200) {
- var data = response.data;
- $scope.allPower= response.data;
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- data[i]["biaoshi"]=false;
- var object = {};
- object.id = data[i].id;
- if (data[i].parent && data[i].parent.id != 0) {
- object.parent = data[i].parent.id;
- }
- angular.extend(object, data[i]);
- object.label = object.title;
- objects.push(object);
- }
- $scope.tile = objects;
- $scope.my_power = convertParentToChildList(objects);
- $scope.tree_power = angular.copy($scope.my_power);
- if ($scope.my_data.length > 0) {
- $scope.doing_asyncpower = false;
- }
- console.log($scope.my_power)
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- // $scope.jry_AllPower=[];
- // $scope.getJry_AllPower=function(){
- // api_user_data.pageMenuByCode("system_menus").then(function(res) {
- // console.log(res.data);
- // $scope.jry_AllPower=res.data
- // })
- // }
- // $scope.getJry_AllPower()
- //管理员 底菜单
- $scope.try_async_powerloadadmin = function() {
- var objects = [];
- // api_conversation.pageMenuByCode("system_menus").then(function(response) {
- api_user_data.getMenu({}).then(function(response) {
- if (response.status == 200) {
- var data = response.data;
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (data[i].parent && data[i].parent.id != 0) {
- object.parent = data[i].parent.id;
- }
- angular.extend(object, data[i]);
- object.label = object.title;
- objects.push(object);
- }
- $scope.tile = objects;
- $scope.my_power = convertParentToChildList(objects);
- $scope.tree_power = angular.copy($scope.my_power);
- if ($scope.tree_power.length > 0) {
- $scope.doing_asyncpower = false;
- }
- } else {
- SweetAlert.swal({
- title: "系统错误!",
- text: "请刷新重试!",
- type: "error"
- });
- }
- });
- };
- //点击角色
- $scope.role = {};
- // $scope.role.flag=1;
- $scope.chaoguan=true;//超级管理员禁止修改判断
- $scope.flagSwitch=true;
- $scope.change = true;
- $scope.my_tree_handler = function(branch) {
- console.log(branch);
- if(branch.flag==0){
- $scope.flagSwitch=true
- }else{
- $scope.flagSwitch=false
- }
- if(branch.label=="超级管理员"){
- $scope.chaoguan=false
- }else{
- $scope.chaoguan=true
- }
- $scope.role = branch;
- for (var i = 0; i < $scope.roledetail.length; i++) {
- if ($scope.role.model == $scope.roledetail[i].name) {
- $scope.role.model = { 'id': $scope.roledetail[i].id, 'name': $scope.roledetail[i].name }
- }
- }
- $scope.formlist = branch.dashboard;
- dashboardaborad($scope.role);
- $scope.try_async_powerload(branch);
- $scope.change = false;
- }
- // if (loginUser.id == 1) {
- // $scope.try_async_powerloadadmin();
- // } else {
- $scope.try_async_powerloadlow();
- // }
- // $scope.try_async_powerloadadmin();
- // console.log(loginUser);
- //start remove
- $scope.getbranchs = {};
- $scope.formbranch = function(branchData) {
- $scope.getbranchs = branchData;
- }
- //change right
- $scope.selectAllBiaoshi=true;
- // 全选/反选
- $scope.allSelect=function(){
- if($scope.selectAllBiaoshi){
- for(var i=0;i<$scope.my_power.length;i++){
- $scope.my_power[i].biaoshi=true;
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- $scope.my_power[i].children[j].biaoshi=true
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- $scope.my_power[i].children[j].children[k].biaoshi=true
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
- }
- }
- }
- }
- }
- }
- }
- $scope.selectAllBiaoshi=false;
- }else{
- for(var i=0;i<$scope.my_power.length;i++){
- $scope.my_power[i].biaoshi=false;
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- $scope.my_power[i].children[j].biaoshi=false
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- $scope.my_power[i].children[j].children[k].biaoshi=false
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
- }
- }
- }
- }
- }
- }
- }
- $scope.selectAllBiaoshi=true;
- }
- }
- // 点击选项
- $scope.changeCheckBox1=function(data){
- console.log($scope.my_power);
- for(var i=0;i<$scope.my_power.length;i++){
- if(data.id === $scope.my_power[i].id){
- if(!$scope.my_power[i].biaoshi){
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- $scope.my_power[i].children[j].biaoshi=false
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- $scope.my_power[i].children[j].children[k].biaoshi=false
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
- }
- }
- }
- }
- }
- }
- }else{
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- $scope.my_power[i].children[j].biaoshi=true
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- $scope.my_power[i].children[j].children[k].biaoshi=true
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- $scope.my_power[i].children[j].children[k].children[l].biaoshi=true
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- $scope.changeCheckBox2=function(){
- for(var i=0;i<$scope.my_power.length;i++){
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- if(!$scope.my_power[i].children[j].biaoshi){
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- $scope.my_power[i].children[j].children[k].biaoshi=false
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
- }
- }
- }
- }
- }else{
- $scope.my_power[i].biaoshi=true
- }
- }
- }
- }
- }
- $scope.changeCheckBox3=function(){
- for(var i=0;i<$scope.my_power.length;i++){
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- if(!$scope.my_power[i].children[j].children[k].biaoshi){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- $scope.my_power[i].children[j].children[k].children[l].biaoshi=false
- }
- }else{
- $scope.my_power[i].biaoshi=true;
- $scope.my_power[i].children[j].biaoshi=true;
- }
- }
- }
- }
- }
- }
- }
- $scope.changeCheckBox4=function(){
- for(var i=0;i<$scope.my_power.length;i++){
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
- $scope.my_power[i].biaoshi=true;
- $scope.my_power[i].children[j].biaoshi=true;
- $scope.my_power[i].children[j].children[k].biaoshi=true;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- //修改权限
- $scope.changeData = function() {
- if($scope.role.id){
- var menu = [];
- $rootScope.isMask = true;
- // 旧的树
- // angular.forEach($scope.getbranchs, function(it) {
- // menu.push({ "id": it.id });
- // })
- // 新的树
- for(var i=0;i<$scope.my_power.length;i++){
- if($scope.my_power[i].biaoshi){
- menu.push({ "id": $scope.my_power[i].id });
- }
- if($scope.my_power[i].children){
- for(var j=0;j<$scope.my_power[i].children.length;j++){
- if($scope.my_power[i].children[j].biaoshi){
- menu.push({ "id": $scope.my_power[i].children[j].id });
- }
- if($scope.my_power[i].children[j].children){
- for(var k=0;k<$scope.my_power[i].children[j].children.length;k++){
- if($scope.my_power[i].children[j].children[k].biaoshi){
- menu.push({ "id": $scope.my_power[i].children[j].children[k].id });
- }
- if($scope.my_power[i].children[j].children[k].children){
- for(var l=0;l<$scope.my_power[i].children[j].children[k].children.length;l++){
- if($scope.my_power[i].children[j].children[k].children[l].biaoshi){
- menu.push({ "id": $scope.my_power[i].children[j].children[k].children[l].id });
- }
- }
- }
- }
- }
- }
- }
- }
- var branch = { 'menu': menu };
- 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 })
- // var modelData = {role: branch};
- api_user_data.addData('role', { 'role': branch }).then(function(response) {
- if (response && response.status == 200) {
- $scope.role={};
- SweetAlert.swal({
- title: "提交成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $rootScope.isMask = false;
- $scope.try_async_load();
- });
- } else {
- SweetAlert.swal({
- title: "系统错误",
- text: "系统错误,请稍后重试!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- }, function() {
- $rootScope.isMask = false;
- });
- }
- })
- }else{
- SweetAlert.swal({
- title: "操作失败",
- text: "请选择需要修改的角色!",
- type: "error",
- })
- }
-
- // $state.go('app.system.form',{formKey:'system_add_menu', service:'api_configure_data', model : JSON.stringify(modelData)});
- }
- //新增角色
- // $scope.addData = function() {
- // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data' });
- // }
- //change menu
- // $scope.choiceMenu = [];
- // $scope.showHandler = function(branch) {
- // $scope.choiceMenu = branch;
- // }
- // $scope.changeMenu = function() {
- // // if ($scope.choiceMenu && $scope.choiceMenu != null) {
- // // }
- // api_configure_data.fetchDataById('menu', $scope.choiceMenu.id).then(function(response) {
- // if (response.status == 200) {
- // if (response.data.link != null) {
- // response.data.type = "link";
- // } else if (response.data.service) {
- // response.data.type = "service";
- // } else if (response.data.event) {
- // response.data.type = "event";
- // }
- // response.data['menu'] = { parent: response.data.parent };
- // var modelData = { model: response.data }
- // $state.go('app.system.form', { formKey: 'system_add_menu', service: 'api_configure_data', model: JSON.stringify(modelData) });
- // }
- // })
- // }
- //remove menu
- $scope.removeData = function() {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function($scope, scope, $modalInstance) {
- $scope.rmvList = [];
- angular.forEach(scope.getbranchs, function(item) {
- $scope.rmvList.push(item.id);
- })
- $scope.ok = function() {
- $modalInstance.close($scope.rmvList);
- };
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- },
- size: 'sm',
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- if (selectedItem.length > 0) {
- api_configure_data.rmvData('menu', selectedItem).then(function(response) {
- if (response.data) {
- SweetAlert.swal({
- title: "删除成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- if (loginUser.id == 1) {
- $scope.try_async_powerloadadmin();
- } else {
- $scope.try_async_powerload();
- }
- });
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error"
- });
- }
- })
- }
- }
- })
- }
- //add role
- $scope.addRole = function() {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/addpower.html',
- controller: function($scope, scope, $modalInstance, api_user_data) {
- $scope.role={
- "role":"",
- "remark":"",
- "flag":0
- }
- $scope.addSwitch=true;
- $scope.addSwitchChange=function(data){
- console.log(data);
- if(data==true){
- $scope.role.flag=0
- }else{
- $scope.role.flag=1
- }
- }
- $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }, { 'id': 4, 'name': '发布流程' }, { 'id': 5, 'name': '知识库模块' }, { 'id': 6, 'name': '资产模块' }, { 'id': 7, 'name': '系统管理模块' }]
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function(role) {
- if(role.role&&role.remark){
- if (role.role) {
- var roledisable = false;
- for (var i = 0; i < scope.my_data.length; i++) {
- if (scope.my_data[i].role == role.role) {
- roledisable = true;
- break;
- }
- }
- if (!roledisable) {
- angular.extend(role, { 'roletype': '0' });
- if (role.model) {
- role.model = role.model.name;
- }
- var fildata = { loginUser: loginUser, role };
- $modalInstance.close(fildata);
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- text: "该角色已存在",
- type: "error"
- })
- }
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- text: "请填写角色名",
- type: "error"
- })
- }
- }else{
- SweetAlert.swal({
- title: "新增失败!",
- text: "请填写必填项",
- type: "error"
- })
- }
- }
- },
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- api_user_data.addData('role', selectedItem).then(function(response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "新增成功!",
- type: "success"
- }, function() {
- $scope.try_async_load();
- })
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- type: "error"
- })
- }
- // $modalInstance.close();
- }
- })
- }
- })
- }
- // $scope.addRole = function(role) {
- // // $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
- // angular.extend(role, { 'roletype': '0' });
- // if (role.model) {
- // role.model = role.model.name;
- // }
- // var fildata = { loginUser: loginUser, role };
- // // var fildata = { loginUser: loginUser, 'role': { 'id': $scope.role.id, 'role': $scope.role.role, 'roletype': $scope.role.roletype, 'model': model, 'remark': $scope.role.remark } };
- // api_user_data.addData('role', fildata).then(function(response) {
- // if (response) {
- // if (response.status == 200) {
- // SweetAlert.swal({
- // title: "新增成功!",
- // type: "success"
- // }, function() {
- // $scope.try_async_load();
- // // $scope.refreshData('expand-right', defaultFilterData);
- // })
- // } else {
- // SweetAlert.swal({
- // title: "新增失败!",
- // type: "error"
- // })
- // }
- // // $modalInstance.close();
- // }
- // })
- // }
- //角色详情
- $scope.roledetail = [{ 'id': 1, 'name': '事件流程' }, { 'id': 2, 'name': '问题流程' }, { 'id': 3, 'name': '变更流程' }]
- //change role
- $scope.changeIfEnableEdit=function(data){
- console.log(data);
- if(data){
- $scope.role.flag=0;
- $scope.flagSwitch=true
- }else{
- $scope.role.flag=1;
- $scope.flagSwitch=false
- }
- }
- $scope.changerole = function(role) {
- if($scope.role.id){
- if($scope.role.role&&$scope.role.remark){
- var model = "";
- if ($scope.role.model) {
- model = $scope.role.model.name
- }
- 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 } };
- api_user_data.addData('role', fildata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- $scope.role={};
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function() {
- $scope.try_async_load();
- // $scope.refreshData('expand-right', defaultFilterData);
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- type: "error"
- })
- }
- // $modalInstance.close();
- }
- })
- }else{
- SweetAlert.swal({
- title: "修改失败!",
- text:"请填写必填项",
- type: "error"
- })
- }
- }else{
- SweetAlert.swal({
- title: "操作失败!",
- text:"请选择需要修改的角色",
- type: "error"
- })
- }
-
- }
- // })
- // }
- //change role
- $scope.changeRole = function() {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/addpower.html',
- controller: function($scope, scope, $modalInstance, api_user_data) {
- $scope.role = scope.role;
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.ok = function(item) {
- var fildata = { loginUser: loginUser, 'role': { 'id': item.id, 'role': item.role, 'roletype': item.roletype } };
- $modalInstance.close(fildata);
- }
- },
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- api_user_data.addData('role', selectedItem).then(function(response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function() {
- $scope.try_async_load();
- // $scope.refreshData('expand-right', defaultFilterData);
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- type: "error"
- })
- }
- // $modalInstance.close();
- }
- })
- }
- })
- }
- //remove role
- $scope.removeRole = function() {
- if ($scope.role && $scope.role.roletype == 0) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function($scope, scope, $modalInstance) {
- var rmvList = [];
- // angular.forEach(scope.getbranchs, function(item) {
- // $scope.rmvList.push(item.id);
- // })
- rmvList.push(scope.role.id);
- $scope.ok = function() {
- $modalInstance.close(rmvList);
- };
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.title = '角色删除';
- $scope.connect = '是否删除该角色'
- },
- size: 'sm',
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- if (selectedItem.length > 0) {
- api_user_data.rmvData('role', selectedItem).then(function(response) {
- if (response.data) {
- $scope.role={};
- SweetAlert.swal({
- title: "删除成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $scope.try_async_load();
- });
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error"
- });
- }
- })
- }
- }
- })
- } else {
- SweetAlert.swal({
- title: "操作错误!",
- text: "该角色不能删除!",
- type: "error"
- });
- }
- }
- //仪表盘
- //查看仪表盘权限
- $scope.doing_asyncdash = true;
- $scope.dashboard_tree = [];
- // $scope.try_async_dashboard = function() {
- // api_user_data.fetchDataList("dashboard", { "idx": 0, "sum": 1000 }).then(function(response) {
- // if (response.status == 200) {
- // var data = response.list;
- // var objects = [];
- // for (var i = 0; i < data.length; i++) {
- // var object = {};
- // object.id = data[i].id;
- // object.label = data[i].name;
- // objects.push(object);
- // }
- // $scope.dashboard_tree = objects;
- // $scope.dashboard_data = angular.copy($scope.dashboard_tree);
- // if ($scope.dashboard_data.length > 0) {
- // $scope.doing_asyncdash = false;
- // }
- // } else {
- // SweetAlert.swal({
- // title: "系统错误!",
- // text: "请刷新重试!",
- // type: "error"
- // });
- // }
- // });
- // }
- // $scope.try_async_dashboard();
- $scope.formlist = {};
- $scope.formdashboard = function(branchData) {
- // $scope.formlist = {};
- $scope.formlist = branchData;
- }
- //修改仪表盘权限
- // var dashboard = [];
- $scope.changeDashboard = function() {
- var firldata = {};
- var dashboard = [];
- $rootScope.isMask = true;
- angular.forEach($scope.formlist, function(item) {
- dashboard.push({ 'id': item.id, 'name': item.label });
- })
- firldata = { 'dashboard': dashboard, 'id': $scope.role.id, 'role': $scope.role.role, 'rolecode': $scope.role.rolecode, 'roletype': $scope.role.roletype, 'menu': $scope.role.menu }
- api_user_data.addData('role', { 'role': firldata }).then(function(response) {
- if (response && response.status == 200) {
- $scope.try_async_load();
- SweetAlert.swal({
- title: "提交成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $rootScope.isMask = false;
- // $scope.formlist = {}
- });
- } else {
- SweetAlert.swal({
- title: "系统错误",
- text: "系统错误,请稍后重试!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- }, function() {
- $rootScope.isMask = false;
- });
- }
- })
- }
- }]);
|