修改登陆事件
This commit is contained in:
42
extend/catcher/generate/template/Content.php
Normal file
42
extend/catcher/generate/template/Content.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace JaguarJack\Generator\Template;
|
||||
|
||||
trait Content
|
||||
{
|
||||
public function header()
|
||||
{
|
||||
$year = date('Y', time());
|
||||
|
||||
return <<<TMP
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* set namespace
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
* @param $namespace
|
||||
* @return string
|
||||
*/
|
||||
public function nameSpace($namespace)
|
||||
{
|
||||
return <<<TMP
|
||||
namespace {$namespace};
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
}
|
246
extend/catcher/generate/template/Controller.php
Normal file
246
extend/catcher/generate/template/Controller.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
namespace JaguarJack\Generator\Template;
|
||||
|
||||
class Controller
|
||||
{
|
||||
use Content;
|
||||
|
||||
/**
|
||||
* use
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
* @return string
|
||||
*/
|
||||
public function uses()
|
||||
{
|
||||
return <<<TMP
|
||||
use think\Request;
|
||||
use catcher\CatchResponse;
|
||||
{USE}
|
||||
|
||||
|
||||
TMP;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* construct
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
* @param $model
|
||||
* @return string
|
||||
*/
|
||||
public function construct($model)
|
||||
{
|
||||
return <<<TMP
|
||||
protected \$model;
|
||||
|
||||
public function __construct({$model} \$model)
|
||||
{
|
||||
\$this->model = \$model;
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
|
||||
}
|
||||
|
||||
public function createClass($class)
|
||||
{
|
||||
return <<<TMP
|
||||
class {$class}
|
||||
{
|
||||
{CONTENT}
|
||||
}
|
||||
TMP;
|
||||
|
||||
}
|
||||
/**
|
||||
* list template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('列表', 'Request $request')}
|
||||
public function index(Request \$request)
|
||||
{
|
||||
return CatchResponse::paginate(\$this->model->getList(\$request->param()));
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* create template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('单页')}
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* save template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $createRequest
|
||||
* @return string
|
||||
*/
|
||||
public function save($createRequest = '')
|
||||
{
|
||||
$request = $createRequest ? 'CreateRequest' : 'Request';
|
||||
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('保存', 'Request ' . $request)}
|
||||
public function save({$request} \$request)
|
||||
{
|
||||
return CatchResponse::success(\$this->model->storeBy(\$request->post()));
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* read template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('读取', '$id')}
|
||||
public function read(\$id)
|
||||
{
|
||||
return CatchResponse::success(\$this->model->findBy(\$id));
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* edit template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('编辑', '\$id')}
|
||||
public function edit(\$id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* update template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $updateRequest
|
||||
* @return string
|
||||
*/
|
||||
public function update($updateRequest = '')
|
||||
{
|
||||
$updateRequest = ($updateRequest ? 'UpdateRequest' : 'Request') . ' $request';
|
||||
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('更新', $updateRequest)}
|
||||
public function update({$updateRequest}, \$id)
|
||||
{
|
||||
return CatchResponse::success(\$this->model->updateBy(\$id, \$request->post()));
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete template
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('删除', '$id')}
|
||||
public function delete(\$id)
|
||||
{
|
||||
return CatchResponse::success(\$this->model->deleteBy(\$id));
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他方法
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
* @param $function
|
||||
* @param string $method
|
||||
* @return string
|
||||
*/
|
||||
public function otherFunction($function, $method = 'get')
|
||||
{
|
||||
$params = $method === 'delete' ? '$id' : 'Request $request';
|
||||
|
||||
return <<<TMP
|
||||
{$this->controllerFunctionComment('', $params)}
|
||||
public function {$function}({$params})
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
||||
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制器方法注释
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $des
|
||||
* @param $params
|
||||
* @return string
|
||||
*/
|
||||
protected function controllerFunctionComment($des, $params = '')
|
||||
{
|
||||
$now = date('Y/m/d H:i', time());
|
||||
|
||||
$params = $params ? '@param ' . $params : '';
|
||||
|
||||
return <<<TMP
|
||||
/**
|
||||
* {$des}
|
||||
*
|
||||
* @time {$now}
|
||||
* {$params}
|
||||
* @return \\think\\Response
|
||||
*/
|
||||
TMP;
|
||||
}
|
||||
|
||||
}
|
155
extend/catcher/generate/template/Model.php
Normal file
155
extend/catcher/generate/template/Model.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace JaguarJack\Generator\Template;
|
||||
|
||||
trait Model
|
||||
{
|
||||
use Content;
|
||||
|
||||
public function getList()
|
||||
{
|
||||
return <<<TMP
|
||||
public function getList()
|
||||
{
|
||||
return \$this->catchSearch()
|
||||
->order(\$this->getPk(), 'desc')
|
||||
->paginate();
|
||||
}
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一对一关联
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $model
|
||||
* @param string $foreignKey
|
||||
* @param string $pk
|
||||
* @return string
|
||||
*/
|
||||
public function hasOne($model, $foreignKey = '', $pk = '')
|
||||
{
|
||||
$func = lcfirst($model);
|
||||
|
||||
return <<<TMP
|
||||
public function {$func}()
|
||||
{
|
||||
return \$this->hasOne({$model}::class{$this->keyRelate($foreignKey, $pk)});
|
||||
}
|
||||
TMP;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $model
|
||||
* @param string $foreignKey
|
||||
* @param string $pk
|
||||
* @return string
|
||||
*/
|
||||
public function hasMany($model, $foreignKey = '', $pk = '')
|
||||
{
|
||||
$func = lcfirst($model);
|
||||
|
||||
return <<<TMP
|
||||
public function {$func}()
|
||||
{
|
||||
return \$this->hasMany({$model}::class{$this->keyRelate($foreignKey, $pk)});
|
||||
}
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程一对多
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $model
|
||||
* @param $middleModel
|
||||
* @param string $foreignKey
|
||||
* @param string $pk
|
||||
* @param string $middleRelateId
|
||||
* @param string $middleId
|
||||
* @return string
|
||||
*/
|
||||
public function hasManyThrough($model, $middleModel, $foreignKey = '', $pk = '', $middleRelateId = '', $middleId = '')
|
||||
{
|
||||
$func = lcfirst($model);
|
||||
|
||||
return <<<TMP
|
||||
public function {$func}()
|
||||
{
|
||||
return \$this->hasManyThrough({$model}::class, {$middleModel}::class{$this->keyRelate($foreignKey, $pk, $middleRelateId, $middleId)});
|
||||
}
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程一对一
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $model
|
||||
* @param $middleModel
|
||||
* @param string $foreignKey
|
||||
* @param string $pk
|
||||
* @param string $middleRelateId
|
||||
* @param string $middleId
|
||||
* @return string
|
||||
*/
|
||||
public function hasOneThrough($model, $middleModel, $foreignKey = '', $pk = '', $middleRelateId = '', $middleId = '')
|
||||
{
|
||||
$func = lcfirst($model);
|
||||
|
||||
return <<<TMP
|
||||
public function {$func}()
|
||||
{
|
||||
return \$this->hasOneThrough({$model}::class, {$middleModel}::class{$this->keyRelate($foreignKey, $pk, $middleRelateId, $middleId)});
|
||||
}
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多对多关联
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param $model
|
||||
* @param string $table
|
||||
* @param string $foreignKey
|
||||
* @param string $relateKey
|
||||
* @return string
|
||||
*/
|
||||
public function belongsToMany($model, $table = '', $foreignKey = '', $relateKey = '')
|
||||
{
|
||||
$func = lcfirst($model);
|
||||
|
||||
$table = !$table ? : ','.$table;
|
||||
|
||||
$relateKey = !$relateKey ? : ','.$relateKey;
|
||||
|
||||
return <<<TMP
|
||||
public function {$func}()
|
||||
{
|
||||
return \$this->hasOneThrough({$model}::class{$table}{$this->keyRelate($foreignKey)}{$relateKey});
|
||||
}
|
||||
TMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模型关联key
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @param string $foreignKey
|
||||
* @param string $pk
|
||||
* @param string $middleRelateId
|
||||
* @param string $middleId
|
||||
* @return string
|
||||
*/
|
||||
public function keyRelate($foreignKey = '', $pk = '', $middleRelateId = '', $middleId = '')
|
||||
{
|
||||
return !$foreignKey ? : ',' . $foreignKey .
|
||||
!$middleRelateId ? : ','. $middleRelateId .
|
||||
!$pk ? : ',' . $pk .
|
||||
!$middleId ? : ',' . $middleId;
|
||||
|
||||
}
|
||||
}
|
42
extend/catcher/generate/template/Request.php
Normal file
42
extend/catcher/generate/template/Request.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace JaguarJack\Generator\Template;
|
||||
|
||||
trait Request
|
||||
{
|
||||
/**
|
||||
* 规则
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return <<<EOT
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
{rules}
|
||||
];
|
||||
}
|
||||
EOT;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*
|
||||
* @time 2020年04月24日
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return <<<EOT
|
||||
public function message(): array
|
||||
{
|
||||
return [
|
||||
{messages}
|
||||
];
|
||||
}
|
||||
EOT;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user