123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999 |
- 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(!$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;
- });
- }
- })
- }
- }]);
|