From a767713971982c669f1bc296107358a25cc82757 Mon Sep 17 00:00:00 2001 From: 1099438829 <1099438829@qq.com> Date: Mon, 1 Mar 2021 00:19:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Article.php | 19 ++++++++++++++++++- app/admin/view/article/add.html | 26 ++++++++++++++++---------- app/admin/view/article/edit.html | 28 +++++++++++++++++----------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index 2ee9ac5..ecf9c77 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\admin\model\Document as aModel; use app\admin\model\DocumentCategory as cModel; +use app\admin\model\DocumentArticle; use app\Request; use app\admin\services\UtilService as Util; @@ -65,6 +66,7 @@ class Article extends AuthController ['type','article'], ['abstract',''], ['keywords',''], + ['content',''], ['description',''], ['is_recommend',0], ['is_top',0], @@ -81,15 +83,30 @@ class Article extends AuthController if ($data['cover_path'] == "") return app("json")->fail("主图不能为空"); $data['writer'] = $data['writer']?:$this->adminInfo['nickname']; $data['uid'] = $this->adminId; + if (!empty($data['content'])){ + $content = $data['content']; + unset($data['content']); + } if ($id=="") { $data['writer'] = $data['writer']?:$this->adminInfo['nickname']; - $res = aModel::save($data); + $id = aModel::insertGetId($data); + if (!empty($content)){ + $updateData = [ + 'id' => $id, + 'content' => $content + ]; + $res = DocumentArticle::save($updateData); + } }else { $ainfo = aModel::get($id); if (!$ainfo)return app("json")->fail("数据不存在"); $res = aModel::where('id',$id)->save($data); + if (!empty($content)){ + //更新文档 + $res = DocumentArticle::where('id',$id)->save(['content'=>$content]); + } } return $res ? app("json")->success("操作成功",'code') : app("json")->fail("操作失败"); } diff --git a/app/admin/view/article/add.html b/app/admin/view/article/add.html index 3527993..2fee57d 100644 --- a/app/admin/view/article/add.html +++ b/app/admin/view/article/add.html @@ -196,20 +196,26 @@ processData: false, contentType: false, success: function (res) { - $("#"+inputName).val(res.data.filePath); - let html ='
\n' + - ' '+res.data.name+'\n' + - '
\n' + - ' \n' + - '
\n' + - '
'; - $('#pic-image').html(html); - $('#pic-image').show().next('li').hide(); + if (res.code == 200){ + $("#"+inputName).val(res.data.filePath); + let html ='
\n' + + ' '+res.data.name+'\n' + + '
\n' + + ' \n' + + '
\n' + + '
'; + $('#pic-image').html(html); + $('#pic-image').show().next('li').hide(); + }else{ + lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); + return false; + } } }); } $(".add-form").submit(function () { let Arr = $('.add-form').serializeArray(); + let checkResult = true; $.each(Arr,function (index,item) { try { switch (item.name) { @@ -239,7 +245,7 @@ if (!checkResult) { return false; } - $.post(url="/admin/cms.cms_article/save",$('.add-form').serialize(),function (res) { + $.post(url="/admin/article/save",$('.add-form').serialize(),function (res) { if (res.code == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');setTimeout(function () {parent.location.reload()},2000)} else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); }); diff --git a/app/admin/view/article/edit.html b/app/admin/view/article/edit.html index 5eb36af..1753966 100644 --- a/app/admin/view/article/edit.html +++ b/app/admin/view/article/edit.html @@ -113,7 +113,7 @@
显示
@@ -196,20 +196,26 @@ processData: false, contentType: false, success: function (res) { - $("#"+inputName).val(res.data.filePath); - let html ='
\n' + - ' '+res.data.name+'\n' + - '
\n' + - ' \n' + - '
\n' + - '
'; - $('#pic-image').html(html); - $('#pic-image').show().next('li').hide(); + if (res.code == 200){ + $("#"+inputName).val(res.data.filePath); + let html ='
\n' + + ' '+res.data.name+'\n' + + '
\n' + + ' \n' + + '
\n' + + '
'; + $('#pic-image').html(html); + $('#pic-image').show().next('li').hide(); + }else{ + lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); + return false; + } } }); } $(".add-form").submit(function () { let Arr = $('.add-form').serializeArray(); + let checkResult = true; $.each(Arr,function (index,item) { try { switch (item.name) { @@ -239,7 +245,7 @@ if (!checkResult) { return false; } - $.post(url="/admin/cms.cms_article/save",$('.add-form').serialize(),function (res) { + $.post(url="/admin/article/save",$('.add-form').serialize(),function (res) { if (res.code == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');setTimeout(function () {parent.location.reload()},2000)} else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); });