add.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style>
  4. .upload-img {
  5. width: 120px;
  6. height: 90px;
  7. overflow: hidden;
  8. position: relative;
  9. border: 1px solid #eee;
  10. padding: 1px;
  11. margin: 5px;
  12. float: left;
  13. }
  14. .upload-close {
  15. position: absolute;
  16. top: 1px;
  17. right: 1px;
  18. }
  19. </style>
  20. {/block}
  21. <!-- 主体 -->
  22. {block name="body"}
  23. <form class="layui-form p-4">
  24. <h3 class="pb-3">新建单页面</h3>
  25. <table class="layui-table layui-table-form">
  26. <tr>
  27. <td class="layui-td-gray">页面标题<font>*</font></td>
  28. <td colspan="3"><input type="text" name="title" lay-verify="required" lay-reqText="请输入页面标题" placeholder="请输入页面标题" class="layui-input"></td>
  29. <td class="layui-td-gray" rowspan="3">缩略图</td>
  30. <td rowspan="3" style="vertical-align:top">
  31. <div class="layui-upload" style="text-align:center;">
  32. <button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">上传封面图(尺寸:750x560)</button>
  33. <div class="layui-upload-list" id="upload_box_thumb">
  34. <img src="" style="width:200px;max-width:200px" />
  35. <input type="hidden" name="thumb" value="">
  36. </div>
  37. </div>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td class="layui-td-gray">关键字<font>*</font></td>
  42. <td colspan="3">
  43. <input type="text" id="keyword_name" name="keyword_names" lay-verify="required" lay-reqText="请选择关键字"
  44. placeholder="请选择关键字" class="layui-input" readonly>
  45. <input type="hidden" id="keyword_id" name="keyword_ids">
  46. </td>
  47. </tr>
  48. <tr>
  49. <td class="layui-td-gray" style="vertical-align:top;">页面摘要</td>
  50. <td colspan="3">
  51. <textarea name="desc" placeholder="请输入页面摘要,200字以内" class="layui-textarea"></textarea>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td class="layui-td-gray">图集相册</td>
  56. <td colspan="5">
  57. <div class="layui-upload">
  58. <button type="button" class="layui-btn layui-btn-sm" id="uploadBtn2">选择上传图片</button>
  59. <div class="layui-upload-list" id="demo2">
  60. <img src="" width="100" style="width:200px;max-width:200px" />
  61. <input type="hidden" name="banner" value="" >
  62. </div>
  63. </div>
  64. </td>
  65. </tr>
  66. <tr>
  67. <td class="layui-td-gray">展示模板<font>*</font></td>
  68. <td>
  69. <select name="template" lay-verify="required" lay-reqText="请选择前台展示模板">
  70. <option value="">请选择前台展示模板</option>
  71. {volist name="$templates" id="vo"}
  72. <option value="{$vo.filename}">{$vo.basename}</option>
  73. {/volist}
  74. </select>
  75. </td>
  76. <td class="layui-td-gray-2">URL文件名称</td>
  77. <td>
  78. <input type="text" name="name" placeholder="请输入URL文件名称" class="layui-input">
  79. </td>
  80. <td class="layui-td-gray">状态</td>
  81. <td>
  82. <input type="radio" name="status" value="1" title="正常" checked>
  83. <input type="radio" name="status" value="0" title="下架">
  84. </td>
  85. </tr>
  86. <tr>
  87. <td colspan="6" class="layui-td-gray" style="text-align:left">页面内容<font>*</font></td>
  88. </tr>
  89. <tr>
  90. <td colspan="6">
  91. <textarea class="layui-textarea" id="container_content"></textarea>
  92. </td>
  93. </tr>
  94. </table>
  95. <div class="pt-3">
  96. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
  97. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  98. </div>
  99. </form>
  100. {/block}
  101. <!-- /主体 -->
  102. <!-- 脚本 -->
  103. {block name="script"}
  104. <script>
  105. // 查找指定的元素在数组中的位置
  106. Array.prototype.indexOf = function (val) {
  107. for (var i = 0; i < this.length; i++) {
  108. if (this[i] == val) {
  109. return i;
  110. }
  111. }
  112. return -1;
  113. };
  114. // 通过索引删除数组元素
  115. Array.prototype.remove = function (val) {
  116. var index = this.indexOf(val);
  117. if (index > -1) {
  118. this.splice(index, 1);
  119. }
  120. };
  121. var moduleInit = ['tool','tagpicker','tinymce'];
  122. function gouguInit() {
  123. var form = layui.form, tool = layui.tool,tagpicker = layui.tagpicker;
  124. //上传缩略图
  125. var upload_thumb = layui.upload.render({
  126. elem: '#upload_btn_thumb',
  127. url: '/admin/api/upload',
  128. done: function (res) {
  129. //如果上传失败
  130. if (res.code == 1) {
  131. return layer.msg('上传失败');
  132. }
  133. //上传成功
  134. $('#upload_box_thumb input').attr('value', res.data.id);
  135. $('#upload_box_thumb img').attr('src', res.data.filepath);
  136. }
  137. });
  138. var tags = new tagpicker({
  139. 'url': '/admin/api/get_keyword_cate',
  140. 'target': 'keyword_name',
  141. 'tag_ids': 'keyword_id',
  142. 'tag_tags': 'keyword_name',
  143. 'height': 500,
  144. 'isDiy': 1
  145. });
  146. //banner图上传
  147. var uploadInst2 = layui.upload.render({
  148. elem: '#uploadBtn2'
  149. , url: '/admin/api/upload'
  150. , done: function (res) {
  151. //如果上传失败
  152. if (res.code == 1) {
  153. return layer.msg('上传失败');
  154. }
  155. //上传成功
  156. var idsStr = $('#demo2 input').val();
  157. var idsArray = [];
  158. if (idsStr != '') {
  159. idsArray = idsStr.split(",");
  160. }
  161. idsArray.push(res.data.id);
  162. $('#demo2 input').attr('value', idsArray.join(','));
  163. $('#demo2').append('<div class="upload-img img-cover" id="uploadImg' + res.data.id + '"><div class="gg-img-cover cover-4-3"><img src="' + res.data.filepath + '"><div class="upload-close"><a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delimg" data-id="' + res.data.id + '">删除</a></div></div></div>');
  164. }
  165. });
  166. $('#demo2').on('click', '[lay-event="delimg"]', function () {
  167. var _id = $(this).data('id');
  168. var idsStr = $('#demo2 input').val();
  169. var idsArray = [];
  170. if (idsStr != '') {
  171. idsArray = idsStr.split(",");
  172. }
  173. idsArray.remove(_id);
  174. $('#demo2 input').attr('value', idsArray.join(','));
  175. $('#uploadImg' + _id).remove();
  176. })
  177. //内容描述富文本编辑器
  178. var edit = layui.tinymce.render({
  179. selector: '#container_content',
  180. height: 500
  181. });
  182. //监听提交
  183. form.on('submit(webform)', function (data) {
  184. data.field.content = tinyMCE.editors['container_content'].getContent();
  185. if (data.field.content == '') {
  186. layer.msg('请先完善内容描述内容');
  187. return false;
  188. }
  189. let callback = function (e) {
  190. layer.msg(e.msg);
  191. if (e.code == 0) {
  192. tool.sideClose(1000);
  193. }
  194. }
  195. tool.post("/admin/pages/add", data.field, callback);
  196. return false;
  197. });
  198. }
  199. </script>
  200. {/block}
  201. <!-- /脚本 -->