用户管理
This commit is contained in:
parent
fa4837487b
commit
330a19e8c3
@ -5,6 +5,8 @@ use catcher\command\InstallCommand;
|
|||||||
use catcher\command\MigrateRunCommand;
|
use catcher\command\MigrateRunCommand;
|
||||||
use catcher\command\ModelGeneratorCommand;
|
use catcher\command\ModelGeneratorCommand;
|
||||||
use catcher\command\ModuleCacheCommand;
|
use catcher\command\ModuleCacheCommand;
|
||||||
|
use catcher\validates\Sometimes;
|
||||||
|
use think\facade\Validate;
|
||||||
use think\Service;
|
use think\Service;
|
||||||
|
|
||||||
class CatchAdminService extends Service
|
class CatchAdminService extends Service
|
||||||
@ -22,5 +24,26 @@ class CatchAdminService extends Service
|
|||||||
MigrateRunCommand::class,
|
MigrateRunCommand::class,
|
||||||
ModelGeneratorCommand::class,
|
ModelGeneratorCommand::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->registerValidates();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function registerValidates(): void
|
||||||
|
{
|
||||||
|
$validates = [
|
||||||
|
new Sometimes(),
|
||||||
|
];
|
||||||
|
|
||||||
|
Validate::maker(function($validate) use ($validates){
|
||||||
|
foreach ($validates as $vali) {
|
||||||
|
$validate->extend($vali->type(), [$vali, 'verify'], $vali->message());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -220,8 +220,8 @@
|
|||||||
<div class="layui-body"></div>
|
<div class="layui-body"></div>
|
||||||
<!-- 底部 -->
|
<!-- 底部 -->
|
||||||
<div class="layui-footer">
|
<div class="layui-footer">
|
||||||
copyright © 2019 <a href="http://easyweb.vip" target="_blank">easyweb.vip</a> all rights reserved.
|
copyright 2017 ~ © {:date('Y', time())} <a href="http://easyweb.vip" target="_blank">catchadmin.com</a> all rights reserved.
|
||||||
<span class="pull-right">Version 3.1.5</span>
|
<span class="pull-right">Version 2.0</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\user\controller;
|
namespace catchAdmin\user\controller;
|
||||||
|
|
||||||
|
use app\Request;
|
||||||
use catchAdmin\user\model\Users;
|
use catchAdmin\user\model\Users;
|
||||||
use catchAdmin\user\request\CreateRequest;
|
use catchAdmin\user\request\CreateRequest;
|
||||||
use catchAdmin\user\request\UpdateRequest;
|
use catchAdmin\user\request\UpdateRequest;
|
||||||
@ -24,33 +25,48 @@ class User extends BaseController
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
|
{
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(Request $request)
|
||||||
|
{
|
||||||
|
return CatchResponse::paginate($this->user->getList($request->param()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @time 2019年12月06日
|
||||||
|
* @throws \Exception
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
{
|
{
|
||||||
$form = new CatchForm();
|
$form = new CatchForm();
|
||||||
|
|
||||||
$form->text('name', '用户名')->id('id')->class('class');
|
$form->formId('userForm');
|
||||||
$form->select('names', '性别')->options(['请选择性别', '男', '女'])->default(1);
|
$form->text('username', '用户名')->verify('required')->placeholder('请输入用户名');
|
||||||
//$form->select('namess', '用户名');
|
$form->text('email', '邮箱')->verify('email')->placeholder('请输入邮箱');
|
||||||
|
$form->password('password', '密码')->id('pwd')->verify('required|psw')->placeholder('请输入密码');
|
||||||
|
$form->password('passwordConfirm', '确认密码')->verify('required|equalTo', ['pwd', '两次密码输入不一致'])->placeholder('请再次输入密码');
|
||||||
|
$form->formBtn('submitUser');
|
||||||
|
|
||||||
$form->render();
|
|
||||||
return $this->fetch([
|
return $this->fetch([
|
||||||
'form' => $form->render()
|
'form' => $form->render(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2019年12月04日
|
|
||||||
* @param CreateRequest $request
|
* @param CreateRequest $request
|
||||||
|
* @time 2019年12月06日
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function create(CreateRequest $request)
|
public function save(CreateRequest $request)
|
||||||
{
|
{
|
||||||
return CatchResponse::success($this->user->storeBy($request->post()));
|
return CatchResponse::success($this->user->storeBy($request->post()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save()
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2019年12月04日
|
* @time 2019年12月04日
|
||||||
@ -62,8 +78,23 @@ class User extends BaseController
|
|||||||
return CatchResponse::success($this->user->findBy($id));
|
return CatchResponse::success($this->user->findBy($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit()
|
public function edit($id)
|
||||||
{}
|
{
|
||||||
|
$user = $this->user->findBy($id, ['id','username', 'email']);
|
||||||
|
$form = new CatchForm();
|
||||||
|
|
||||||
|
$form->formId('userForm');
|
||||||
|
$form->text('username', '用户名')->verify('required')->default($user->username)->placeholder('请输入用户名');
|
||||||
|
$form->text('email', '邮箱')->verify('email')->default($user->email)->placeholder('请输入邮箱');
|
||||||
|
$form->password('password', '密码')->id('pwd')->placeholder('请输入密码');
|
||||||
|
$form->password('passwordConfirm', '确认密码')->verify('equalTo', ['pwd', '两次密码输入不一致'])->placeholder('请再次输入密码');
|
||||||
|
$form->formBtn('submitUser');
|
||||||
|
|
||||||
|
return $this->fetch([
|
||||||
|
'form' => $form->render(),
|
||||||
|
'uid' => $user->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -88,4 +119,37 @@ class User extends BaseController
|
|||||||
return CatchResponse::success($this->user->deleteBy($id));
|
return CatchResponse::success($this->user->deleteBy($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @param $id
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function switchStatus($id): \think\response\Json
|
||||||
|
{
|
||||||
|
$user = $this->user->findBy($id);
|
||||||
|
return CatchResponse::success($this->user->updateBy($id, [
|
||||||
|
'status' => $user->status == Users::ENABLE ? Users::DISABLE : Users::ENABLE,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @param $id
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
*/
|
||||||
|
public function recover($id): \think\response\Json
|
||||||
|
{
|
||||||
|
$trashedUser = $this->user->findBy($id, ['*'], true);
|
||||||
|
|
||||||
|
if ($this->user->where('email', $trashedUser->email)->find()) {
|
||||||
|
return CatchResponse::fail(sprintf('该恢复用户的邮箱 [%s] 已被占用', $trashedUser->email));
|
||||||
|
}
|
||||||
|
|
||||||
|
return CatchResponse::success($this->user->recover($id));
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,8 +37,7 @@ class Users extends Migrator
|
|||||||
->addColumn('last_login_time', 'integer',array('default'=>0,'comment'=>'最后登录时间', 'signed' => false))
|
->addColumn('last_login_time', 'integer',array('default'=>0,'comment'=>'最后登录时间', 'signed' => false))
|
||||||
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'创建时间', 'signed' => false ))
|
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'创建时间', 'signed' => false ))
|
||||||
->addColumn('updated_at', 'integer', array('default'=>0,'comment'=>'更新时间', 'signed' => false))
|
->addColumn('updated_at', 'integer', array('default'=>0,'comment'=>'更新时间', 'signed' => false))
|
||||||
->addColumn('delete_at', 'integer', array('null'=>true,'comment'=>'删除状态,0未删除 >0 已删除', 'signed' => false))
|
->addColumn('deleted_at', 'integer', array('null'=>true,'comment'=>'删除状态,0未删除 >0 已删除', 'signed' => false))
|
||||||
->addIndex(array('email'), array('unique' => true))
|
|
||||||
->create();
|
->create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,32 @@ class Users extends BaseModel
|
|||||||
'last_login_time', // 最后登录时间
|
'last_login_time', // 最后登录时间
|
||||||
'created_at', // 创建时间
|
'created_at', // 创建时间
|
||||||
'updated_at', // 更新时间
|
'updated_at', // 更新时间
|
||||||
'delete_at', // 删除状态,0未删除 >0 已删除
|
'deleted_at', // 删除状态,0未删除 >0 已删除
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set password
|
||||||
|
*
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @param $value
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
public function setPasswordAttr($value)
|
||||||
|
{
|
||||||
|
return password_hash($value, PASSWORD_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList($search)
|
||||||
|
{
|
||||||
|
return (($search['trash'] ?? false) ? static::onlyTrashed() : $this)->when($search['username'] ?? false, function ($query) use ($search){
|
||||||
|
return $query->whereLike('username', $search['username']);
|
||||||
|
})
|
||||||
|
->when($search['email'] ?? false, function ($query) use ($search){
|
||||||
|
return $query->whereLike('email', $search['email']);
|
||||||
|
})
|
||||||
|
->when($search['status'] ?? false, function ($query) use ($search){
|
||||||
|
return $query->where('status', $search['status']);
|
||||||
|
})->paginate($search['limit'] ?? $this->limit);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,15 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\user\request;
|
namespace catchAdmin\user\request;
|
||||||
|
|
||||||
use catchAdmin\user\validate\CreateValidate;
|
use catchAdmin\user\model\Users;
|
||||||
use catcher\base\BaseRequest;
|
use catcher\base\BaseRequest;
|
||||||
|
|
||||||
class CreateRequest extends BaseRequest
|
class CreateRequest extends BaseRequest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected function getValidate()
|
protected function rules(): array
|
||||||
{
|
{
|
||||||
// TODO: Implement getValidate() method.
|
// TODO: Implement rules() method.
|
||||||
return new CreateValidate();
|
return [
|
||||||
|
'username|用户名' => 'require|max:20',
|
||||||
|
'password|密码' => 'require|min:5|max:12',
|
||||||
|
'email|邮箱' => 'require|email|unique:'.Users::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function message(): array
|
||||||
|
{
|
||||||
|
// TODO: Implement message() method.
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\user\request;
|
namespace catchAdmin\user\request;
|
||||||
|
|
||||||
use catchAdmin\user\validate\UpdateValidate;
|
use catchAdmin\user\model\Users;
|
||||||
use catcher\base\BaseRequest;
|
use catcher\base\BaseRequest;
|
||||||
|
|
||||||
class UpdateRequest extends BaseRequest
|
class UpdateRequest extends BaseRequest
|
||||||
{
|
{
|
||||||
protected function getValidate()
|
protected function rules(): array
|
||||||
{
|
{
|
||||||
// TODO: Implement getValidate() method.
|
// TODO: Implement rules() method.
|
||||||
return new UpdateValidate();
|
return [
|
||||||
|
'username|用户名' => 'require|max:20',
|
||||||
|
'password|密码' => 'sometimes|min:5|max:12',
|
||||||
|
'passwordConfirm|密码' => 'sometimes|confirm:password',
|
||||||
|
'email|邮箱' => 'require|email|unique:'.Users::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function message(): array
|
||||||
|
{
|
||||||
|
// TODO: Implement message() method.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$router->resource('user', '\catchAdmin\user\controller\User');
|
$router->resource('user', '\catchAdmin\user\controller\User');
|
||||||
|
// 用户列表
|
||||||
|
$router->get('users', '\catchAdmin\user\controller\User/list');
|
||||||
|
// 切换状态
|
||||||
|
$router->put('user/switch/status/<id>', '\catchAdmin\user\controller\User/switchStatus');
|
||||||
|
$router->put('user/recover/<id>', '\catchAdmin\user\controller\User/recover');
|
||||||
|
@ -1,10 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
{$form|raw}
|
||||||
<html lang="en">
|
<script>
|
||||||
<head>
|
layui.use(['layer', 'form', 'admin', 'formX'], function () {
|
||||||
<meta charset="UTF-8">
|
var $ = layui.jquery;
|
||||||
<title>Title</title>
|
var layer = layui.layer;
|
||||||
</head>
|
var form = layui.form;
|
||||||
<body>
|
var admin = layui.admin;
|
||||||
|
var mUser = admin.getLayerData('#userForm'); // 列表页面传递的数据,#modelUserForm这个只要写弹窗内任意一个元素的id即可
|
||||||
</body>
|
// 回显数据
|
||||||
</html>
|
form.val('userForm', mUser);
|
||||||
|
// 表单提交事件
|
||||||
|
form.on('submit(submitUser)', function (data) {
|
||||||
|
layer.load(2);
|
||||||
|
var url = mUser ? '{:url("user")}' : '{:url("user")}';
|
||||||
|
$.post(url, data.field, function (response) {
|
||||||
|
layer.closeAll('loading');
|
||||||
|
if (response.code == 10000) {
|
||||||
|
layer.msg(response.msg, {icon: 1});
|
||||||
|
admin.putLayerData('formOk', true, '#userForm'); // 设置操作成功的标识,#modelUserForm这个只要写弹窗内任意一个元素的id即可
|
||||||
|
admin.closeDialog('#userForm'); // 关闭页面层弹窗
|
||||||
|
} else {
|
||||||
|
layer.msg(response.msg, {icon: 2});
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
@ -1,10 +1,27 @@
|
|||||||
<!DOCTYPE html>
|
{$form|raw}
|
||||||
<html lang="en">
|
<script>
|
||||||
<head>
|
layui.use(['layer', 'form', 'admin', 'formX'], function () {
|
||||||
<meta charset="UTF-8">
|
var $ = layui.jquery;
|
||||||
<title>Title</title>
|
var layer = layui.layer;
|
||||||
</head>
|
var form = layui.form;
|
||||||
<body>
|
var admin = layui.admin;
|
||||||
|
var mUser = admin.getLayerData('#userForm'); // 列表页面传递的数据,#modelUserForm这个只要写弹窗内任意一个元素的id即可
|
||||||
</body>
|
// 回显数据
|
||||||
</html>
|
form.val('userForm', mUser);
|
||||||
|
var uid = "{$uid}";
|
||||||
|
// 表单提交事件
|
||||||
|
form.on('submit(submitUser)', function (data) {
|
||||||
|
admin.req('/user/' + uid, data.field, function (response) {
|
||||||
|
layer.closeAll('loading');
|
||||||
|
if (response.code == 10000) {
|
||||||
|
layer.msg(response.msg, {icon: 1});
|
||||||
|
admin.putLayerData('formOk', true, '#userForm'); // 设置操作成功的标识,#modelUserForm这个只要写弹窗内任意一个元素的id即可
|
||||||
|
admin.closeDialog('#userForm'); // 关闭页面层弹窗
|
||||||
|
} else {
|
||||||
|
layer.msg(response.msg, {icon: 2});
|
||||||
|
}
|
||||||
|
}, 'put');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
@ -3,26 +3,34 @@
|
|||||||
{block name="search"}
|
{block name="search"}
|
||||||
<div class="layui-form toolbar">
|
<div class="layui-form toolbar">
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
{php}echo $form{/php}
|
|
||||||
<div class="layui-inline">
|
|
||||||
<label class="layui-form-label w-auto">账 号:</label>
|
|
||||||
<div class="layui-input-inline mr0">
|
|
||||||
<input name="username" class="layui-input" type="text" placeholder="输入账号"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="layui-inline">
|
<div class="layui-inline">
|
||||||
<label class="layui-form-label w-auto">用户名:</label>
|
<label class="layui-form-label w-auto">用户名:</label>
|
||||||
<div class="layui-input-inline mr0">
|
<div class="layui-input-inline">
|
||||||
<input name="nickName" class="layui-input" type="text" placeholder="输入用户名"/>
|
<input name="username" class="layui-input" type="text" placeholder="输入用户名"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-inline">
|
<div class="layui-inline">
|
||||||
<label class="layui-form-label w-auto">性 别:</label>
|
<label class="layui-form-label w-auto">邮箱:</label>
|
||||||
<div class="layui-input-inline mr0">
|
<div class="layui-input-inline mr0">
|
||||||
<select name="sex">
|
<input name="email" class="layui-input" type="text" placeholder="输入邮箱"/>
|
||||||
<option value="">选择性别</option>
|
</div>
|
||||||
<option value="男">男</option>
|
</div>
|
||||||
<option value="女">女</option>
|
<div class="layui-inline">
|
||||||
|
<label class="layui-form-label w-auto">状态:</label>
|
||||||
|
<div class="layui-input-inline mr0">
|
||||||
|
<select name="status">
|
||||||
|
<option value="">选择状态</option>
|
||||||
|
<option value="1">正常</option>
|
||||||
|
<option value="2">禁用</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-inline">
|
||||||
|
<label class="layui-form-label w-auto">回收站:</label>
|
||||||
|
<div class="layui-input-inline mr0">
|
||||||
|
<select name="trash">
|
||||||
|
<option value="">选择</option>
|
||||||
|
<option value="1">恢复数据</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -37,6 +45,16 @@
|
|||||||
{/block}
|
{/block}
|
||||||
{block name="table"}
|
{block name="table"}
|
||||||
<table class="layui-table" id="tableUser" lay-filter="tableUser"></table>
|
<table class="layui-table" id="tableUser" lay-filter="tableUser"></table>
|
||||||
|
<!-- 表格操作列 -->
|
||||||
|
<script type="text/html" id="tableBarUser">
|
||||||
|
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
|
||||||
|
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="{{d.deleted_at ? 'recover' : 'del'}}">{{d.deleted_at ? '恢复' : '删除'}}</a>
|
||||||
|
</script>
|
||||||
|
<!-- 表格状态列 -->
|
||||||
|
<script type="text/html" id="tableStateUser">
|
||||||
|
<input type="checkbox" lay-filter="ckStateUser" value="{{d.id}}" lay-skin="switch"
|
||||||
|
lay-text="正常|禁用" {{d.status==1?'checked':''}}/>
|
||||||
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
{block name="script"}
|
{block name="script"}
|
||||||
<script>
|
<script>
|
||||||
@ -51,23 +69,30 @@
|
|||||||
// 渲染表格
|
// 渲染表格
|
||||||
var insTb = table.render({
|
var insTb = table.render({
|
||||||
elem: '#tableUser',
|
elem: '#tableUser',
|
||||||
url: '../../json/user.json',
|
url: '{:url("users")}',
|
||||||
page: true,
|
page: true,
|
||||||
|
response: {
|
||||||
|
statusCode: 10000,
|
||||||
|
},
|
||||||
toolbar: true,
|
toolbar: true,
|
||||||
cellMinWidth: 100,
|
cellMinWidth: 100,
|
||||||
cols: [[
|
cols: [[
|
||||||
{type: 'numbers', title: '#'},
|
{type: 'id', title: '#', field: 'id'},
|
||||||
{field: 'username', sort: true, title: '账号'},
|
{field: 'username', sort: true, title: '用户名'},
|
||||||
{field: 'nickName', sort: true, title: '用户名'},
|
{field: 'email', sort: true, title: '邮箱'},
|
||||||
{field: 'sex', sort: true, title: '性别'},
|
{field: 'status', sort: true, title: '状态', templet: '#tableStateUser'},
|
||||||
{
|
{
|
||||||
field: 'createTime', sort: true, templet: function (d) {
|
field: 'created_at', sort: true, templet: function (d) {
|
||||||
return util.toDateString(d.createTime);
|
return util.toDateString(d.created_at);
|
||||||
}, title: '创建时间'
|
}, title: '创建时间'
|
||||||
},
|
},
|
||||||
{field: 'state', sort: true, templet: '#tableStateUser', title: '状态'},
|
{
|
||||||
|
field: 'updated_at', sort: true, templet: function (d) {
|
||||||
|
return util.toDateString(d.updated_at);
|
||||||
|
}, title: '更新时间'
|
||||||
|
},
|
||||||
{align: 'center', toolbar: '#tableBarUser', title: '操作', minWidth: 200}
|
{align: 'center', toolbar: '#tableBarUser', title: '操作', minWidth: 200}
|
||||||
]]
|
]],
|
||||||
});
|
});
|
||||||
|
|
||||||
// 添加
|
// 添加
|
||||||
@ -87,40 +112,48 @@
|
|||||||
if (layEvent === 'edit') { // 修改
|
if (layEvent === 'edit') { // 修改
|
||||||
showEditModel(data);
|
showEditModel(data);
|
||||||
} else if (layEvent === 'del') { // 删除
|
} else if (layEvent === 'del') { // 删除
|
||||||
doDel(data.userId, data.nickName);
|
doDel(data.id, data.username);
|
||||||
} else if (layEvent === 'reset') { // 重置密码
|
} else if (layEvent === 'reset') { // 重置密码
|
||||||
resetPsw(data.userId, data.nickName);
|
resetPsw(data.id, data.username);
|
||||||
|
} else if (layEvent === 'recover') {
|
||||||
|
recover(data.id, data.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 显示表单弹窗
|
function recover(uid, username) {
|
||||||
function showEditModel(mUser) {
|
console.log(username)
|
||||||
admin.open({
|
layer.confirm('确定要恢复“' + username + '”吗?', {
|
||||||
type: 1,
|
skin: 'layui-layer-admin',
|
||||||
title: (mUser ? '修改' : '添加') + '用户',
|
shade: .1
|
||||||
content: $('#modelUser').html(),
|
}, function (i) {
|
||||||
success: function (layero, dIndex) {
|
layer.close(i);
|
||||||
$(layero).children('.layui-layer-content').css('overflow', 'visible');
|
admin.req('/user/recover/'+ uid,{}, function(res){
|
||||||
var url = mUser ? '../../json/ok.json' : '../../json/ok.json';
|
|
||||||
mUser && (mUser.roleId = mUser.roles[0].roleId);
|
|
||||||
// 回显数据
|
|
||||||
form.val('modelUserForm', mUser);
|
|
||||||
// 表单提交事件
|
|
||||||
form.on('submit(modelSubmitUser)', function (data) {
|
|
||||||
layer.load(2);
|
|
||||||
$.get(url, data.field, function (res) {
|
|
||||||
layer.closeAll('loading');
|
layer.closeAll('loading');
|
||||||
if (res.code == 200) {
|
if (res.code == 10000) {
|
||||||
layer.close(dIndex);
|
|
||||||
layer.msg(res.msg, {icon: 1});
|
layer.msg(res.msg, {icon: 1});
|
||||||
insTb.reload({}, 'data');
|
insTb.reload({}, 'data');
|
||||||
} else {
|
} else {
|
||||||
layer.msg(res.msg, {icon: 2});
|
layer.msg(res.msg, {icon: 2});
|
||||||
}
|
}
|
||||||
}, 'json');
|
}, 'put');
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// 显示表单弹窗
|
||||||
|
function showEditModel(mUser) {
|
||||||
|
var layIndex = admin.open({
|
||||||
|
title: (mUser ? '修改' : '添加') + '用户',
|
||||||
|
url: mUser ? '/user/'+mUser.id + '/edit':'/user/create',
|
||||||
|
data: mUser, // 传递数据到表单页面
|
||||||
|
end: function () {
|
||||||
|
if (admin.getLayerData(layIndex, 'formOk')) { // 判断表单操作成功标识
|
||||||
|
insTb.reload(); // 成功刷新表格
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function (layero, dIndex) {
|
||||||
|
// 弹窗超出范围不出现滚动条
|
||||||
|
$(layero).children('.layui-layer-content').css('overflow', 'visible');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,60 +164,31 @@
|
|||||||
shade: .1
|
shade: .1
|
||||||
}, function (i) {
|
}, function (i) {
|
||||||
layer.close(i);
|
layer.close(i);
|
||||||
layer.load(2);
|
admin.req('/user/'+ userId,{}, function(res){
|
||||||
$.get('../../json/ok.json', {
|
|
||||||
userId: userId
|
|
||||||
}, function (res) {
|
|
||||||
layer.closeAll('loading');
|
layer.closeAll('loading');
|
||||||
if (res.code == 200) {
|
if (res.code == 10000) {
|
||||||
layer.msg(res.msg, {icon: 1});
|
layer.msg(res.msg, {icon: 1});
|
||||||
insTb.reload({}, 'data');
|
insTb.reload({}, 'data');
|
||||||
} else {
|
} else {
|
||||||
layer.msg(res.msg, {icon: 2});
|
layer.msg(res.msg, {icon: 2});
|
||||||
}
|
}
|
||||||
}, 'json');
|
}, 'delete');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户状态
|
// 修改用户状态
|
||||||
form.on('switch(ckStateUser)', function (obj) {
|
form.on('switch(ckStateUser)', function (obj) {
|
||||||
layer.load(2);
|
admin.req('/user/switch/status/'+obj.value,{}, function(res){
|
||||||
$.get('../../json/ok.json', {
|
|
||||||
userId: obj.elem.value,
|
|
||||||
state: obj.elem.checked ? 0 : 1
|
|
||||||
}, function (res) {
|
|
||||||
layer.closeAll('loading');
|
layer.closeAll('loading');
|
||||||
if (res.code == 200) {
|
if (res.code == 10000) {
|
||||||
layer.msg(res.msg, {icon: 1});
|
layer.msg(res.msg, {icon: 1});
|
||||||
} else {
|
} else {
|
||||||
layer.msg(res.msg, {icon: 2});
|
layer.msg(res.msg, {icon: 2});
|
||||||
$(obj.elem).prop('checked', !obj.elem.checked);
|
$(obj.elem).prop('checked', !obj.elem.checked);
|
||||||
form.render('checkbox');
|
form.render('checkbox');
|
||||||
}
|
}
|
||||||
}, 'json');
|
}, 'put');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重置密码
|
|
||||||
function resetPsw(userId, nickName) {
|
|
||||||
layer.confirm('确定要重置“' + nickName + '”的登录密码吗?', {
|
|
||||||
skin: 'layui-layer-admin',
|
|
||||||
shade: .1
|
|
||||||
}, function (i) {
|
|
||||||
layer.close(i);
|
|
||||||
layer.load(2);
|
|
||||||
$.get('../../json/ok.json', {
|
|
||||||
userId: userId
|
|
||||||
}, function (res) {
|
|
||||||
layer.closeAll('loading');
|
|
||||||
if (res.code == 200) {
|
|
||||||
layer.msg(res.msg, {icon: 1});
|
|
||||||
} else {
|
|
||||||
layer.msg(res.msg, {icon: 2});
|
|
||||||
}
|
|
||||||
}, 'json');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{/block}
|
{/block}
|
@ -6,11 +6,12 @@ namespace catcher;
|
|||||||
* @package catcher
|
* @package catcher
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @method text($column, $label = ''): self
|
* @method CatchForm text($column, $label = '')
|
||||||
* @method image($column, $label = ''): self
|
* @method CatchForm image($column, $label = '')
|
||||||
* @method radio($column, $label = ''): self
|
* @method CatchForm radio($column, $label = '')
|
||||||
* @method select($column, $label = ''): self
|
* @method CatchForm select($column, $label = '')
|
||||||
* @method textarea($column, $label = ''): self
|
* @method CatchForm textarea($column, $label = '')
|
||||||
|
* @method CatchForm password($column, $label = '')
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CatchForm
|
class CatchForm
|
||||||
@ -19,10 +20,48 @@ class CatchForm
|
|||||||
|
|
||||||
private $fields = [];
|
private $fields = [];
|
||||||
|
|
||||||
|
protected $action;
|
||||||
|
|
||||||
|
protected $method;
|
||||||
|
|
||||||
|
protected $enctype;
|
||||||
|
|
||||||
|
protected $formId;
|
||||||
|
|
||||||
|
protected $btn;
|
||||||
|
|
||||||
|
public function action($acton)
|
||||||
|
{
|
||||||
|
$this->action = $acton;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function method($method)
|
||||||
|
{
|
||||||
|
$this->method = $method;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formId($formId)
|
||||||
|
{
|
||||||
|
$this->formId = $formId;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enctype($enctype ="multipart/form-data")
|
||||||
|
{
|
||||||
|
$this->enctype = $enctype;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function id($id)
|
public function id($id)
|
||||||
{
|
{
|
||||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||||
'id' => $id,
|
'id' => sprintf('id="%s"', $id),
|
||||||
]);
|
]);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -57,6 +96,7 @@ class CatchForm
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function disabled()
|
public function disabled()
|
||||||
{
|
{
|
||||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||||
@ -87,7 +127,8 @@ class CatchForm
|
|||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$form = '';
|
$form = sprintf('<form id="%s" lay-filter="%s" class="layui-form model-form">', $this->formId, $this->formId);
|
||||||
|
|
||||||
foreach ($this->fields as $field) {
|
foreach ($this->fields as $field) {
|
||||||
$form .= sprintf($this->baseField(),
|
$form .= sprintf($this->baseField(),
|
||||||
$field['labelClass'] ?? '',
|
$field['labelClass'] ?? '',
|
||||||
@ -97,9 +138,17 @@ class CatchForm
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $form;
|
return $form . $this->btn. '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function append($append)
|
||||||
|
{
|
||||||
|
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||||
|
'append' => $append,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function __call($method, $arguments)
|
public function __call($method, $arguments)
|
||||||
{
|
{
|
||||||
@ -111,6 +160,7 @@ class CatchForm
|
|||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'type' => $method,
|
'type' => $method,
|
||||||
'label' => $label,
|
'label' => $label,
|
||||||
|
'inline' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -128,23 +178,62 @@ class CatchForm
|
|||||||
private function baseField()
|
private function baseField()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
'<div class="layui-inline">
|
'<div class="layui-form-item">
|
||||||
<label class="layui-form-label%s">%s: </label>
|
<label class="layui-form-label%s">%s: </label>
|
||||||
<div class="layui-input-inline %s">
|
<div class="layui-input-block%s">
|
||||||
%s
|
%s
|
||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* form btn
|
||||||
|
*
|
||||||
|
* @time 2019年12月06日
|
||||||
|
* @param $filter
|
||||||
|
* @param string $position
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function formBtn($filter, $position = 'text-right')
|
||||||
|
{
|
||||||
|
$this->btn = sprintf('<div class="layui-form-item %s">
|
||||||
|
<button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
|
||||||
|
<button class="layui-btn" lay-filter="%s" lay-submit>保存</button>
|
||||||
|
</div>', $position, $filter);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verify($rule, $equalTo = [])
|
||||||
|
{
|
||||||
|
if (empty($equalTo)) {
|
||||||
|
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||||
|
'verify' => sprintf('lay-verType="tips" lay-verify="%s"', $rule),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
[$id, $msg] = $equalTo;
|
||||||
|
|
||||||
|
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||||
|
'verify' => sprintf(' lay-verType="tips" lay-verify="%s" lay-equalTo="#%s"
|
||||||
|
lay-equalToText="%s" ', $rule, $id, $msg),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
private function textField($field)
|
private function textField($field)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
sprintf('<input name="%s" class="layui-input %s" value="%s" type="text" %s %s %s>',
|
sprintf('<input name="%s" class="layui-input %s" %s value="%s" type="text" %s %s %s%s>',
|
||||||
$field['name'],
|
$field['name'],
|
||||||
$field['class'],
|
$field['id'] ?? '',
|
||||||
|
$field['class'] ?? '',
|
||||||
$field['default'] ?? '',
|
$field['default'] ?? '',
|
||||||
$field['readonly'] ?? '',
|
$field['readonly'] ?? '',
|
||||||
$field['placeholder'] ?? '',
|
$field['placeholder'] ?? '',
|
||||||
$field['disabled'] ?? ''
|
$field['disabled'] ?? '',
|
||||||
|
$field['verify'] ?? ''
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -162,6 +251,16 @@ class CatchForm
|
|||||||
return $select . '</select>';
|
return $select . '</select>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function passwordField($field)
|
||||||
|
{
|
||||||
|
return sprintf('<input name="%s" class="layui-input" %s type="password" %s %s>',
|
||||||
|
$field['name'],
|
||||||
|
$field['id'] ?? '',
|
||||||
|
$field['verify'] ?? '',
|
||||||
|
$field['placeholder'] ?? ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function radioField()
|
private function radioField()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -11,10 +11,18 @@ abstract class BaseModel extends \think\Model
|
|||||||
use TransTrait;
|
use TransTrait;
|
||||||
use BaseOptionsTrait;
|
use BaseOptionsTrait;
|
||||||
|
|
||||||
protected $createTime = 'create_at';
|
protected $createTime = 'created_at';
|
||||||
|
|
||||||
protected $updateTime = 'update_at';
|
protected $updateTime = 'updated_at';
|
||||||
|
|
||||||
protected $deleteTime = 'delete_at';
|
protected $deleteTime = 'deleted_at';
|
||||||
|
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
|
protected $limit = 10;
|
||||||
|
|
||||||
|
// 开启
|
||||||
|
public const ENABLE = 1;
|
||||||
|
// 禁用
|
||||||
|
public const DISABLE = 2;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catcher\base;
|
namespace catcher\base;
|
||||||
|
|
||||||
use catcher\validates\Uniques;
|
use catcher\validates\Sometimes;
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
abstract class BaseValidate extends Validate
|
abstract class BaseValidate extends Validate
|
||||||
@ -18,8 +18,12 @@ abstract class BaseValidate extends Validate
|
|||||||
|
|
||||||
abstract protected function getRules(): array ;
|
abstract protected function getRules(): array ;
|
||||||
|
|
||||||
|
/**
|
||||||
private function register()
|
*
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function register(): void
|
||||||
{
|
{
|
||||||
if (!empty($this->newValidates())) {
|
if (!empty($this->newValidates())) {
|
||||||
foreach ($this->newValidates() as $validate) {
|
foreach ($this->newValidates() as $validate) {
|
||||||
@ -28,10 +32,15 @@ abstract class BaseValidate extends Validate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
private function newValidates()
|
*
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function newValidates(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
new Sometimes(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ trait BaseOptionsTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->save()) {
|
if ($this->save()) {
|
||||||
return $this->id;
|
return $this->{$this->getPk()};
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -42,7 +42,7 @@ trait BaseOptionsTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($model->save()) {
|
if ($model->save()) {
|
||||||
$model->id;
|
return $model->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -53,21 +53,37 @@ trait BaseOptionsTrait
|
|||||||
* @time 2019年12月03日
|
* @time 2019年12月03日
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param array $field
|
* @param array $field
|
||||||
|
* @param bool $trash
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function findBy($id, array $field = ['*'])
|
public function findBy($id, array $field = ['*'], $trash = false)
|
||||||
{
|
{
|
||||||
return static::where($this->getPk(), $id)->select($field)->find();
|
if ($trash) {
|
||||||
|
return static::onlyTrashed()->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::where($this->getPk(), $id)->field($field)->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2019年12月03日
|
* @time 2019年12月03日
|
||||||
* @param $id
|
* @param $id
|
||||||
|
* @param $force
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function deleteBy($id)
|
public function deleteBy($id, $force = false)
|
||||||
{
|
{
|
||||||
return static::destory($id);
|
return static::destroy($id, $force);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @time 2019年12月07日
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function recover($id)
|
||||||
|
{
|
||||||
|
return static::onlyTrashed()->find($id)->restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
extend/catcher/validates/Sometimes.php
Normal file
28
extend/catcher/validates/Sometimes.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace catcher\validates;
|
||||||
|
|
||||||
|
class Sometimes implements ValidateInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function type(): string
|
||||||
|
{
|
||||||
|
// TODO: Implement type() method.
|
||||||
|
return 'sometimes';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verify($value): bool
|
||||||
|
{
|
||||||
|
// TODO: Implement verify() method.
|
||||||
|
if ($value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function message(): string
|
||||||
|
{
|
||||||
|
// TODO: Implement message() method.
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ interface ValidateInterface
|
|||||||
{
|
{
|
||||||
public function type(): string ;
|
public function type(): string ;
|
||||||
|
|
||||||
public function verify($value, $field): bool ;
|
public function verify($value): bool ;
|
||||||
|
|
||||||
public function message(): string ;
|
public function message(): string ;
|
||||||
}
|
}
|
||||||
|
19
extend/think-module/composer.json
Normal file
19
extend/think-module/composer.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "jaguarjack/think-module",
|
||||||
|
"description": "thinkphp module",
|
||||||
|
"type": "library",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "jaguarjack",
|
||||||
|
"email": "njphper@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"jaguarjack\\think\\module\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"require": {}
|
||||||
|
}
|
213
extend/think-module/config/module.php
Normal file
213
extend/think-module/config/module.php
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Nwidart\Modules\Activators\FileActivator;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Module Namespace
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Default module namespace.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'namespace' => 'module',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Module Stubs
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Default module stubs.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'stubs' => [
|
||||||
|
'enabled' => false,
|
||||||
|
'path' => base_path() . '/vendor/nwidart/laravel-modules/src/Commands/stubs',
|
||||||
|
'files' => [
|
||||||
|
'routes/web' => 'Routes/web.php',
|
||||||
|
'routes/api' => 'Routes/api.php',
|
||||||
|
'views/index' => 'Resources/views/index.blade.php',
|
||||||
|
'views/master' => 'Resources/views/layouts/master.blade.php',
|
||||||
|
'scaffold/config' => 'Config/config.php',
|
||||||
|
'composer' => 'composer.json',
|
||||||
|
'assets/js/app' => 'Resources/assets/js/app.js',
|
||||||
|
'assets/sass/app' => 'Resources/assets/sass/app.scss',
|
||||||
|
'webpack' => 'webpack.mix.js',
|
||||||
|
'package' => 'package.json',
|
||||||
|
],
|
||||||
|
'replacements' => [
|
||||||
|
'routes/web' => ['LOWER_NAME', 'STUDLY_NAME'],
|
||||||
|
'routes/api' => ['LOWER_NAME'],
|
||||||
|
'webpack' => ['LOWER_NAME'],
|
||||||
|
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE'],
|
||||||
|
'views/index' => ['LOWER_NAME'],
|
||||||
|
'views/master' => ['LOWER_NAME', 'STUDLY_NAME'],
|
||||||
|
'scaffold/config' => ['STUDLY_NAME'],
|
||||||
|
'composer' => [
|
||||||
|
'LOWER_NAME',
|
||||||
|
'STUDLY_NAME',
|
||||||
|
'VENDOR',
|
||||||
|
'AUTHOR_NAME',
|
||||||
|
'AUTHOR_EMAIL',
|
||||||
|
'MODULE_NAMESPACE',
|
||||||
|
'PROVIDER_NAMESPACE',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'gitkeep' => true,
|
||||||
|
],
|
||||||
|
'paths' => [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Modules path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This path used for save the generated module. This path also will be added
|
||||||
|
| automatically to list of scanned folders.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'module' => root_path('module'),
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Modules assets path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may update the modules assets path.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'assets' => public_path('module'),
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| The migrations path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Where you run 'module:publish-migration' command, where do you publish the
|
||||||
|
| the migration files?
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'migration' => root_path('database/migrations'),
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Generator path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Customise the paths where the folders will be generated.
|
||||||
|
| Set the generate key to false to not generate that folder
|
||||||
|
*/
|
||||||
|
'generator' => [
|
||||||
|
'config' => ['path' => 'Config', 'generate' => true],
|
||||||
|
'command' => ['path' => 'Console', 'generate' => true],
|
||||||
|
'migration' => ['path' => 'Database/Migrations', 'generate' => true],
|
||||||
|
'seeder' => ['path' => 'Database/Seeders', 'generate' => true],
|
||||||
|
'factory' => ['path' => 'Database/factories', 'generate' => true],
|
||||||
|
'model' => ['path' => 'Entities', 'generate' => true],
|
||||||
|
'routes' => ['path' => 'Routes', 'generate' => true],
|
||||||
|
'controller' => ['path' => 'Http/Controllers', 'generate' => true],
|
||||||
|
'filter' => ['path' => 'Http/Middleware', 'generate' => true],
|
||||||
|
'request' => ['path' => 'Http/Requests', 'generate' => true],
|
||||||
|
'provider' => ['path' => 'Providers', 'generate' => true],
|
||||||
|
'assets' => ['path' => 'Resources/assets', 'generate' => true],
|
||||||
|
'lang' => ['path' => 'Resources/lang', 'generate' => true],
|
||||||
|
'views' => ['path' => 'Resources/views', 'generate' => true],
|
||||||
|
'test' => ['path' => 'Tests/Unit', 'generate' => true],
|
||||||
|
'test-feature' => ['path' => 'Tests/Feature', 'generate' => true],
|
||||||
|
'repository' => ['path' => 'Repositories', 'generate' => false],
|
||||||
|
'event' => ['path' => 'Events', 'generate' => false],
|
||||||
|
'listener' => ['path' => 'Listeners', 'generate' => false],
|
||||||
|
'policies' => ['path' => 'Policies', 'generate' => false],
|
||||||
|
'rules' => ['path' => 'Rules', 'generate' => false],
|
||||||
|
'jobs' => ['path' => 'Jobs', 'generate' => false],
|
||||||
|
'emails' => ['path' => 'Emails', 'generate' => false],
|
||||||
|
'notifications' => ['path' => 'Notifications', 'generate' => false],
|
||||||
|
'resource' => ['path' => 'Transformers', 'generate' => false],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Scan Path
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you define which folder will be scanned. By default will scan vendor
|
||||||
|
| directory. This is useful if you host the package in packagist website.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'scan' => [
|
||||||
|
'enabled' => false,
|
||||||
|
'paths' => [
|
||||||
|
base_path('vendor/*/*'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Composer File Template
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is the config for composer.json file, generated by this package
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'composer' => [
|
||||||
|
'vendor' => 'nwidart',
|
||||||
|
'author' => [
|
||||||
|
'name' => 'Nicolas Widart',
|
||||||
|
'email' => 'n.widart@gmail.com',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Caching
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is the config for setting up caching feature.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'cache' => [
|
||||||
|
'enabled' => false,
|
||||||
|
'key' => 'laravel-modules',
|
||||||
|
'lifetime' => 60,
|
||||||
|
],
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Choose what laravel-modules will register as custom namespaces.
|
||||||
|
| Setting one to false will require you to register that part
|
||||||
|
| in your own Service Provider class.
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
'register' => [
|
||||||
|
'translations' => true,
|
||||||
|
/**
|
||||||
|
* load files on boot or register method
|
||||||
|
*
|
||||||
|
* Note: boot not compatible with asgardcms
|
||||||
|
*
|
||||||
|
* @example boot|register
|
||||||
|
*/
|
||||||
|
'files' => 'register',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Activators
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You can define new types of activators here, file, database etc. The only
|
||||||
|
| required parameter is 'class'.
|
||||||
|
| The file activator will store the activation status in storage/installed_modules
|
||||||
|
*/
|
||||||
|
'activators' => [
|
||||||
|
'file' => [
|
||||||
|
'class' => FileActivator::class,
|
||||||
|
'statuses-file' => base_path('modules_statuses.json'),
|
||||||
|
'cache-key' => 'activator.installed',
|
||||||
|
'cache-lifetime' => 604800,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'activator' => 'file',
|
||||||
|
];
|
17
extend/think-module/src/ThinkModuleService.php
Normal file
17
extend/think-module/src/ThinkModuleService.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace jaguarjack\think\module;
|
||||||
|
|
||||||
|
use jaguarjack\think\module\command\CreateModuleCommand;
|
||||||
|
use jaguarjack\think\module\command\DiscoverModuleServiceCommand;
|
||||||
|
use think\Service;
|
||||||
|
|
||||||
|
class ThinkModuleService extends Service
|
||||||
|
{
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->commands([
|
||||||
|
CreateModuleCommand::class,
|
||||||
|
DiscoverModuleServiceCommand::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
131
extend/think-module/src/command/CreateModuleCommand.php
Normal file
131
extend/think-module/src/command/CreateModuleCommand.php
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
namespace jaguarjack\think\module\command;
|
||||||
|
|
||||||
|
use catcher\CatchAdmin;
|
||||||
|
use think\console\Command;
|
||||||
|
use think\console\Input;
|
||||||
|
use think\console\input\Argument;
|
||||||
|
use think\console\Output;
|
||||||
|
|
||||||
|
class CreateModuleCommand extends Command
|
||||||
|
{
|
||||||
|
protected $module;
|
||||||
|
|
||||||
|
protected $moduleDir;
|
||||||
|
|
||||||
|
protected $namespaces;
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('module:create')
|
||||||
|
->addArgument('module', Argument::REQUIRED, 'module name')
|
||||||
|
->setDescription('create module service');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(Input $input, Output $output)
|
||||||
|
{
|
||||||
|
$this->module = strtolower($input->getArgument('module'));
|
||||||
|
|
||||||
|
$this->moduleDir = CatchAdmin::moduleDirectory($this->module);
|
||||||
|
|
||||||
|
$this->namespaces = CatchAdmin::NAME . '\\\\' . $this->module . '\\\\';
|
||||||
|
|
||||||
|
$this->createController();
|
||||||
|
$this->createRequest();
|
||||||
|
$this->createModel();
|
||||||
|
// $this->createService();
|
||||||
|
$this->createView();
|
||||||
|
$this->createValidate();
|
||||||
|
$this->createRoute();
|
||||||
|
$this->moduleJson();
|
||||||
|
|
||||||
|
$output->warning('module created');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function createController()
|
||||||
|
{
|
||||||
|
mkdir($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR);
|
||||||
|
return file_put_contents($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR . 'Index.php', str_replace(
|
||||||
|
['{CLASS}', '{NAMESPACE}', '{MODULE}'],
|
||||||
|
['Index', $this->namespaces . 'controller', $this->module],
|
||||||
|
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'stubs'.DIRECTORY_SEPARATOR. 'controller.stub')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function createModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createView()
|
||||||
|
{
|
||||||
|
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'view');
|
||||||
|
|
||||||
|
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'index.html', '');
|
||||||
|
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'create.html', '');
|
||||||
|
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'edit.html', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createValidate()
|
||||||
|
{
|
||||||
|
$validatePath = $this->moduleDir . DIRECTORY_SEPARATOR . 'validate' . DIRECTORY_SEPARATOR;
|
||||||
|
mkdir($validatePath);
|
||||||
|
file_put_contents($validatePath . 'CreateValidate.php', str_replace(
|
||||||
|
['{Namespace}', '{Class}'],
|
||||||
|
[$this->namespaces . 'validate', 'Create'],
|
||||||
|
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub')));
|
||||||
|
|
||||||
|
file_put_contents($validatePath . 'UpdateValidate.php', str_replace(
|
||||||
|
['{Namespace}', '{Class}'],
|
||||||
|
[$this->namespaces . 'validate', 'Update'],
|
||||||
|
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub')));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createRequest()
|
||||||
|
{
|
||||||
|
$requestPath = $this->moduleDir . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR;
|
||||||
|
mkdir($requestPath);
|
||||||
|
file_put_contents($validatePath . 'CreateRequest.php', str_replace(
|
||||||
|
['{Namespace}', '{Class}'],
|
||||||
|
[$this->namespaces . 'request', 'Create'],
|
||||||
|
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub')));
|
||||||
|
|
||||||
|
file_put_contents($validatePath . 'UpdateRequest.php', str_replace(
|
||||||
|
['{Namespace}', '{Class}'],
|
||||||
|
[$this->namespaces . 'request', 'Update'],
|
||||||
|
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub')));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function database()
|
||||||
|
{
|
||||||
|
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database');
|
||||||
|
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR.'migrations');
|
||||||
|
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR . 'seeds');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function moduleJson()
|
||||||
|
{
|
||||||
|
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'module.json', str_replace(
|
||||||
|
['{MODULE}', '{SERVICE}'],
|
||||||
|
[$this->module, $this->namespaces. ucfirst($this->module) . 'Service'],
|
||||||
|
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'module.stub')));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createRoute()
|
||||||
|
{
|
||||||
|
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'route.php',
|
||||||
|
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'route.stub'));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createService()
|
||||||
|
{
|
||||||
|
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR . ucfirst($this->module) . 'Service.php', str_replace(
|
||||||
|
['{CLASS}', '{NAMESPACE}'],
|
||||||
|
[ucfirst($this->module), $this->namespaces . '\\' . $this->module],
|
||||||
|
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'provider.stub')));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
namespace jaguarjack\think\module\command;
|
||||||
|
|
||||||
|
use think\console\Command;
|
||||||
|
use think\console\Input;
|
||||||
|
use think\console\input\Argument;
|
||||||
|
use think\console\input\Option;
|
||||||
|
use think\console\Output;
|
||||||
|
|
||||||
|
class DiscoverModuleServiceCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('module:service')
|
||||||
|
->setDescription('discover module service');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(Input $input, Output $output)
|
||||||
|
{
|
||||||
|
$this->getModuleServices();
|
||||||
|
|
||||||
|
$output->writeln('module service generator succeed!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取模块
|
||||||
|
*
|
||||||
|
* @time 2019年11月27日
|
||||||
|
* @return bool
|
||||||
|
* @throws \ReflectionException
|
||||||
|
*/
|
||||||
|
protected function getModuleServices(): bool
|
||||||
|
{
|
||||||
|
$modules = glob(root_path('module') .'*');
|
||||||
|
$moduleServices = [];
|
||||||
|
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
if (file_exists($module . DIRECTORY_SEPARATOR . 'module.json')) {
|
||||||
|
$moduleJson = file_get_contents($module . DIRECTORY_SEPARATOR . 'module.json');
|
||||||
|
$moduleServices = array_merge($moduleServices, \json_decode($moduleJson, true)['services']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$moduleServices = $this->checkModuleService($moduleServices);
|
||||||
|
|
||||||
|
$header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL;
|
||||||
|
|
||||||
|
$content =
|
||||||
|
'<?php ' . PHP_EOL . $header . 'return ' .
|
||||||
|
|
||||||
|
var_export($moduleServices, true) . ';';
|
||||||
|
|
||||||
|
file_put_contents($this->app->getRootPath() . 'module/services.php', $content);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @time 2019年11月29日
|
||||||
|
* @param $moduleServices
|
||||||
|
* @throws \ReflectionException
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function checkModuleService($moduleServices)
|
||||||
|
{
|
||||||
|
$new = [];
|
||||||
|
|
||||||
|
foreach ($moduleServices as $key => $service) {
|
||||||
|
$selfReflection = new \ReflectionClass($service);
|
||||||
|
// if service set property 'cache' && set cache => false
|
||||||
|
// the service will not be cached
|
||||||
|
// finally will boot it
|
||||||
|
if ($selfReflection->hasProperty('cache') && !$selfReflection->getProperty('cache')) {
|
||||||
|
$new[$service] = true;
|
||||||
|
} else {
|
||||||
|
$new[$service] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
}
|
21
extend/think-module/src/command/stubs/command.stub
Normal file
21
extend/think-module/src/command/stubs/command.stub
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
namespace {NAMESPACE};
|
||||||
|
|
||||||
|
use think\console\Command;
|
||||||
|
use think\console\Input;
|
||||||
|
use think\console\input\Argument;
|
||||||
|
use think\console\input\Option;
|
||||||
|
use think\console\Output;
|
||||||
|
|
||||||
|
class {CLASS}Command extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('')
|
||||||
|
->setDescription('');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(Input $input, Output $output)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
25
extend/think-module/src/command/stubs/composer.stub
Normal file
25
extend/think-module/src/command/stubs/composer.stub
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "$VENDOR$/$LOWER_NAME$",
|
||||||
|
"description": "",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "$AUTHOR_NAME$",
|
||||||
|
"email": "$AUTHOR_EMAIL$"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\$PROVIDER_NAMESPACE$\\$STUDLY_NAME$ServiceProvider"
|
||||||
|
],
|
||||||
|
"aliases": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
extend/think-module/src/command/stubs/controller.stub
Normal file
35
extend/think-module/src/command/stubs/controller.stub
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
namespace {NAMESPACE};
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
|
||||||
|
class {CLASS} extends BaseController
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return $this->fetch('{MODULE}::index');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return $this->fetch('{MODULE}::create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public function read()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public function edit()
|
||||||
|
{
|
||||||
|
return $this->fetch('{MODULE}::edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{}
|
||||||
|
|
||||||
|
}
|
11
extend/think-module/src/command/stubs/event.stub
Normal file
11
extend/think-module/src/command/stubs/event.stub
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace {NAMESPACE};
|
||||||
|
|
||||||
|
class {CLASS}
|
||||||
|
{
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
33
extend/think-module/src/command/stubs/migration.stub
Normal file
33
extend/think-module/src/command/stubs/migration.stub
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Migrator;
|
||||||
|
use think\migration\db\Column;
|
||||||
|
|
||||||
|
class {CLASS} 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
10
extend/think-module/src/command/stubs/model.stub
Normal file
10
extend/think-module/src/command/stubs/model.stub
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {NAMESPACE};
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class {CLASS} extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = $FILLABLE$;
|
||||||
|
}
|
13
extend/think-module/src/command/stubs/module.stub
Normal file
13
extend/think-module/src/command/stubs/module.stub
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"alias": "{MODULE}",
|
||||||
|
"description": "",
|
||||||
|
"keywords": [],
|
||||||
|
"order": 0,
|
||||||
|
"services": [
|
||||||
|
"{SERVICE}"
|
||||||
|
],
|
||||||
|
"aliases": {},
|
||||||
|
"files": [],
|
||||||
|
"requires": []
|
||||||
|
}
|
23
extend/think-module/src/command/stubs/provider.stub
Normal file
23
extend/think-module/src/command/stubs/provider.stub
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
namespace {NAMESPACE};
|
||||||
|
|
||||||
|
use think\Service;
|
||||||
|
|
||||||
|
class {CLASS}Service extends Service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->loadRoutesFrom(__DIR__ . DIRECTORY_SEPARATOR . 'route.php');
|
||||||
|
|
||||||
|
$this->loadViewFrom();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadViewFrom(): void
|
||||||
|
{
|
||||||
|
moduleViewPathManager()->set('login', __DIR__ . DIRECTORY_SEPARATOR . 'view' .DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
}
|
17
extend/think-module/src/command/stubs/request.stub
Normal file
17
extend/think-module/src/command/stubs/request.stub
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace {NAMESPACE};
|
||||||
|
|
||||||
|
use catcher\base\BaseRequest;
|
||||||
|
|
||||||
|
class {CLASS}Request extends BaseRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @time 2019年11月27日
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getValidate()
|
||||||
|
{
|
||||||
|
// TODO: Implement getValidate() method.
|
||||||
|
}
|
||||||
|
}
|
5
extend/think-module/src/command/stubs/route.stub
Normal file
5
extend/think-module/src/command/stubs/route.stub
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// you should user `$router`
|
||||||
|
// $router->get('index', 'controller@method');
|
||||||
|
|
19
extend/think-module/src/command/stubs/seeder.stub
Normal file
19
extend/think-module/src/command/stubs/seeder.stub
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Seeder;
|
||||||
|
|
||||||
|
class {CLASS} extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run Method.
|
||||||
|
*
|
||||||
|
* Write your database seeder using this method.
|
||||||
|
*
|
||||||
|
* More information on writing seeders is available here:
|
||||||
|
* http://docs.phinx.org/en/latest/seeding.html
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
extend/think-module/src/command/stubs/validate.stub
Normal file
11
extend/think-module/src/command/stubs/validate.stub
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
namespace {Namespace};
|
||||||
|
|
||||||
|
use catcher\base\BaseValidate;
|
||||||
|
|
||||||
|
class {Class}Validate extends BaseValidate
|
||||||
|
{
|
||||||
|
protected $rule = [
|
||||||
|
// todo your rules
|
||||||
|
];
|
||||||
|
}
|
@ -31,60 +31,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 表格操作列 -->
|
|
||||||
<script type="text/html" id="tableBarUser">
|
|
||||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
|
|
||||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
|
||||||
<a class="layui-btn layui-btn-xs" lay-event="reset">重置密码</a>
|
|
||||||
</script>
|
|
||||||
<!-- 表格状态列 -->
|
|
||||||
<script type="text/html" id="tableStateUser">
|
|
||||||
<input type="checkbox" lay-filter="ckStateUser" value="{{d.userId}}" lay-skin="switch"
|
|
||||||
lay-text="正常|锁定" {{d.state==0?'checked':''}}/>
|
|
||||||
</script>
|
|
||||||
<!-- 表单弹窗 -->
|
<!-- 表单弹窗 -->
|
||||||
<script type="text/html" id="modelUser">
|
|
||||||
<form id="modelUserForm" lay-filter="modelUserForm" class="layui-form model-form">
|
|
||||||
<input name="userId" type="hidden"/>
|
|
||||||
<div class="layui-form-item">
|
|
||||||
<label class="layui-form-label">账号</label>
|
|
||||||
<div class="layui-input-block">
|
|
||||||
<input name="username" placeholder="请输入账号" type="text" class="layui-input" maxlength="20"
|
|
||||||
lay-verType="tips" lay-verify="required" required/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
|
||||||
<label class="layui-form-label">用户名</label>
|
|
||||||
<div class="layui-input-block">
|
|
||||||
<input name="nickName" placeholder="请输入用户名" type="text" class="layui-input" maxlength="20"
|
|
||||||
lay-verType="tips" lay-verify="required" required/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
|
||||||
<label class="layui-form-label">性别</label>
|
|
||||||
<div class="layui-input-block">
|
|
||||||
<input type="radio" name="sex" value="男" title="男" checked/>
|
|
||||||
<input type="radio" name="sex" value="女" title="女"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
|
||||||
<label class="layui-form-label">角色</label>
|
|
||||||
<div class="layui-input-block">
|
|
||||||
<select name="roleId" lay-verType="tips" lay-verify="required">
|
|
||||||
<option value="">请选择角色</option>
|
|
||||||
<option value="1">管理员</option>
|
|
||||||
<option value="2">普通用户</option>
|
|
||||||
<option value="3">游客</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="layui-form-item text-right">
|
|
||||||
<button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
|
|
||||||
<button class="layui-btn" lay-filter="modelSubmitUser" lay-submit>保存</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- js部分 -->
|
<!-- js部分 -->
|
||||||
<script type="text/javascript" src="__CATCH_ADMIN_LIBS__/layui/layui.js"></script>
|
<script type="text/javascript" src="__CATCH_ADMIN_LIBS__/layui/layui.js"></script>
|
||||||
<script type="text/javascript" src="__CATCH_ADMIN_JS__/common.js?v=315"></script>
|
<script type="text/javascript" src="__CATCH_ADMIN_JS__/common.js?v=315"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user