用户管理

This commit is contained in:
wuyanwen
2019-12-07 17:31:38 +08:00
parent fa4837487b
commit 330a19e8c3
35 changed files with 1181 additions and 214 deletions

View File

@@ -6,11 +6,12 @@ namespace catcher;
* @package catcher
*
*
* @method text($column, $label = ''): self
* @method image($column, $label = ''): self
* @method radio($column, $label = ''): self
* @method select($column, $label = ''): self
* @method textarea($column, $label = ''): self
* @method CatchForm text($column, $label = '')
* @method CatchForm image($column, $label = '')
* @method CatchForm radio($column, $label = '')
* @method CatchForm select($column, $label = '')
* @method CatchForm textarea($column, $label = '')
* @method CatchForm password($column, $label = '')
*
*/
class CatchForm
@@ -19,10 +20,48 @@ class CatchForm
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)
{
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
'id' => $id,
'id' => sprintf('id="%s"', $id),
]);
return $this;
}
@@ -57,6 +96,7 @@ class CatchForm
return $this;
}
public function disabled()
{
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
@@ -87,19 +127,28 @@ class CatchForm
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) {
$form .= sprintf($this->baseField(),
$field['labelClass'] ?? '',
$field['label'],
$field['inlineClass'] ?? '',
$this->{$field['type'].'Field'}($field));
$this->{$field['type'].'Field'}($field)) ;
}
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)
{
@@ -111,6 +160,7 @@ class CatchForm
'name' => $this->name,
'type' => $method,
'label' => $label,
'inline' => false,
];
return $this;
@@ -128,23 +178,62 @@ class CatchForm
private function baseField()
{
return
'<div class="layui-inline">
<label class="layui-form-label %s">%s: </label>
<div class="layui-input-inline %s">
'<div class="layui-form-item">
<label class="layui-form-label%s">%s: </label>
<div class="layui-input-block%s">
%s
</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)
{
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['class'],
$field['id'] ?? '',
$field['class'] ?? '',
$field['default'] ?? '',
$field['readonly'] ?? '',
$field['placeholder'] ?? '',
$field['disabled'] ?? ''
$field['disabled'] ?? '',
$field['verify'] ?? ''
);
}
@@ -162,6 +251,16 @@ class CatchForm
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()
{}

View File

@@ -11,10 +11,18 @@ abstract class BaseModel extends \think\Model
use TransTrait;
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;
}

View File

@@ -1,7 +1,7 @@
<?php
namespace catcher\base;
use catcher\validates\Uniques;
use catcher\validates\Sometimes;
use think\Validate;
abstract class BaseValidate extends Validate
@@ -18,8 +18,12 @@ abstract class BaseValidate extends Validate
abstract protected function getRules(): array ;
private function register()
/**
*
* @time 2019年12月07日
* @return void
*/
private function register(): void
{
if (!empty($this->newValidates())) {
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 [
new Sometimes(),
];
}
}

View File

@@ -19,7 +19,7 @@ trait BaseOptionsTrait
}
if ($this->save()) {
return $this->id;
return $this->{$this->getPk()};
}
return false;
@@ -42,7 +42,7 @@ trait BaseOptionsTrait
}
if ($model->save()) {
$model->id;
return $model->id;
}
return false;
@@ -53,21 +53,37 @@ trait BaseOptionsTrait
* @time 2019年12月03日
* @param $id
* @param array $field
* @param bool $trash
* @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日
* @param $id
* @param $force
* @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();
}
}

View 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 '';
}
}

View File

@@ -5,7 +5,7 @@ interface ValidateInterface
{
public function type(): string ;
public function verify($value, $field): bool ;
public function verify($value): bool ;
public function message(): string ;
}