From f09b9d3e823661f251e4eddf32097ccf8ed775ed Mon Sep 17 00:00:00 2001 From: funadmin <994927909@qq.com> Date: Sun, 3 Sep 2023 20:01:24 +0800 Subject: [PATCH] builder --- src/builder/FormBuilder.php | 12 + src/builder/TableBuilder.php | 373 +++++++++++++++++-------------- src/builder/layout/add.html | 4 + src/builder/layout/builder.js | 123 +++++----- src/builder/layout/edit.html | 4 + src/builder/layout/table.html | 23 +- src/curd/service/CurdService.php | 3 +- src/helper/FormHelper.php | 12 +- src/helper/ZipHelper.php | 4 +- 9 files changed, 319 insertions(+), 239 deletions(-) diff --git a/src/builder/FormBuilder.php b/src/builder/FormBuilder.php index a8ddf9c..830fbf7 100644 --- a/src/builder/FormBuilder.php +++ b/src/builder/FormBuilder.php @@ -550,6 +550,18 @@ public function script(string $name,$options=[]){ } return $this; } + + /** + * js 内js + * @param $js + * @return $this + */ + public function extrajs($js,$options=[]){ + $reg = '/([\s\S]*?)<\/script>/im'; + preg_match($reg, $script,$match); + $this->extraJs = empty($match)?$script:$match[1]; + return $this; + } public function style(string $name,$options=[]){ if($options['merge']){ $this->formHtml[] = Form::style($name,$options); diff --git a/src/builder/TableBuilder.php b/src/builder/TableBuilder.php index d6527b8..ce160ee 100644 --- a/src/builder/TableBuilder.php +++ b/src/builder/TableBuilder.php @@ -26,15 +26,16 @@ class TableBuilder protected $driver = 'mysql'; protected $database = 'funadmin'; protected $tablePrefix = 'fun_'; - protected $fields = []; - protected $node = []; - protected $methods = []; - protected $script = ''; - protected $js = ''; - protected $style = ''; - protected $link = ''; - protected $html = ''; - protected $requests = [ + public $fields = []; + public $node = []; + public $methods = []; + public $script = ''; + public $extraJs = ''; + public $js = ''; + public $style = ''; + public $link = ''; + public $html = ''; + public $requests = [ 'index_url' => 'index', 'add_url' => 'add', 'edit_url' => 'edit', @@ -47,50 +48,49 @@ class TableBuilder 'import_url' => 'import', 'recycle_url' => 'recycle', ]; - protected $options = [ - 'index' => [ - 'elem' => 'list', - 'id' => 'list', - 'init' => '', - 'url' => 'index', - 'defaultToolbar' => ['filter', 'print', 'exports'], - 'primaryKey' => 'id', - 'page' => true, - 'limits'=>[15, 30, 50, 100, 200, 500, 1000, 5000, 10000], - 'limit'=> 15, - 'searchInput' => true, - 'searchShow' => false, - 'searchTpl' => '', - 'lineStyle' => '', - 'rowDouble' => true, - 'cols' => [ - [] - ], - 'toolbar' => ['refresh', 'add', 'destroy', 'import', 'export', 'recycle'], - 'operat' => ['restore', 'delete'], + public $index = [ + 'elem' => 'list', + 'id' => 'list', + 'init' => '', + 'url' => 'index', + 'defaultToolbar' => ['filter', 'print', 'exports'], + 'primaryKey' => 'id', + 'page' => true, + 'limits'=>[15, 30, 50, 100, 200, 500, 1000, 5000, 10000], + 'limit'=> 15, + 'searchInput' => true, + 'searchShow' => false, + 'searchTpl' => '', + 'lineStyle' => '', + 'rowDouble' => true, + 'cols' => [ + [] ], - 'recycle' => [ - 'elem' => 'list', - 'id' => 'list', - 'url' => 'recycle', - 'defaultToolbar' => ['filter', 'print', 'exports'], - 'toolbar' => ['refresh', 'delete', 'restore'], - 'primaryKey' => 'id', - 'page' => true, - 'limits'=>[15, 30, 50, 100, 200, 500, 1000, 5000, 10000], - 'limit'=> 15, - 'searchInput' => true, - 'searchShow' => false, - 'searchTpl' => '', - 'lineStyle' => '', - 'rowDouble' => true, - 'cols' => [ - [] - ], - 'operat' => ['restore', 'delete'], - + 'toolbar' => ['refresh', 'add', 'destroy', 'import', 'export', 'recycle'], + 'operat' => ['edit', 'delete'], + ]; + public $recycle = [ + 'elem' => 'list', + 'id' => 'list', + 'url' => 'recycle', + 'defaultToolbar' => ['filter', 'print', 'exports'], + 'toolbar' => ['refresh', 'delete', 'restore'], + 'primaryKey' => 'id', + 'page' => true, + 'limits'=>[15, 30, 50, 100, 200, 500, 1000, 5000, 10000], + 'limit'=> 15, + 'searchInput' => true, + 'searchShow' => false, + 'searchTpl' => '', + 'lineStyle' => '', + 'rowDouble' => true, + 'cols' => [ + [] ], + 'operat' => ['restore', 'delete'], + ]; + public $options = []; /** * @var */ @@ -119,19 +119,33 @@ private function __clone() /** * 私有化构造函数 */ - private function __construct(array $options = []) + private function __construct(array $config = []) { - $this->fields = $options['fields'] ?? []; + $this->fields = $config['fields'] ?? []; // 初始化 - $this->template = $options['template'] ?? '../../../vendor/funadmin/fun-addons/src/builder/layout/table'; - $this->options['index']['url'] = __u('index'); - $this->options['recycle']['url'] = __u('recycle'); - $this->modelClass = $options['model'] ?? ($options['modelClass'] ?? ''); - $this->driver = $options['driver'] ?? 'mysql'; + $this->template = $config['template'] ?? '../../../vendor/funadmin/fun-addons/src/builder/layout/table'; + $this->modelClass = $config['model'] ?? ($config['modelClass'] ?? ''); + $this->driver = $config['driver'] ?? 'mysql'; $this->tablePrefix = config('database.connections.' . $this->driver . '.prefix'); $this->database = Config::get('database.connections' . '.' . $this->driver . '.database'); + foreach ($this->requests as &$request) { + $request = __u($request); + } + unset($request); + } + // 表格options + public function options(array $data=[], string $tableId = 'list'){ + if(request()->action()=='index' && empty($data)) { + $this->index['url'] = __u(request()->action()); + $this->options[$tableId] = $this->index; + }elseif(request()->action()=='recycle' && empty($data)){ + $this->index['url'] = __u(request()->action()); + $this->options[$tableId] = $this->recycle; + }else{ + $this->options[$tableId] = $data; + } + return $this; } - public function node(array $node = []) { foreach ($node as $item) { @@ -140,39 +154,39 @@ public function node(array $node = []) return $this; } - public function url(string|array|object $url, $action = 'index') + public function url(string|array|object $url, string $tableId = 'list') { - $this->options[$action]['url'] = $url; + $this->options[$tableId]['url'] = $url; return $this; } - public function data(array $data=[], string $action = 'index') + public function data(array $data=[], string $tableId = 'list') { - $this->options[$action]['data'] = $data; + $this->options[$tableId]['data'] = $data; return $this; } - public function searchShow(bool $show = false, string $action = 'index') + public function searchShow(bool $show = false, string $tableId = 'list') { - $this->options[$action]['searchShow'] = $show; + $this->options[$tableId]['searchShow'] = $show; return $this; } - public function searchTpl(string $tpl = '', string $action = 'index') + public function searchTpl(string $tpl = '', string $tableId = 'list') { - $this->options[$action]['searchTpl'] = $tpl; + $this->options[$tableId]['searchTpl'] = $tpl; return $this; } - public function rowDouble(bool $rowDouble = true, string $action = 'index') + public function rowDouble(bool $rowDouble = true, string $tableId = 'list') { - $this->options[$action]['rowDouble'] = $rowDouble; + $this->options[$tableId]['rowDouble'] = $rowDouble; return $this; } - public function searchInput($show = true, string $action = 'index') + public function searchInput($show = true, string $tableId = 'list') { - $this->options[$action]['searchInput'] = $show; + $this->options[$tableId]['searchInput'] = $show; return $this; } @@ -180,9 +194,12 @@ public function searchInput($show = true, string $action = 'index') * @param $column * @return $this */ - public function col(array $column = [], string $action = 'index') + public function col(array $column = [], string $tableId = 'list') { - array_push($this->options[$action]['cols'][0], $column); + if(!$this->options[$tableId]){ + $this->options(); + } + array_push($this->options[$tableId]['cols'][0], $column); return $this; } @@ -190,226 +207,229 @@ public function col(array $column = [], string $action = 'index') * @param $columns * @return $this */ - public function cols($columns = [], string $action = 'index') + public function cols($columns = [], string $tableId = 'list') { + if(!$this->options[$tableId]){ + $this->options(); + } if (!empty($columns)) { foreach ($columns as $column) { - call_user_func_array([$this, 'col'], [$column, $action]); + call_user_func_array([$this, 'col'], [$column, $tableId]); } } return $this; } - public function width(string $width, string $action = 'index') + public function width(string $width, string $tableId = 'list') { - $this->options[$action]['width'] = $width; + $this->options[$tableId]['width'] = $width; return $this; } - public function height(string $height, string $action = 'index') + public function height(string $height, string $tableId = 'list') { - $this->options[$action]['height'] = $height; + $this->options[$tableId]['height'] = $height; return $this; } - public function cellMinWidth(string $cellMinWidth, string $action = 'index') + public function cellMinWidth(string $cellMinWidth, string $tableId = 'list') { - $this->options[$action]['cellMinWidth'] = $cellMinWidth; + $this->options[$tableId]['cellMinWidth'] = $cellMinWidth; return $this; } - public function lineStyle(string $lineStyle, string $action = 'index') + public function lineStyle(string $lineStyle, string $tableId = 'list') { - $this->options[$action]['lineStyle'] = $lineStyle; + $this->options[$tableId]['lineStyle'] = $lineStyle; return $this; } - public function className(string $className, string $action = 'index') + public function className(string $className, string $tableId = 'list') { - $this->options[$action]['className'] = $className; + $this->options[$tableId]['className'] = $className; return $this; } - public function css(string $css, string $action = 'index') + public function css(string $css, string $tableId = 'list') { - $this->options[$action]['css'] = $css; + $this->options[$tableId]['css'] = $css; return $this; } - public function escape(bool $escape, string $action = 'index') + public function escape(bool $escape, string $tableId = 'list') { - $this->options[$action]['escape'] = $escape; + $this->options[$tableId]['escape'] = $escape; return $this; } - public function totalRow(string $totalRow, string $action = 'index') + public function totalRow(string $totalRow, string $tableId = 'list') { - $this->options[$action]['totalRow'] = $totalRow; + $this->options[$tableId]['totalRow'] = $totalRow; return $this; } - public function page(bool $page = true, string $action = 'index') + public function page(bool $page = true, string $tableId = 'list') { - $this->options[$action]['page'] = $page; + $this->options[$tableId]['page'] = $page; return $this; } - public function pagebar(string $pagebar, string $action = 'index') + public function pagebar(string $pagebar, string $tableId = 'list') { - $this->options[$action]['pagebar'] = $pagebar; + $this->options[$tableId]['pagebar'] = $pagebar; return $this; } - public function limit(int $limit, string $action = 'index') + public function limit(int $limit, string $tableId = 'list') { - $this->options[$action]['limit'] = $limit; + $this->options[$tableId]['limit'] = $limit; return $this; } - public function limits(array $limits = [], string $action = 'index') + public function limits(array $limits = [], string $tableId = 'list') { - $this->options[$action]['limits'] = $limits; + $this->options[$tableId]['limits'] = $limits; return $this; } - public function loading(bool $loading, string $action = 'index') + public function loading(bool $loading, string $tableId = 'list') { - $this->options[$action]['loading'] = $loading; + $this->options[$tableId]['loading'] = $loading; return $this; } - public function scrollPos(string $scrollPos, string $action = 'index') + public function scrollPos(string $scrollPos, string $tableId = 'list') { //fixed 重载数据时,保持滚动条位置不变reset 重载数据时,滚动条位置恢复置顶default 默认方式,无需设置。即重载数据或切换分页 - $this->options[$action]['scrollPos'] = $scrollPos; + $this->options[$tableId]['scrollPos'] = $scrollPos; return $this; } /** * dblclick|click * @param string $editTrigger - * @param string $action + * @param string $tableId * @return $this */ - public function editTrigger(string $editTrigger, string $action = 'index') + public function editTrigger(string $editTrigger, string $tableId = 'list') { - $this->options[$action]['editTrigger'] = $editTrigger; + $this->options[$tableId]['editTrigger'] = $editTrigger; return $this; } - public function title(string $title, string $action = 'index') + public function title(string $title, string $tableId = 'list') { - $this->options[$action]['title'] = $title; + $this->options[$tableId]['title'] = $title; return $this; } - public function text(array $text, string $action = 'index') + public function text(array $text, string $tableId = 'list') { - $this->options[$action]['text'] = $text; + $this->options[$tableId]['text'] = $text; return $this; } - public function autoSort(bool $autoSort, string $action = 'index') + public function autoSort(bool $autoSort, string $tableId = 'list') { - $this->options[$action]['autoSort'] = $autoSort; + $this->options[$tableId]['autoSort'] = $autoSort; return $this; } - public function initSort(array $initSort, string $action = 'index') + public function initSort(array $initSort, string $tableId = 'list') { - $this->options[$action]['initSort'] = $initSort; + $this->options[$tableId]['initSort'] = $initSort; return $this; } - public function skin(string $skin, string $action = 'index') + public function skin(string $skin, string $tableId = 'list') { - $this->options[$action]['skin'] = $skin;//grid|line|row|nob + $this->options[$tableId]['skin'] = $skin;//grid|line|row|nob return $this; } - public function size(string $size, string $action = 'index') + public function size(string $size, string $tableId = 'list') { - $this->options[$action]['size'] = $size;//sm|md|lg + $this->options[$tableId]['size'] = $size;//sm|md|lg return $this; } - public function even(string $even, string $action = 'index') + public function even(string $even, string $tableId = 'list') { - $this->options[$action]['even'] = $even; + $this->options[$tableId]['even'] = $even; return $this; } - public function before(string $before, string $action = 'index') + public function before(string $before, string $tableId = 'list') { - $this->options[$action]['before'] = $before; + $this->options[$tableId]['before'] = $before; return $this; } - public function done(mixed $done, string $action = 'index') + public function done(mixed $done, string $tableId = 'list') { - $this->options[$action]['done'] = $done; + $this->options[$tableId]['done'] = $done; return $this; } - public function error(mixed $error, string $action = 'index') + public function error(mixed $error, string $tableId = 'list') { - $this->options[$action]['error'] = $error; + $this->options[$tableId]['error'] = $error; return $this; } - public function method(string $method = 'GET', string $action = 'index') + public function method(string $method = 'GET', string $tableId = 'list') { - $this->options[$action]['method'] = $method; + $this->options[$tableId]['method'] = $method; return $this; } - public function where(mixed $where, string $action = 'index') + public function where(mixed $where, string $tableId = 'list') { - $this->options[$action]['where'] = $where; + $this->options[$tableId]['where'] = $where; return $this; } - public function headers(mixed $headers, string $action = 'index') + public function headers(mixed $headers, string $tableId = 'list') { - $this->options[$action]['headers'] = $headers; + $this->options[$tableId]['headers'] = $headers; return $this; } - public function contentType(mixed $contentType, string $action = 'index') + public function contentType(mixed $contentType, string $tableId = 'list') { - $this->options[$action]['contentType'] = $contentType; + $this->options[$tableId]['contentType'] = $contentType; return $this; } - public function dataType(mixed $dataType, string $action = 'index') + public function dataType(mixed $dataType, string $tableId = 'list') { - $this->options[$action]['dataType'] = $dataType; + $this->options[$tableId]['dataType'] = $dataType; return $this; } - public function request(mixed $request, string $action = 'index') + public function request(mixed $request, string $tableId = 'list') { - $this->options[$action]['request'] = $request; + $this->options[$tableId]['request'] = $request; return $this; } - public function parseData(mixed $parseData, string $action = 'index') + public function parseData(mixed $parseData, string $tableId = 'list') { - $this->options[$action]['parseData'] = $parseData; + $this->options[$tableId]['parseData'] = $parseData; return $this; } - public function cellMaxWidth(string $cellMaxWidth, string $action = 'index') + public function cellMaxWidth(string $cellMaxWidth, string $tableId = 'list') { - $this->options[$action]['cellMaxWidth'] = $cellMaxWidth; + $this->options[$tableId]['cellMaxWidth'] = $cellMaxWidth; } - public function maxHeight(string $maxHeight, string $action = 'index') + public function maxHeight(string $maxHeight, string $tableId = 'list') { - $this->options[$action]['maxHeight '] = $maxHeight; + $this->options[$tableId]['maxHeight '] = $maxHeight; } @@ -418,16 +438,16 @@ public function maxHeight(string $maxHeight, string $action = 'index') * @param string $key 主键名称 * @return $this */ - public function primaryKey($key = 'id', string $action = 'index') + public function primaryKey($key = 'id', string $tableId = 'list') { - $this->options[$action]['primaryKey'] = $key; + $this->options[$tableId]['primaryKey'] = $key; return $this; } - public function pageSize($pageSize = [], string $action = 'index') + public function pageSize($pageSize = [], string $tableId = 'list') { - $this->options[$action]['pageSize'] = !empty($pageSize) ? $pageSize : []; + $this->options[$tableId]['pageSize'] = !empty($pageSize) ? $pageSize : []; return $this; } @@ -436,58 +456,65 @@ public function pageSize($pageSize = [], string $action = 'index') * @param $data * @return $this */ - public function extra($data = [], string $action = 'index') + public function extra($data = [], string $tableId = 'list') { - $this->options[$action] = array_merge($this->options[$action], $data); + $this->options[$tableId] = array_merge($this->options[$tableId], $data); return $this; } - public function tree($data = [], string $action = 'index') + public function tree($data = [], string $tableId = 'list') { if (!empty($data)) { - $this->options[$action]['tree'] = $data; + $this->options[$tableId]['tree'] = $data; } return $this; } - public function style($style = '', string $action = 'index') + public function style($style = '', string $tableId = 'list') { $this->style = $style; return $this; } - public function link(string|array $link = '', string $action = 'index') + public function link(string|array $link = '', string $tableId = 'list') { $this->link = Form::link($link,[]); return $this; } - public function js(string|array$js = '', string $action = 'index') + public function js(string|array$js = '', string $tableId = 'list') { $this->js = Form::js($js,[]); return $this; } - public function script(string$script = '', string $action = 'index') + public function script(string$script = '', string $tableId = 'list') { $this->script = $script; return $this; } + public function extraJs(string$script = '', string $tableId = 'list') + { + $reg = '/([\s\S]*?)<\/script>/im'; + preg_match($reg, $script,$match); + $this->extraJs = empty($match)?$script:$match[1]; + return $this; + } /** * 设置额外HTML代码 * @param string $html 额外HTML代码 * @return $this */ - public function html($html = '', string $action = 'index') + public function html($html = '', string $tableId = 'list') { $this->html = $html; return $this; } - public function index(array $options = [], string $action = 'index') + public function index(array $options = [], string $tableId = 'list') { - $this->options[$action] = array_merge($this->options[$action], $options); + $this->options[$tableId] = array_merge($this->options[$tableId], $options); return $this; } - public function recycle(array $options = [], string $action = 'recycle') + public function recycle(array $options = [], string $tableId = 'recycle') { if ($options == false) { foreach ($this->options as $key => $value) { @@ -497,7 +524,7 @@ public function recycle(array $options = [], string $action = 'recycle') unset($this->options['recycle']); } } - $this->options[$action] = array_merge($this->options[$action], $options); + $this->options[$tableId] = array_merge($this->options[$tableId], $options); return $this; } @@ -505,9 +532,9 @@ public function recycle(array $options = [], string $action = 'recycle') * @param array $request * @return $this */ - public function requests(array $request = [], string $action = 'index') + public function requests(array $request = [], string $tableId = 'list') { - $this->options[$action]['requests'] = $request; + $this->options[$tableId]['requests'] = $request; $this->requests = array_merge($this->requests, $request); return $this; } @@ -518,35 +545,35 @@ public function requests(array $request = [], string $action = 'index') * @param array $extra 扩展参数(待用) * @return $this */ - public function operat(array $operat = [], $action = 'index') + public function operat(array $operat = [], string $tableId = 'list') { - array_push($this->options[$action]['cols'][0], $operat); + array_push($this->options[$tableId]['cols'][0], $operat); return $this; } - public function elem(string $elem,$action='index') + public function elem(string $elem,string $tableId = 'list') { - $this->options[$action]['elem'] = $elem; + $this->options[$tableId]['elem'] = $elem; return $this; } - public function id(string $id, string $action = 'index') + public function id(string $id, string $tableId = 'list') { - $this->options[$action]['id'] = $id; + $this->options[$tableId]['id'] = $id; return $this; } - public function defaultToolbar(array $default = ['filter', 'print', 'exports'], string $action = 'index') + public function defaultToolbar(array $default = ['filter', 'print', 'exports'], string $tableId = 'list') { - $this->options[$action]['defaultToolbar'] = $default; + $this->options[$tableId]['defaultToolbar'] = $default; return $this; } - public function toolbar($buttons = [], string $action = 'index') + public function toolbar($buttons = [], string $tableId = 'list') { - $this->options[$action]['toolbar'] = $buttons; + $this->options[$tableId]['toolbar'] = $buttons; return $this; } @@ -562,7 +589,7 @@ public function assign(array $data = []) 'requests' => $this->requests, 'html' => $this->html, 'tableScript' => $this->script, - 'tableJs' => $this->js, + 'extraJs' => $this->extraJs, 'tableStyle' => $this->style, 'tableLink' => $this->link, 'data' => $data, diff --git a/src/builder/layout/add.html b/src/builder/layout/add.html index 8d23b73..1bb1946 100644 --- a/src/builder/layout/add.html +++ b/src/builder/layout/add.html @@ -9,4 +9,8 @@ diff --git a/src/builder/layout/builder.js b/src/builder/layout/builder.js index d07e3b3..a1ccfac 100644 --- a/src/builder/layout/builder.js +++ b/src/builder/layout/builder.js @@ -16,74 +16,89 @@ define(['table', 'form'], function (Table, Form) { }; switch (ACTION) { case 'index': - if (typeof options !== "undefined" && options[ACTION]) { - Controller[ACTION] = function () { - Table.init = { - table_elem: options[ACTION]['elem'], - tableId: options[ACTION]['id'], - requests: requests, - }; - options[ACTION]['elem'] = '#' + options[ACTION]['elem'] - options[ACTION]['init'] = Table.init; - op = options[ACTION]; - console.log(op) - var table = Table.render(options[ACTION]); - Table.api.bindEvent(Table.init.tableId); - }; + Controller[ACTION] = function () { + if (typeof tableOptions === "object") { + layui.each(tableOptions, function (i, v) { + Table.init[i] = init = { + table_elem: tableOptions[i]['elem'], + tableId: tableOptions[i]['id'], + requests: requests, + }; + tableOptions[i]['elem'] = '#' + tableOptions[i]['elem'] + tableOptions[i]['init'] = init; + Table.render(tableOptions[i]); + Table.api.bindEvent(tableOptions[i]['id']); + }) + } + if (typeof extraJs !=="undefined") { + eval(extraJs); + } } break; case 'add': case 'edit': case 'copy': - if (typeof options !== "undefined" && options[ACTION]) { - Controller[ACTION] = function () { - Table.init = { - table_elem: options[ACTION]['elem'], - tableId: options[ACTION]['id'], - requests: requests, - }; - options[ACTION]['elem'] = '#' + options[ACTION]['elem']; - options[ACTION]['init'] = Table.init; - var table = Table.render(options[ACTION]); - Table.api.bindEvent(options[ACTION]['id']); - }; - } Controller[ACTION] = function () { + if (typeof tableOptions === "object") { + layui.each(tableOptions, function (i, v) { + Table.init[i] = { + table_elem: tableOptions[i]['elem'], + tableId: tableOptions[i]['id'], + requests: requests, + }; + tableOptions[i]['elem'] = '#' + tableOptions[i]['elem'] + tableOptions[i]['init'] = Table.init; + Table.render(tableOptions[i]); + Table.api.bindEvent(tableOptions[i]['id']); + }) + } + if (typeof extraJs !=="undefined") { + eval(extraJs); + } Controller.api.bindevent() - }; + } break; case 'recycle': - if (typeof options !== "undefined" && options[ACTION]) { - Controller[ACTION] = function () { - Table.init = { - table_elem: options[ACTION]['elem'], - tableId: options[ACTION]['id'], - requests: requests, - }; - options[ACTION]['elem'] = '#' + options[ACTION]['elem']; - options[ACTION]['init'] = Table.init; - var table = Table.render(options[ACTION]); - Table.api.bindEvent(Table.init.tableId); - }; + Controller[ACTION] = function () { + if (typeof tableOptions === "object") { + layui.each(tableOptions, function (i, v) { + Table.init[i] = { + table_elem: tableOptions[i]['elem'], + tableId: tableOptions[i]['id'], + requests: requests, + }; + tableOptions[i]['elem'] = '#' + tableOptions[i]['elem'] + tableOptions[i]['init'] = Table.init; + Table.render(tableOptions[i]); + Table.api.bindEvent(tableOptions[i]['id']); + }) + } + if (typeof extraJs !=="undefined") { + eval(extraJs); + } } + break; default: - if (typeof options !== "undefined" && options[ACTION]) { - Controller[ACTION] = function () { - Table.init = { - table_elem: options[ACTION]['elem'], - tableId: options[ACTION]['id'], - requests: requests, - }; - options[ACTION]['elem'] = '#' + options[ACTION]['elem']; - options[ACTION]['init'] = Table.init; - var table = Table.render(options[ACTION]); - Table.api.bindEvent(options[ACTION]['id']); - }; - } Controller[ACTION] = function () { + if (typeof tableOptions === "object") { + layui.each(tableOptions, function (i, v) { + Table.init[i] = { + table_elem: tableOptions[i]['elem'], + tableId: tableOptions[i]['id'], + requests: requests, + }; + tableOptions[i]['elem'] = '#' + tableOptions[i]['elem'] + tableOptions[i]['init'] = Table.init; + Table.render(tableOptions[i]); + Table.api.bindEvent(tableOptions[i]['id']); + }) + } + if (typeof extraJs !=="undefined") { + eval(extraJs); + } Controller.api.bindevent() - }; + } break; } return Controller; diff --git a/src/builder/layout/edit.html b/src/builder/layout/edit.html index 8d23b73..7fd873d 100644 --- a/src/builder/layout/edit.html +++ b/src/builder/layout/edit.html @@ -9,4 +9,8 @@ diff --git a/src/builder/layout/table.html b/src/builder/layout/table.html index cb0d5ea..5484988 100644 --- a/src/builder/layout/table.html +++ b/src/builder/layout/table.html @@ -2,8 +2,9 @@ {if $tableStyle}{$tableStyle|raw}}{/if} {if $tableJs}{$tableJs}{/if} {$html|raw} - - +{/volist} +{else /} +
+{/if} diff --git a/src/curd/service/CurdService.php b/src/curd/service/CurdService.php index cad84fa..c034509 100644 --- a/src/curd/service/CurdService.php +++ b/src/curd/service/CurdService.php @@ -1036,6 +1036,7 @@ protected function getFieldList($model='',$field = '*') $v['comment'] = str_replace(':', ':', $v['comment']); $v['name'] = $v['COLUMN_NAME']; $v['value'] = $v['COLUMN_DEFAULT']; + $v['DATA_TYPE'] = strtolower($v['DATA_TYPE']); if($v['COLUMN_KEY'] == 'PRI'){ $this->primaryKey = $v['name']; } @@ -1086,7 +1087,7 @@ protected function getFieldList($model='',$field = '*') } // 指定后缀结尾且类型为varchar || char,文件上传 if ($this->hasSuffix($fieldsName, $this->config['imageSuffix']) && - (($v['DATA_TYPE'] == 'varchar') || $v['DATA_TYPE'] == 'char')) { + (in_array($v['DATA_TYPE'],['varchar','char','text','smalltext','tinytext','mediumtext','longtext','json']))) { $comment = explode('=', $v['comment']); $v['comment'] = $comment[0]; $v['type'] = "image"; diff --git a/src/helper/FormHelper.php b/src/helper/FormHelper.php index d73e163..2f05c48 100644 --- a/src/helper/FormHelper.php +++ b/src/helper/FormHelper.php @@ -523,7 +523,7 @@ public function checkbox($name = '', $list = [], $options = [], $value = '') $value_tmp = $k; $name_tmp = $name[$v[0]]; $input .= <<getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v[1])}"/>'; +getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v[1])}"/> EOF; } else { $check = ''; @@ -535,7 +535,7 @@ public function checkbox($name = '', $list = [], $options = [], $value = '') $value_tmp = $k; $name_tmp =$name[$k]; $input .= <<getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v)}"/>'; +getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" {$check} title="{$this->__($v)}"/> EOF; } } @@ -543,7 +543,7 @@ public function checkbox($name = '', $list = [], $options = [], $value = '') $value_tmp = $value; $name_tmp ="{$name}[]"; $input .= <<getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" title="{$this->__($value)}"/>'; +getDataPropAttr($name_tmp,$value_tmp,$options)} class="{$this->getClass($options)}" type="checkbox" title="{$this->__($value)}"/> EOF; } $str = << {$this->label($name, $options)}
- getDataPropAttr($name,$value,$options)} class="layui-input {$this->getClass($options)}" type="text" /> + getDataPropAttr($name,$value,$options)} class="layui-input {$this->getClass($options)} {$this->readonlyOrdisabled($options)}" type="text" />
EOF; @@ -1421,7 +1421,7 @@ protected function filter($options = []) { $filter = ''; if (isset($options['filter'])) { - $filter = 'lay-filter="' . $options['filter'] . '"'; + $filter = ' lay-filter="' . $options['filter'] . '"'; } return $filter; } @@ -1433,7 +1433,7 @@ protected function search($options = []) { $search = ''; if (!isset($options['search']) || $options['search'] == true) { - $search = 'lay-search'; + $search = ' lay-search'; } return $search; } diff --git a/src/helper/ZipHelper.php b/src/helper/ZipHelper.php index e058f22..2d2933f 100644 --- a/src/helper/ZipHelper.php +++ b/src/helper/ZipHelper.php @@ -56,7 +56,7 @@ public static function unzip( $zipFile,$folderPath,$addon=0) { // Initialize archive object if (!class_exists('ZipArchive')) { - throw new \Exception('ZinArchive not find'); + throw new \Exception('ZipArchive not find'); } $zip = new \ZipArchive(); try { @@ -80,4 +80,4 @@ public static function unzip( $zipFile,$folderPath,$addon=0) return $fileDir; } -} \ No newline at end of file +}