add.html 6.7 KB

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