123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- (function () {
- var app = angular.module('devself.common');
- app.controller("MenuManageCtrl", function ($scope, $http, $alert, $modal, AuthUser, $state, $loading,$bsRouterState) {
- $scope.title = '菜单管理';
- $state.params=$bsRouterState.$params($scope);
- //分页设置
- $scope.selectdata = {pageindex: 1, pagesize: 10, ptotal: 0};
- $scope.hasPermission = {
- show: true
- };
- //当前用户获取
- //test url要加上?uid=1121131017
- $scope.user = AuthUser.getUser();
- //选择的菜单名称
- $scope.MenuName = '';
- //选择的菜单编号
- $scope.MenuNo = '';
- //所有的菜单记录
- $scope.menuLists = [];
- $scope.curMenuID = "";
- //加载所有的父菜单记录
- $scope.getMenuList = function () {
- $loading.show();
- $http.get("../../api/menumanage/alltopparentmenus", {
- params: {
- 'menuname': $scope.MenuName,
- 'menuno': $scope.MenuNo,
- appid: $state.params.appid
- }
- }).then(function (value) {
- $scope.menuLists = value.data.item;
- $scope.updatePDutyList();
- $loading.hide();
- }, function (reason) {
- $loading.hide();
- console.log(reason);
- });
- };
- //查询对应菜单数据
- $scope.searchMenu = function () {
- $scope.getMenuList();
- /*
- $http.get("../../api/menumanage/getmenulists", { params: { 'MenuName': $scope.MenuName, 'MenuNo': $scope.MenuNo, 'appid': $state.params.appid } }).then(function (result) {
- $scope.menuLists = result.data.item;
- $scope.updatePDutyList();
- }, function () {
- console.log("无匹配条件数据");
- });*/
- };
- //加载子菜单
- $scope.loadChildMenu = function (item) {
- $scope.searchParam = "";//查询条件清空
- if (!item.isExpand)//如果该节点未展开
- {
- item.isExpand = true;
- $scope.getMenuByParentID(item);
- } else {
- item.isExpand = false;
- }
- };
- //根据当前项的menuID找到其所有的子菜单
- $scope.getMenuByParentID = function (item) {
- $http.get("../../api/menumanage/childmenubyparentid", {
- params: {
- 'parentid': item.menuid,
- 'appid': $state.params.appid
- }
- }).then(function (result) {
- item.childMenus = result.data.item;
- }, function () {
- console.log("无匹配项");
- });
- };
- $scope.getMenuList();
- //页面数据更新
- $scope.updatePDutyList = function () {
- $scope.tempMenu = [];
- $scope.selectdata.ptotal = $scope.menuLists.length;
- var firstLength = ($scope.selectdata.pageindex - 1) * $scope.selectdata.pagesize;
- var lastLength = ($scope.selectdata.pageindex * $scope.selectdata.pagesize) < $scope.selectdata.ptotal ?
- ($scope.selectdata.pageindex * $scope.selectdata.pagesize) : $scope.selectdata.ptotal;
- for (var i = firstLength; i < lastLength; i++) {
- $scope.tempMenu.push($scope.menuLists[i]);
- }
- };
- //监视页数变化
- $scope.$watch("selectdata.pageindex", function (newVal, oldVal) {
- $scope.updatePDutyList();
- });
- //删除选中菜单项
- $scope.delete = function (item) {
- $http.get("../../api/menumanage/childmenubyparentid", {
- params: {
- 'parentid': item.menuid,
- 'appid': $state.params.appid
- }
- }).then(function (result) {
- if (result.data.item.length > 0) {
- $alert({content: '有子菜单项不能删除!', type: 'info', placement: 'top', show: true, duration: 3});
- } else {
- if (!confirm("确认删除?")) {
- return;
- }
- $http.get("../../api/menumanage/deletemenubyid", {params: {'menuid': item.menuid}}).then(function (result) {
- $scope.getMenuList();
- $scope.showalert(result.data.msg);
- }, function () {
- console.log("无匹配项");
- });
- }
- }, function () {
- console.log("无匹配项");
- });
- };
- var MyModalController = function ($scope, $http) {
- $scope.edit = {
- menuParentName: "",
- menuParentId: ""
- };
- $scope.title = "菜单信息";
- $scope.menu = $scope.data;
- $scope.edit.menuParentId = $scope.menu.parentmenuid;
- $scope.selectParent = function () {
- if ($scope.hasPermission.show) {
- myselectModal.$promise.then(myselectModal.show);
- }
- };
- //获取原父级菜单
- $scope.getParentName = function () {
- if ($scope.menu.parentmenuid == null || $scope.menu.parentmenuid == "") {
- $scope.edit.menuParentName = "顶层菜单";
- } else {
- $http.get("../../api/menumanage/findmenubymenuid", {params: {'menuid': $scope.menu.parentmenuid}}).then(function (result) {
- $scope.edit.menuParentName = result.data.item.menuname;
- }, function () {
- console.log("无匹配项");
- });
- }
- };
- $scope.getParentName();
- //加载所有的父菜单记录
- var selecModalController = function ($scope, $http) {
- //加载所有的父菜单记录
- $scope.getMenus = function () {
- $.ajax({
- url: "../../api/menumanage/alltopparentmenus",
- data: {appid: $state.params.appid, menuname: '', menuno: ''},
- type: 'get',
- contentType: 'application/json',
- success: function (res) {
- $scope.$apply(function () {
- $scope.selectMenus = res.item;
- })
- },
- error: function (res) {
- console.log(res);
- }
- });
- };
- //加载子菜单
- $scope.loadChild = function (item) {
- if (!item.isExpand)//如果该节点未展开
- {
- item.isExpand = true;
- $scope.getMenuByPID(item);
- } else {
- item.isExpand = false;
- }
- };
- //根据当前项的menuID找到其所有的子菜单
- $scope.getMenuByPID = function (item) {
- $http.get("../../api/menumanage/childmenubyparentid", {
- params: {
- 'parentid': item.menuid,
- 'appid': $state.params.appid
- }
- }).then(function (result) {
- item.childs = result.data.item;
- }, function () {
- console.log("无匹配项");
- });
- };
- $scope.getMenus();
- $scope.changeChoose = function (item) {
- if ($scope.curMenuID != item.menuid) {
- $scope.curMenuID = item.menuid;
- if (item.isleaf == false) {
- $scope.FinalmenuParentName = item.menuname;
- $scope.FinalmenuParentId = item.menuid;
- } else {
- $scope.FinalmenuParentName = "";
- $scope.FinalmenuParentId = null;
- $alert({
- title: '提示:',
- content: "不能选择叶节点作为父级菜单",
- placement: 'top',
- type: 'info',
- show: true,
- duration: 3,
- container: "#selectParentMenu"
- });
- }
- }
- };
- $scope.choose = function () {
- if ($scope.FinalmenuParentId != null) {
- $scope.edit.menuParentName = $scope.FinalmenuParentName;
- $scope.edit.menuParentId = $scope.FinalmenuParentId;
- myselectModal.$promise.then(myselectModal.hide);
- } else {
- $alert({
- title: '提示:',
- content: "未选择有效的父级菜单",
- placement: 'top',
- type: 'info',
- show: true,
- duration: 3,
- container: "#selectParentMenu"
- });
- }
- };
- };
- selecModalController.$inject = ['$scope', '$http'];
- var myselectModal = $modal({
- scope: $scope,
- title: '选择父菜单',
- resolve: {
- load: ['$ocLazyLoad', function ($ocLazyLoad) {
- $ocLazyLoad.load('../js/template/modal_userselect.css');
- $ocLazyLoad.load('../js/setting/MenuManage/selectMenu.css');
- return true;
- }]
- },
- templateUrl: '../js/setting/MenuManage/selectParentMenu.html',
- controller: selecModalController,
- show: false,
- animation: 'am-fade-and-slide-top'
- });
- //保存菜单项
- $scope.saveMenu = function () {
- $scope.menu.parentmenuid = $scope.edit.menuParentId;
- $scope.sameLevel = [];
- $scope.sameLevelName = [];
- $scope.hassame = false;
- if ($scope.menu.parentmenuid == "" || $scope.menu.parentmenuidFindMenuByMenuId == null) {
- $http.get("../../api/menumanage/childmenubyparentid", {
- params: {
- 'parentid': "",
- 'appid': $state.params.appid
- }
- }).then(function (result) {
- $scope.sameLevel = result.data.items;
- angular.forEach($scope.sameLevel, function (data) {
- if (($scope.menu.menuname == data.menuname || $scope.menu.menuno == data.menuno) && $scope.menu.menuid != data.menuid) {
- $scope.hassame = true;
- }
- });
- if ($scope.hassame) {
- $scope.showalert("同级已存在与此同名的菜单,不可新增!");
- } else {
- $.ajax({
- url: "../../api/menumanage/savemenu",
- data: JSON.stringify($scope.menu),
- type: 'post',
- contentType: 'application/json',
- success: function (res) {
- $scope.$apply(function () {
- $scope.getMenuList();
- myModal.$promise.then(myModal.hide);
- $scope.showalert(res.msg);
- })
- },
- error: function (res) {
- console.log(res);
- }
- });
- }
- }, function () {
- console.log("无匹配项");
- });
- } else {
- $http.get("../../api/menumanage/childmenubyparentid", {
- params: {
- 'parentid': $scope.menu.parentmenuid,
- 'appid': $state.params.appid
- }
- }).then(function (result) {
- $scope.sameLevel = result.data.items;
- angular.forEach($scope.sameLevel, function (data) {
- if (($scope.menu.menuname == data.menuname || $scope.menu.menuno == data.menuno) && $scope.menu.menuid != data.menuid) {
- $scope.hassame = true;
- }
- });
- if ($scope.hassame) {
- $scope.showalert("同级已存在与此同名的菜单,不可新增!");
- } else {
- $.ajax({
- url: "../../api/menumanage/savemenu",
- data: JSON.stringify($scope.menu),
- type: 'post',
- contentType: 'application/json',
- success: function (res) {
- $scope.$apply(function () {
- $scope.getMenuList();
- myModal.$promise.then(myModal.hide);
- $scope.showalert(res.msg);
- })
- },
- error: function (res) {
- console.log(res);
- }
- });
- }
- }, function () {
- console.log("无匹配项");
- });
- }
- };
- };
- MyModalController.$inject = ['$scope', '$http'];
- var myModal = $modal({
- scope: $scope,
- title: '菜单信息',
- templateUrl: '../js/setting/MenuManage/editMenu.html',
- controller: MyModalController,
- show: false,
- animation: 'am-fade-and-slide-top'
- });
- $scope.editModal = function (menu) {
- if (menu.menuid != null) {
- $scope.hasPermission.show = true;
- $http.get("../../api/menumanage/findmenubymenuid", {params: {'menuid': menu.menuid}}).then(function (result) {
- $scope.data = result.data.item;
- myModal.$promise.then(myModal.show);
- }, function () {
- console.log("无匹配项");
- });
- } else {
- $scope.data = menu;
- }
- };
- //新增菜单项
- $scope.addMenu = function () {
- $scope.hasPermission.show = true;
- $scope.newMenu = {
- menuid: null,
- applicationid: $state.params.appid,
- parentmenuid: "",
- menusystem: "",
- menuorder: "",
- menuno: "",
- menuname: "",
- menuprogram: "",
- menupic: "",
- menudesc: "",
- isvisible: 1,
- isleaf: 1
- };
- $scope.editModal($scope.newMenu);
- myModal.$promise.then(myModal.show);
- };
- //提示函数
- $scope.showalert = function (data) {
- $alert({title: '提示:', content: data, placement: 'top', type: 'info', show: true, duration: 3});
- };
- $scope.reset = function () {
- //选择的菜单名称
- $scope.MenuName = '';
- //选择的菜单编号
- $scope.MenuNo = '';
- }
- });
- })();
|