From 1a7718be0c2297f0b62b378208886d6a17869ba0 Mon Sep 17 00:00:00 2001 From: augushong Date: Fri, 4 Mar 2022 12:11:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E7=BC=96=E8=BE=91=E5=99=A8;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Post.php | 331 +++++++++++++++--------------- public/static/css/skin-1.css | 116 ++++++----- view/admin/post/create.html | 93 ++------- view/admin/post/edit.html | 249 ++++++---------------- view/admin/post/edit_content.html | 200 ++++++++++++++++++ view/admin/post/index.html | 191 ++++++++--------- 6 files changed, 615 insertions(+), 565 deletions(-) create mode 100644 view/admin/post/edit_content.html diff --git a/app/admin/controller/Post.php b/app/admin/controller/Post.php index 9baea3e..5335217 100644 --- a/app/admin/controller/Post.php +++ b/app/admin/controller/Post.php @@ -15,195 +15,204 @@ use think\Request; class Post extends Common { - /** - * 显示资源列表 - * - * @return \think\Response - */ - public function index() - { - // + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index() + { + // - $list = ModelPost::with(['categorys.category','tags.tag']) - ->where('type',$this->request->param('type',1)) - ->order('id desc') - ->paginate(); + $list = ModelPost::with(['categorys.category', 'tags.tag']) + ->where('type', $this->request->param('type', 1)) + ->order('id desc') + ->paginate(); - View::assign('list', $list); + View::assign('list', $list); - return View::fetch(); - } - - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ - public function create() - { - // - - return View::fetch(); - } - - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - // - $post_data = $request->post(); - - $post_data['uid'] = uniqid(); - - $categorys = []; - $tags = []; - if (isset($post_data['categorys'])) { - $categorys = $post_data['categorys']; - unset($post_data['categorys']); - } - if (isset($post_data['tags'])) { - $tags = $post_data['tags']; - unset($post_data['tags']); + return View::fetch(); } - $model_post = ModelPost::create($post_data); + /** + * 显示创建资源表单页. + * + * @return \think\Response + */ + public function create() + { + // - foreach ($categorys as $category) { - PostCategory::create([ - 'post_id' => $model_post->id, - 'category_id' => $category - ]); - } - foreach ($tags as $tag) { - PostTag::create([ - 'post_id' => $model_post->id, - 'tag_id' => $tag - ]); + return View::fetch(); } - return $this->success('添加成功',url('index',['type'=>$this->request->param('type')])); - } + /** + * 保存新建的资源 + * + * @param \think\Request $request + * @return \think\Response + */ + public function save(Request $request) + { + // + $post_data = $request->post(); - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } + $post_data['uid'] = uniqid(); - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // + $categorys = []; + $tags = []; + if (isset($post_data['categorys'])) { + $categorys = $post_data['categorys']; + unset($post_data['categorys']); + } + if (isset($post_data['tags'])) { + $tags = $post_data['tags']; + unset($post_data['tags']); + } - $model_post = ModelPost::find($id); + $model_post = ModelPost::create($post_data); + foreach ($categorys as $category) { + PostCategory::create([ + 'post_id' => $model_post->id, + 'category_id' => $category + ]); + } + foreach ($tags as $tag) { + PostTag::create([ + 'post_id' => $model_post->id, + 'tag_id' => $tag + ]); + } - View::assign('post', $model_post); - - return View::fetch(); - } - - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - $post_data = $request->post(); - - $model_post = ModelPost::find($id); - - $categorys = []; - $tags = []; - if (isset($post_data['categorys'])) { - $categorys = $post_data['categorys']; - unset($post_data['categorys']); - } - if (isset($post_data['tags'])) { - $tags = $post_data['tags']; - unset($post_data['tags']); + return $this->success('添加成功', url('index', ['type' => $this->request->param('type')])); } - $model_post->save($post_data); - - $old_category_list = PostCategory::where('post_id', $id)->select(); - $old_category_id_list = array_column((array)$old_category_list, 'id'); - $old_tag_list = PostTag::where('post_id', $id)->select(); - $old_tag_id_list = array_column((array)$old_tag_list, 'id'); - - // 旧的有新的没有 - foreach ($old_category_list as $model_category) { - if (!in_array($model_category->id, $categorys)) { - $model_category->delete(); - } - } - foreach ($old_tag_list as $model_tag) { - if (!in_array($model_tag->id, $tags)) { - $model_tag->delete(); - } + /** + * 显示指定的资源 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + // } + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit($id) + { + // - // 旧的没有新的有 - foreach ($categorys as $category) { - if (!in_array($category, $old_category_id_list)) { + $model_post = ModelPost::find($id); - PostCategory::create([ - 'post_id' => $model_post->id, - 'category_id' => $category - ]); - } + + View::assign('post', $model_post); + + return View::fetch(); } - foreach ($tags as $tag) { - if (!in_array($tag, $old_tag_id_list)) { + public function editContent($id) + { + $model_post = ModelPost::find($id); - PostTag::create([ - 'post_id' => $model_post->id, - 'tag_id' => $tag - ]); - } + + View::assign('post', $model_post); + return View::fetch(); } - return $this->success('保存成功', url('index',['type'=>$model_post->getData('type')])); - } + /** + * 保存更新的资源 + * + * @param \think\Request $request + * @param int $id + * @return \think\Response + */ + public function update(Request $request, $id) + { + // + $post_data = $request->post(); - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // + $model_post = ModelPost::find($id); - $model_post = ModelPost::find($id); + $categorys = []; + $tags = []; + if (isset($post_data['categorys'])) { + $categorys = $post_data['categorys']; + unset($post_data['categorys']); + } + if (isset($post_data['tags'])) { + $tags = $post_data['tags']; + unset($post_data['tags']); + } - $model_post->delete(); + $model_post->save($post_data); - PostCategory::where('post_id',$id)->delete(); + $old_category_list = PostCategory::where('post_id', $id)->select(); + $old_category_id_list = array_column((array)$old_category_list, 'id'); + $old_tag_list = PostTag::where('post_id', $id)->select(); + $old_tag_id_list = array_column((array)$old_tag_list, 'id'); - PostTag::where('post_id',$id)->delete(); + // 旧的有新的没有 + foreach ($old_category_list as $model_category) { + if (!in_array($model_category->id, $categorys)) { + $model_category->delete(); + } + } + foreach ($old_tag_list as $model_tag) { + if (!in_array($model_tag->id, $tags)) { + $model_tag->delete(); + } + } - return json_message(); - } + + // 旧的没有新的有 + foreach ($categorys as $category) { + if (!in_array($category, $old_category_id_list)) { + + PostCategory::create([ + 'post_id' => $model_post->id, + 'category_id' => $category + ]); + } + } + + foreach ($tags as $tag) { + if (!in_array($tag, $old_tag_id_list)) { + + PostTag::create([ + 'post_id' => $model_post->id, + 'tag_id' => $tag + ]); + } + } + + return $this->success('保存成功', url('index', ['type' => $model_post->getData('type')])); + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + // + + $model_post = ModelPost::find($id); + + $model_post->delete(); + + PostCategory::where('post_id', $id)->delete(); + + PostTag::where('post_id', $id)->delete(); + + return json_message(); + } } diff --git a/public/static/css/skin-1.css b/public/static/css/skin-1.css index 5506544..c2f885e 100644 --- a/public/static/css/skin-1.css +++ b/public/static/css/skin-1.css @@ -1,28 +1,27 @@ -@media screen and (max-width: 768px){ +@media screen and (max-width: 768px) {} -} -.layui-nav-tree .layui-nav-item a:hover{ +.layui-nav-tree .layui-nav-item a:hover { background-color: #6699CC; } -.layui-bg-black{ - background-color: #66CCFF !important; +.layui-bg-black { + background-color: #66CCFF !important; } -.layui-nav-tree .layui-nav-child dd.layui-this, -.layui-nav-tree .layui-nav-child dd.layui-this a, -.layui-nav-tree .layui-this, -.layui-nav-tree .layui-this > a, -.layui-nav-tree .layui-this > a:hover{ +.layui-nav-tree .layui-nav-child dd.layui-this, +.layui-nav-tree .layui-nav-child dd.layui-this a, +.layui-nav-tree .layui-this, +.layui-nav-tree .layui-this>a, +.layui-nav-tree .layui-this>a:hover { background-color: #6699CC; } -.layui-layout-admin .layui-logo{ - color: #fff; +.layui-layout-admin .layui-logo { + color : #fff; line-height: 45px; } -.layui-layout-admin .layui-header{ +.layui-layout-admin .layui-header { background-color: #39BDFF; } @@ -30,17 +29,17 @@ background-color: #66CCFF; } -.layui-header{ +.layui-header { height: 45px; } -.layui-nav .layui-nav-item{ +.layui-nav .layui-nav-item { line-height: 45px; } .layui-nav .layui-nav-item a { color: #FFFFFF; - + } .layui-nav .layui-nav-child a { @@ -53,94 +52,103 @@ background-color: #CCFFFF; } -.layui-tab-brief > .layui-tab-title .layui-this{ +.layui-tab-brief>.layui-tab-title .layui-this { color: #66CCFF; } -.layui-tab-brief > .layui-tab-more li.layui-this::after, .layui-tab-brief > .layui-tab-title .layui-this::after{ +.layui-tab-brief>.layui-tab-more li.layui-this::after, +.layui-tab-brief>.layui-tab-title .layui-this::after { border-color: #66CCFF; } -.layui-btn{ +.layui-btn { background-color: #66CCFF; } -.layui-form-radio > i:hover, .layui-form-radioed > i{ + +.layui-form-radio>i:hover, +.layui-form-radioed>i { color: #66CCFF; } -.layui-elem-quote{ +.layui-elem-quote { border-color: #66CCFF; } -.layui-laydate td.layui-this{ +.layui-laydate td.layui-this { background-color: #66CCFF !important; } -.layui-form-checkbox[lay-skin="primary"]:hover i{ +.layui-form-checkbox[lay-skin="primary"]:hover i { border-color: #66CCFF; } -.layui-form-checked[lay-skin="primary"] i{ - border-color: #66CCFF !important; + +.layui-form-checked[lay-skin="primary"] i { + border-color : #66CCFF !important; background-color: #66CCFF !important; } -.layui-form-select dl dd.layui-this{ - background-color: #66CCFF; +.layui-form-select dl dd.layui-this { + background-color: #66CCFF; } -.layui-form-label{ - width: unset; - padding: 3px 3px; - float: unset; - text-align: left; - font-weight: 600; - font-size: 15px; +.layui-form-label { + width : unset; + padding : 3px 3px; + float : unset; + text-align : left; + font-weight: 600; + font-size : 15px; } -.layui-input-block{ - margin-left: 0; +.layui-input-block { + margin-left: 0; } -.layui-form-pane .layui-form-label{ - float: left; - font-weight: normal; - font-size: 14px; +.layui-form-pane .layui-form-label { + float : left; + font-weight: normal; + font-size : 14px; } -.layui-nav-tree .layui-nav-item a{ - height: 35px; +.layui-nav-tree .layui-nav-item a { + height : 35px; line-height: 35px; } -.layui-nav-tree{ +.layui-nav-tree { width: 140px; } -.layui-layout-admin .layui-side{ + +.layui-layout-admin .layui-side { width: 140px; - top: 45px; + top : 45px; } -.layui-layout-admin .layui-footer{ - left: 140px; - height: 35px; + +.layui-layout-admin .layui-footer { + left : 140px; + height : 35px; line-height: 35px; } -.layui-layout-admin .layui-body{ - top: 45px; + +.layui-layout-admin .layui-body { + top : 45px; + bottom: 35px; } -.layui-side-scroll{ +.layui-side-scroll { width: 140px; } -.layui-body{ +.layui-body { left: 140px; } -.layui-nav .layui-nav-child dd.layui-this a, .layui-nav-child dd.layui-this{ +.layui-nav .layui-nav-child dd.layui-this a, +.layui-nav-child dd.layui-this { background-color: #19B3FF; } -.layui-nav-tree .layui-nav-bar{ +.layui-nav-tree .layui-nav-bar { background-color: #66CCFF; } \ No newline at end of file diff --git a/view/admin/post/create.html b/view/admin/post/create.html index fe3ad34..e7dded5 100644 --- a/view/admin/post/create.html +++ b/view/admin/post/create.html @@ -7,8 +7,6 @@ 内容管理 {include file="common/_require"} - - + + + + + + + + +
+ {include file="common/_header"} + + {include file="common/left_post"} + +
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + + {include file="common/_footer"} + +
+ + + + + + + \ No newline at end of file diff --git a/view/admin/post/index.html b/view/admin/post/index.html index e745958..6807f40 100644 --- a/view/admin/post/index.html +++ b/view/admin/post/index.html @@ -2,115 +2,116 @@ - - - - 内容管理 - {include file="common/_require"} + + + + 内容管理 + {include file="common/_require"} - + -
- {include file="common/_header"} +
+ {include file="common/_header"} - {include file="common/left_post"} + {include file="common/left_post"} -
+
-
-
- - 首页 - 系统信息 - +
+
+ + 首页 + 系统信息 + +
+
+
+ 添加 +
+
+
+ + + + + + + + + + + + + + + + {volist name='list' id='vo'} + + + + + + + + + + + + + + {/volist} + {if condition="count($list) == 0" } + + + + {/if} + +
ID名称封面简介排序状态分类标签操作
{$vo.id}{$vo.title}{$vo.desc_short}{$vo.sort}{$vo.status_name} + {volist name='vo.categorys_list' id='category'} +

{:str_repeat('|--',$category.level)}{$category.title}

+ {/volist} +
+ {volist name='vo.tags_list' id='tag'} + {$tag.title} + {/volist} + +
+ 查看 + 设置 + 编辑 +
删除
+
+
暂无数据
+
+ {$list|raw} +
+
+
-
-
- 添加 -
-
-
- - - - - - - - - - - - - - - - {volist name='list' id='vo'} - - - - - - - - - - - - - - {/volist} - {if condition="count($list) == 0" } - - - - {/if} - -
ID名称封面简介排序状态分类标签操作
{$vo.id}{$vo.title}{$vo.desc_short}{$vo.sort}{$vo.status_name} - {volist name='vo.categorys_list' id='category'} -

{:str_repeat('|--',$category.level)}{$category.title}

- {/volist} -
- {volist name='vo.tags_list' id='tag'} - {$tag.title} - {/volist} - -
- 查看 - 编辑 -
删除
-
-
暂无数据
-
- {$list|raw} -
-
-
+ {include file="common/_footer"}
- {include file="common/_footer"} -
- + \ No newline at end of file