Template-.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html>
  2. <html class="x-admin-sm">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="renderer" content="webkit">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  8. <link rel="shortcut icon" href="../favicon.ico">
  9. <link rel="bookmark" href="../favicon.ico">
  10. <link rel="stylesheet" href="../css/font.css">
  11. <link rel="stylesheet" href="../css/xadmin.css">
  12. <link rel="stylesheet" href="../layui/css/layui.css">
  13. <script type="text/javascript" src="../layui/layui.js" charset="utf-8"></script>
  14. <script type="text/javascript" src="../js/xadmin.js"></script>
  15. <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
  16. <!--[if lt IE 9]>
  17. <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  18. <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  19. <![endif]--></head>
  20. <body>
  21. <div class="layui-fluid">
  22. <div class="layui-row">
  23. <form class="layui-form">
  24. <div class="layui-form-item">
  25. <label class="layui-form-label">
  26. <span class="x-red">*</span>图片</label>
  27. <div class="layui-input-inline">
  28. <div class="layui-upload">
  29. <button type="button" class="layui-btn" id="test1">上传图片</button>
  30. <div class="layui-upload-list">
  31. <img {{if gt .id 0 }}
  32. src="{{.Date.T_img}}"
  33. {{end}} style="max-height: 100px;height: 100px" class="layui-upload-img" id="demo1">
  34. <p id="demoText"></p>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="layui-form-item">
  40. <label for="T_name" class="layui-form-label">
  41. <span class="x-red">*</span>名称</label>
  42. <div class="layui-input-inline">
  43. <input {{if gt .id 0 }}
  44. value="{{.Date.Id}}"
  45. {{end}} type="text" id="T_name" name="T_name" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
  46. </div>
  47. <div class="layui-form-item">
  48. <label class="layui-form-label">
  49. <span class="x-red">*</span>分类</label>
  50. <div class="layui-input-inline">
  51. <select lay-filter="T_class" id="T_class" name="T_class" class="valid" >
  52. {{range $index, $elem := .Class_List}}
  53. <option value="{{$elem.Id}}" {{if gt $.id 0 }}
  54. {{if eq $.Date.T_class $elem.Id }}
  55. selected
  56. {{end}}
  57. {{end}}
  58. >{{$elem.T_name}}</option>
  59. {{end}}
  60. </select>
  61. </div>
  62. </div>
  63. <div class="layui-form-item">
  64. <label for="T_int" class="layui-form-label">
  65. <span class="x-red">*</span>数字</label>
  66. <div class="layui-input-inline">
  67. <input {{if gt .id 0 }}
  68. value="{{.Date.T_int}}"
  69. {{end}} type="text" id="T_int" name="T_int" placeholder="¥" autocomplete="off" class="layui-input">
  70. </div>
  71. <div class="layui-form-mid layui-word-aux">
  72. <span class="x-red">*</span>
  73. </div>
  74. </div>
  75. <div class="layui-form-item layui-form-text">
  76. <label for="T_text" class="layui-form-label">描述</label>
  77. <div class="layui-input-block">
  78. <textarea class="layui-textarea" id="T_text" style="display: none" >
  79. {{if gt .id 0 }}
  80. {{.Date.T_text}}
  81. {{end}}
  82. </textarea>
  83. </div>
  84. </div>
  85. <div class="layui-form-item" style="text-align: center;margin-top: 20px">
  86. <!-- <label for="L_repass" class="layui-form-label"></label>-->
  87. <button class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button></div>
  88. </form>
  89. </div>
  90. </div>
  91. <script>
  92. layui.use(['form', 'layer',"layedit"],
  93. function() {
  94. $ = layui.jquery;
  95. var form = layui.form,
  96. layer = layui.layer;
  97. var layedit = layui.layedit
  98. layedit.set({
  99. uploadImage: {
  100. url: '/UpFile' //接口url
  101. }
  102. });
  103. //构建一个默认的编辑器
  104. var index = layedit.build('T_text', {
  105. height: 580 //设置编辑器高度,
  106. });
  107. //监听提交
  108. form.on('submit(add)',
  109. function(data) {
  110. console.log("=== submit(add) ==");
  111. console.log(data);
  112. $.ajax({
  113. type: 'POST',
  114. url: 'List_Post',//发送请求
  115. data: {
  116. id:"{{.id}}",
  117. T_name:data.field.T_name,
  118. T_class:data.field.T_class,
  119. T_int:data.field.T_int,
  120. T_img:T_img,
  121. T_text:layedit.getContent(index),
  122. },
  123. success: function(result) {
  124. console.log(result)
  125. if(result.Code == 200){
  126. layer.msg("操作成功", {
  127. icon: 1,
  128. time: 2000
  129. });
  130. }else {
  131. layer.msg("错误:"+result.Msg, {
  132. icon: 2,
  133. time: 2000
  134. });
  135. }
  136. //
  137. //关闭当前frame
  138. parent.layer.close(parent.layer.getFrameIndex(window.name));
  139. parent.location.reload();
  140. form.render('select');
  141. // return false;
  142. }
  143. });
  144. return false;
  145. });
  146. });
  147. </script>
  148. <script>
  149. T_img = "{{.Date.T_img}}"
  150. layui.use('upload', function(){
  151. var $ = layui.jquery
  152. ,upload = layui.upload;
  153. //普通图片上传
  154. var uploadInst = upload.render({
  155. elem: '#test1'
  156. ,url: '/UpFile' //改成您自己的上传接口
  157. ,before: function(obj){
  158. //预读本地文件示例,不支持ie8
  159. obj.preview(function(index, file, result){
  160. $('#demo1').attr('src', result); //图片链接(base64)
  161. });
  162. }
  163. ,done: function(res){
  164. console.log(res)
  165. //如果上传失败
  166. if(res.code != 0){
  167. return layer.msg('上传失败');
  168. }
  169. T_img = res.data.src
  170. console.log(T_img)
  171. //上传成功
  172. }
  173. ,error: function(){
  174. console.log("error")
  175. //演示失败状态,并实现重传
  176. var demoText = $('#demoText');
  177. demoText.html('<span style="color: #ff5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
  178. demoText.find('.demo-reload').on('click', function(){
  179. uploadInst.upload();
  180. });
  181. }
  182. });
  183. //绑定原始文件域
  184. upload.render({
  185. elem: '#test20'
  186. ,url: 'https://httpbin.org/post' //改成您自己的上传接口
  187. ,done: function(res){
  188. layer.msg('上传成功');
  189. console.log(res)
  190. }
  191. });
  192. });
  193. </script>
  194. </body>
  195. </html>