This commit is contained in:
ichynul 2020-01-27 18:13:04 +08:00
commit 778f837fa4
16 changed files with 407 additions and 0 deletions

1
README.md Executable file
View File

@ -0,0 +1 @@
tpextbuilder

27
composer.json Executable file
View File

@ -0,0 +1,27 @@
{
"name": "ichynul/tpextbuilder",
"description": "thinkphp extension",
"type": "project",
"keywords": [
"thinkphp"
],
"homepage": "http://www.ynyysc.com/",
"license": "Apache-2.0",
"authors": [
{
"name": "ichynul",
"email": "ichynul@outlook.com"
}
],
"require": {
"topthink/framework": "5.1.*"
},
"autoload": {
"psr-4": {
"tpext\\builder": "src/"
},
"files": [
"src/helper.php"
]
}
}

1
src/common.php Executable file
View File

@ -0,0 +1 @@
<?php

57
src/common/Builder.php Normal file
View File

@ -0,0 +1,57 @@
<?php
namespace tpext\builder\common;
use tpext\myadmin\common\Plugin;
class Builder implements Renderable
{
private $view = '';
protected $title = null;
protected $desc = null;
protected $rows = [];
protected $__row__ = null;
public function __construct($title = '', $desc = '')
{
$this->title = $title;
$this->desc = $desc;
$this->view = Plugin::getInstance()->getRoot() . implode(DIRECTORY_SEPARATOR, ['src', 'view', 'content.html']);
}
public function row()
{
$row = new Row();
$this->rows[] = $row;
$this->__row__ = $row;
return $row;
}
public function column($size = 12)
{
if (!$this->__row__) {
$this->row();
}
return $this->__row__->column($size);
}
public function form($size = 12)
{
return $this->column($size)->form();
}
public function table($size = 12)
{
return $this->column($size)->table();
}
public function render()
{
return Response::create($template, 'view')->assign($vars)->config($config);
}
}

30
src/common/Column.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace tpext\builder\common;
class Column implements Renderable
{
protected $size = 12;
protected $elms = [];
public function __construct($size = 12)
{
$this->size = $size;
}
public function form()
{
return 0;
}
public function table()
{
return 0;
}
public function render()
{
}
}

34
src/common/Form.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace tpext\builder\common;
class Row implements Renderable
{
protected $cols = [];
protected $__col__ = null;
public function column($size = 12)
{
$col = new Column($size);
$this->cols[] = $col;
$this->__col__ = $col;
return $col;
}
public function form($size = 12)
{
return $this->column($size)->form();
}
public function table($size = 12)
{
return $this->column($size)->table();
}
public function render()
{
}
}

17
src/common/Plugin.php Executable file
View File

@ -0,0 +1,17 @@
<?php
namespace tpext\builder\common;
use tpext\common\Plugin as basePlugin;
class Plugin extends basePlugin
{
protected $name = 'tpext.builder.plugin';
protected $__root__ = __DIR__ . '/../../';
public function pluginInit($info = [])
{
return parent::pluginInit($info);
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace tpext\builder\common;
interface Renderable
{
public function reader();
}

34
src/common/Row.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace tpext\builder\common;
class Row implements Renderable
{
protected $cols = [];
protected $__col__ = null;
public function column($size = 12)
{
$col = new Column($size);
$this->cols[] = $col;
$this->__col__ = $col;
return $col;
}
public function form($size = 12)
{
return $this->column($size)->form();
}
public function table($size = 12)
{
return $this->column($size)->table();
}
public function render()
{
}
}

45
src/common/Table.php Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace tpext\builder\common;
use tpext\builder\table\Column;
class Row implements Renderable
{
protected $headers = [];
protected $cols = [];
protected $data = [];
public function column($name, $label = '')
{
if (empty($label)) {
$label = ucfirst($name);
}
$col = new Column($name, $label);
$this->cols[] = $col;
$this->headers[] = $label;
return $col;
}
public function getHeaders()
{
return $this->headers;
}
public function setData($data)
{
$this->data = $data;
}
public function getData()
{
return $this->data;
}
public function render()
{
}
}

45
src/displayers/Field.php Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace tpext\builder\displayer;
use tpext\builder\common\Renderable;
class Field implements Renderable
{
protected $view = '';
protected $value = '';
protected $icon = '';
protected $rules = '';
protected $options = [];
protected $editable = true;
public function __construct($options = [])
{
$this->options = $options;
}
public function options($options)
{
$this->options = $options;
}
public function value($val)
{
$this->value = $val;
}
public function setEditable($editable = true)
{
$this->editable = $editable;
}
public function render()
{
return $this->value;
}
}

8
src/displayers/Html.php Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace tpext\builder\displayer;
class Text extends Field
{
protected $view = 'html';
}

8
src/displayers/Text.php Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace tpext\builder\displayer;
class Text extends Field
{
protected $view = 'text';
}

18
src/helper.php Normal file
View File

@ -0,0 +1,18 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
use tpext\common\ExtLoader;
$classMap = [
//'tpext\\lyatadmin\\common\\Module',
//'tpext\\lyatadmin\common\\Plugin',
];
ExtLoader::watch('app_init',tpext\behavior\AppInit::class);

43
src/table/Column.php Normal file
View File

@ -0,0 +1,43 @@
<?php
namespace tpext\builder\table;
use tpext\builder\common\Renderable;
use tpext\builder\displayer\Text;
use tpext\builder\displayer\Field;
class Column implements Renderable
{
protected $attributes = [];
protected $name;
protected $label;
protected $displayer;
protected $options = [];
public function __construct($name, $label)
{
$this->name = $name;
$this->label = $label;
$this->displayer = new Field();
}
public function text($options = [])
{
$this->displayer = new Text();
$this->options = $options;
}
public function options($options)
{
$this->options = array_merge($this->options, $options);
}
public function render()
{
}
}

31
src/view/content.html Executable file
View File

@ -0,0 +1,31 @@
{extend name="$admin_layout"/}
{block name="style"}
{/block}
{block name="content"}
{notempty name="rows"}
<div class="content">
{volist name="rows" id="row"}
<div class="row">
{notempty name="row.cols"}
{volist name="row.cols" id="col"}
<div class="col-md-{$col.size}}">
{notempty name="col.elms"}
{/notempty}
</div>
{/volist}
{/notempty}
</div>
{/volist}
</div>
{/notempty}
{/block}
{block name="script"}
{/block}
</body>
</html>