初始化仓库
This commit is contained in:
51
admin/components/UI/Widget/Alert.php
Normal file
51
admin/components/UI/Widget/Alert.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
/**
|
||||
* 警告信息
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Alert extends Widget
|
||||
{
|
||||
|
||||
protected string $type = 'info';
|
||||
private ?string $title;
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @param string|array $content
|
||||
* @param string|null $title
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct($content, string $title = null, callable $callback = NULL)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->content = $content;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本类型
|
||||
* @param $name
|
||||
* @return $this
|
||||
*/
|
||||
public function type($name): self
|
||||
{
|
||||
$this->type = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
return [
|
||||
'nodeName' => 'a-alert',
|
||||
'title' => $this->title,
|
||||
'type' => $this->type,
|
||||
'child' => $this->content
|
||||
];
|
||||
}
|
||||
}
|
||||
12
admin/components/UI/Widget/Append/Element.php
Normal file
12
admin/components/UI/Widget/Append/Element.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget\Append;
|
||||
|
||||
/**
|
||||
* Class Element
|
||||
* @package backend\components\UI\Widget\Append
|
||||
*/
|
||||
trait Element
|
||||
{
|
||||
|
||||
}
|
||||
63
admin/components/UI/Widget/Badge.php
Normal file
63
admin/components/UI/Widget/Badge.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
|
||||
/**
|
||||
* Class Badges
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Badge extends Widget
|
||||
{
|
||||
|
||||
private string $content;
|
||||
private string $size = 'medium';
|
||||
private string $type;
|
||||
|
||||
/**
|
||||
* Badges constructor.
|
||||
* @param $content
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct($content, callable $callback = NULL)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
* @param $value
|
||||
* @return $this
|
||||
*/
|
||||
public function color($value): self
|
||||
{
|
||||
$this->type = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 大小
|
||||
* @param string $size
|
||||
* @return $this
|
||||
*/
|
||||
public function size(string $size = ''): self
|
||||
{
|
||||
$this->size = $size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
return [
|
||||
'nodeName' => 'a-tag',
|
||||
'color' => $this->type,
|
||||
'size' => $this->size,
|
||||
'child' => $this->content
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
38
admin/components/UI/Widget/Form.php
Normal file
38
admin/components/UI/Widget/Form.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
/**
|
||||
* Class Form
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Form extends Widget
|
||||
{
|
||||
|
||||
private \backend\components\UI\Form $form;
|
||||
|
||||
public function __construct($data, callable $callback = null)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
$this->form = new \backend\components\UI\Form($data, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
return $this->form->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $method
|
||||
* @param $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
return $this->form->$method(...$arguments);
|
||||
}
|
||||
|
||||
}
|
||||
64
admin/components/UI/Widget/Icon.php
Normal file
64
admin/components/UI/Widget/Icon.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Widget\Append\Element;
|
||||
|
||||
/**
|
||||
*图标组件
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Icon extends Widget
|
||||
{
|
||||
use Element;
|
||||
|
||||
private string $content;
|
||||
private bool $layout = false;
|
||||
private int $size;
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct(string $content, ?callable $callback = null)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置大小
|
||||
* @param int $size
|
||||
* @return $this
|
||||
*/
|
||||
public function size(int $size): self
|
||||
{
|
||||
$this->size = $size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$icon = $this->content;
|
||||
if (strpos($icon, '<svg') !== false) {
|
||||
return [
|
||||
'nodeName' => 'n-icon',
|
||||
'size' => $this->size,
|
||||
'child' => [
|
||||
'nodeName' => 'rich-text',
|
||||
'class' => implode(' ', $this->class),
|
||||
'nodes' => $icon
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'nodeName' => 'icon-' . $icon,
|
||||
'class' => implode(' ', $this->class),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
63
admin/components/UI/Widget/Images.php
Normal file
63
admin/components/UI/Widget/Images.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
/**
|
||||
* Class Images
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Images extends Widget
|
||||
{
|
||||
|
||||
private array $list;
|
||||
private int $size = 60;
|
||||
|
||||
/**
|
||||
* Images constructor.
|
||||
* @param array $list
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct(array $list, callable $callback = NULL)
|
||||
{
|
||||
$this->list = $list;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图像大小
|
||||
* @param int $size
|
||||
* @return $this
|
||||
*/
|
||||
public function size(int $size): self
|
||||
{
|
||||
$this->size = $size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->list as $vo) {
|
||||
$list[] = [
|
||||
'nodeName' => 'a-image',
|
||||
'src' => $vo,
|
||||
'width' => $this->size,
|
||||
'height' => $this->size,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'nodeName' => 'a-image-preview-group',
|
||||
'infinite' => true,
|
||||
'child' => [
|
||||
'nodeName' => 'a-space',
|
||||
'child' => $list
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
26
admin/components/UI/Widget/Item.php
Normal file
26
admin/components/UI/Widget/Item.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
|
||||
/**
|
||||
* 项目回调
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Item
|
||||
{
|
||||
public $params;
|
||||
|
||||
public function __construct($params = [])
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
$this->{$method}[] = $arguments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
303
admin/components/UI/Widget/Link.php
Normal file
303
admin/components/UI/Widget/Link.php
Normal file
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\Facades\Permission;
|
||||
use admin\components\UI\Tools;
|
||||
use admin\components\UI\Widget\Append\Element;
|
||||
use admin\components\UI\yii\Str;
|
||||
|
||||
/**
|
||||
* 链接组件
|
||||
* Class Link
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Link extends Widget
|
||||
{
|
||||
use Element;
|
||||
|
||||
protected string $name;
|
||||
protected string $route;
|
||||
protected string $url;
|
||||
protected bool $absolute = false;
|
||||
protected array $params = [];
|
||||
protected array $fields = [];
|
||||
protected ?\Closure $show = null;
|
||||
protected string $button = '';
|
||||
protected string $type = 'default';
|
||||
protected string $status = 'normal';
|
||||
protected bool $block = false;
|
||||
protected string $model = '';
|
||||
protected array $data = [];
|
||||
protected array $class = [];
|
||||
protected array $typeConfig = [];
|
||||
protected string $icon = '';
|
||||
protected string $auth = '';
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $route
|
||||
* @param array $params
|
||||
* @param bool $absolute
|
||||
*/
|
||||
public function __construct(string $name, string $route = '', array $params = [], bool $absolute = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->route = $route;
|
||||
$this->params = $params ?: [];
|
||||
$this->absolute = $absolute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return $this
|
||||
*/
|
||||
public function fields($params): self
|
||||
{
|
||||
$this->fields = $params;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接类型
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @return $this
|
||||
*/
|
||||
public function type(string $name = 'default', array $config = []): self
|
||||
{
|
||||
$this->type = $name;
|
||||
$this->typeConfig = $config;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型配置
|
||||
* @return array
|
||||
*/
|
||||
public function getTypeConfig(): array
|
||||
{
|
||||
return $this->typeConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据模型
|
||||
* @param string $model
|
||||
* @return $this
|
||||
*/
|
||||
public function model(string $model): self
|
||||
{
|
||||
$this->model = $model;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图标
|
||||
* @param $icon
|
||||
* @return $this
|
||||
*/
|
||||
public function icon($icon): self
|
||||
{
|
||||
$this->icon = $icon;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按钮属性
|
||||
* @param string $type
|
||||
* @param string $status
|
||||
* @param bool $block
|
||||
* @return $this
|
||||
*/
|
||||
public function button(string $type = 'primary', string $status = 'medium', bool $block = false): self
|
||||
{
|
||||
$this->button = $type;
|
||||
$this->status = $status;
|
||||
$this->block = $block;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由
|
||||
* @return string
|
||||
*/
|
||||
public function getRoute(): string
|
||||
{
|
||||
return $this->route;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示隐藏
|
||||
* @param callable $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function show(callable $callback): self
|
||||
{
|
||||
$this->show = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义权限
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function can(string $name): self
|
||||
{
|
||||
if (strpos($name, '.') !== false) {
|
||||
$this->auth = $name;
|
||||
} else {
|
||||
$this->auth = $this->route . '|' . $name;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取url
|
||||
* @return false|string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
if (!$this->isAuth()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->show && !call_user_func($this->show)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return app_route($this->route, $this->params, $this->absolute, $this->model, $this->fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$url = $this->getUrl();
|
||||
|
||||
if (!$url) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$object = [
|
||||
'nodeName' => 'route',
|
||||
];
|
||||
|
||||
switch ($this->type) {
|
||||
case 'default':
|
||||
$object['vBind:href'] = $url;
|
||||
break;
|
||||
case 'blank':
|
||||
$object['nodeName'] = 'a';
|
||||
$object['vBind:href'] = $url;
|
||||
$object['target'] = '_blank';
|
||||
$object['child'] = $this->name;
|
||||
break;
|
||||
case 'dialog':
|
||||
$object['vBind:href'] = $url;
|
||||
$object['type'] = 'dialog';
|
||||
$object['title'] = $this->name;
|
||||
break;
|
||||
case 'drawer':
|
||||
$object['vBind:href'] = $url;
|
||||
$object['type'] = 'dialog';
|
||||
$object['mode'] = 'drawer';
|
||||
$object['title'] = $this->name;
|
||||
break;
|
||||
case 'ajax':
|
||||
$object['vBind:href'] = $url;
|
||||
$object['type'] = 'ajax';
|
||||
$object['title'] = '确认进行' . $this->name . '操作?';
|
||||
break;
|
||||
}
|
||||
$object = array_merge($object, $this->typeConfig);
|
||||
|
||||
if ($this->button) {
|
||||
$link = [
|
||||
'nodeName' => 'a-button',
|
||||
'class' => implode(' ', $this->class),
|
||||
'type' => $this->button,
|
||||
'status' => $this->status,
|
||||
'child' => [
|
||||
$this->name
|
||||
]
|
||||
];
|
||||
if ($this->icon) {
|
||||
$link['child'][] = (new Icon($this->icon))->attr('vSlot:icon', '')->getRender();
|
||||
}
|
||||
if ($this->block) {
|
||||
$link['long'] = true;
|
||||
}
|
||||
} else {
|
||||
$link = [
|
||||
'nodeName' => 'span',
|
||||
'class' => 'arco-link arco-link-status-normal ' . implode(' ', $this->class),
|
||||
'child' => [
|
||||
$this->name
|
||||
]
|
||||
];
|
||||
if ($this->icon) {
|
||||
$link['child'][] = (new Icon($this->icon))->class('mr-2')->getRender();
|
||||
}
|
||||
}
|
||||
|
||||
$object['child'] = $link;
|
||||
|
||||
return array_merge($object, $this->attr);
|
||||
|
||||
}
|
||||
|
||||
private function isAuth(): bool
|
||||
{
|
||||
return true;
|
||||
//// 路由不存在
|
||||
//if (!\Route::has($this->route)) {
|
||||
// return false;
|
||||
//}
|
||||
//// 验证是否公共类
|
||||
//$public = \Route::getRoutes()->getByName($this->route)->getAction('public');
|
||||
//if ($public) {
|
||||
// return true;
|
||||
//}
|
||||
//// 验证是否当前守护器
|
||||
//$app = Str::before($this->route, '.');
|
||||
//if ($app <> Permission::getGuerd()) {
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//// 设置通用页面权限
|
||||
//if (Str::afterLast($this->route, '.') === 'page') {
|
||||
// if ($this->params['id']) {
|
||||
// $this->can('edit');
|
||||
// } else {
|
||||
// $this->can('add');
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//// 验证自定义权限
|
||||
//if ($this->auth) {
|
||||
// if (!auth($app)->user()->can($this->auth)) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//// 验证通用权限
|
||||
//if (auth($app)->user()->can($this->route)) {
|
||||
// return true;
|
||||
//}
|
||||
//return false;
|
||||
}
|
||||
|
||||
}
|
||||
51
admin/components/UI/Widget/Lists.php
Normal file
51
admin/components/UI/Widget/Lists.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
|
||||
/**
|
||||
* Class Lists
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Lists extends Widget
|
||||
{
|
||||
|
||||
private array $data;
|
||||
|
||||
/**
|
||||
* Lists constructor.
|
||||
* @param $data
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct($data, callable $callback = NULL)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
|
||||
$inner = [];
|
||||
$i = 0;
|
||||
foreach ($this->data as $item) {
|
||||
$inner[] = [
|
||||
'nodeName' => 'a-list-item',
|
||||
'child' => $item
|
||||
];
|
||||
}
|
||||
|
||||
return $inner ? [
|
||||
'nodeName' => 'a-list',
|
||||
'child' => $inner
|
||||
] : [
|
||||
'nodeName' => 'a-empty',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
75
admin/components/UI/Widget/Menu.php
Normal file
75
admin/components/UI/Widget/Menu.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Widget\Link;
|
||||
|
||||
/**
|
||||
* 下拉菜单
|
||||
* Class Menu
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Menu extends Widget
|
||||
{
|
||||
|
||||
protected string $name;
|
||||
protected string $type;
|
||||
protected array $link = [];
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct(string $name, string $type = 'primary', callable $callback = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $route
|
||||
* @param array $params
|
||||
*
|
||||
* @return Link
|
||||
*/
|
||||
public function link(string $name, string $route = '', array $params = []): Link
|
||||
{
|
||||
$link = new Link($name, $route, $params);
|
||||
$this->link[] = $link;
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->link as $class) {
|
||||
$list[] = [
|
||||
'nodeName' => 'a-doption',
|
||||
'child' => $class->render(),
|
||||
];
|
||||
}
|
||||
return [
|
||||
'nodeName' => 'a-dropdown',
|
||||
'child' => [
|
||||
[
|
||||
'nodeName' => 'a-button',
|
||||
'type' => $this->type,
|
||||
'child' => $this->name
|
||||
],
|
||||
[
|
||||
'nodeName' => 'div',
|
||||
'vSlot:content' => '',
|
||||
'child' => $list
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
71
admin/components/UI/Widget/Progress.php
Normal file
71
admin/components/UI/Widget/Progress.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
use admin\components\UI\Widget\Append\Element;
|
||||
|
||||
/**
|
||||
* Class Progress
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Progress extends Widget
|
||||
{
|
||||
use Element;
|
||||
|
||||
private $value;
|
||||
private string $color = 'default';
|
||||
private string $size = 'medium';
|
||||
|
||||
|
||||
/**
|
||||
* Progress constructor.
|
||||
* @param $value
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct($value, callable $callback = NULL)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $color
|
||||
* @return $this
|
||||
*/
|
||||
public function color(string $color): self
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $size
|
||||
* @return $this
|
||||
*/
|
||||
public function size($size = 'medium'): self
|
||||
{
|
||||
$this->size = (bool)$size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$node = [
|
||||
'nodeName' => 'a-progress',
|
||||
'size' => $this->size,
|
||||
'status' => $this->color,
|
||||
];
|
||||
if (is_numeric($this->value)) {
|
||||
$node['percent'] = $this->value;
|
||||
}else {
|
||||
$node['vBind:percent'] = $this->value;
|
||||
}
|
||||
return $node;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
63
admin/components/UI/Widget/Row.php
Normal file
63
admin/components/UI/Widget/Row.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
|
||||
/**
|
||||
* 行布局组件
|
||||
* Class Row
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Row extends Widget
|
||||
{
|
||||
|
||||
private array $column = [];
|
||||
|
||||
/**
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct(callable $callback = NULL)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置列
|
||||
* @param callable $callback
|
||||
* @param int $width
|
||||
* @return $this
|
||||
*/
|
||||
public function column(callable $callback, int $width = 0): self
|
||||
{
|
||||
$this->column[] = [
|
||||
'width' => $width,
|
||||
'callback' => $callback,
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
|
||||
$nodes = [];
|
||||
foreach ($this->column as $vo) {
|
||||
$nodes[] = [
|
||||
'nodeName' => 'div',
|
||||
'class' => $vo['width'] ? "row-span-{$vo['width']}" : '',
|
||||
'child' => call_user_func($vo['callback'])
|
||||
];
|
||||
}
|
||||
return [
|
||||
'nodeName' => 'div',
|
||||
'class' => 'grid grid-flow-col gap-x-4',
|
||||
'child' => $nodes
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
68
admin/components/UI/Widget/StatsCard.php
Normal file
68
admin/components/UI/Widget/StatsCard.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
|
||||
/**
|
||||
* 统计卡片
|
||||
* Class StatsCard
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class StatsCard extends Widget
|
||||
{
|
||||
|
||||
private int $column;
|
||||
private array $items = [];
|
||||
|
||||
/**
|
||||
* @param callable|null $callback
|
||||
* @param int $column
|
||||
*/
|
||||
public function __construct(callable $callback = null, int $column = 4)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $num
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function item($name, $num): self
|
||||
{
|
||||
$this->items[] = [
|
||||
'name' => $name,
|
||||
'num' => $num,
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$childs = [];
|
||||
foreach ($this->items as $vo) {
|
||||
$childs[] = [
|
||||
'nodeName' => 'div',
|
||||
'child' => [
|
||||
'nodeName' => 'a-statistic',
|
||||
'title' => $vo['name'],
|
||||
'value' => $vo['num'],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'nodeName' => 'div',
|
||||
'class' => 'grid gap-4 grid-cols-' . $this->column,
|
||||
'child' => $childs
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
44
admin/components/UI/Widget/Table.php
Normal file
44
admin/components/UI/Widget/Table.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
|
||||
/**
|
||||
* Class Table
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Table extends Widget
|
||||
{
|
||||
|
||||
private \backend\components\UI\Table $table;
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param callable|null $callback
|
||||
*/
|
||||
public function __construct($data, callable $callback = NULL)
|
||||
{
|
||||
$this->callback = $callback;
|
||||
$this->table = new \backend\components\UI\Table($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
return $this->table->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $method
|
||||
* @param $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
return $this->table->$method(...$arguments);
|
||||
}
|
||||
|
||||
}
|
||||
165
admin/components/UI/Widget/TreeList.php
Normal file
165
admin/components/UI/Widget/TreeList.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
/**
|
||||
* Class TreeList
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class TreeList extends Widget
|
||||
{
|
||||
|
||||
private $key;
|
||||
private string $field;
|
||||
private string $event;
|
||||
private ?string $url = null;
|
||||
private ?string $sortUrl = null;
|
||||
private ?string $filter = null;
|
||||
private bool $search = true;
|
||||
private array $keyword = [];
|
||||
private array $menu = [];
|
||||
private array $fieldNames = [];
|
||||
private $labelNode = [];
|
||||
|
||||
/**
|
||||
* @param $default
|
||||
* @param string $field
|
||||
* @param string $event
|
||||
*/
|
||||
public function __construct($default, string $field = '', string $event = '')
|
||||
{
|
||||
$this->key = $default;
|
||||
$this->field = $field;
|
||||
$this->event = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bool
|
||||
* @param array $keyword
|
||||
* @return $this
|
||||
*/
|
||||
public function search(bool $bool = true, array $keyword = []): self
|
||||
{
|
||||
$this->search = $bool;
|
||||
$this->keyword = $keyword;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function menu(array $data = []): self
|
||||
{
|
||||
$this->menu = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $url
|
||||
* @return $this
|
||||
*/
|
||||
public function url(string $url = null): self
|
||||
{
|
||||
$this->url = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $url
|
||||
* @return $this
|
||||
*/
|
||||
public function sortUrl(string $url = null): self
|
||||
{
|
||||
$this->sortUrl = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filter
|
||||
* @return $this
|
||||
*/
|
||||
public function filter(string $filter): self
|
||||
{
|
||||
$this->filter = $filter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fieldNames(array $map): self
|
||||
{
|
||||
$this->fieldNames = $map;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $node
|
||||
* @return $this
|
||||
*/
|
||||
public function label($node): TreeList
|
||||
{
|
||||
$this->labelNode = $node;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$urlPaths = parse_url(substr($this->url, 0, strrpos($this->url, "/")));
|
||||
$tree = [
|
||||
'nodeName' => 'widget-tree',
|
||||
'url' => $this->url,
|
||||
'sortUrl' => $this->sortUrl,
|
||||
'search' => $this->search,
|
||||
'keywords' => $this->keyword,
|
||||
'requestEventName' => md5($this->event),
|
||||
'vBind:filter' => $this->filter ?: '',
|
||||
'refreshUrls' => [trim($urlPaths['path'], '/')],
|
||||
'iconColor' => ['blue', 'cyan', 'green', 'orange', 'red', 'purple'],
|
||||
'vModel:value' => "data.filter['{$this->field}']",
|
||||
];
|
||||
|
||||
if ($this->fieldNames) {
|
||||
$tree['fieldNames'] = $this->fieldNames;
|
||||
}
|
||||
|
||||
if ($this->labelNode) {
|
||||
$tree['child'] = [
|
||||
'nodeName' => 'span',
|
||||
'vSlot:label' => 'item',
|
||||
'child' => $this->labelNode
|
||||
];
|
||||
}
|
||||
|
||||
$menu = [];
|
||||
if ($this->menu) {
|
||||
foreach ($this->menu as $key => $vo) {
|
||||
$url = $vo['url'];
|
||||
$event = $vo['event'];
|
||||
$tmp = [
|
||||
'text' => $vo['name'],
|
||||
];
|
||||
$tmp['key'] = $key;
|
||||
if ($event) {
|
||||
$tmp['event'] = $event;
|
||||
} else {
|
||||
switch ($vo['type']) {
|
||||
case 'dialog':
|
||||
$tmp['event'] = $url ? "window.router.dialog($url)" : "window.dialog.alert({content: '未定义链接数据'})";
|
||||
break;
|
||||
case 'ajax':
|
||||
$tmp['event'] = $url ? "window.router.ajax($url, {_method: 'POST', _title: '确认进行{$vo['name']}操作?'})" : "window.dialog.alert({content: '未定义链接数据'})";
|
||||
break;
|
||||
default:
|
||||
$tmp['event'] = $url ? "window.router.push($url)" : "window.dialog.alert({content: '未定义链接数据'})";
|
||||
}
|
||||
}
|
||||
$menu[] = $tmp;
|
||||
}
|
||||
$tree['contextMenus'] = $menu;
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
}
|
||||
110
admin/components/UI/Widget/Widget.php
Normal file
110
admin/components/UI/Widget/Widget.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Widget;
|
||||
|
||||
use admin\components\UI\Tools;
|
||||
|
||||
/**
|
||||
* Class Widget
|
||||
* @package backend\components\UI\Widget
|
||||
*/
|
||||
class Widget
|
||||
{
|
||||
protected ?\Closure $callback;
|
||||
|
||||
protected array $class = [];
|
||||
protected array $attr = [];
|
||||
protected array $style = [];
|
||||
protected $callbackData;
|
||||
|
||||
/**
|
||||
* 属性数据
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function attr(string $name, string $value): self
|
||||
{
|
||||
$this->attr[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* class样式
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function class(string $name): self
|
||||
{
|
||||
$this->class[] = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置样式
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function style(string $name, string $value): self
|
||||
{
|
||||
$this->style[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置变量
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($name, $value): self
|
||||
{
|
||||
$this->$name = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取变量
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue($name)
|
||||
{
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并数组
|
||||
* @param array $array
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public function mergeArray(array $array, string $str = ''): string
|
||||
{
|
||||
return implode($str, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调设置
|
||||
* @return $this
|
||||
*/
|
||||
public function next(): Widget
|
||||
{
|
||||
if (!$this->callback) {
|
||||
return $this;
|
||||
}
|
||||
$this->callbackData = call_user_func($this->callback, $this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRender(): array
|
||||
{
|
||||
return array_merge($this->render(), $this->attr);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user