save.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <style>
  2. .ck-editor__editable_inline {
  3. height: 400px !important;
  4. }
  5. </style>
  6. <article class="cl pd-20">
  7. <form action="{:url('/sys/article/save')}" method="post" class="form form-horizontal" id="form-save">
  8. <input type="hidden" name="id" value="{$data['id']}">
  9. <input type="hidden" name="content_type" value="{$data['content_type']}">
  10. <div class="row cl">
  11. <label class="form-label col-xs-4 col-sm-2">
  12. <span class="c-red">*</span>栏目:</label>
  13. <div class="formControls col-xs-8 col-sm-6">
  14. <span class="select-box inline">
  15. <select name="cid" class="select" id="cid">
  16. <option value="">所有栏目</option>
  17. {foreach $category_tree as $value}
  18. <option value="{$value.id}" {eq name='data.cid' value="$value.id" }selected{/eq}>{$value.name}
  19. </option>
  20. {notempty name="value.child"}
  21. {foreach $value.child as $val}
  22. <option value="{$val.id}" {eq name='data.cid' value="$val.id" }selected{/eq}>--{$val.name}
  23. </option>
  24. {notempty name="val.child"}
  25. {foreach $val.child as $vo}
  26. <option value="{$vo.id}" {eq name='data.cid' value="$vo.id" }selected{/eq}>&nbsp;&nbsp;└
  27. --{$vo.name}
  28. </option>
  29. {/foreach}
  30. {/notempty}
  31. {/foreach}
  32. {/notempty}
  33. {/foreach}
  34. </select>
  35. </span>
  36. </div>
  37. <div class="col-3"> </div>
  38. </div>
  39. <div class="row cl">
  40. <label class="form-label col-xs-4 col-sm-2">
  41. <span class="c-red">*</span>标题:</label>
  42. <div class="formControls col-xs-8 col-sm-6">
  43. <input type="text" class="input-text" value="{$data.title}" placeholder="请填写标题" id="title" name="title">
  44. </div>
  45. <div class="col-3"> </div>
  46. </div>
  47. <div class="row cl">
  48. <label class="form-label col-xs-4 col-sm-2">
  49. 作者: </label>
  50. <div class="formControls col-xs-4 col-sm-2">
  51. <input type="text" class="input-text" value="{$data.writer}" placeholder="作者" id="writer" name="writer">
  52. </div>
  53. <label class="form-label col-xs-4 col-sm-2">
  54. 来源:</label>
  55. <div class="formControls col-xs-4 col-sm-2">
  56. <input type="text" class="input-text" value="{$data.source}" placeholder="来源" id="source" name="source">
  57. </div>
  58. <div class="col-3"> </div>
  59. </div>
  60. <div class="row cl">
  61. <div class="col-3"> </div>
  62. </div>
  63. <div class="row cl">
  64. <label class="form-label col-xs-4 col-sm-2">
  65. 标题图:</label>
  66. <div class="formControls col-xs-6 col-sm-4">
  67. <input type="text" class="input-text" value="{$data.titlepic}" name="titlepic" id="titlepic">
  68. <div style="width: 160px;height: 160px;">
  69. <a href="javascript:void(0);" onclick="uploadPicture()">
  70. <img id="view-titlepic"
  71. src="{$data.titlepic ? $data.titlepic : '/static/images/upload_picture.png'}" alt="标题图"
  72. title="{$data.titlepic ? '更换' : '添加'}标题图" style="max-width: 160px;max-height: 160px;">
  73. </a>
  74. </div>
  75. </div>
  76. <label class="form-label col-xs-2 col-sm-2">
  77. <a class="btn btn-success radius" href="javascript:void(0);" onclick="uploadPicture()">{$data.titlepic ? '更换' :
  78. '添加'}标题图</a></label>
  79. <div class="col-3"> </div>
  80. </div>
  81. <div class="row cl">
  82. <label class="form-label col-xs-4 col-sm-2">
  83. 关键词:</label>
  84. <div class="formControls col-xs-8 col-sm-6">
  85. <input type="text" class="input-text" value="{$data.keywords}" placeholder="关键词" id="keywords"
  86. name="keywords">
  87. <span class="c-red">多个关键词用英文','分割</span>
  88. </div>
  89. <div class="col-3"> </div>
  90. </div>
  91. <div class="row cl">
  92. <label class="form-label col-xs-4 col-sm-2">内容简介:</label>
  93. <div class="formControls col-xs-8 col-sm-6">
  94. <textarea name="summary" id="summary" cols="" rows="" class="textarea" placeholder="说点什么...最多输入500个字符"
  95. datatype="*10-100" dragonfly="true" onKeyUp="textarealength(this,500)">{$data.summary}</textarea>
  96. <p class="textarea-numberbar">
  97. <em class="textarea-length">0</em>/500
  98. </p>
  99. </div>
  100. <div class="col-3"> </div>
  101. </div>
  102. <div class="row cl">
  103. <label class="form-label col-xs-4 col-sm-2">文章正文:</label>
  104. </div>
  105. <div class="row cl">
  106. <label class="form-label col-xs-1 col-sm-1"></label>
  107. <div class="formControls col-xs-11 col-sm-10">
  108. <div id="editor">{$data.content|raw}</div>
  109. </div>
  110. </div>
  111. <div class="row cl">
  112. <label class="form-label col-xs-2 col-sm-2">
  113. 点击量:</label>
  114. <div class="formControls col-xs-4 col-sm-2">
  115. <input type="number" class="input-text" value="{$data.hits}" id="hits" name="hits"
  116. style="width: 120px;">
  117. </div>
  118. <label class="form-label col-xs-2 col-sm-2">
  119. 排序:</label>
  120. <div class="formControls col-xs-4 col-sm-2">
  121. <input type="number" class="input-text" value="{$data.sort}" id="sort" name="sort"
  122. style="width: 120px;">
  123. </div>
  124. </div>
  125. <div class="row cl">
  126. <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
  127. <button type="button" class="btn btn-success radius" id="form-button-save">确&nbsp;定</button>
  128. <button type="button" class="btn btn-default radius" onclick="window.history.back();"
  129. style="margin-left:20px;">取&nbsp;消</button>
  130. </div>
  131. </div>
  132. </form>
  133. </article>
  134. <!-- 标题图上传 -->
  135. <div>
  136. <form id="form-upload_picture">
  137. <input type="file" hidden name="image" id="upload_picture">
  138. </form>
  139. </div>
  140. <!--请在下方写此页面业务相关的脚本-->
  141. <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/jquery.validate.js"></script>
  142. <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/messages_zh.js"></script>
  143. <script type="text/javascript" src="/static/plugins/jquery.validation/1.14.0/validate-methods.js"></script>
  144. <script type="text/javascript" src="/static/plugins/ckeditor/ckeditor5/ckeditor.js"></script>
  145. <script type="text/javascript">
  146. $(function () {
  147. ClassicEditor.create(document.querySelector('#editor'), {
  148. toolbar: {
  149. items: [
  150. 'sourceEditing', '|',
  151. 'bold', 'italic', 'strikethrough', 'underline', 'subscript', 'superscript', '|',
  152. 'heading', '|',
  153. 'fontfamily', 'fontsize', 'fontColor', 'fontBackgroundColor', 'highlight', '|',
  154. 'alignment', 'outdent', 'indent', '|',
  155. 'undo', 'redo',
  156. '-',
  157. 'link', 'imageUpload', 'imageInsert', 'mediaEmbed', 'insertTable', '|',
  158. 'code', 'codeBlock', 'blockQuote', '|',
  159. 'findAndReplace', 'horizontalLine', 'numberedList', 'bulletedList',
  160. ],
  161. shouldNotGroupWhenFull: true
  162. },
  163. licenseKey: '',
  164. //图片上传
  165. simpleUpload: {
  166. // The URL the images are uploaded to.
  167. uploadUrl: '/sys/file_manager/ckeditorUploadImage'
  168. },
  169. //自定义字体
  170. fontFamily: {
  171. options: [
  172. 'default',
  173. '微软雅黑,Microsoft YaHei',
  174. '新宋体,NSimSun',
  175. '楷体_GB2312,KaiTi_GB2312',
  176. '黑体,SimHei',
  177. '隶书,LiSu',
  178. '幼园,YouYuan',
  179. 'Blackoak Std',
  180. 'Arial',
  181. 'Georgia',
  182. 'Tahoma',
  183. 'Trebuchet MS',
  184. 'verdana',
  185. ]
  186. },
  187. }).then(editor => {
  188. window.editor = editor;
  189. }).catch(error => {
  190. console.error('Oops, something went wrong!');
  191. console.error('Please, report the following error on https://github.com/ckeditor/ckeditor5/issues with the build id and the error stack trace:');
  192. console.warn('Build id: z4e2d8lqju9w-6lwv92tbu4hm');
  193. console.error(error);
  194. });
  195. })
  196. // window.editor.editing.view.change(writer => {
  197. // writer.setStyle('height', '400px', editor.editing.view.document.getRoot());
  198. // });
  199. function validator(params) {
  200. return $("#form-save").validate({
  201. debug: true,
  202. rules: {
  203. title: {
  204. required: true,
  205. }
  206. , summary: {
  207. maxlength: 500,
  208. }
  209. , sort: {
  210. max: 99
  211. }
  212. , cid: {
  213. required: true
  214. }
  215. },
  216. messages: {
  217. title: {
  218. required: "标题不能为空"
  219. }
  220. , cid: {
  221. required: "栏目不能为空"
  222. }
  223. }
  224. });
  225. }
  226. $("#form-button-save").click(function () {
  227. if (!validator().form()) {
  228. return false
  229. }
  230. const content = window.editor.getData();
  231. $("<input/>").attr("type", "hidden").attr("name", "content").val(content).appendTo($("#form-save"));
  232. $("#form-save")[0].submit();
  233. })
  234. //添加标题图
  235. const file = document.querySelector('input[type="file"]');
  236. function uploadPicture() {
  237. // file模拟input点击事件
  238. var evt = new MouseEvent("click", {
  239. bubbles: false,
  240. cancelable: true,
  241. view: window,
  242. });
  243. file.dispatchEvent(evt, uploadfn());
  244. }
  245. function uploadfn() {
  246. file.oninput = function () {
  247. if (file.files && file.files[0]) {
  248. var formData = new FormData();
  249. formData.append("upload_file", file.files[0]);
  250. $.ajax({
  251. url: '{:url("/sys/file_manager/uploadImage")}',
  252. type: "post",
  253. data: formData,
  254. processData: false, // 告诉jQuery不要去处理发送的数据
  255. contentType: false, // 告诉jQuery不要去设置Content-Type请求头
  256. dataType: 'json',
  257. success: function (res) {
  258. // console.log(res);
  259. var img = res.data.filename;
  260. $("#view-titlepic").attr('src', img);
  261. $("#titlepic").val(img);
  262. layer.msg(res.msg, {
  263. icon: 1,
  264. time: 1000
  265. });
  266. },
  267. error: function (res) {
  268. layer.msg(res.msg, {
  269. icon: 5,
  270. time: 1000
  271. });
  272. return false;
  273. },
  274. complete: function () {
  275. document.getElementById('form-upload_picture').reset();
  276. }
  277. });
  278. }
  279. }
  280. }
  281. </script>