add_config.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {include file="public/header" /}
  2. <body class="gray-bg">
  3. <div class="layui-fluid layui-col-md12">
  4. <div class="layui-card">
  5. <div class="layui-card-body layui-form">
  6. <div class="layui-row layui-col-space10 layui-form-item ">
  7. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  8. <label class="layui-form-label">配置标识</label>
  9. <div class="layui-input-block">
  10. <input type="text" name="name" lay-verify="required|name" placeholder="用于config函数调用,只能使用英文且不能重复" class="layui-input ">
  11. </div>
  12. </div>
  13. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  14. <label class="layui-form-label">配置标题</label>
  15. <div class="layui-input-block">
  16. <input type="text" name="title" lay-verify="required" placeholder="用于后台显示的配置标题" class="layui-input ">
  17. </div>
  18. </div>
  19. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  20. <label class="layui-form-label">配置类型</label>
  21. <div class="layui-input-block">
  22. <select name="type" id="type" lay-verify="required" lay-search="" lay-filter="types" >
  23. <option value="">请选择类型</option>
  24. {if !empty($Think.config.config_type_list)}
  25. {volist name="Think.config.config_type_list" id="type"}
  26. <option value="{$key}">{$type}</option>
  27. {/volist}
  28. {/if}
  29. </select>
  30. </div>
  31. </div>
  32. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  33. <label class="layui-form-label">配置分组</label>
  34. <div class="layui-input-block">
  35. <select name="group" lay-verify="required" lay-search="">
  36. <option value="">请选择分组</option>
  37. {if !empty($Think.config.config_group_list)}
  38. {volist name="Think.config.config_group_list" id="type"}
  39. <option value="{$key}">{$type}</option>
  40. {/volist}
  41. {/if}
  42. </select>
  43. </div>
  44. </div>
  45. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  46. <label class="layui-form-label">配置值</label>
  47. <div class="layui-input-block">
  48. <input type="text" name="value" lay-verify="required" placeholder="用于config函数调用显示的值" class="layui-input ">
  49. </div>
  50. </div>
  51. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  52. <label class="layui-form-label">配置项</label>
  53. <div class="layui-input-block">
  54. <textarea name="extra" placeholder="如果是枚举型,需要配置该项" lay-verify="extra" class="layui-textarea"></textarea>
  55. </div>
  56. </div>
  57. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  58. <label class="layui-form-label">配置描述</label>
  59. <div class="layui-input-block">
  60. <textarea name="remark" lay-verify="required" placeholder="配置详细说明" class="layui-textarea"></textarea>
  61. </div>
  62. </div>
  63. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  64. <label class="layui-form-label">排序</label>
  65. <div class="layui-input-block">
  66. <input type="text" name="sort" lay-verify="required|sort" placeholder="用于显示的顺序" class="layui-input " value="50">
  67. </div>
  68. </div>
  69. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  70. <label class="layui-form-label">状态</label>
  71. <div class="layui-input-block">
  72. <input type="radio" name="status" value="1" title="启用" checked>
  73. <input type="radio" name="status" value="2" title="禁用" >
  74. </div>
  75. </div>
  76. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  77. <div class="layui-input-block">
  78. <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
  79. </button>
  80. <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. {include file="public/footer" /}
  88. <script>
  89. layui.use(['form'], function() {
  90. var form = layui.form;
  91. form.verify({
  92. name:function(value,item){
  93. if(!/^[a-zA-Z_]*$/.test(value)){
  94. return '只能使用英文和下划线且不能重复';
  95. }
  96. var checkResult = "";
  97. $.ajax({
  98. url:"{:url('Config/checkConfig')}",
  99. type:'post',
  100. data:"name="+value,
  101. async: false,//必须同步
  102. success:function(res){
  103. if(res.code == 100){
  104. checkResult = "该配置标识已存在";
  105. }
  106. }
  107. })
  108. return checkResult;
  109. },
  110. extra: function(value,item){
  111. var type = $('#type').find("option:selected").text();
  112. if(type == "枚举" && value == ""){
  113. return "配置类型为枚举,配置项必填";
  114. }
  115. },
  116. sort:[/^(0|[1-9]\d*)$/,'排序值只能为非负整数']
  117. });
  118. form.on('submit(component-form-element)', function (data) {
  119. $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
  120. $.ajax({
  121. url:"{:url('add_config')}",
  122. type:'post',
  123. dataType:'json',
  124. data:data.field,
  125. success:function(res){
  126. if (res.code == 200) {
  127. wk.success(res.msg,'wk.layer_close()');
  128. } else {
  129. wk.error(res.msg,'$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\')');
  130. }
  131. }
  132. })
  133. });
  134. });
  135. </script>
  136. </body>
  137. </html>