main.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. <link rel="stylesheet" href="../../../admin/css/other/user.css" />
  12. </head>
  13. <body class="pear-container">
  14. <div class="layui-card">
  15. <div class="layui-card-body">
  16. <form class="layui-form">
  17. <div class="layui-form-item">
  18. <label class="layui-form-label">字典名称</label>
  19. <div class="layui-input-inline">
  20. <input type="text" name="name" placeholder="" class="layui-input">
  21. </div>
  22. <label class="layui-form-label">字典编码</label>
  23. <div class="layui-input-inline">
  24. <input type="text" name="type" placeholder="" class="layui-input">
  25. </div>
  26. <button class="pear-btn pear-btn-md-0 pear-btn-primary" lay-submit lay-filter="query">
  27. <i class="layui-icon layui-icon-search"></i>
  28. 查询
  29. </button>
  30. <button type="reset" class="pear-btn pear-btn-md-0">
  31. <i class="layui-icon layui-icon-refresh"></i>
  32. 重置
  33. </button>
  34. </div>
  35. </form>
  36. </div>
  37. </div>
  38. <div class="layui-card">
  39. <div class="layui-card-body">
  40. <table id="table" lay-filter="table"></table>
  41. </div>
  42. </div>
  43. </body>
  44. <script type="text/html" id="toolbar">
  45. <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
  46. <i class="pear-icon pear-icon-add"></i>
  47. 新增
  48. </button>
  49. <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
  50. <i class="pear-icon pear-icon-ashbin"></i>
  51. 删除
  52. </button>
  53. </script>
  54. <script type="text/html" id="bar">
  55. <a class="cool-line-btn cool-bg-blue" lay-event="edit">编辑</a>
  56. <div class="cool-line-divider"></div>
  57. <a class="cool-line-btn cool-bg-blue" lay-event="remove">删除</a>
  58. </script>
  59. <script type="text/html" id="enableTpl">
  60. <input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch"
  61. lay-text="启用|禁用" lay-filter="switch" {{ d.enable== 1 ? 'checked' : '' }} />
  62. </script>
  63. <script type="text/html" id="createTimeTpl">
  64. {{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}
  65. </script>
  66. <script type="text/html" id="typeTpl">
  67. <a href="javascript:;" style="cursor: pointer;color: #409eff;" lay-event="toItem" >{{d.type}}</a>
  68. </script>
  69. <script src="../../../component/layui/layui.js"></script>
  70. <script src="../../../component/pear/pear.js"></script>
  71. <script>
  72. layui.use(['request', 'table', 'form', 'popup', 'common'], function () {
  73. var request = layui.request,
  74. table = layui.table,
  75. form = layui.form,
  76. popup = layui.popup,
  77. common = layui.common;
  78. var MODULE_PATH = "/system/dict/v1/";
  79. request.tableRender({
  80. url: MODULE_PATH,
  81. cols: [
  82. [
  83. {type: 'checkbox'},
  84. {title: '字典名称', field: 'name', align: 'center'},
  85. {title: '字典编码', field: 'type', align: 'center', templet: '#typeTpl'},
  86. {title: '字典描述', field: 'remark', align: 'center', templet: '#sexTpl'},
  87. {title: '状态', field: 'enable', align: 'center', templet: '#enableTpl'},
  88. {title: '创建时间', field: 'createTime', align: 'center', templet: '#createTimeTpl',},
  89. {title: '操作', toolbar: '#bar', align: 'center'}
  90. ]
  91. ]
  92. });
  93. table.on('tool(table)', function (obj) {
  94. if (obj.event === 'toItem') {
  95. f.item(obj);
  96. }
  97. else if (obj.event === 'edit') {
  98. f.edit(obj);
  99. }
  100. else if (obj.event === 'remove') {
  101. f.remove(obj.data.id)
  102. }
  103. });
  104. table.on('toolbar(table)', function (obj) {
  105. if (obj.event === 'add') {
  106. f.save();
  107. }
  108. else if (obj.event === 'batchRemove') {
  109. f.remove(common.checkField(obj,'id'));
  110. }
  111. });
  112. form.on('submit(query)', function (data) {
  113. refresh(data.field);
  114. return false;
  115. });
  116. form.on('switch(switch)', function (obj) {
  117. request.http({
  118. url: MODULE_PATH,
  119. type: 'put',
  120. data: {id: obj.value, enable: obj.elem.checked? 1: 0},
  121. loading: true,
  122. success: function (result) {
  123. refresh();
  124. if (result.success) {
  125. popup.success(result.msg);
  126. } else {
  127. popup.failure(result.msg);
  128. }
  129. }
  130. });
  131. });
  132. var f = {
  133. save: function() {
  134. layer.open({
  135. type: 2,
  136. title: '新增',
  137. shade: 0.1,
  138. area: ['500px', '400px'],
  139. content: ['add.html', 'no']
  140. });
  141. },
  142. item: function(obj) {
  143. var url = 'view/system/dict/item/main.html?type='+ obj.data.type,
  144. layId = 'dict_item'+ obj.data.type,
  145. title = '字典项管理';
  146. parent.layui.tab.addTabOnlyByElem('content',{id: layId, title: title, url: url, close: true})
  147. },
  148. edit: function(obj) {
  149. layer.open({
  150. type: 2,
  151. title: '修改',
  152. shade: 0.1,
  153. area: ['500px', '400px'],
  154. content: ['add.html?id=' + obj.data.id, 'no']
  155. });
  156. },
  157. remove: function(ids) {
  158. request.http({
  159. url: MODULE_PATH,
  160. type: 'delete',
  161. data: {ids: ids},
  162. success: function (result) {
  163. refresh();
  164. if (result.success) {
  165. popup.success(result.msg);
  166. } else {
  167. popup.failure(result.msg);
  168. }
  169. }
  170. })
  171. }
  172. };
  173. window.refresh = function (param) {
  174. table.reload('table', {where: param});
  175. };
  176. })
  177. </script>
  178. </html>