edit.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style type="text/css">
  4. .editormd-code-toolbar select {display: inline-block}
  5. .editormd li {list-style: inherit;}
  6. </style>
  7. {/block}
  8. <!-- 主体 -->
  9. {block name="body"}
  10. <form class="layui-form p-4">
  11. <h3 class="pb-3">编辑文章表</h3>
  12. <table class="layui-table layui-table-form">
  13. <tr>
  14. <td class="layui-td-gray">文章标题<font>*</font></td>
  15. <td colspan="7"> <input type="text" name="title" lay-verify="required" lay-reqText="请输入文章标题"
  16. autocomplete="off" placeholder="请输入文章标题" class="layui-input" value="{$detail.title}"></td>
  17. </tr>
  18. <tr>
  19. <td class="layui-td-gray">文章分类<font>*</font></td>
  20. <td>
  21. <select name="cate_id" lay-verify="required" lay-reqText="请选择分类">
  22. <option value="">请选择分类</option>
  23. {volist name=":set_recursion(get_article_cate())" id="v"}
  24. <option value="{$v.id}" {eq name="$detail.cate_id" value="$v.id" }selected{/eq}>{$v.title}
  25. </option>
  26. {/volist}
  27. </select>
  28. </td>
  29. <td class="layui-td-gray">关键字<font>*</font></td>
  30. <td>
  31. <input type="text" id="keyword_name" name="keyword_names" autocomplete="off" lay-verify="required"
  32. lay-reqText="请选择关键字" placeholder="请选择关键字" class="layui-input" value="{$detail.keyword_names}"
  33. readonly>
  34. <input type="hidden" id="keyword_id" name="keywords_id" autocomplete="off"
  35. value="{$detail.keyword_ids}">
  36. </td>
  37. <td class="layui-td-gray">状态<font>*</font></td>
  38. <td>
  39. <input type="radio" name="status" value="1" title="正常" {eq name="$detail.status" value="1"
  40. }checked{/eq}>
  41. <input type="radio" name="status" value="0" title="下架" {eq name="$detail.status" value="0"
  42. }checked{/eq}>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td class="layui-td-gray">排序</td>
  47. <td>
  48. <input type="text" name="sort" placeholder="请输入排序,数字" autocomplete="off" class="layui-input"
  49. value="{$detail.sort}">
  50. </td>
  51. <td class="layui-td-gray">首页显示</td>
  52. <td>
  53. <input type="radio" name="is_home" value="1" title="是" {eq name="$detail.is_home" value="1"
  54. }checked{/eq}>
  55. <input type="radio" name="is_home" value="0" title="否" {eq name="$detail.is_home" value="0"
  56. }checked{/eq}>
  57. </td>
  58. <td class="layui-td-gray">属性</td>
  59. <td>
  60. <select name="type">
  61. <option value="">请选择属性</option>
  62. <option value="1" {eq name="$detail.type" value="1" }selected{/eq}>精华</option>
  63. <option value="2" {eq name="$detail.type" value="2" }selected{/eq}>热门</option>
  64. <option value="3" {eq name="$detail.type" value="3" }selected{/eq}>推荐</option>
  65. </select>
  66. </td>
  67. </tr>
  68. <tr>
  69. <td class="layui-td-gray">是否原创</td>
  70. <td>
  71. <input type="radio" name="original" value="1" title="是" {eq name="$detail.original" value="1"
  72. }checked{/eq}>
  73. <input type="radio" name="original" value="0" title="否" {eq name="$detail.original" value="0"
  74. }checked{/eq}>
  75. </td>
  76. <td class="layui-td-gray">作者/来源</td>
  77. <td>
  78. <input type="text" name="origin" class="layui-input" autocomplete="off" placeholder="请输入文章来源"
  79. value="{$detail.origin}">
  80. </td>
  81. <td class="layui-td-gray">来源链接</td>
  82. <td>
  83. <input type="text" name="origin_url" class="layui-input" autocomplete="off" placeholder="请输入来源链接"
  84. value="{$detail.origin_url}">
  85. </td>
  86. </tr>
  87. <tr>
  88. <td class="layui-td-gray" style="vertical-align:top;">摘要</td>
  89. <td colspan="3">
  90. <textarea name="desc" placeholder="请输入摘要,不能超过200个字" class="layui-textarea">{$detail.desc}</textarea>
  91. </td>
  92. <td class="layui-td-gray" style="vertical-align:top;">缩略图</td>
  93. <td>
  94. <div class="layui-upload">
  95. <button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">上传缩略图(尺寸:640x360)</button>
  96. <div class="layui-upload-list" id="upload_box_thumb" style="width: 120px; height:66px; overflow: hidden;">
  97. <img src="{:get_file($detail.thumb)}" onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;" style="max-width: 100%; height:66px;" />
  98. <input type="hidden" name="thumb" value="{$detail.thumb}">
  99. </div>
  100. </div>
  101. </td>
  102. </tr>
  103. {eq name="$editor" value="1"}
  104. <tr>
  105. <td colspan="6" class="layui-td-gray" style="text-align:left">文章内容<font>*</font><span class="ml-4 red">当前为TinyMCE富文本编辑器,可在【系统管理->系统配置->其他配置】中切换为mardown编辑器</span></td>
  106. </tr>
  107. <tr>
  108. <td colspan="6">
  109. <textarea placeholder="请输入内容" class="layui-textarea" id="container_content">{$detail.content}</textarea>
  110. </td>
  111. </tr>
  112. {else/}
  113. <tr>
  114. <td colspan="6" class="layui-td-gray" style="text-align:left">文章内容<font>*</font><span class="ml-4 red">当前为mardown编辑器,可在【系统管理->系统配置->其他配置】中切换为TinyMCE富文本编辑器</span></td>
  115. </tr>
  116. <tr>
  117. <td colspan="6">
  118. <div style="margin-top:-2px; margin-right:2px">
  119. <textarea id="mdContent" style="display:none;">{$detail.md_content|raw}</textarea>
  120. <div id="docContent"></div>
  121. </div>
  122. </td>
  123. </tr>
  124. {/eq}
  125. </table>
  126. <div class="pt-3">
  127. <input type="hidden" name="id" value="{$detail.id}"/>
  128. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
  129. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  130. </div>
  131. </form>
  132. {/block}
  133. <!-- /主体 -->
  134. <!-- 脚本 -->
  135. {block name="script"}
  136. <script>
  137. const editorType = '{$editor}';
  138. var moduleInit;
  139. if (editorType == 1) {
  140. moduleInit = ['tool', 'tagpicker', 'tinymce'];
  141. }
  142. else {
  143. moduleInit = ['tool', 'tagpicker', 'editormd'];
  144. }
  145. function gouguInit() {
  146. var form = layui.form, tool = layui.tool,tagpicker = layui.tagpicker;
  147. var tags = new tagpicker({
  148. 'url': '/admin/api/get_keyword_cate',
  149. 'target': 'keyword_name',
  150. 'tag_ids': 'keyword_id',
  151. 'tag_tags': 'keyword_name',
  152. 'height': 500,
  153. 'isDiy': 1
  154. });
  155. //上传缩略图
  156. var upload_thumb = layui.upload.render({
  157. elem: '#upload_btn_thumb',
  158. url: '/admin/api/upload',
  159. done: function (res) {
  160. //如果上传失败
  161. if (res.code == 1) {
  162. layer.msg('上传失败');
  163. return false;
  164. }
  165. //上传成功
  166. $('#upload_box_thumb input').attr('value', res.data.id);
  167. $('#upload_box_thumb img').attr('src', res.data.filepath);
  168. }
  169. });
  170. if (editorType == 1) {
  171. var editor = layui.tinymce;
  172. var edit = editor.render({
  173. selector: "#container_content",
  174. height: 500
  175. });
  176. //监听提交
  177. form.on('submit(webform)', function (data) {
  178. data.field.content = tinyMCE.editors['container_content'].getContent();
  179. if (data.field.content == '') {
  180. layer.msg('请先完善文章内容');
  181. return false;
  182. }
  183. let callback = function (e) {
  184. layer.msg(e.msg);
  185. if (e.code == 0) {
  186. tool.sideClose(1000);
  187. }
  188. }
  189. tool.post("/admin/article/edit", data.field, callback);
  190. return false;
  191. });
  192. }
  193. else {
  194. var editor = layui.editormd;
  195. var edit = editor.render('docContent', {
  196. markdown: document.getElementById('mdContent').value
  197. });
  198. //监听提交
  199. form.on('submit(webform)', function (data) {
  200. if (data.field.mdContent == '') {
  201. layer.msg('请先完善文章内容');
  202. return false;
  203. }
  204. let callback = function (e) {
  205. layer.msg(e.msg);
  206. if (e.code == 0) {
  207. tool.sideClose(1000);
  208. }
  209. }
  210. tool.post("/admin/article/edit", data.field, callback);
  211. return false;
  212. });
  213. }
  214. }
  215. </script>
  216. {/block}
  217. <!-- /脚本 -->