add.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style>
  4. .layui-upload-add {position: relative;padding:16px 0;font-size:14px;box-sizing: border-box;text-align: center;cursor: pointer;color: #999;width:100%; background-color:#F5FAFF}
  5. .layui-upload-add .layui-icon{font-size:48px; color:#3c9cff}
  6. .gallery-item{background-color:#fff; padding:12px 12px 0; position:relative; padding-right:268px; margin:12px 0; box-sizing: border-box;border: 1px solid #eee;}
  7. .gallery-item .gallery-thumb{width:256px; height:144px; position:absolute; top:12px; right:12px; text-align:center;}
  8. .gallery-item .layui-btn-group{position:absolute; top:12px; right:12px; display:none;}
  9. .gallery-item:hover .layui-btn-group{display:block;}
  10. .gallery-thumb img {display: block;width: 100%;height: 100%;object-fit: cover;}
  11. .gallery-from .layui-form-label{width:50px;}
  12. </style>
  13. {/block}
  14. <!-- 主体 -->
  15. {block name="body"}
  16. <form class="layui-form p-3">
  17. <div class="layui-row layui-col-space12">
  18. <div class="layui-col-md8">
  19. <table class="layui-table layui-table-form">
  20. <tr>
  21. <td class="layui-td-gray">图集标题<font>*</font></td>
  22. <td><input type="text" name="title" lay-verify="required" lay-reqText="请输入图集标题" placeholder="请输入图集标题" class="layui-input"></td>
  23. </tr>
  24. <tr>
  25. <td class="layui-td-gray" style="vertical-align:top;">图集简介</td>
  26. <td>
  27. <textarea name="desc" placeholder="请输入图集简介,200字以内" class="layui-textarea"></textarea>
  28. </td>
  29. </tr>
  30. </table>
  31. <div id="imgList"></div>
  32. <div class="layui-row" style="border:1px solid #eee;">
  33. <div class="layui-col-xs6" id="upload-one">
  34. <div class="layui-upload-add">
  35. <i class="layui-icon">&#xe681;</i>
  36. <p>单个上传图片</p>
  37. </div>
  38. </div>
  39. <div class="layui-col-xs6" id="upload-more">
  40. <div class="layui-upload-add">
  41. <i class="layui-icon">&#xe67c;</i>
  42. <p>批量上传图片</p>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="layui-col-md4">
  48. <table class="layui-table layui-table-form">
  49. <tr>
  50. <td class="layui-td-gray">图集分类<font>*</font></td>
  51. <td>
  52. <select name="cate_id" lay-verify="required" lay-reqText="请选择图集分类">
  53. <option value="">请选择图集分类</option>
  54. {volist name=":set_recursion(get_gallery_cate())" id="v"}
  55. <option value="{$v.id}">{$v.title}</option>
  56. {/volist}
  57. </select>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td class="layui-td-gray">状态<font>*</font></td>
  62. <td>
  63. <input type="radio" name="status" value="1" title="正常" checked>
  64. <input type="radio" name="status" value="0" title="下架">
  65. </td>
  66. </tr>
  67. <tr>
  68. <td class="layui-td-gray">关键字<font>*</font></td>
  69. <td>
  70. <input type="text" id="keyword_name" name="keyword_names" lay-verify="required" lay-reqText="请选择关键字"
  71. placeholder="请选择关键字" class="layui-input" readonly>
  72. <input type="hidden" id="keyword_id" name="keyword_ids">
  73. </td>
  74. </tr>
  75. <tr>
  76. <td class="layui-td-gray">封面图</td>
  77. <td style="vertical-align:top">
  78. <div class="layui-upload" style="text-align:center;">
  79. <button type="button" class="layui-btn layui-btn-sm" id="uploadBtn">上传图集封面图(尺寸:500x500)</button>
  80. <div class="layui-upload-list" id="demo1">
  81. <img src="" width="100" style="width:200px;max-width:200px" />
  82. <input type="hidden" name="thumb" value="">
  83. </div>
  84. </div>
  85. </td>
  86. </tr>
  87. <tr>
  88. <td class="layui-td-gray">作者/来源</td>
  89. <td>
  90. <input type="text" name="origin" class="layui-input" autocomplete="off" placeholder="请输入来源" value="">
  91. </td>
  92. </tr>
  93. <tr>
  94. <td class="layui-td-gray">属性</td>
  95. <td>
  96. <select name="type">
  97. <option value="">请选择属性</option>
  98. <option value="3">置顶</option>
  99. <option value="2">精华</option>
  100. <option value="1">推荐</option>
  101. </select>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td class="layui-td-gray">首页显示</td>
  106. <td>
  107. <input type="radio" name="is_home" value="1" title="是" checked>
  108. <input type="radio" name="is_home" value="0" title="否">
  109. </td>
  110. </tr>
  111. <tr>
  112. <td class="layui-td-gray">排序</td>
  113. <td>
  114. <input type="text" name="sort" value="0" lay-verify="number" placeholder="请输入排序,数字" class="layui-input">
  115. </td>
  116. </tr>
  117. </table>
  118. <div class="py-3">
  119. <input type="hidden" name="id" value="0">
  120. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
  121. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  122. <button lay-event="back" class="layui-btn layui-btn-primary">关闭</button>
  123. </div>
  124. </div>
  125. </form>
  126. {/block}
  127. <!-- /主体 -->
  128. <!-- 脚本 -->
  129. {block name="script"}
  130. <script>
  131. var moduleInit = ['tool', 'tagpicker','uploadplus'];
  132. function gouguInit() {
  133. var form = layui.form, tool = layui.tool,element = layui.element, tagspicker = layui.tagpicker, upload = layui.upload, uploadplus = layui.uploadplus;
  134. var tags = new tagspicker({
  135. 'url': '/admin/api/get_keyword_cate',
  136. 'target': 'keyword_name',
  137. 'tag_ids': 'keyword_id',
  138. 'tag_tags': 'keyword_name',
  139. 'height': 500,
  140. 'isDiy': 1
  141. });
  142. var upload_one = new uploadplus({
  143. 'url': '/admin/api/upload/thumb/500',
  144. 'target': 'upload-one',
  145. 'type': 1,
  146. 'callback':function(res){
  147. console.log(res);
  148. appendImg(res,0);
  149. }
  150. });
  151. var upload_more = new uploadplus({
  152. 'url': '/admin/api/upload/thumb/500',
  153. 'target': 'upload-more',
  154. 'type': 2,
  155. 'callback':function(res){
  156. console.log(res);
  157. for(let i=0;i<res.length;i++){
  158. appendImg(res[i],0);
  159. }
  160. }
  161. });
  162. $('#imgList').on('click','.item-edit',function(){
  163. let id=$(this).data('id');
  164. let that = $(this);
  165. var upload_one = new uploadplus({
  166. 'url': '/admin/api/upload/thumb/500',
  167. 'target': that,
  168. 'type': 1,
  169. 'callback':function(res){
  170. console.log(res);
  171. appendImg(res,id);
  172. }
  173. });
  174. });
  175. $('#imgList').on('click','.item-del',function(){
  176. let id=$(this).data('id');
  177. $('#item_'+id).remove();
  178. });
  179. //缩略图上传
  180. var uploadInst = upload.render({
  181. elem: '#uploadBtn'
  182. , url: '/admin/api/upload/thumb/500'
  183. , done: function (res) {
  184. //如果上传失败
  185. if (res.code == 1) {
  186. return layer.msg('上传失败');
  187. }
  188. //上传成功
  189. $('#demo1 input').attr('value', res.data.id);
  190. $('#demo1 img').attr('src', res.data.filepath);
  191. }
  192. });
  193. //监听返回
  194. $('body').on('click', '[lay-event="back"]', function () {
  195. tool.tabClose();
  196. return false;
  197. });
  198. //监听提交
  199. form.on('submit(webform)', function (data) {
  200. let callback = function (e) {
  201. if (e.code == 0) {
  202. tool.tabRefresh(94);
  203. layer.confirm('保存成功,关闭当前页面吗?', { icon: 3, title: '提示' }, function (index) {
  204. tool.tabClose();
  205. });
  206. } else {
  207. layer.msg(e.msg);
  208. }
  209. }
  210. tool.post("/admin/gallery/add", data.field, callback);
  211. return false;
  212. });
  213. function appendImg(res,id){
  214. if(id == 0){
  215. id = Date.now();
  216. $('#imgList').append(`<div class="gallery-item" id="item_${id}">
  217. <div class="gallery-from">
  218. <table class="layui-table layui-table-form" style="margin-top:0">
  219. <tr>
  220. <td class="layui-td-gray">标题<font>*</font></td>
  221. <td><input type="text" class="layui-input img-name-input" name="img_title[]" value="${res.name}" placeholder="" autocomplete="off"></td>
  222. <td class="layui-td-gray">排序</td>
  223. <td style="width:60px"><input type="text" name="img_sort[]" value="" placeholder="" autocomplete="off" class="layui-input"></td>
  224. </tr>
  225. <tr>
  226. <td class="layui-td-gray" style="vertical-align:top;">简介</td>
  227. <td colspan="3">
  228. <textarea name="img_desc[]" value="" placeholder="" class="layui-textarea" style="min-height:75px;"></textarea>
  229. <input type="hidden" name="img_file[]" class="img-file-input" value="${res.id}">
  230. <input type="hidden" name="img_filepath[]" class="img-filepath-input" value="${res.filepath}">
  231. <input type="hidden" name="img_name[]" class="img-name-input" value="${res.name}">
  232. <input type="hidden" name="img_link[]" class="img-link-input" value="">
  233. </td>
  234. </tr>
  235. </table>
  236. </div>
  237. <div class="gallery-thumb">
  238. <img src="${res.filepath}" class="img-filepath">
  239. </div>
  240. <div class="layui-btn-group">
  241. <span class="layui-btn layui-btn-xs item-edit" title="编辑" data-id="${id}">编辑</span>
  242. <span class="layui-btn layui-btn-xs layui-btn-danger item-del" data-id="${id}" title="删除">删除</span>
  243. </div>
  244. </div>`);
  245. }
  246. else{
  247. $('#item_'+id).find('.img-filepath').attr('src',res.filepath);
  248. $('#item_'+id).find('.img-name-input').val(res.name);
  249. $('#item_'+id).find('.img-filepath-input').val(res.filepath);
  250. $('#item_'+id).find('.img-name-input').val(res.name);
  251. $('#item_'+id).find('.img-file-input').val(res.id);
  252. }
  253. }
  254. }
  255. </script>
  256. {/block}
  257. <!-- /脚本 -->