menuManage.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. (function () {
  2. var app = angular.module('devself.common');
  3. app.controller("MenuManageCtrl", function ($scope, $http, $alert, $modal, AuthUser, $state, $loading,$bsRouterState) {
  4. $scope.title = '菜单管理';
  5. $state.params=$bsRouterState.$params($scope);
  6. //分页设置
  7. $scope.selectdata = {pageindex: 1, pagesize: 10, ptotal: 0};
  8. $scope.hasPermission = {
  9. show: true
  10. };
  11. //当前用户获取
  12. //test url要加上?uid=1121131017
  13. $scope.user = AuthUser.getUser();
  14. //选择的菜单名称
  15. $scope.MenuName = '';
  16. //选择的菜单编号
  17. $scope.MenuNo = '';
  18. //所有的菜单记录
  19. $scope.menuLists = [];
  20. $scope.curMenuID = "";
  21. //加载所有的父菜单记录
  22. $scope.getMenuList = function () {
  23. $loading.show();
  24. $http.get("../../api/menumanage/alltopparentmenus", {
  25. params: {
  26. 'menuname': $scope.MenuName,
  27. 'menuno': $scope.MenuNo,
  28. appid: $state.params.appid
  29. }
  30. }).then(function (value) {
  31. $scope.menuLists = value.data.item;
  32. $scope.updatePDutyList();
  33. $loading.hide();
  34. }, function (reason) {
  35. $loading.hide();
  36. console.log(reason);
  37. });
  38. };
  39. //查询对应菜单数据
  40. $scope.searchMenu = function () {
  41. $scope.getMenuList();
  42. /*
  43. $http.get("../../api/menumanage/getmenulists", { params: { 'MenuName': $scope.MenuName, 'MenuNo': $scope.MenuNo, 'appid': $state.params.appid } }).then(function (result) {
  44. $scope.menuLists = result.data.item;
  45. $scope.updatePDutyList();
  46. }, function () {
  47. console.log("无匹配条件数据");
  48. });*/
  49. };
  50. //加载子菜单
  51. $scope.loadChildMenu = function (item) {
  52. $scope.searchParam = "";//查询条件清空
  53. if (!item.isExpand)//如果该节点未展开
  54. {
  55. item.isExpand = true;
  56. $scope.getMenuByParentID(item);
  57. } else {
  58. item.isExpand = false;
  59. }
  60. };
  61. //根据当前项的menuID找到其所有的子菜单
  62. $scope.getMenuByParentID = function (item) {
  63. $http.get("../../api/menumanage/childmenubyparentid", {
  64. params: {
  65. 'parentid': item.menuid,
  66. 'appid': $state.params.appid
  67. }
  68. }).then(function (result) {
  69. item.childMenus = result.data.item;
  70. }, function () {
  71. console.log("无匹配项");
  72. });
  73. };
  74. $scope.getMenuList();
  75. //页面数据更新
  76. $scope.updatePDutyList = function () {
  77. $scope.tempMenu = [];
  78. $scope.selectdata.ptotal = $scope.menuLists.length;
  79. var firstLength = ($scope.selectdata.pageindex - 1) * $scope.selectdata.pagesize;
  80. var lastLength = ($scope.selectdata.pageindex * $scope.selectdata.pagesize) < $scope.selectdata.ptotal ?
  81. ($scope.selectdata.pageindex * $scope.selectdata.pagesize) : $scope.selectdata.ptotal;
  82. for (var i = firstLength; i < lastLength; i++) {
  83. $scope.tempMenu.push($scope.menuLists[i]);
  84. }
  85. };
  86. //监视页数变化
  87. $scope.$watch("selectdata.pageindex", function (newVal, oldVal) {
  88. $scope.updatePDutyList();
  89. });
  90. //删除选中菜单项
  91. $scope.delete = function (item) {
  92. $http.get("../../api/menumanage/childmenubyparentid", {
  93. params: {
  94. 'parentid': item.menuid,
  95. 'appid': $state.params.appid
  96. }
  97. }).then(function (result) {
  98. if (result.data.item.length > 0) {
  99. $alert({content: '有子菜单项不能删除!', type: 'info', placement: 'top', show: true, duration: 3});
  100. } else {
  101. if (!confirm("确认删除?")) {
  102. return;
  103. }
  104. $http.get("../../api/menumanage/deletemenubyid", {params: {'menuid': item.menuid}}).then(function (result) {
  105. $scope.getMenuList();
  106. $scope.showalert(result.data.msg);
  107. }, function () {
  108. console.log("无匹配项");
  109. });
  110. }
  111. }, function () {
  112. console.log("无匹配项");
  113. });
  114. };
  115. var MyModalController = function ($scope, $http) {
  116. $scope.edit = {
  117. menuParentName: "",
  118. menuParentId: ""
  119. };
  120. $scope.title = "菜单信息";
  121. $scope.menu = $scope.data;
  122. $scope.edit.menuParentId = $scope.menu.parentmenuid;
  123. $scope.selectParent = function () {
  124. if ($scope.hasPermission.show) {
  125. myselectModal.$promise.then(myselectModal.show);
  126. }
  127. };
  128. //获取原父级菜单
  129. $scope.getParentName = function () {
  130. if ($scope.menu.parentmenuid == null || $scope.menu.parentmenuid == "") {
  131. $scope.edit.menuParentName = "顶层菜单";
  132. } else {
  133. $http.get("../../api/menumanage/findmenubymenuid", {params: {'menuid': $scope.menu.parentmenuid}}).then(function (result) {
  134. $scope.edit.menuParentName = result.data.item.menuname;
  135. }, function () {
  136. console.log("无匹配项");
  137. });
  138. }
  139. };
  140. $scope.getParentName();
  141. //加载所有的父菜单记录
  142. var selecModalController = function ($scope, $http) {
  143. //加载所有的父菜单记录
  144. $scope.getMenus = function () {
  145. $.ajax({
  146. url: "../../api/menumanage/alltopparentmenus",
  147. data: {appid: $state.params.appid, menuname: '', menuno: ''},
  148. type: 'get',
  149. contentType: 'application/json',
  150. success: function (res) {
  151. $scope.$apply(function () {
  152. $scope.selectMenus = res.item;
  153. })
  154. },
  155. error: function (res) {
  156. console.log(res);
  157. }
  158. });
  159. };
  160. //加载子菜单
  161. $scope.loadChild = function (item) {
  162. if (!item.isExpand)//如果该节点未展开
  163. {
  164. item.isExpand = true;
  165. $scope.getMenuByPID(item);
  166. } else {
  167. item.isExpand = false;
  168. }
  169. };
  170. //根据当前项的menuID找到其所有的子菜单
  171. $scope.getMenuByPID = function (item) {
  172. $http.get("../../api/menumanage/childmenubyparentid", {
  173. params: {
  174. 'parentid': item.menuid,
  175. 'appid': $state.params.appid
  176. }
  177. }).then(function (result) {
  178. item.childs = result.data.item;
  179. }, function () {
  180. console.log("无匹配项");
  181. });
  182. };
  183. $scope.getMenus();
  184. $scope.changeChoose = function (item) {
  185. if ($scope.curMenuID != item.menuid) {
  186. $scope.curMenuID = item.menuid;
  187. if (item.isleaf == false) {
  188. $scope.FinalmenuParentName = item.menuname;
  189. $scope.FinalmenuParentId = item.menuid;
  190. } else {
  191. $scope.FinalmenuParentName = "";
  192. $scope.FinalmenuParentId = null;
  193. $alert({
  194. title: '提示:',
  195. content: "不能选择叶节点作为父级菜单",
  196. placement: 'top',
  197. type: 'info',
  198. show: true,
  199. duration: 3,
  200. container: "#selectParentMenu"
  201. });
  202. }
  203. }
  204. };
  205. $scope.choose = function () {
  206. if ($scope.FinalmenuParentId != null) {
  207. $scope.edit.menuParentName = $scope.FinalmenuParentName;
  208. $scope.edit.menuParentId = $scope.FinalmenuParentId;
  209. myselectModal.$promise.then(myselectModal.hide);
  210. } else {
  211. $alert({
  212. title: '提示:',
  213. content: "未选择有效的父级菜单",
  214. placement: 'top',
  215. type: 'info',
  216. show: true,
  217. duration: 3,
  218. container: "#selectParentMenu"
  219. });
  220. }
  221. };
  222. };
  223. selecModalController.$inject = ['$scope', '$http'];
  224. var myselectModal = $modal({
  225. scope: $scope,
  226. title: '选择父菜单',
  227. resolve: {
  228. load: ['$ocLazyLoad', function ($ocLazyLoad) {
  229. $ocLazyLoad.load('../js/template/modal_userselect.css');
  230. $ocLazyLoad.load('../js/setting/MenuManage/selectMenu.css');
  231. return true;
  232. }]
  233. },
  234. templateUrl: '../js/setting/MenuManage/selectParentMenu.html',
  235. controller: selecModalController,
  236. show: false,
  237. animation: 'am-fade-and-slide-top'
  238. });
  239. //保存菜单项
  240. $scope.saveMenu = function () {
  241. $scope.menu.parentmenuid = $scope.edit.menuParentId;
  242. $scope.sameLevel = [];
  243. $scope.sameLevelName = [];
  244. $scope.hassame = false;
  245. if ($scope.menu.parentmenuid == "" || $scope.menu.parentmenuidFindMenuByMenuId == null) {
  246. $http.get("../../api/menumanage/childmenubyparentid", {
  247. params: {
  248. 'parentid': "",
  249. 'appid': $state.params.appid
  250. }
  251. }).then(function (result) {
  252. $scope.sameLevel = result.data.items;
  253. angular.forEach($scope.sameLevel, function (data) {
  254. if (($scope.menu.menuname == data.menuname || $scope.menu.menuno == data.menuno) && $scope.menu.menuid != data.menuid) {
  255. $scope.hassame = true;
  256. }
  257. });
  258. if ($scope.hassame) {
  259. $scope.showalert("同级已存在与此同名的菜单,不可新增!");
  260. } else {
  261. $.ajax({
  262. url: "../../api/menumanage/savemenu",
  263. data: JSON.stringify($scope.menu),
  264. type: 'post',
  265. contentType: 'application/json',
  266. success: function (res) {
  267. $scope.$apply(function () {
  268. $scope.getMenuList();
  269. myModal.$promise.then(myModal.hide);
  270. $scope.showalert(res.msg);
  271. })
  272. },
  273. error: function (res) {
  274. console.log(res);
  275. }
  276. });
  277. }
  278. }, function () {
  279. console.log("无匹配项");
  280. });
  281. } else {
  282. $http.get("../../api/menumanage/childmenubyparentid", {
  283. params: {
  284. 'parentid': $scope.menu.parentmenuid,
  285. 'appid': $state.params.appid
  286. }
  287. }).then(function (result) {
  288. $scope.sameLevel = result.data.items;
  289. angular.forEach($scope.sameLevel, function (data) {
  290. if (($scope.menu.menuname == data.menuname || $scope.menu.menuno == data.menuno) && $scope.menu.menuid != data.menuid) {
  291. $scope.hassame = true;
  292. }
  293. });
  294. if ($scope.hassame) {
  295. $scope.showalert("同级已存在与此同名的菜单,不可新增!");
  296. } else {
  297. $.ajax({
  298. url: "../../api/menumanage/savemenu",
  299. data: JSON.stringify($scope.menu),
  300. type: 'post',
  301. contentType: 'application/json',
  302. success: function (res) {
  303. $scope.$apply(function () {
  304. $scope.getMenuList();
  305. myModal.$promise.then(myModal.hide);
  306. $scope.showalert(res.msg);
  307. })
  308. },
  309. error: function (res) {
  310. console.log(res);
  311. }
  312. });
  313. }
  314. }, function () {
  315. console.log("无匹配项");
  316. });
  317. }
  318. };
  319. };
  320. MyModalController.$inject = ['$scope', '$http'];
  321. var myModal = $modal({
  322. scope: $scope,
  323. title: '菜单信息',
  324. templateUrl: '../js/setting/MenuManage/editMenu.html',
  325. controller: MyModalController,
  326. show: false,
  327. animation: 'am-fade-and-slide-top'
  328. });
  329. $scope.editModal = function (menu) {
  330. if (menu.menuid != null) {
  331. $scope.hasPermission.show = true;
  332. $http.get("../../api/menumanage/findmenubymenuid", {params: {'menuid': menu.menuid}}).then(function (result) {
  333. $scope.data = result.data.item;
  334. myModal.$promise.then(myModal.show);
  335. }, function () {
  336. console.log("无匹配项");
  337. });
  338. } else {
  339. $scope.data = menu;
  340. }
  341. };
  342. //新增菜单项
  343. $scope.addMenu = function () {
  344. $scope.hasPermission.show = true;
  345. $scope.newMenu = {
  346. menuid: null,
  347. applicationid: $state.params.appid,
  348. parentmenuid: "",
  349. menusystem: "",
  350. menuorder: "",
  351. menuno: "",
  352. menuname: "",
  353. menuprogram: "",
  354. menupic: "",
  355. menudesc: "",
  356. isvisible: 1,
  357. isleaf: 1
  358. };
  359. $scope.editModal($scope.newMenu);
  360. myModal.$promise.then(myModal.show);
  361. };
  362. //提示函数
  363. $scope.showalert = function (data) {
  364. $alert({title: '提示:', content: data, placement: 'top', type: 'info', show: true, duration: 3});
  365. };
  366. $scope.reset = function () {
  367. //选择的菜单名称
  368. $scope.MenuName = '';
  369. //选择的菜单编号
  370. $scope.MenuNo = '';
  371. }
  372. });
  373. })();