article-edit.art 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {{extend './common/layout.art'}}
  2. {{block 'main'}}
  3. <!-- 子模板的相对路径相对的是当前文件,因为它是由模板引擎解析的,而不是浏览器-->
  4. {{include './common/header.art'}}
  5. <!-- 主体内容 -->
  6. <div class="content">
  7. {{include './common/sider.art'}}
  8. <div class="main">
  9. <!-- 分类标题 -->
  10. <div class="title">
  11. <h4>{{@article ? article._id: ''}}</h4>
  12. </div>
  13. <!-- /分类标题 -->
  14. <form class="form-container" action={{link}} method="post" enctype="multipart/form-data">
  15. <div class="form-group">
  16. <label>标题</label>
  17. <input type="text" class="form-control" placeholder="请输入文章标题" name="title" value={{article && article.title}}>
  18. </div>
  19. <div class="form-group">
  20. <label>作者</label>
  21. <input type="text" class="form-control" readonly name="author" value={{@userInfo._id}}>
  22. </div>
  23. <div class="form-group">
  24. <label>发布时间</label>
  25. <input type="date" class="form-control" name="publishDate" value={{article && dateformat(article.publishDate, 'yyyy-mm-dd')}}>
  26. </div>
  27. <div class="form-group">
  28. <label for="exampleInputFile">文章封面</label>
  29. <input type="file" name="cover" id="file" value=""{{article && article.cover}}"">
  30. <div class="thumbnail-waper">
  31. <img class="img-thumbnail" src="{{article && article.cover}}" id="preview">
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <label>内容</label>
  36. <textarea class="form-control" id="editor" name="content">{{article && article.content}}</textarea>
  37. </div>
  38. <div class="buttons">
  39. <input type="submit" class="btn btn-primary" value={{button}}>
  40. </div>
  41. </form>
  42. </div>
  43. </div>
  44. <!-- /主体内容 -->
  45. {{/block}}
  46. {{block 'script'}}
  47. <script src="lib/ckeditor5/ckeditor.js"></script>
  48. <script type="text/javascript">
  49. let editor;
  50. ClassicEditor
  51. .create( document.querySelector('#editor'))
  52. .then(newEditor => {
  53. editor = newEditor;
  54. })
  55. .catch( error => {
  56. console.error( error );
  57. });
  58. // 获取数据
  59. // const editorData = editor.getData();
  60. var file = document.querySelector('#file');
  61. // 监听文件上传事件
  62. file.onchange = function () {
  63. var reader = new FileReader();
  64. // 读取文件
  65. reader.readAsDataURL(this.files[0])
  66. reader.onload = function () {
  67. $('#preview').prop('src', reader.result)
  68. }
  69. }
  70. </script>
  71. {{/block}}