edit.html 11 KB

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