ModuleMgr.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. var ModuleMgr = function () {
  2. var exports = {};
  3. exports.options = {};
  4. exports.options.ParentId = "";
  5. //初始化数据
  6. exports.initGridPage = function () {
  7. //layout布局
  8. $('#layout').layout({
  9. applyDemoStyles: false,
  10. onresize: function () {
  11. $(window).resize();
  12. },
  13. height: $.fn.getLayoutHeight()
  14. });
  15. //初始化
  16. $(window).resize(function (e) {
  17. window.setTimeout(function () {
  18. $("#layout").css({ "height": $.fn.getLayoutHeight() });
  19. $('#gridTable').setGridWidth(($('.gridPanel').width()));
  20. $("#gridTable").setGridHeight($.fn.getGridHeight());
  21. $("#itemTree").setTreeHeight($.fn.getLayoutContentHeight());
  22. }, 100);
  23. e.stopPropagation();
  24. });
  25. //查询条件
  26. $("#queryCondition .dropdown-menu li").click(function () {
  27. var text = $(this).find('a').html();
  28. var value = $(this).find('a').attr('data-value');
  29. $("#queryCondition .dropdown-text").html(text).attr('data-value', value);
  30. });
  31. //查询回车
  32. $('#txt_Keyword').bind('keypress', function (event) {
  33. if (event.keyCode == "13") {
  34. $('.lr-search').trigger("click");
  35. }
  36. });
  37. //注册事件
  38. $(".titlePanel").on("click", ".lr-replace,.lr-add,.lr-edit,.lr-delete,.lr-search", function () {
  39. var $this = $(this);
  40. //添加地址
  41. if ($this.hasClass('lr-replace')) {
  42. reload();
  43. }
  44. else if ($this.hasClass('lr-add')) {
  45. exports.btnAdd();
  46. } else if ($this.hasClass('lr-edit')) {
  47. exports.btnEdit();
  48. } else if ($this.hasClass('lr-delete')) {
  49. exports.btnDelete();
  50. } else if ($this.hasClass('lr-search')) {
  51. exports.btnSearch();
  52. }
  53. });
  54. };
  55. //加载树
  56. exports.loadTree = function () {
  57. var item = {
  58. height: $.fn.getLayoutContentHeight(),
  59. url: "/content/supermgr/json/ModuleTree.json",
  60. onnodeclick: function (item) {
  61. exports.options.ParentId = item.id;
  62. $('.lr-search').trigger("click");
  63. }
  64. };
  65. //初始化
  66. $("#itemTree").treeview(item);
  67. };
  68. //加载Grid
  69. exports.loadGrid = function () {
  70. var selectedRowIndex = 0;
  71. exports.options.$gridTable = $("#gridTable");
  72. exports.options.$gridTable.jqGrid({
  73. datatype: "json",
  74. url: "/content/supermgr/json/ModuleGrid.json",
  75. height: $.fn.getGridHeight(),
  76. autowidth: true,
  77. colModel: [
  78. { label: "主键", name: "Id", index: "Id", hidden: true },
  79. { label: "编号", name: "EnCode", index: "EnCode", width: 150, align: "left" },
  80. { label: "名称", name: "FullName", index: "FullName", width: 150, align: "left" },
  81. { label: "地址", name: "UrlAddress", index: "UrlAddress", width: 350, align: "left" },
  82. { label: "目标", name: "Target", index: "Target", width: 60, align: "center" },
  83. {
  84. label: "菜单", name: "IsMenu", index: "IsMenu", width: 50, align: "center",
  85. formatter: function (cellvalue, options, rowObject) {
  86. return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\"></i>";
  87. }
  88. },
  89. {
  90. label: "展开", name: "AllowExpand", index: "AllowExpand", width: 50, align: "center",
  91. formatter: function (cellvalue, options, rowObject) {
  92. return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
  93. }
  94. },
  95. {
  96. label: "公共", name: "IsPublic", index: "IsPublic", width: 50, align: "center",
  97. formatter: function (cellvalue, options, rowObject) {
  98. return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
  99. }
  100. },
  101. {
  102. label: "有效", name: "EnabledMark", index: "EnabledMark", width: 50, align: "center",
  103. formatter: function (cellvalue, options, rowObject) {
  104. return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
  105. }
  106. },
  107. { label: "描述", name: "Description", index: "Description", width: 100, align: "left" }
  108. ],
  109. shrinkToFit: false,
  110. altclass: 'altRowsColour',
  111. rowNum: "10000",
  112. rownumbers: true,
  113. onSelectRow: function () {
  114. selectedRowIndex = $("#" + this.id).getGridParam('selrow');
  115. },
  116. gridComplete: function () {
  117. $("#" + this.id).setSelection(selectedRowIndex, false);
  118. }
  119. });
  120. }
  121. //搜索
  122. exports.btnSearch=function() {
  123. exports.options.$gridTable.jqGrid('setGridParam', {
  124. url: "/content/supermgr/json/ModuleGrid.json",
  125. postData: {
  126. ParentId: exports.options.ParentId,
  127. conditionJson: $("#queryCondition").find('.dropdown-text').attr('data-value'),
  128. searchKeyWord: $("#txt_Keyword").val()
  129. },
  130. }).trigger('reloadGrid');
  131. }
  132. //删除
  133. exports.btnDelete= function () {
  134. var keyValue = $("#gridTable").jqGridRowValue("Id");
  135. if (keyValue) {
  136. $.fn.deleteForm({
  137. url: "/SysMgr/ModuleMgr/RemoveForm",
  138. param: { keyValue: keyValue },
  139. success: function(data) {
  140. $("#gridTable").resetSelection();
  141. $("#gridTable").trigger("reloadGrid");
  142. }
  143. });
  144. } else {
  145. $.fn.modalMsg('请选择需要删除的数据项!', "warning");
  146. }
  147. }
  148. //编辑
  149. exports.btnEdit=function() {
  150. var keyValue = $("#gridTable").jqGridRowValue("Id");
  151. if (checkedRow(keyValue)) {
  152. $.fn.modalOpen({
  153. id: "Form",
  154. title: '编辑功能',
  155. url: '/pages/supermgr/ModuleForm.html?keyValue=' + keyValue,
  156. width: "700px",
  157. height: "430px",
  158. btn: null
  159. });
  160. }
  161. }
  162. //添加
  163. exports.btnAdd = function() {
  164. if (!exports.options.ParentId) {
  165. $.fn.modalMsg('请在左侧选择某一项!', "warning");
  166. return false;
  167. }
  168. $.fn.modalOpen({
  169. id: "Form",
  170. title: '添加功能',
  171. url: '/pages/supermgr/ModuleForm.html?parentId=' + exports.options.ParentId,
  172. btn: null,
  173. width: "700px",
  174. height: "430px"
  175. });
  176. };
  177. /**********************表单************************/
  178. //加载表单
  179. exports.loadForm= function(readonly) {
  180. exports.options.KeyValue = $.fn.request('keyValue');
  181. exports.options.ParentId = $.fn.request('parentId');
  182. exports.options.ModuleId = $("#Id").val();
  183. $(function () {
  184. //加载导向
  185. $('#wizard').wizard().on('change', function (e, data) {
  186. var $finish = $("#btn_finish");
  187. var $next = $("#btn_next");
  188. if (data.direction == "next") {
  189. if (data.step == 1) {
  190. $finish.removeAttr('disabled');
  191. $next.attr('disabled', 'disabled');
  192. }
  193. else {
  194. $finish.attr('disabled', 'disabled');
  195. }
  196. } else {
  197. $finish.attr('disabled', 'disabled');
  198. $next.removeAttr('disabled');
  199. }
  200. });
  201. exports.initFormControl(readonly);
  202. exports.buttonOperation();
  203. exports.getButtonGrid();
  204. $('.selectmoduleicon').bind('click', function() {
  205. exports.btnModuleSelectIcon();
  206. });
  207. //为模块按钮管理注册事件
  208. $(".modulebtn").on("click", ".lr-add-button,.lr-edit-button,.lr-delete-button,.lr-copy-button", function () {
  209. var $this = $(this);
  210. if ($this.hasClass('lr-add-button')) {
  211. exports.btnModuleBtnAdd();
  212. } else if ($this.hasClass('lr-edit-button')) {
  213. exports.btnModuleBtnEdit();
  214. } else if ($this.hasClass('lr-delete-button')) {
  215. exports.btnModuleBtnDelete();
  216. } else if ($this.hasClass('lr-copy-button')) {
  217. exports.btnModuleBtnCopy();
  218. }
  219. });
  220. });
  221. }
  222. /**
  223. * 选取模块图标
  224. * @returns {}
  225. */
  226. exports.btnModuleSelectIcon = function () {
  227. $.fn.modalOpen({
  228. id: "SelectIcon",
  229. title: '选取图标',
  230. url: '/SysMgr/ModuleMgr/SelectIcon?ControlId=Icon',
  231. width: "1000px",
  232. height: "600px",
  233. btn: false,
  234. allowOverParent:true
  235. });
  236. }
  237. //初始化表单
  238. exports.initFormControl = function (readonly) {
  239. //目标
  240. $("#Target").ComboBox({
  241. description: "==请选择==",
  242. height: "200px"
  243. });
  244. //上级
  245. $("#ParentId").ComboBoxTree({
  246. url: "/content/supermgr/json/ModuleTree.json",
  247. description: "==请选择==",
  248. height: "195px",
  249. allowSearch: true
  250. });
  251. //获取表单
  252. if (!!exports.options.KeyValue) {
  253. $.fn.setForm({
  254. url: "/content/supermgr/json/ModuleFrom.json",
  255. param: { keyValue: exports.options.KeyValue },
  256. success: function (data) {
  257. $("#form1").SetWebControls(data);
  258. if (data.IsMenu === 1) {
  259. $("#btn_next").removeAttr('disabled');
  260. $("#btn_finish").attr('disabled', 'disabled');
  261. }
  262. if (readonly) {
  263. $("#form1").find('.form-control,.ui-select,input').attr('disabled', 'disabled');
  264. }
  265. }
  266. });
  267. } else {
  268. $("#ParentId").ComboBoxTreeSetValue(exports.options.ParentId);
  269. }
  270. }
  271. //保存表单
  272. exports.acceptClick = function () {
  273. if (!$('#form1').Validform()) {
  274. return false;
  275. }
  276. var postData = $("#form1").GetWebControls(exports.options.KeyValue);
  277. if (postData["ParentId"] == "") {
  278. postData["ParentId"] = 0;
  279. }
  280. postData["moduleButtonListJson"] = JSON.stringify(exports.options.ButtonJson);
  281. // postData["moduleColumnListJson"] = JSON.stringify(exports.options.ColumnJson);
  282. $.fn.submitForm({
  283. url: "/SysMgr/ModuleMgr/SaveForm?keyValue=" + exports.options.KeyValue,
  284. param: postData,
  285. loading: "正在保存数据...",
  286. success: function() {
  287. $.currentIframe().$("#gridTable").trigger("reloadGrid");
  288. }
  289. });
  290. }
  291. /**
  292. * 按钮操作(上一步、下一步、完成、关闭)
  293. * @returns {}
  294. */
  295. exports.buttonOperation=function() {
  296. var $last = $("#btn_last");
  297. var $next = $("#btn_next");
  298. var $finish = $("#btn_finish");
  299. //如果是菜单,开启 上一步、下一步
  300. $("#IsMenu").click(function () {
  301. if (!$(this).attr("checked")) {
  302. $(this).attr("checked", true)
  303. $next.removeAttr('disabled');
  304. $finish.attr('disabled', 'disabled');
  305. } else {
  306. $(this).attr("checked", false)
  307. $next.attr('disabled', 'disabled');
  308. $finish.removeAttr('disabled');
  309. }
  310. });
  311. //完成提交保存
  312. $finish.click(function() {
  313. exports.acceptClick();
  314. });
  315. }
  316. /**
  317. * 获取按钮列表
  318. * @returns {}
  319. */
  320. exports.getButtonGrid = function () {
  321. var moduleId = exports.options.ModuleId;
  322. $.ajax({
  323. url: "/content/supermgr/json/ModuleButtonList.json?moduleId=" + escape(moduleId),
  324. type: "get",
  325. dataType: "json",
  326. success: function (data) {
  327. exports.options.ButtonJson = data;
  328. window.ButtonJson = exports.options.ButtonJson;
  329. },
  330. });
  331. exports.options.$buttonGrid = $("#gridTable-button");
  332. exports.options.$buttonGrid.jqGrid({
  333. unwritten: false,
  334. url: "/content/supermgr/json/ModuleButtonTree.json?moduleId=" + escape(moduleId),
  335. datatype: "json",
  336. height: $(window).height() - 121,
  337. width: $(window).width() - 11,
  338. colModel: [
  339. { label: "主键", name: "Id", hidden: true },
  340. { label: "名称", name: "FullName", width: 140, align: "left", sortable: false },
  341. { label: "编号", name: "EnCode", width: 140, align: "left", sortable: false },
  342. { label: "地址", name: "ActionAddress", width: 500, align: "left", sortable: false },
  343. ],
  344. treeGrid: true,
  345. treeGridModel: "nested",
  346. ExpandColumn: "EnCode",
  347. rowNum: "all",
  348. rownumbers: true
  349. });
  350. }
  351. /**
  352. * 添加模块按钮
  353. * @returns {}
  354. */
  355. exports.btnModuleBtnAdd=function() {
  356. var parentId = $("#gridTable-button").jqGridRowValue("Id");
  357. $.fn.modalOpen({
  358. id: "buttonForm",
  359. title: '添加按钮',
  360. url: '/SysMgr/ModuleMgr/ButtonForm?parentId=' + parentId + "&moduleId=" + escape(exports.options.ModuleId),
  361. width: "450px",
  362. height: "300px",
  363. callBack: function (iframeId) {
  364. top.frames[iframeId].buttonAcceptClick(function (data) {
  365. exports.options.ButtonJson.push(data);
  366. exports.buttonListToListTreeJson(exports.options.ButtonJson);
  367. window.ButtonJson = exports.options.ButtonJson;
  368. });
  369. }
  370. });
  371. }
  372. /**
  373. * 编辑模块按钮
  374. * @returns {}
  375. */
  376. exports.btnModuleBtnEdit=function() {
  377. var moduleButtonId = $("#gridTable-button").jqGridRowValue("Id");
  378. if (checkedRow(moduleButtonId)) {
  379. $.fn.modalOpen({
  380. id: "buttonForm",
  381. title: '编辑按钮',
  382. url: '/SysMgr/ModuleMgr/ButtonForm?moduleButtonId=' + moduleButtonId + "&moduleId=" + +escape(exports.options.ModuleId),
  383. width: "450px",
  384. height: "300px",
  385. callBack: function (iframeId) {
  386. top.frames[iframeId].buttonAcceptClick(function (data) {
  387. $.each(exports.options.ButtonJson, function (i) {
  388. if (exports.options.ButtonJson[i].Id == moduleButtonId) {
  389. exports.options.ButtonJson[i] = data;
  390. }
  391. });
  392. exports.buttonListToListTreeJson(exports.options.ButtonJson);
  393. window.ButtonJson = exports.options.ButtonJson;
  394. });
  395. }
  396. });
  397. }
  398. }
  399. /**
  400. * 删除模块按钮
  401. * @returns {}
  402. */
  403. exports.btnModuleBtnDelete = function() {
  404. var moduleButtonId = $("#gridTable-button").jqGridRowValue("Id");
  405. if (checkedRow(moduleButtonId)) {
  406. $.each(exports.options.ButtonJson, function(i) {
  407. if (exports.options.ButtonJson[i].Id == moduleButtonId) {
  408. exports.options.ButtonJson.splice(i, 1);
  409. exports.buttonListToListTreeJson(exports.options.ButtonJson);
  410. window.ButtonJson = exports.options.ButtonJson;
  411. return false;
  412. }
  413. });
  414. }
  415. };
  416. /**
  417. * 复制模块按钮
  418. * @returns {}
  419. */
  420. exports.btnModuleBtnCopy=function() {
  421. var moduleButtonId = $("#gridTable-button").jqGridRowValue("Id");
  422. if (checkedRow(moduleButtonId)) {
  423. $.fn.modalOpen({
  424. id: "OptionModule",
  425. title: '将按钮复制到指定功能里面',
  426. url: '/SysMgr/ModuleMgr/ButtonOptionModule?keyValue=' + moduleButtonId,
  427. width: "500px",
  428. height: "500px",
  429. callBack: function (iframeId) {
  430. top.frames[iframeId].buttonOptionModuleLoadForm();
  431. }
  432. });
  433. }
  434. }
  435. /**
  436. * 处理Json
  437. * @param {} buttonJson
  438. * @returns {}
  439. */
  440. exports.buttonListToListTreeJson= function (buttonJson) {
  441. $.ajax({
  442. url: "/SysMgr/ModuleMgr/ModuleButtonListToListTreeJson",
  443. data: { moduleButtonJson: JSON.stringify(buttonJson) },
  444. type: "post",
  445. dataType: "json",
  446. success: function (data) {
  447. exports.options.$buttonGrid.clearGridData();
  448. exports.options.$buttonGrid[0].addJSONData(data);
  449. },
  450. });
  451. }
  452. ///*************************按钮Form页***********************************************
  453. /**
  454. * 按钮Form加载
  455. * @returns {}
  456. */
  457. exports.buttonLoadForm = function () {
  458. exports.options.ParentId = $.fn.request('parentId');
  459. exports.options.ModuleButtonId = $.fn.request('moduleButtonId');
  460. exports.options.ModuleId = $.fn.request('moduleId');
  461. $(function() {
  462. exports.buttonInitControl();
  463. });
  464. }
  465. /**
  466. * 按钮
  467. * @returns {}
  468. */
  469. exports.buttonInitControl = function () {
  470. var dataJson = top.Form.ButtonJson;
  471. //上级
  472. $("#ParentId").ComboBoxTree({
  473. url: "/content/supermgr/json/ModuleButtonList.json",
  474. param: { moduleButtonJson: JSON.stringify(dataJson) },
  475. method: "post",
  476. description: "==请选择==",
  477. height: "150px"
  478. });
  479. if (!!exports.options.ModuleButtonId) {
  480. $.each(dataJson, function (i) {
  481. var row = dataJson[i];
  482. if (row.Id === exports.options.ModuleButtonId) {
  483. $("#form1").SetWebControls(row);
  484. }
  485. });
  486. } else {
  487. $("#ModuleId").val(exports.options.ModuleId);
  488. if (!!exports.options.ParentId) {
  489. $("#ParentId").ComboBoxTreeSetValue(exports.options.ParentId);
  490. } else {
  491. $("#ParentId").ComboBoxTreeSetValue(0);
  492. }
  493. }
  494. }
  495. /**
  496. * 按钮保存表单
  497. * @returns {}
  498. */
  499. exports.buttonAcceptClick = function(callback) {
  500. if (!$('#form1').Validform()) {
  501. return false;
  502. }
  503. var data = $("#form1").GetWebControls(exports.options.ModuleButtonId);
  504. if (data["ParentId"] == "") {
  505. data["ParentId"] = 0;
  506. }
  507. if (data["ModuleId"] == "") {
  508. data["ModuleId"] = newGuid();
  509. }
  510. callback(data);
  511. $.fn.modalClose();
  512. };
  513. /**
  514. * 复制按钮操作Form
  515. * @returns {}
  516. */
  517. exports.buttonOptionModuleLoadForm = function () {
  518. exports.options.KeyValue = $.fn.request('keyValue');
  519. $(function() {
  520. exports.buttonGetModuleTree();
  521. });
  522. }
  523. /**
  524. * 加载功能模块树
  525. * @returns {}
  526. */
  527. exports.buttonGetModuleTree = function () {
  528. var item = {
  529. onnodeclick: function (item) {
  530. exports.options.ModuleId = item.id;
  531. },
  532. url: "/content/supermgr/json/ModuleButtonTree.json"
  533. };
  534. $("#ModuleTree").treeview(item);
  535. }
  536. /**
  537. * 按钮复制保存
  538. * @returns {}
  539. */
  540. exports.buttonOptionModuleAcceptClick=function() {
  541. if (exports.options.ModuleId) {
  542. $.fn.setForm({
  543. url: "/SysMgr/ModuleMgr/ModuleButtonCopyForm",
  544. param: { keyValue: exports.options.KeyValue, moduleId: exports.options.ModuleId },
  545. loading: "正在提交数据...",
  546. success: function () {
  547. }
  548. })
  549. } else {
  550. $.fn.modalMsg('请选择系统功能!', "warning");
  551. }
  552. }
  553. return exports;
  554. };