feat: 新增导航相关接口
This commit is contained in:
57
app/admin/controller/v1/Navigation.php
Normal file
57
app/admin/controller/v1/Navigation.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\SysNavigationItemModel;
|
||||
use app\admin\model\v1\SysNavigationLinkTypeModel;
|
||||
|
||||
/**
|
||||
* 导航管理控制器
|
||||
*/
|
||||
class Navigation
|
||||
{
|
||||
// 导航链接类型
|
||||
public function linkType()
|
||||
{
|
||||
$types = SysNavigationLinkTypeModel::withoutField(['sort'])
|
||||
->order(['sort' => 'asc', 'id' => 'asc'])
|
||||
->select();
|
||||
|
||||
return success('获取成功', $types);
|
||||
}
|
||||
|
||||
// 导航分页
|
||||
public function index()
|
||||
{
|
||||
$param = request()->get([
|
||||
'name',
|
||||
'nav_id',
|
||||
'created_at',
|
||||
'page/d' => 1,
|
||||
'size/d' => 10,
|
||||
]);
|
||||
|
||||
$navigations = SysNavigationItemModel::withoutField([
|
||||
'created_at',
|
||||
'updated_at'
|
||||
])
|
||||
->with(['navigation' => function ($query) {
|
||||
$query->field(['id', 'name' => 'nav_name']);
|
||||
}])
|
||||
->withSearch(['name', 'created_at'], [
|
||||
'name' => $param['name']??null,
|
||||
'created_at' => $param['created_at']??null
|
||||
])
|
||||
->navId($param['nav_id']??null)
|
||||
->order(['sort' => 'asc', 'id' => 'asc'])
|
||||
->paginate([
|
||||
'page' => $param['page'],
|
||||
'list_rows' => $param['size'],
|
||||
])
|
||||
->bindAttr('navigation', ['nav_name'])
|
||||
->hidden(['nav_id', 'navigation']);
|
||||
|
||||
return success('获取成功', $navigations);
|
||||
}
|
||||
}
|
||||
46
app/admin/model/v1/SysNavigationItemModel.php
Normal file
46
app/admin/model/v1/SysNavigationItemModel.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 导航数据模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationItemModel extends Model
|
||||
{
|
||||
// 关联导航
|
||||
public function navigation()
|
||||
{
|
||||
return $this->belongsTo(SysNavigationModel::class, 'nav_id', 'id');
|
||||
}
|
||||
|
||||
// 名称搜索
|
||||
public function searchNameAttr($query, $value, $data)
|
||||
{
|
||||
if (empty($value)) return;
|
||||
$query->where('name', 'like', "%{$value}%");
|
||||
}
|
||||
|
||||
// 新增时间搜索
|
||||
public function searchCreatedAtAttr($query, $value, $data)
|
||||
{
|
||||
if (empty($value)) return;
|
||||
if (is_array($value)) {
|
||||
if (count($value) > 1) {
|
||||
$query->whereBetweenTime('created_at', $value[0], $value[1]);
|
||||
} else {
|
||||
$query->whereTime('created_at', '>=', $value[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导航查询
|
||||
public function scopeNavId($query, $value)
|
||||
{
|
||||
if (empty($value)) return;
|
||||
$query->where('nav_id', '=', $value);
|
||||
}
|
||||
}
|
||||
15
app/admin/model/v1/SysNavigationLinkTypeModel.php
Normal file
15
app/admin/model/v1/SysNavigationLinkTypeModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use app\common\model\SysNavigationLinkTypeBaseModel;
|
||||
|
||||
/**
|
||||
* 导航链接类型模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationLinkTypeModel extends SysNavigationLinkTypeBaseModel
|
||||
{
|
||||
//
|
||||
}
|
||||
15
app/admin/model/v1/SysNavigationModel.php
Normal file
15
app/admin/model/v1/SysNavigationModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use app\common\model\SysNavigationBaseModel;
|
||||
|
||||
/**
|
||||
* 导航模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationModel extends SysNavigationBaseModel
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -406,6 +406,15 @@ Route::group('v1', function () {
|
||||
// 菜单删除
|
||||
Route::delete('delete/:id', 'Menu/delete');
|
||||
});
|
||||
|
||||
// 导航管理
|
||||
Route::group('navigation', function() {
|
||||
// 导航数据类型
|
||||
Route::get('link/type', 'Navigation/linkType');
|
||||
|
||||
// 导航分页
|
||||
Route::get('index', 'Navigation/index');
|
||||
});
|
||||
})->prefix('v1.');
|
||||
|
||||
Route::miss(function() {
|
||||
|
||||
15
app/common/model/SysNavigationBaseModel.php
Normal file
15
app/common/model/SysNavigationBaseModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 导航模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationBaseModel extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'sys_navigation';
|
||||
|
||||
}
|
||||
35
app/common/model/SysNavigationItemBaseModel.php
Normal file
35
app/common/model/SysNavigationItemBaseModel.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 导航数据模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationItemBaseModel extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'sys_navigation_item';
|
||||
|
||||
// 主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'nav_id' => 'int',
|
||||
'pid' => 'int',
|
||||
'name' => 'string',
|
||||
'icon' => 'string',
|
||||
'link_type' => 'int',
|
||||
'link' => 'string',
|
||||
'sort' => 'int',
|
||||
'blank' => 'int',
|
||||
'status' => 'int',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
24
app/common/model/SysNavigationLinkTypeBaseModel.php
Normal file
24
app/common/model/SysNavigationLinkTypeBaseModel.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 导航链接类型模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationLinkTypeBaseModel extends BaseModel
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'sys_navigation_link_type';
|
||||
|
||||
// 主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'type_name' => 'string',
|
||||
'sort' => 'int'
|
||||
];
|
||||
}
|
||||
@@ -29,9 +29,7 @@ class CreateSysNavigation extends Migrator
|
||||
{
|
||||
$table = $this->table('sys_navigation', ['engine' => 'InnoDB', 'comment' => '系统导航表']);
|
||||
$table->addColumn('language_id', 'integer', ['null' => false, 'comment' => '语言ID'])
|
||||
->addColumn('at_platform', 'string', ['limit' => 8, 'null' => false, 'comment' => '所在平台: pc为电脑, mobile为手机'])
|
||||
->addColumn('at_page', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航所在页面标识'])
|
||||
->addColumn('at_position', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航所在页面位置: top为顶部导航, footer为底部导航'])
|
||||
->addColumn('at_page', 'string', ['limit' => 64, 'null' => true, 'comment' => '导航所在页面路径'])
|
||||
->addColumn('unique_label', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航唯一标识'])
|
||||
->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '导航名称'])
|
||||
->addColumn('desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '导航描述'])
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
|
||||
class SysNavigationLinkType 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('sys_navigation_link_type', ['engine' => 'InnoDB', 'comment' => '系统导航链接类型']);
|
||||
$table->addColumn('type_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '类型名称'])
|
||||
->addColumn('sort', 'integer', ['limit' => 11, 'null' => false, 'default' => 0, 'comment' => '排序'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user