完成文档分类

This commit is contained in:
augushong
2021-03-29 12:33:31 +08:00
parent 6fd50e255d
commit a993db8781
11 changed files with 94 additions and 53 deletions

View File

@@ -126,13 +126,10 @@ class Category extends Common
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
// //
$post_data = $request->post(); $post_data = $request->post();
$model_category = ModelCategory::where('title',$post_data['title']) $model_category = ModelCategory::where('title',$post_data['title'])
->where('pid',$post_data['pid']) ->where('pid',$post_data['pid'])
->where('type',$post_data['type'])
->where('id','<>',$id) ->where('id','<>',$id)
->find(); ->find();

View File

@@ -19,7 +19,8 @@ class Post extends Common
{ {
parent::initialize(); parent::initialize();
ModelPost::quickSelect(true); $list_post = ModelPost::quickSelect(true);
} }
/** /**
@@ -118,7 +119,9 @@ class Post extends Common
// //
$model_post = ModelPost::find($id); $model_post = ModelPost::find($id);
$list_category = Category::where('status', 1)->order('sort asc')->select();
View::assign('list_category', $list_category);
View::assign('post', $model_post); View::assign('post', $model_post);

View File

@@ -16,14 +16,14 @@ class Index extends Common
* *
* @return \think\Response * @return \think\Response
*/ */
public function index($post_id = 0) public function index($post_id = 0,$category_id = 0)
{ {
$list_post = Post::quickSelect();
$list_post = Post::quickSelect();
if (empty($post_id)) { if (empty($post_id)) {
$model_post = $list_post->first(); $model_post = $list_post->first()->post->first();
} else { } else {
$model_post = $list_post->where('id', $post_id)->first(); $model_post = $list_post->where('id',$category_id)->column('post')[0]->where('id', $post_id)->first();
} }
View::assign('model_post', $model_post); View::assign('model_post', $model_post);

View File

@@ -2,4 +2,4 @@
use think\facade\Route; use think\facade\Route;
Route::rule('doc/[:post_id]','Index/index'); Route::rule('doc/[:category_id]/[:post_id]','Index/index');

View File

@@ -17,6 +17,12 @@ class Category extends Model
public static $allCategory = []; public static $allCategory = [];
public function post()
{
return $this->hasMany(Post::class, 'category_id');
}
/** /**
* 获取指定id下的所有分类 * 获取指定id下的所有分类
* *
@@ -127,5 +133,4 @@ class Category extends Model
->where('level', $this->getData('level')) ->where('level', $this->getData('level'))
->select(); ->select();
} }
} }

View File

@@ -25,6 +25,11 @@ class Post extends Model
protected $defaultSoftDelete = 0; protected $defaultSoftDelete = 0;
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
public function categorys() public function categorys()
{ {
return $this->hasMany(PostCategory::class, 'post_id'); return $this->hasMany(PostCategory::class, 'post_id');
@@ -162,11 +167,15 @@ class Post extends Model
$list_post = Cache::get($cacke_key); $list_post = Cache::get($cacke_key);
if (empty($list_post) || $clear) { if (empty($list_post) || $clear) {
$list_post = Post::where('status', 1)->order('sort desc')->select();
$list_post = Category::with(['post'])->where('type', 'default')
->where('status', 1)
->order('sort asc')
->select();
Cache::set($cacke_key, $list_post, 600); Cache::set($cacke_key, $list_post, 600);
} }
return $list_post; return $list_post;
} }
} }

View File

@@ -3,6 +3,12 @@
border-right: 1px solid #bbb; border-right: 1px solid #bbb;
} }
.ul-nav-tree-group-title{
font-size: 16px;
font-weight: 600;
line-height: 2;
}
.ul-nav-tree-item { .ul-nav-tree-item {
display : flex; display : flex;
align-items: baseline; align-items: baseline;

View File

@@ -143,8 +143,10 @@
<div class="layui-form-label">分类</div> <div class="layui-form-label">分类</div>
<div class="layui-input-block"> <div class="layui-input-block">
<select name="category_id" lay-verify=""> <select name="category_id" lay-verify="">
<option value="0">请选择一个城市</option> <option value="0">请选择一个分类</option>
{volist name='list_category' id='vo'}
<option value="{$vo.id}">{$vo.title}</option>
{/volist}
</select> </select>
</div> </div>
</div> </div>

View File

@@ -140,7 +140,17 @@
<input type="radio" name="status" value="0" title="不发布"> <input type="radio" name="status" value="0" title="不发布">
</div> </div>
</div> </div>
<div class="layui-form-item">
<div class="layui-form-label">分类</div>
<div class="layui-input-block">
<select name="category_id" lay-verify="">
<option value="0">请选择一个分类</option>
{volist name='list_category' id='vo'}
<option value="{$vo.id}">{$vo.title}</option>
{/volist}
</select>
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<div class="layui-form-label">跳转链接</div> <div class="layui-form-label">跳转链接</div>
<div class="layui-input-block"> <div class="layui-input-block">
@@ -315,6 +325,7 @@
is_top: '{$post->getData("is_top")}', is_top: '{$post->getData("is_top")}',
jump_to_url_status: '{$post->getData("jump_to_url_status")}', jump_to_url_status: '{$post->getData("jump_to_url_status")}',
tpl_name: '{$post->getData("tpl_name")}', tpl_name: '{$post->getData("tpl_name")}',
category_id: '{$post->getData("category_id")}',
}) })
form.on('submit(save)', function (data) { form.on('submit(save)', function (data) {

View File

@@ -62,9 +62,7 @@
<td>{$vo.sort}</td> <td>{$vo.sort}</td>
<td>{$vo.status_name}</td> <td>{$vo.status_name}</td>
<td> <td>
{volist name='vo.categorys_list' id='category'} {$vo.category.title|default="未分类"}
<p>{:str_repeat('|--',$category.level)}{$category.title}</p>
{/volist}
</td> </td>
<td> <td>
{volist name='vo.tags_list' id='tag'} {volist name='vo.tags_list' id='tag'}

View File

@@ -30,8 +30,15 @@
<div class="layui-row layui-col-space6 " style="margin-top: 15px;"> <div class="layui-row layui-col-space6 " style="margin-top: 15px;">
<div class="layui-col-md3"> <div class="layui-col-md3">
<div class="ul-nav-tree ul-padding-md"> <div class="ul-nav-tree ul-padding-md">
{volist name='list_post' id='post'}
<a href="{:url('Index/index',['post_id'=>$post.id])}" class="ul-nav-tree-item"> {volist name='list_post' id='category'}
<div class="ul-nav-tree-group">
<div class="ul-nav-tree-group-title">
{$category.title}
</div>
<div class="ul-nav-tree-group-main">
{volist name='category.post' id='post'}
<a href="{:url('Index/index',['post_id'=>$post.id,'category_id'=>$post.category_id])}" class="ul-nav-tree-item">
<div class="ul-nav-tree-item-title"> <div class="ul-nav-tree-item-title">
{$post.title} {$post.title}
</div> </div>
@@ -40,6 +47,9 @@
</div> </div>
</a> </a>
{/volist} {/volist}
</div>
</div>
{/volist}
</div> </div>
</div> </div>