add.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="keywords" content="">
  8. <meta name="description" content="">
  9. <title text="系统菜单"></title>
  10. <link rel="stylesheet" href="../../../component/pear/css/pear.css">
  11. <style>
  12. .pear-btn-success {background-color: #2d8cf0 !important;}
  13. </style>
  14. </head>
  15. <body>
  16. <form class="layui-form" lay-filter="edit">
  17. <input type="hidden" name="id">
  18. <div class="mainBox">
  19. <div class="main-container">
  20. <div class="layui-form-item">
  21. <label class="layui-form-label layui-required">上级菜单:</label>
  22. <div class="layui-input-block">
  23. <div id="tree"></div>
  24. </div>
  25. </div>
  26. <div class="layui-form-item">
  27. <label class="layui-form-label layui-required">菜单名称:</label>
  28. <div class="layui-input-block">
  29. <input type="text" name="title" placeholder="菜单名称" lay-verify="required"
  30. autocomplete="off" class="layui-input" value="">
  31. </div>
  32. </div>
  33. <div class="layui-form-item">
  34. <label class="layui-form-label layui-required">权限类型:</label>
  35. <div class="layui-input-block">
  36. <input type="radio" lay-filter="type" name="type" value="0" title="目录">
  37. <input type="radio" lay-filter="type" name="type" value="1" title="菜单">
  38. <input type="radio" lay-filter="type" name="type" value="2" title="按钮">
  39. </div>
  40. </div>
  41. <div class="layui-form-item">
  42. <label class="layui-form-label">菜单图标:</label>
  43. <div class="layui-input-block">
  44. <input type="text" id="icon" name="icon" lay-filter="icon"
  45. class="layui-input">
  46. </div>
  47. </div>
  48. <div class="layui-form-item" id="codeItem">
  49. <label class="layui-form-label">权限标识:</label>
  50. <div class="layui-input-block">
  51. <input type="text" id="code" name="code" placeholder="权限标识:sys:menu:main"
  52. class="layui-input" autocomplete="off">
  53. </div>
  54. </div>
  55. <div class="layui-form-item" id="urlItem">
  56. <label class="layui-form-label">菜单路径:</label>
  57. <div class="layui-input-block">
  58. <input type="text" id="href" name="href" placeholder="菜单路径: /system/menu/main"
  59. class="layui-input" autocomplete="off">
  60. </div>
  61. </div>
  62. <div class="layui-form-item">
  63. <label class="layui-form-label layui-required">菜单排序:</label>
  64. <div class="layui-input-block">
  65. <input type="text" name="sort" placeholder="请输入排序号"
  66. class="layui-input" autocomplete="off" lay-verify="required">
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="bottom">
  72. <div class="button-container">
  73. <button type="submit" class="pear-btn pear-btn-success"
  74. lay-submit="" lay-filter="save">保 存
  75. </button>
  76. <button type="submit" class="pear-btn" id="close">
  77. 关 闭
  78. </button>
  79. </div>
  80. </div>
  81. </form>
  82. <script src="../../../component/layui/layui.js"></script>
  83. <script src="../../../component/pear/pear.js"></script>
  84. <script src="../../../component/js/xm-select.js"></script>
  85. <script>
  86. layui.use(['request', 'form', 'iconPicker', 'popup'], function () {
  87. var $ = layui.jquery,
  88. request = layui.request,
  89. form = layui.form,
  90. iconPicker = layui.iconPicker,
  91. popup = layui.popup;
  92. var MODULE_PATH = "/system/menu/v1/";
  93. var menuSelectTree = xmSelect.render({
  94. el: '#tree',
  95. name: 'parentId', // 表单提交name
  96. model: {label: {type: 'text'}},
  97. layVerify: 'required', // 必填
  98. clickClose: true, // 点击关闭
  99. tree: {
  100. show: true, // 是否显示树状结构
  101. showLine: false, // 是否显示虚线
  102. strict: false, // 是否严格遵守父子模式
  103. expandedKeys: [1], // 默认展开节点的数组, 为 true 时, 展开所有节点
  104. },
  105. prop: { // key value 名称修改
  106. name: 'title',
  107. value: 'id'
  108. },
  109. on: function (data) {
  110. if (data.isAdd) {
  111. return data.change.slice(0, 1)
  112. }
  113. },
  114. data: []
  115. });
  116. layer.ready(function() {
  117. request.httpGet(MODULE_PATH + 'selectTree', function(result) {
  118. if (result.success) {
  119. menuSelectTree.update({
  120. data: result.data,
  121. autoRow: true,
  122. });
  123. var id = request.getQueryString("id");
  124. if (id) {
  125. request.httpGet(MODULE_PATH + id, function (result) {
  126. form.val('edit', result.data);
  127. // xmSelect回显
  128. menuSelectTree.setValue([result.data.parentId]);
  129. // 单选框事件回显
  130. window.init(result.data.type);
  131. // 图标选择器回显
  132. iconPicker.checkIcon("icon", result.data.icon);
  133. });
  134. }
  135. }
  136. });
  137. });
  138. // 单选框点击事件
  139. form.on("radio(type)", function () {
  140. window.init(this.value);
  141. });
  142. window.init = function(type) {
  143. if (parseInt(type) === 0) {
  144. $("#urlItem").hide();
  145. $("#codeItem").hide();
  146. $("#url").val("");
  147. $("#code").val("");
  148. } else if (parseInt(type) === 1) {
  149. $("#urlItem").show();
  150. $("#codeItem").show();
  151. } else if (parseInt(type) === 2) {
  152. $("#urlItem").hide();
  153. $("#codeItem").show();
  154. $("#url").val("");
  155. }
  156. };
  157. // 图标选择器
  158. iconPicker.render({
  159. elem: '#icon', // 选择器,推荐使用input
  160. type: 'fontClass', // 数据类型:fontClass/unicode,推荐使用 fontClass
  161. search: true, // 是否开启搜索:true/false
  162. page: true, // 是否开启分页
  163. limit: 12 // 每页显示数量,默认12
  164. });
  165. form.on('submit(save)', function (data) {
  166. if (data.field.icon.indexOf("layui-icon ") === -1) {
  167. data.field.icon = "layui-icon " + data.field.icon;
  168. }
  169. request.http({
  170. url: MODULE_PATH,
  171. type: (data.field.id ? 'put':'post'),
  172. data: data.field,
  173. success: function (res) {
  174. if (res.success) {
  175. popup.success(res.msg, function () {
  176. parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
  177. parent.render();
  178. })
  179. } else {
  180. popup.failure(res.msg);
  181. }
  182. }
  183. });
  184. return false;
  185. });
  186. $('#close').on('click', function () {
  187. parent.layer.closeAll();
  188. });
  189. })
  190. </script>
  191. </body>
  192. </html>