sysmanager.module.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /// <reference path="E:\ZLSoft\109-中联开发管理系统\ZLPMS\PMS.WebUI\Content/Scripts/zlpms.js" />
  2. function viewModel() {
  3. //编辑时所需要的ID
  4. this.id = "";
  5. //加载上级目录
  6. this.loadmenus = function () {
  7. //验证名称是否重复
  8. $('#name').textbox({
  9. delay: 3000,
  10. validateOnBlur: true,
  11. validType: "remote['/SysManager/CheckModuleNameExists?id=0','name']",
  12. invalidMessage: '请重新填写该名称,已重复'
  13. });
  14. $('#parentid').combotree({
  15. url: '/SysManager/GetModuleTree',
  16. method: 'GET'
  17. });
  18. //绑定清空事件
  19. $('#clear').click(function () {
  20. $('#parentid').combotree('clear');
  21. });
  22. }
  23. //初始化(主界面列表)
  24. this.init = function () {
  25. $('#treegrid').treegrid({
  26. url: '/SysManager/ModuleQueryList',
  27. idField: 'ID',
  28. treeField: '名称',
  29. method: 'GET',
  30. fit: true,
  31. toolbar: '#toolbar',
  32. rownumbers: true,
  33. columns: [[
  34. { field: '名称', title: '名称', width: 180 },
  35. { field: '图标', title: '图标', width: 40, align: 'center', formatter: function (value, row, index) { return ZLPMS.SetIcons(row.图标, '#000') } },
  36. { field: '地址', title: '地址', width: 200 },
  37. { field: '启用', title: '启用', align: 'center', width: 80, formatter: function (value, row, index) { return ZLPMS.SetIsActiveIcon(row.启用); } },
  38. { field: '首页', title: '首页', align: 'center', width: 80, formatter: function (value, row, index) { return ZLPMS.SetIsActiveIcon(row.首页); } },
  39. { field: '序号', title: '序号', align: 'center', width: 60 },
  40. { field: '备注', title: '备注', width: 350 }
  41. ]]
  42. });
  43. //增加
  44. $('#btn-add').click(function () {
  45. //top.PublicFun.OpenWindow('新建模块', '/SysManager/ModuleInfo', ['500px', '400px']);
  46. top.ZLPMS.OpenWindow({
  47. title: '新建模块',
  48. url: '/SysManager/ModuleInfo',
  49. area: ['650px', '500px'],
  50. yes: function (index, layero) {
  51. Forms.Submit(index, layero);
  52. },
  53. });
  54. });
  55. //修改
  56. $('#btn-edit').click(function () {
  57. var row = $('#treegrid').treegrid('getSelected');
  58. if (row != null) {
  59. //打开编辑窗口
  60. top.ZLPMS.OpenWindow({
  61. title: '修改模块',
  62. url: '/SysManager/ModuleInfo/' + row.ID,
  63. area: ['650px', '500px'],
  64. yes: function (index, layero) {
  65. Forms.Submit(index, layero);
  66. //刷新
  67. List.Reload();
  68. },
  69. });
  70. } else {
  71. top.ZLPMS.Msg("请选择一行操作的记录", 2);
  72. }
  73. });
  74. $('#btn-ref').click(function () {
  75. //刷新
  76. List.Reload();
  77. });
  78. //删除
  79. $('#btn-del').click(function () {
  80. var t = $('#treegrid');
  81. var row = t.treegrid('getSelected');
  82. if (row != null) {
  83. //检查是否有子级节点,如果有子级节点,则禁止删除
  84. var child = row.children;
  85. if (child != undefined && child.length > 0) {
  86. //包含子节点,不能删除
  87. top.ZLPMS.Msg('包含子节点,无法直接删除,请先删除子节点!', 0);
  88. return;
  89. }
  90. //确认删除对话框
  91. var idx = top.ZLPMS.Confirm('您确定要删除选择的记录吗?删除后不可还原,如果不使用建议禁用模块', 3, function () {
  92. //执行删除
  93. List.Del(row.ID);
  94. //刷新
  95. List.Reload();
  96. //关闭弹出窗口
  97. top.ZLPMS.CloseWindow(idx);
  98. });
  99. } else {
  100. top.ZLPMS.Msg("请选择一行记录后执行操作", 0);
  101. }
  102. });
  103. //分配按钮
  104. $('#btn-fun').click(function () {
  105. var t = $('#treegrid');
  106. var row = t.treegrid('getSelected');
  107. if (row != null) {
  108. //打开编辑窗口
  109. top.ZLPMS.OpenWindow({
  110. title: '分配模块功能',
  111. url: '/SysManager/ModuleButtonList/' + row.ID,
  112. area: ['680px', '550px'],
  113. yes: function (index, layero) {
  114. top.ZLPMS.CloseWindow(index);
  115. },
  116. });
  117. } else {
  118. top.ZLPMS.Msg("请选择一行记录后执行操作", 0);
  119. }
  120. });
  121. }
  122. //加载功能列表
  123. this.initfuns = function (mid) {
  124. var that = this;
  125. this.id = mid;
  126. //加载功能列表(清单)
  127. $('#dgfuns').datagrid({
  128. url: '/SysManager/ButtonListActive/0',
  129. rownumbers: true,
  130. method: 'get',
  131. fit: true,
  132. border: false,
  133. columns: [[
  134. { checkbox: true, field: 'ID', width: 20 },
  135. {
  136. field: '图标', title: '图标', width: 40, align: 'center', formatter: function (value, row, index) {
  137. return "<i class='" + row.图标 + "' style=\"color:" + row.颜色 + "\"></i>";
  138. }
  139. },
  140. { field: '名称', title: '名称', width: 80 },
  141. { field: '标识', title: '标识', width: 80 }
  142. ]],
  143. toolbar: [{
  144. iconCls: 'fa fa-hand-stop-o',
  145. text: '分配功能',
  146. handler: function () { that.authbutton(); }
  147. },
  148. {
  149. iconCls: 'fa fa-refresh',
  150. text: '刷新',
  151. handler: function () { $('#dgfuns').datagrid('reload', {}); }
  152. }],
  153. })
  154. //加载已授权的功能列表
  155. $('#dgmodulefuns').datagrid({
  156. url: '/SysManager/ButtonListActive/' + mid,
  157. rownumbers: true,
  158. method: 'get',
  159. fit: true,
  160. border: false,
  161. columns: [[
  162. { checkbox: true, field: 'ID', width: 20 },
  163. { field: '分组名', title: '分组名', width: 70 },
  164. {
  165. field: '图标', title: '图标', width: 40, align: 'center', formatter: function (value, row, index) {
  166. return "<i class='" + row.图标 + "' style=\"color:" + row.颜色 + "\"></i>";
  167. }
  168. },
  169. { field: '名称', title: '名称', width: 80 },
  170. { field: '标识', title: '标识', width: 80 },
  171. { field: '序号', title: '序号', width: 40 }
  172. ]],
  173. toolbar: [{
  174. iconCls: 'fa fa-hand-stop-o',
  175. text: '移除功能',
  176. handler: function () { that.removeAuthButton(); }
  177. },
  178. {
  179. iconCls: 'fa fa-refresh',
  180. text: '刷新',
  181. handler: function () { that.refreshModulefuns(); }
  182. }, {
  183. text: '上移',
  184. handler: function () { }
  185. }, {
  186. text: '下移',
  187. handler: function () { }
  188. }],
  189. })
  190. }
  191. //绑定数据
  192. this.bindData = function (id) {
  193. this.id = id;
  194. //验证防止名称重复
  195. $('#name').textbox({
  196. validType: "remote['/SysManager/CheckModuleNameExists?id=" + id + "','name']"
  197. });
  198. //加载修改内容
  199. $.ajax({
  200. url: '/SysManager/GetModuleInfo/' + id,
  201. method: 'GET',
  202. success: function (data) {
  203. if (data.code == 200) {
  204. $('#id').val(id);
  205. $('#parentid').combotree('setValue', data.obj[0].上级ID);
  206. $('#name').textbox('setValue', data.obj[0].名称);
  207. $('#address').textbox('setValue', data.obj[0].地址);
  208. $('#icons').textbox('setValue', data.obj[0].图标);
  209. $('#ordnum').numberspinner('setValue', data.obj[0].序号);
  210. $('#remark').textbox('setValue', data.obj[0].备注);
  211. //设置值
  212. ZLPMS.SetFormVal('ff', { "isactive": data.obj[0].启用 == 1 ? true : false, "ishome": data.obj[0].首页 == 1 ? true : false });
  213. } else {
  214. //弹出错误消息
  215. ZLPMS.Alert(data.msg, 1);
  216. }
  217. }
  218. })
  219. }
  220. //授权已选择的记录
  221. this.authbutton = function () {
  222. var that = this;
  223. var rows = $('#dgfuns').datagrid('getSelections');
  224. if (rows.length > 0) {
  225. //获取到选择的ID列表
  226. var bids = '';//授权按钮集合,多个使用','号分离
  227. for (var i = 0; i < rows.length; i++) {
  228. bids += ',' + rows[i].ID;
  229. }
  230. ZLPMS.Prompt('请录入一个分组名称', 0, function (text) {
  231. $.ajax({
  232. url: '/SysManager/PostAuthButtons/',
  233. method: 'post',
  234. data: { id: this.id, buttonids: bids, group: text },
  235. success: function (data) {
  236. if (data.code == 200) {
  237. //提交成功,刷新已授权的目录
  238. that.refreshModulefuns();
  239. }
  240. else {//分配失败
  241. ZLPMS.Msg(data.msg, 0);
  242. }
  243. }
  244. });
  245. });
  246. } else {
  247. ZLPMS.Msg('请选择一个功能后进行授权到该模块', 0);
  248. }
  249. }
  250. //移除选择的授权
  251. this.removeAuthButton = function () {
  252. var that = this;
  253. var rows = $('#dgmodulefuns').datagrid('getSelections');
  254. if (rows.length > 0) {
  255. var idx = ZLPMS.Confirm('您确定要移除该功能吗?', 3, function (index) {
  256. var ids = '';
  257. for (var i = 0; i < rows.length; i++) {
  258. ids += ',' + rows[i].ID;
  259. }//end for get ids
  260. $.ajax({
  261. url: '/SysManager/PostRemoveAuthButtons',
  262. method: 'post',
  263. data: { ids: ids },
  264. success: function (data) {
  265. if (data.code == 200) {
  266. //提交成功,刷新已授权的目录
  267. that.refreshModulefuns();
  268. ZLPMS.CloseWindow(idx);
  269. }
  270. else {//分配失败
  271. ZLPMS.Msg(data.msg, 0);
  272. }
  273. }
  274. });
  275. });
  276. } else {
  277. ZLPMS.Msg('请选择一个需要移除的功能', 0);
  278. }
  279. }
  280. //刷新已授权的模块
  281. this.refreshModulefuns = function () {
  282. $('#dgmodulefuns').datagrid('reload');
  283. }
  284. //加载工具栏,参数(toolbar:查询返回的json数组,groupname加载对象)
  285. //this.loadToolbars = function (tools, groupname) {
  286. // if (tools.length > 0) {
  287. // //读取所有按钮
  288. // for (var i = 0; i < tools.length; i++) {
  289. // var tool = tools[i];
  290. // var id = tool.标识;
  291. // var name = tool.名称;
  292. // var icons = tool.图标;
  293. // var colors = tool.颜色;
  294. // var iconhtml = "<i class=\"" + icons + "\" style=\"color:" + colors + "\">" + " " + name + "</i>"
  295. // var html = "<a href='#' id='" + id + "' class='easyui-linkbutton' data-options=\"plain:true\">" + iconhtml + "</a>";
  296. // $('#' + groupname).append(html);
  297. // }//end for
  298. // }
  299. //}
  300. }
  301. //表单操作
  302. var Forms = {
  303. //表单提交
  304. Submit: function (index, layero) {
  305. var iframeWin = top.window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  306. iframeWin.Forms.PostData(index);//调用子页面的方法,得到子页面返回的ids
  307. },
  308. //加载数据(测试)
  309. Load: function (data) {
  310. $('#ff').form('load', data);
  311. },
  312. //读取数据
  313. PostData: function (index) {
  314. //执行提交验证
  315. var r = $('#ff').form('validate');
  316. if (r) {//post到后台
  317. var url = '/SysManager/PostSaveModule';
  318. var param = ZLPMS.FormToObject('ff');
  319. //复选框
  320. //var ck = $("[id='isactive']:checked").val();
  321. $.post(url, param, function (data) {
  322. if (data.code == 200) {
  323. top.ZLPMS.CloseWindow(index);
  324. top.ZLPMS.Msg(data.msg);
  325. } else {
  326. ZLPMS.Msg(data.msg, 2);
  327. }
  328. });
  329. }
  330. return null;
  331. }
  332. };
  333. var List = {
  334. Reload: function () {
  335. $('#treegrid').treegrid('reload');
  336. },
  337. //根据ID删除模块
  338. Del: function (id) {
  339. $.ajax({
  340. url: '/SysManager/DeleteModule',
  341. data: { id: id },
  342. method: 'post',
  343. success: function (data) {
  344. if (data.code != 200) {
  345. ZLPMS.Alert(data.msg, 0);
  346. }
  347. }
  348. });
  349. }
  350. };