add.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
  2. <div style="margin: 10px 0px">
  3. <blockquote class="layui-elem-quote">
  4. 说明:新建管理员默认密码为:george518
  5. </blockquote>
  6. </div>
  7. <form class="layui-form" action="" method="post" >
  8. <div class="layui-form-item">
  9. <label class="layui-form-label">登录账号</label>
  10. <div class="layui-input-inline">
  11. <input type="text" name="login_name" id="login_name" lay-verify="required" autocomplete="off" placeholder="登录账号" class="layui-input" value="">
  12. </div>
  13. <div class="layui-form-mid layui-word-aux">*英文,数字或_,6位以上</div>
  14. </div>
  15. <div class="layui-form-item">
  16. <label class="layui-form-label">真实姓名</label>
  17. <div class="layui-input-inline">
  18. <input type="text" name="real_name" id="real_name" lay-verify="required" autocomplete="off" placeholder="真实姓名" class="layui-input" value="">
  19. </div>
  20. <div class="layui-form-mid layui-word-aux">*</div>
  21. </div>
  22. <div class="layui-form-item">
  23. <label class="layui-form-label">手机号码</label>
  24. <div class="layui-input-inline">
  25. <input type="text" name="phone" lay-verify="phone|required" autocomplete="off" placeholder="手机号码" class="layui-input" value="">
  26. </div>
  27. <div class="layui-form-mid layui-word-aux">*</div>
  28. </div>
  29. <div class="layui-form-item">
  30. <label class="layui-form-label">电子邮箱</label>
  31. <div class="layui-input-inline">
  32. <input type="text" name="email" id="email" lay-verify="email" autocomplete="off" placeholder="电子邮箱" class="layui-input" value="">
  33. </div>
  34. <div class="layui-form-mid layui-word-aux">*</div>
  35. </div>
  36. <div class="layui-form-item">
  37. <label class="layui-form-label">选择角色</label>
  38. <div class="layui-input-block">
  39. {{range $k, $v := .role}}
  40. <input type="checkbox" name="role_ids" lay-filter="role_ids" title="{{$v.role_name}}" value="{{$v.id}}">
  41. {{end}}
  42. </div>
  43. <div class="layui-form-mid layui-word-aux">*</div>
  44. </div>
  45. <input type="hidden" value="" id="roleids" name="roleids">
  46. <div class="layui-form-item">
  47. <div class="layui-input-block">
  48. <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
  49. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  50. </div>
  51. </div>
  52. </form>
  53. </div>
  54. <script>
  55. var $;
  56. layui.config({
  57. base : "js/"
  58. }).use(['form','element','layer','jquery'],function(){
  59. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  60. var $ = layui.jquery;
  61. var role_ids = [];
  62. form.on('checkbox(role_ids)', function(data){
  63. if(data.elem.checked==true){
  64. role_ids.push(data.value)
  65. }else{
  66. $.each(role_ids,function(index,item){
  67. // index是索引值(即下标) item是每次遍历得到的值;
  68. if(item==data.value){
  69. role_ids.splice(index,1);
  70. }
  71. });
  72. }
  73. $("#roleids").val(role_ids.join(","));
  74. });
  75. form.on('submit(sub)', function(data){
  76. var form_data = $("form").serialize();
  77. $.post('{{urlfor "AdminController.AjaxSave"}}', form_data, function (out) {
  78. if (out.status == 0) {
  79. layer.msg("操作成功",{icon: 1},function () {
  80. window.location.reload()
  81. })
  82. } else {
  83. layer.msg(out.message)
  84. }
  85. }, "json");
  86. return false;
  87. });
  88. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  89. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  90. form.render();
  91. });
  92. </script>