mirror of
https://gitee.com/ulthon/layui-ul.git
synced 2026-07-01 10:32:49 +08:00
完成文档分类
This commit is contained in:
@@ -126,13 +126,10 @@ class Category extends Common
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_category = ModelCategory::where('title',$post_data['title'])
|
||||
->where('pid',$post_data['pid'])
|
||||
->where('type',$post_data['type'])
|
||||
->where('id','<>',$id)
|
||||
->find();
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ class Post extends Common
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
ModelPost::quickSelect(true);
|
||||
$list_post = ModelPost::quickSelect(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +119,9 @@ class Post extends Common
|
||||
//
|
||||
|
||||
$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);
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ class Index extends Common
|
||||
*
|
||||
* @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)) {
|
||||
$model_post = $list_post->first();
|
||||
$model_post = $list_post->first()->post->first();
|
||||
} 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);
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
use think\facade\Route;
|
||||
|
||||
Route::rule('doc/[:post_id]','Index/index');
|
||||
Route::rule('doc/[:category_id]/[:post_id]','Index/index');
|
||||
@@ -17,26 +17,32 @@ class Category extends Model
|
||||
public static $allCategory = [];
|
||||
|
||||
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->hasMany(Post::class, 'category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定id下的所有分类
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public static function getListLevel($id = '',$type = 1)
|
||||
public static function getListLevel($id = '', $type = 1)
|
||||
{
|
||||
|
||||
if(empty(self::$allCategory)){
|
||||
if (empty(self::$allCategory)) {
|
||||
|
||||
$model_list = Category::where('type',$type)->order('sort asc')->select();
|
||||
self::$allCategory = array2level($model_list,0,0);
|
||||
$model_list = Category::where('type', $type)->order('sort asc')->select();
|
||||
self::$allCategory = array2level($model_list, 0, 0);
|
||||
}
|
||||
|
||||
if(!empty($id)){
|
||||
if (!empty($id)) {
|
||||
$list = [];
|
||||
$in_category = [$id];
|
||||
foreach (self::$allCategory as $category) {
|
||||
if(in_array($category->pid,$in_category)){
|
||||
if (in_array($category->pid, $in_category)) {
|
||||
$list[] = $category;
|
||||
$in_category[] = $category->id;
|
||||
}
|
||||
@@ -57,7 +63,7 @@ class Category extends Model
|
||||
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class,'category_id');
|
||||
return $this->hasMany(PostCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +78,7 @@ class Category extends Model
|
||||
$list_post = [];
|
||||
|
||||
foreach ($list_post_category as $list_post_category) {
|
||||
array_push($list_post,$list_post_category->post);
|
||||
array_push($list_post, $list_post_category->post);
|
||||
}
|
||||
|
||||
return $list_post;
|
||||
@@ -87,32 +93,32 @@ class Category extends Model
|
||||
{
|
||||
$list_post_category = $this->getAttr('posts');
|
||||
|
||||
$list_post = array_column($list_post_category->append(['post'])->toArray(),'post');
|
||||
$list_post = array_column($list_post_category->append(['post'])->toArray(), 'post');
|
||||
|
||||
return $list_post;
|
||||
}
|
||||
|
||||
public function getTplNameAttr($value)
|
||||
{
|
||||
return Config::get('view_type.category.'.$value);
|
||||
return Config::get('view_type.category.' . $value);
|
||||
}
|
||||
|
||||
public function getModelParentAttr()
|
||||
{
|
||||
$pid = $this->getData('pid');
|
||||
|
||||
if($pid == 0){
|
||||
if ($pid == 0) {
|
||||
return $this;
|
||||
}
|
||||
return Category::where('id',$pid)->find();
|
||||
return Category::where('id', $pid)->find();
|
||||
}
|
||||
|
||||
// 返回除自身以外的其他的同级同类的分类
|
||||
public function getModelSiblingsAttr()
|
||||
{
|
||||
return Category::where('pid',$this->getData('pid'))
|
||||
->where('level',$this->getData('level'))
|
||||
->where('id','<>',$this->getData('id'))
|
||||
return Category::where('pid', $this->getData('pid'))
|
||||
->where('level', $this->getData('level'))
|
||||
->where('id', '<>', $this->getData('id'))
|
||||
->select();
|
||||
}
|
||||
|
||||
@@ -123,9 +129,8 @@ class Category extends Model
|
||||
*/
|
||||
public function getModelSameParentAttr()
|
||||
{
|
||||
return Category::where('pid',$this->getData('pid'))
|
||||
->where('level',$this->getData('level'))
|
||||
return Category::where('pid', $this->getData('pid'))
|
||||
->where('level', $this->getData('level'))
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ class Post extends Model
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'category_id');
|
||||
}
|
||||
|
||||
public function categorys()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class, 'post_id');
|
||||
@@ -162,11 +167,15 @@ class Post extends Model
|
||||
$list_post = Cache::get($cacke_key);
|
||||
|
||||
if (empty($list_post) || $clear) {
|
||||
$list_post = Post::where('status', 1)->order('sort desc')->select();
|
||||
Cache::set($cacke_key, $list_post,600);
|
||||
|
||||
$list_post = Category::with(['post'])->where('type', 'default')
|
||||
->where('status', 1)
|
||||
->order('sort asc')
|
||||
->select();
|
||||
|
||||
Cache::set($cacke_key, $list_post, 600);
|
||||
}
|
||||
|
||||
return $list_post;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
border-right: 1px solid #bbb;
|
||||
}
|
||||
|
||||
.ul-nav-tree-group-title{
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
.ul-nav-tree-item {
|
||||
display : flex;
|
||||
align-items: baseline;
|
||||
|
||||
@@ -143,8 +143,10 @@
|
||||
<div class="layui-form-label">分类</div>
|
||||
<div class="layui-input-block">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -140,7 +140,17 @@
|
||||
<input type="radio" name="status" value="0" title="不发布">
|
||||
</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-label">跳转链接</div>
|
||||
<div class="layui-input-block">
|
||||
@@ -315,6 +325,7 @@
|
||||
is_top: '{$post->getData("is_top")}',
|
||||
jump_to_url_status: '{$post->getData("jump_to_url_status")}',
|
||||
tpl_name: '{$post->getData("tpl_name")}',
|
||||
category_id: '{$post->getData("category_id")}',
|
||||
})
|
||||
|
||||
form.on('submit(save)', function (data) {
|
||||
|
||||
@@ -40,9 +40,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th >名称</th>
|
||||
<th>名称</th>
|
||||
<th>封面</th>
|
||||
<th >简介</th>
|
||||
<th>简介</th>
|
||||
<th>排序</th>
|
||||
<th>状态</th>
|
||||
<th>分类</th>
|
||||
@@ -62,9 +62,7 @@
|
||||
<td>{$vo.sort}</td>
|
||||
<td>{$vo.status_name}</td>
|
||||
<td>
|
||||
{volist name='vo.categorys_list' id='category'}
|
||||
<p>{:str_repeat('|--',$category.level)}{$category.title}</p>
|
||||
{/volist}
|
||||
{$vo.category.title|default="未分类"}
|
||||
</td>
|
||||
<td>
|
||||
{volist name='vo.tags_list' id='tag'}
|
||||
|
||||
@@ -30,8 +30,15 @@
|
||||
<div class="layui-row layui-col-space6 " style="margin-top: 15px;">
|
||||
<div class="layui-col-md3">
|
||||
<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">
|
||||
{$post.title}
|
||||
</div>
|
||||
@@ -40,6 +47,9 @@
|
||||
</div>
|
||||
</a>
|
||||
{/volist}
|
||||
</div>
|
||||
</div>
|
||||
{/volist}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user