Kaynağa Gözat

前端html不再通过js生成,变为创建文章时生成并存储,从而提高页面流畅,已安装程序需要同步后执行数据迁移,已存在文章需要通过手动修改

Moell 9 yıl önce
ebeveyn
işleme
ba952036ab

+ 2 - 0
app/Http/Controllers/Backend/ArticleController.php

@@ -66,6 +66,7 @@ class ArticleController extends Controller
         $article = $this->article->create([
             'title' => $request->title,
             'content'   => $request->get('markdown-content'),
+            'html_content'   => $request->get('html-content'),
             'keyword'   => $request->keyword,
             'desc' => $request->desc,
             'cate_id'   => $request->cate_id,
@@ -123,6 +124,7 @@ class ArticleController extends Controller
             $data['keyword']    = $request->keyword;
             $data['cate_id']    = $request->cate_id;
             $data['content']    = $request->get('markdown-content');
+            $data['html_content']    = $request->get('html-content');
             if ($this->article->update($data, $id)) {
                 $articleTagService->updateArticleTags($id, $request->tags);
                 return redirect('backend/article')

+ 1 - 1
database/migrations/2016_07_25_130523_create_articles_table.php

@@ -17,7 +17,7 @@ class CreateArticlesTable extends Migration
             $table->string('title', 200)->default('')->comment('文章标题');
             $table->string('keyword')->default('')->comment('keywords');
             $table->string('desc')->default('')->comment('描述');
-            $table->longText('content')->defualt('')->comment('文章内容');
+            $table->longText('content')->nullable()->comment('文章内容,markdown格式');
             $table->integer('user_id')->default(0)->comment('文章编写人,对应users表');
             $table->integer('cate_id')->default(0)->comment('文章分类');
             $table->integer('comment_count')->default(0)->comment('评论数量');

+ 31 - 0
database/migrations/2016_09_21_134642_add_html_content_to_articles_table.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddHtmlContentToArticlesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('articles', function (Blueprint $table) {
+            $table->longText('html_content')->nullable()->comment('文章内容,html格式');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('articles', function (Blueprint $table) {
+            $table->dropColumn('html_content');
+        });
+    }
+}

+ 1 - 1
public/default/css/index.css

@@ -205,7 +205,7 @@
     margin: 0;
 }
 #moell-home .text-inner .article-info {
-    color: #ffffff;
+    color: rgba(255, 255, 255, 0.8);
 }
 #moell-home .gradient {
     position: absolute;

+ 1 - 21
public/js/backend.js

@@ -29,27 +29,7 @@ $(function() {
         categoryForm.data('bootstrapValidator').resetForm(true);
         categoryForm[0].reset();
     });
-
-    /* 文章操作验证 */
-    $("#article-form").bootstrapValidator({
-        validatorDefaultParam,
-        fields : {
-            title : {
-                validators : {
-                    notEmpty : {
-                        message : "文章标题不能为空"
-                    }
-                }
-            },
-            cate_id : {
-                validators : {
-                    notEmpty : {
-                        message : "请选择文章分类"
-                    }
-                }
-            }
-        }
-    });
+    
 
     $("#article-form #reset-btn").click(function(){
         var articleForm = $("#article-form");

+ 39 - 10
resources/views/backend/article/create.blade.php

@@ -48,7 +48,7 @@
                             <label for="content">文章内容</label>
                             <div id="editormd">
                                 <textarea class="editormd-markdown-textarea" style="display:none;" id="content" name="markdown-content"></textarea>
-                                <!-- <textarea class="editormd-html-textarea" style="display:none;"  name="html-content"></textarea> -->
+                                <textarea style="display:none;"  name="html-content"></textarea>
                             </div>
                         </div>
                         <div class="form-group">
@@ -74,7 +74,7 @@
 
 
                     <div class="box-footer">
-                        <button type="submit" class="btn btn-primary">发布</button>
+                        <button type="submit" id="submit-article" class="btn btn-primary">发布</button>
                         <button type="button" id="reset-btn" class="btn btn-warning">重置</button>
                     </div>
                 </form>
@@ -88,14 +88,43 @@
 @section('javascript')
     <script src="{{ asset('editor.md/editormd.min.js') }}"></script>
     <script>
-        $(function() {
-            var editor = editormd("editormd", {
-                path        : "{{ asset('/editor.md/lib/') }}/",
-                height  : 500,
-                syncScrolling : "single",
-                toolbarAutoFixed: false,
-                saveHTMLToTextarea : true
-            });
+
+        var editor = editormd("editormd", {
+            path        : "{{ asset('/editor.md/lib/') }}/",
+            height  : 500,
+            syncScrolling : "single",
+            toolbarAutoFixed: false,
+            saveHTMLToTextarea : false
+        });
+
+        /* 文章操作验证 */
+        $("#article-form").bootstrapValidator({
+            live: 'disables',
+            message: "This Values is not valid",
+            feedbackIcons: {
+                valid: 'glyphicon ',
+                invalid: 'glyphicon ',
+                validating: 'glyphicon glyphicon-refresh'
+            },
+            fields : {
+                title : {
+                    validators : {
+                        notEmpty : {
+                            message : "文章标题不能为空"
+                        }
+                    }
+                },
+                cate_id : {
+                    validators : {
+                        notEmpty : {
+                            message : "请选择文章分类"
+                        }
+                    }
+                }
+            }
+        }).on('success.form.bv', function(e) {
+            var html = editor.getPreviewedHTML();
+            $("#article-form textarea[name='html-content']").val(html);
         });
     </script>
 @endsection

+ 38 - 9
resources/views/backend/article/edit.blade.php

@@ -48,7 +48,7 @@
                             <label for="content">文章内容</label>
                             <div id="editormd">
                                 <textarea class="editormd-markdown-textarea" style="display:none;" id="content" name="markdown-content">{{ $article->content }}</textarea>
-                                <!-- <textarea class="editormd-html-textarea" style="display:none;"  name="html-content"></textarea> -->
+                                <textarea  style="display:none;"  name="html-content"></textarea>
                             </div>
                         </div>
                         <div class="form-group">
@@ -90,14 +90,43 @@
 @section('javascript')
     <script src="{{ asset('editor.md/editormd.min.js') }}"></script>
     <script>
-        $(function() {
-            var editor = editormd("editormd", {
-                path        : " {{ asset('/editor.md/lib/') }}/",
-                height  : 500,
-                syncScrolling : "single",
-                toolbarAutoFixed: false,
-                saveHTMLToTextarea : true
-            });
+
+        var editor = editormd("editormd", {
+            path        : " {{ asset('/editor.md/lib/') }}/",
+            height  : 500,
+            syncScrolling : "single",
+            toolbarAutoFixed: false,
+            saveHTMLToTextarea : false
+        });
+
+        /* 文章操作验证 */
+        $("#article-form").bootstrapValidator({
+            live: 'disables',
+            message: "This Values is not valid",
+            feedbackIcons: {
+                valid: 'glyphicon ',
+                invalid: 'glyphicon ',
+                validating: 'glyphicon glyphicon-refresh'
+            },
+            fields : {
+                title : {
+                    validators : {
+                        notEmpty : {
+                            message : "文章标题不能为空"
+                        }
+                    }
+                },
+                cate_id : {
+                    validators : {
+                        notEmpty : {
+                            message : "请选择文章分类"
+                        }
+                    }
+                }
+            }
+        }).on('success.form.bv', function(e) {
+            var html = editor.getPreviewedHTML();
+            $("#article-form textarea[name='html-content']").val(html);
         });
     </script>
 @endsection

+ 4 - 4
resources/views/default/show_article.blade.php

@@ -35,8 +35,8 @@
 @endsection
 
 @section('content')
-    <div id="content-markdown" style="padding:0;">
-        <textarea  style="display:none;">{!! $article->content !!}</textarea>
+    <div class="markdown-body editormd-html-preview" style="padding:0;">
+        {!! $article->html_content !!}
     </div>
 
     <div class="panel panel-default" style="margin-top:5px;">
@@ -72,7 +72,7 @@
     <script src="{{ asset('editor.md/lib/jquery.flowchart.min.js') }}"></script>
 
     <script src="{{ asset('editor.md/editormd.min.js') }}"></script>
-    <script>
+    {{--<<script>
         $(function(){
             editormd.markdownToHTML("content-markdown", {
                 //htmlDecode      : true,       // 开启 HTML 标签解析,为了安全性,默认不开启
@@ -93,5 +93,5 @@
 
             });
         });
-    </script>
+    </script>--}}
 @endsection