customPlugin.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * customPlugin.js 自定义插件
  3. * des:需要引用bootstrap和jquery
  4. */
  5. ; (function ($) {
  6. $.fn.extend({
  7. /**
  8. *渲染左侧导航菜单
  9. */
  10. renderLeftMenu: function (options) {
  11. //var json = [{ "state": { "checked": false }, "nodes": [{ "state": { "checked": false }, "nodes": [{ "state": { "checked": false }, "nodes": [], "id": "4", "text": "添加申请单" }, { "state": { "checked": false }, "nodes": [], "id": "7", "text": "扫描件上传" }, { "state": { "checked": false }, "nodes": [], "id": "8", "text": "申请单列表" }, { "state": { "checked": false }, "nodes": [], "id": "9", "text": "质检回退列表" }], "id": "3", "text": "录单管理" }, { "state": { "checked": false }, "nodes": [{ "state": { "checked": false }, "nodes": [], "id": "10", "text": "待质检申请列表" }, { "state": { "checked": false }, "nodes": [], "id": "11", "text": "待签约申请单列表" }, { "state": { "checked": false }, "nodes": [], "id": "12", "text": "已质检申请单列表" }], "id": "5", "text": "订单管理" }, { "state": { "checked": false }, "nodes": [{ "state": { "checked": false }, "nodes": [], "id": "13", "text": "运营审核列表" }, { "state": { "checked": false }, "nodes": [{ "state": { "checked": false }, "nodes": [], "id": "21", "text": "添加" }], "id": "14", "text": "运营审核历史列表" }], "id": "6", "text": "合同管理" }], "id": "2", "text": "根权限目录" }];
  12. var defaults = {
  13. data: [],
  14. onSuccess: function () { }//成功后执行
  15. }
  16. var opts = $.extend({}, defaults, options);
  17. var $this = $(this);
  18. $this.html('');
  19. bindData();
  20. opts.onSuccess();
  21. return $this;
  22. //绑定数据
  23. function bindData() {
  24. var json = opts.data;
  25. if (json && json.length) {
  26. $this.html('');
  27. $.each(json, function (i, item) {
  28. RenderFirstMenu(json[0].nodes);
  29. });
  30. }
  31. //渲染LevType=1的一级菜单
  32. function RenderFirstMenu(json) {
  33. $.each(json, function (i, item) {
  34. item.id = "menu_" + item.id;//防止id冲突
  35. item.ParentID = "menu_" + item.ParentID;
  36. var $menu = $('<li id="' + item.id + '" parentid="' + item.ParentID + '" class="treeview">'
  37. + '<a href="' + item.Url + '"><i class="' + item.ImgUrl + '"></i><span>' + item.text + '</span></a>'
  38. + '</li>'
  39. );
  40. if (item.nodes.length > 0) {
  41. RenderSecondMenu(item.nodes, $menu);
  42. }
  43. $this.append($menu);
  44. });
  45. }
  46. //渲染LevType=2的二级菜单
  47. function RenderSecondMenu(json, $parentMenu) {
  48. var $ul = $('<ul class="treeview-menu"></ul>');
  49. $.each(json, function (i, item) {
  50. item.id = "menu_" + item.id;//防止id冲突
  51. item.ParentID = "menu_" + item.ParentID;
  52. var $menu = $('<li id="' + item.id + '" parentid="' + item.ParentID + '">'
  53. + '<a href="' + item.Url + '">'
  54. + '<i class="' + item.ImgUrl + '"></i>'
  55. + '<span>' + item.text + '</span>'
  56. + '</a>'
  57. + '</li>');
  58. $ul.append($menu);
  59. });
  60. $parentMenu.append($ul);
  61. }
  62. }
  63. },
  64. });
  65. $.extend({
  66. /**
  67. *dialog
  68. *des:提示框
  69. */
  70. showMsg: function (options) {
  71. var defaults = {
  72. text: '成功',
  73. title: '提示'
  74. }
  75. var opts = $.extend({}, defaults, options);
  76. BootstrapDialog.show({
  77. title: '提示',
  78. size: BootstrapDialog.SIZE_SMALL,
  79. type: BootstrapDialog.TYPE_DEFAULT,
  80. message: opts.text,
  81. buttons: [{
  82. label: '确定',
  83. action: function (dialog) {
  84. dialog.close();
  85. }
  86. }]
  87. });
  88. },
  89. /**
  90. *dialog
  91. *des:提示框
  92. */
  93. showMsgText:function(text)
  94. {
  95. $.showMsg({ text: text });
  96. }
  97. });
  98. })(jQuery);