mirror of
https://gitee.com/ulthon/layui-ul.git
synced 2026-07-08 13:22:47 +08:00
完成文档分类
This commit is contained in:
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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');
|
||||||
@@ -17,26 +17,32 @@ class Category extends Model
|
|||||||
public static $allCategory = [];
|
public static $allCategory = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function post()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Post::class, 'category_id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定id下的所有分类
|
* 获取指定id下的所有分类
|
||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @return void
|
* @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();
|
$model_list = Category::where('type', $type)->order('sort asc')->select();
|
||||||
self::$allCategory = array2level($model_list,0,0);
|
self::$allCategory = array2level($model_list, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($id)){
|
if (!empty($id)) {
|
||||||
$list = [];
|
$list = [];
|
||||||
$in_category = [$id];
|
$in_category = [$id];
|
||||||
foreach (self::$allCategory as $category) {
|
foreach (self::$allCategory as $category) {
|
||||||
if(in_array($category->pid,$in_category)){
|
if (in_array($category->pid, $in_category)) {
|
||||||
$list[] = $category;
|
$list[] = $category;
|
||||||
$in_category[] = $category->id;
|
$in_category[] = $category->id;
|
||||||
}
|
}
|
||||||
@@ -51,13 +57,13 @@ class Category extends Model
|
|||||||
|
|
||||||
public function getTitleImgAttr($value)
|
public function getTitleImgAttr($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
return get_source_link($value);
|
return get_source_link($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function posts()
|
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 = [];
|
$list_post = [];
|
||||||
|
|
||||||
foreach ($list_post_category as $list_post_category) {
|
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;
|
return $list_post;
|
||||||
@@ -86,34 +92,34 @@ class Category extends Model
|
|||||||
public function getPostsListAttr()
|
public function getPostsListAttr()
|
||||||
{
|
{
|
||||||
$list_post_category = $this->getAttr('posts');
|
$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;
|
return $list_post;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTplNameAttr($value)
|
public function getTplNameAttr($value)
|
||||||
{
|
{
|
||||||
return Config::get('view_type.category.'.$value);
|
return Config::get('view_type.category.' . $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModelParentAttr()
|
public function getModelParentAttr()
|
||||||
{
|
{
|
||||||
$pid = $this->getData('pid');
|
$pid = $this->getData('pid');
|
||||||
|
|
||||||
if($pid == 0){
|
if ($pid == 0) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
return Category::where('id',$pid)->find();
|
return Category::where('id', $pid)->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回除自身以外的其他的同级同类的分类
|
// 返回除自身以外的其他的同级同类的分类
|
||||||
public function getModelSiblingsAttr()
|
public function getModelSiblingsAttr()
|
||||||
{
|
{
|
||||||
return Category::where('pid',$this->getData('pid'))
|
return Category::where('pid', $this->getData('pid'))
|
||||||
->where('level',$this->getData('level'))
|
->where('level', $this->getData('level'))
|
||||||
->where('id','<>',$this->getData('id'))
|
->where('id', '<>', $this->getData('id'))
|
||||||
->select();
|
->select();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,9 +129,8 @@ class Category extends Model
|
|||||||
*/
|
*/
|
||||||
public function getModelSameParentAttr()
|
public function getModelSameParentAttr()
|
||||||
{
|
{
|
||||||
return Category::where('pid',$this->getData('pid'))
|
return Category::where('pid', $this->getData('pid'))
|
||||||
->where('level',$this->getData('level'))
|
->where('level', $this->getData('level'))
|
||||||
->select();
|
->select();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
|
||||||
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;
|
return $list_post;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -143,9 +143,11 @@
|
|||||||
<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'}
|
||||||
</select>
|
<option value="{$vo.id}">{$vo.title}</option>
|
||||||
|
{/volist}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
@@ -154,9 +156,9 @@
|
|||||||
<input type="text" name="jump_to_url" class="layui-input">
|
<input type="text" name="jump_to_url" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
</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">
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -40,9 +40,9 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th >名称</th>
|
<th>名称</th>
|
||||||
<th>封面</th>
|
<th>封面</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.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'}
|
||||||
|
|||||||
@@ -30,15 +30,25 @@
|
|||||||
<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-item-title">
|
<div class="ul-nav-tree-group">
|
||||||
{$post.title}
|
<div class="ul-nav-tree-group-title">
|
||||||
|
{$category.title}
|
||||||
</div>
|
</div>
|
||||||
<div class="ul-nav-tree-item-desc">
|
<div class="ul-nav-tree-group-main">
|
||||||
{$post.desc}
|
{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>
|
||||||
|
<div class="ul-nav-tree-item-desc">
|
||||||
|
{$post.desc}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{/volist}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</div>
|
||||||
{/volist}
|
{/volist}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user