create_and_edit.blade.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. @extends('layouts.app')
  2. @section('content')
  3. @include('shared._error')
  4. <div class="ui centered grid container stackable">
  5. <div class="twelve wide column">
  6. <div class="ui segment">
  7. <a class="ui right corner label compose-help" href="javascript:;">
  8. <i class="info icon"></i>
  9. </a>
  10. <div class="content extra-padding">
  11. <div class="ui header text-center text gery" style="margin:10px 0 40px">
  12. @if($book->id)
  13. <i class="icon paint brush"></i>编辑 {{ $book->title }}
  14. <a href="{{ route('course.books.index') }}">教程</a>
  15. @else
  16. <i class="icon paint brush"></i>新建
  17. <a href="{{ route('course.books.index') }}">教程</a>
  18. @endif
  19. </div>
  20. @if($book->id)
  21. <form id="category-update-form"
  22. class="ui form"
  23. style="min-height: 50px;"
  24. action="{{ route('course.books.update', $book->id) }}" method="POST" accept-charset="UTF-8">
  25. <input type="hidden" name="_method" value="PUT">
  26. @else
  27. <form id="category-create-form"
  28. style="min-height: 50px;"
  29. class="ui form"
  30. action="{{ route('course.books.store') }}" method="POST" accept-charset="UTF-8">
  31. @endif
  32. <input type="hidden" name="_token" value="{{ csrf_token() }}">
  33. <div class="field">
  34. <label>名称</label>
  35. <input class="form-control" type="text" name="title"
  36. id="title-field" value="{{ old('title', $book->title ) }}"
  37. placeholder="请填写教程名称" required="">
  38. </div>
  39. <div class="field">
  40. <label>价格</label>
  41. <input class="form-control" type="text" name="prices"
  42. id="title-field" value="{{ old('prices', $book->prices ? $book->prices : '19.99' ) }}"
  43. placeholder="请输入价格(必填)" required="">
  44. </div>
  45. <div class="field">
  46. <label>简介</label>
  47. {{-- 加载 markdown 编辑器 --}}
  48. <div class="markdown-base">
  49. <textarea
  50. id="markdown-editor"
  51. name="excerpt"
  52. placeholder="请填写教程简介。"
  53. rows="6">{{ old('excerpt', $book->excerpt ) }}</textarea>
  54. </div>
  55. </div>
  56. {{-- 封面 --}}
  57. <div class="field">
  58. <label>封面</label>
  59. <input type="hidden" name="image_id" value="{{ old('image_id', $book->image_id) }}">
  60. <img id="upload-img"
  61. class="upload-img image-border ui popover"
  62. data-variation="inverted"
  63. data-content="【点击我】上传图片吧"
  64. src="{{ assert_images($book->image['path']) }}" width="320">
  65. </div>
  66. <div contenteditable="true" id="pastebin"></div>
  67. <div class="ui message">
  68. <button type="submit" class="ui button primary publish-btn loading-on-clicked" id="">
  69. <i class="icon send"></i>
  70. 保存
  71. </button>
  72. </div>
  73. </form>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. @endsection
  79. @section('script')
  80. @include('common.markdown_edit')
  81. <script type="text/javascript">
  82. var markdown = new Markdown();
  83. markdown.init({
  84. 'textarea': {
  85. 'id': 'markdown-editor',
  86. }
  87. });
  88. // 封面上传
  89. $("#upload-img").click(function () {
  90. let self = this;
  91. new MyUploadOne({
  92. 'file_type': 'course',
  93. success: function (res) {
  94. let path = assert_images(res.data.path);
  95. $(self).attr('src', path);
  96. $(self).closest('form').find("input[name='image_id']").val(res.data.id);
  97. }
  98. });
  99. });
  100. </script>
  101. @endsection