完善文章管理

This commit is contained in:
2020-04-18 20:43:44 +08:00
parent 84c1a51b86
commit 7238e1770c
9 changed files with 305 additions and 5 deletions

View File

@@ -74,6 +74,7 @@ php think reset_password
- 文件管理 - 文件管理
- 后台日志 - 后台日志
- 支持轮播图,导航,小程序导航(打开方式)等设置 - 支持轮播图,导航,小程序导航(打开方式)等设置
- 实现CMS后台
- 适配手机端,实现table转卡片样式 - 适配手机端,实现table转卡片样式

View File

@@ -189,5 +189,15 @@ class Post extends Common
public function delete($id) 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();
} }
} }

View File

@@ -8,11 +8,57 @@ class ColumnFormat
public static function timestamp($name){ public static function timestamp($name){
return Column::make($name,'integer') return Column::make($name,'integer')
->setLimit(10) ->setLimit(10)
->setSigned(false); ->setSigned(false)
->setDefault(0);
} }
public static function loadDeleteTime(){
return Column::make('delete_time','integer') public static function stringLong($name)
{
return Column::make($name,'string')
->setLimit(500)
->setDefault('');
}
public static function stringNormal($name)
{
return Column::make($name,'string')
->setLimit(100)
->setDefault('');
}
public static function stringUrl($name)
{
return Column::make($name,'string')
->setLimit(300)
->setDefault('');
}
public static function stringMd5($name)
{
return Column::make($name,'string')
->setLimit(32)
->setDefault('');
}
public static function stringShort($name)
{
return Column::make($name,'string')
->setLimit(20)
->setDefault('');
}
public static function integerTypeStatus($name)
{
return Column::make($name,'integer')
->setLimit(10) ->setLimit(10)
->setSigned(false)
->setDefault(0);
}
public static function integer($name)
{
return Column::make($name,'integer')
->setDefault(0)
->setLimit(20)
->setSigned(false); ->setSigned(false);
} }
} }

View File

@@ -0,0 +1,60 @@
<?php
use app\common\ColumnFormat;
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTablePost extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('post',['comment'=>"内容文章"]);
$table->addColumn(ColumnFormat::stringNormal('title')->setComment('标题'));
$table->addColumn(ColumnFormat::stringUrl('poster')->setComment('封面'));
$table->addColumn(ColumnFormat::timestamp('create_time'));
$table->addColumn(ColumnFormat::timestamp('update_time'));
$table->addColumn(ColumnFormat::timestamp('delete_time'));
$table->addColumn(Column::make('content','text'));
$table->addColumn(Column::make('content_html','text'));
$table->addColumn(ColumnFormat::stringLong('desc')->setDefault('描述'));
$table->addColumn(ColumnFormat::integerTypeStatus('is_top')->setComment('是否置顶'));
$table->addColumn(ColumnFormat::integerTypeStatus('status')->setComment('1:显示,0:不显示'));
$table->addColumn(ColumnFormat::timestamp('publish_time')->setComment('发表时间'));
$table->addColumn(ColumnFormat::integer('hits')->setComment('访问量'));
$table->addColumn(ColumnFormat::stringUrl('jump_to_url')->setComment('跳转链接'));
$table->addColumn(ColumnFormat::integerTypeStatus('jump_to_url_status')->setComment('0:不显示,1:显示连接,2:自动跳转'));
$table->addColumn(ColumnFormat::integer('sort')->setComment('排序,越大越靠前'));
$table->addColumn(ColumnFormat::integerTypeStatus('type')->setComment('类型,1:文章,有分类有标签,2:页面,无分类无标签'));
$table->addColumn(Column::make('files','text')->setComment('附件'));
$table->addColumn(Column::make('pictures','text')->setComment('相册'));
$table->addIndex('type');
$table->addIndex('status');
$table->addIndex('delete_time');
$table->addIndex('hits');
$table->addIndex('is_top');
$table->create();
}
}

View File

@@ -0,0 +1,43 @@
<?php
use app\common\ColumnFormat;
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTablePostCategory extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('post_category',['comment'=>'文章分类关联表']);
$table->addColumn(ColumnFormat::integer('post_id'))
->addColumn(ColumnFormat::integer('category_id'))
->addColumn(ColumnFormat::timestamp('create_time'))
->addColumn(ColumnFormat::timestamp('update_time'))
->addColumn(ColumnFormat::timestamp('delete_time'))
->addIndex('post_id')
->addIndex('category_id')
->create();
}
}

View File

@@ -0,0 +1,42 @@
<?php
use app\common\ColumnFormat;
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTablePostTag extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('post_tag',['comment'=>'文章分类关联表']);
$table->addColumn(ColumnFormat::integer('post_id'))
->addColumn(ColumnFormat::integer('tag_id'))
->addColumn(ColumnFormat::timestamp('create_time'))
->addColumn(ColumnFormat::timestamp('update_time'))
->addColumn(ColumnFormat::timestamp('delete_time'))
->addIndex('post_id')
->addIndex('tag_id')
->create();
}
}

View File

@@ -0,0 +1,43 @@
<?php
use app\common\ColumnFormat;
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTableCategory extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('category')
->setComment('分类表')
->addColumn(ColumnFormat::stringNormal('title'))
->addColumn(ColumnFormat::timestamp('create_time'))
->addColumn(ColumnFormat::timestamp('update_time'))
->addColumn(ColumnFormat::timestamp('delete_time'))
->addColumn(ColumnFormat::integer('pid')->setComment('上级id'))
->addColumn(ColumnFormat::integer('level')->setDefault(1)->setComment('层级'))
->addIndex('pid')
->create();
}
}

View File

@@ -0,0 +1,40 @@
<?php
use app\common\ColumnFormat;
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTableTag extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('tag')
->setComment('分类表')
->addColumn(ColumnFormat::stringNormal('title'))
->addColumn(ColumnFormat::timestamp('create_time'))
->addColumn(ColumnFormat::timestamp('update_time'))
->addColumn(ColumnFormat::timestamp('delete_time'))
->create();
}
}

View File

@@ -59,8 +59,7 @@
<td>{$vo.sort}</td> <td>{$vo.sort}</td>
<td> <td>
<div class="layui-btn-container"> <div class="layui-btn-container">
<a class="layui-btn layui-btn-sm" <a class="layui-btn layui-btn-sm" href="{:url('edit',['id'=>$vo.id])}">编辑</a>
href="{:url('edit',['id'=>$vo.id])}">编辑</a>
<div class="layui-btn layui-btn-sm delete">删除</div> <div class="layui-btn layui-btn-sm delete">删除</div>
</div> </div>
</td> </td>
@@ -81,6 +80,22 @@
</div> </div>
{include file="common/_footer"} {include file="common/_footer"}
</div> </div>
<script>
$('.delete').click(function () {
var item = this;
layer.confirm('确定要删除吗?', function () {
$.get('{:url("delete")}', {
id: $(item).parents('.item').data('id')
}, function (result) {
layer.msg('删除成功');
$(item).parents('.item').remove();
})
})
})
</script>
</body> </body>
</html> </html>