This commit is contained in:
walkor 2022-12-08 11:29:55 +08:00
parent 3a28bd3837
commit b2b669856b
7 changed files with 32 additions and 25 deletions

View File

@ -1,6 +1,8 @@
<?php <?php
namespace plugin\admin\app\common; namespace plugin\admin\app\common;
use support\exception\BusinessException;
class LayuiForm class LayuiForm
{ {
@ -21,7 +23,7 @@ class LayuiForm
* @param $indent * @param $indent
* @return string * @return string
*/ */
public function html($indent = 0) public function html($indent = 0): string
{ {
return str_replace("\n", "\n" . str_repeat(' ', $indent), $this->htmlContent); return str_replace("\n", "\n" . str_repeat(' ', $indent), $this->htmlContent);
} }
@ -31,7 +33,7 @@ class LayuiForm
* @param $indent * @param $indent
* @return string * @return string
*/ */
public function js($indent = 0) public function js($indent = 0): string
{ {
return str_replace("\n", "\n" . str_repeat(' ', $indent), $this->jsContent); return str_replace("\n", "\n" . str_repeat(' ', $indent), $this->jsContent);
} }
@ -41,7 +43,7 @@ class LayuiForm
* @param $options * @param $options
* @return array * @return array
*/ */
protected function options($options) protected function options($options): array
{ {
array_walk_recursive($options, function(&$item, $key){ array_walk_recursive($options, function(&$item, $key){
if (is_string($item)) { if (is_string($item)) {
@ -572,10 +574,11 @@ EOF;
$options['props']['clickClose'] = $options['props']['clickClose'] ?? true; $options['props']['clickClose'] = $options['props']['clickClose'] ?? true;
$options['props']['radio'] = $options['props']['radio'] ?? true; $options['props']['radio'] = $options['props']['radio'] ?? true;
$options['props']['tree'] = array_merge_recursive([ $options['props']['tree'] = array_merge_recursive([
'show' => true, '$show' => true,
'strict' => false, '$strict' => false,
'clickCheck' => true, '$clickCheck' => true,
'clickExpand' => false '$clickExpand' => false,
'$expandedKeys' => '$initValue'
], $options['props']['tree'] ?? []); ], $options['props']['tree'] ?? []);
$this->apiSelect($options); $this->apiSelect($options);
} }
@ -586,10 +589,11 @@ EOF;
*/ */
public function treeSelectMulti($options) public function treeSelectMulti($options)
{ {
$options['props']['tree'] = array_merge_recursive(['show' => true], $options['props']['tree'] ?? []); $options['props']['tree'] = array_merge_recursive(['show' => true,
'$expandedKeys' => '$initValue'], $options['props']['tree'] ?? []);
$options['props']['toolbar'] = array_merge_recursive([ $options['props']['toolbar'] = array_merge_recursive([
'show' => true, '$show' => true,
'list' => [ 'ALL', 'CLEAR', 'REVERSE' ] '$list' => [ 'ALL', 'CLEAR', 'REVERSE' ]
], $options['props']['toolbar'] ?? []); ], $options['props']['toolbar'] ?? []);
$this->apiSelect($options); $this->apiSelect($options);
} }
@ -611,6 +615,7 @@ EOF;
foreach ($props as $key => $item) { foreach ($props as $key => $item) {
if (is_array($item)) { if (is_array($item)) {
$item = json_encode($item, JSON_UNESCAPED_UNICODE); $item = json_encode($item, JSON_UNESCAPED_UNICODE);
$item = preg_replace('/"\$([^"]+)"/', '$1', $item);
$options_string .= "\n".($url?' ':' ')."$key: $item,"; $options_string .= "\n".($url?' ':' ')."$key: $item,";
} else if (is_string($item)) { } else if (is_string($item)) {
$options_string .= "\n".($url?' ':' ')."$key: \"$item\","; $options_string .= "\n".($url?' ':' ')."$key: \"$item\",";
@ -675,10 +680,11 @@ EOF;
/** /**
* 构建表单 * 构建表单
* @param $table * @param $table
* @param $type * @param string $type
* @return LayuiForm * @return LayuiForm
* @throws BusinessException
*/ */
static public function buildForm($table, $type = 'insert') static public function buildForm($table, string $type = 'insert'): LayuiForm
{ {
if (!in_array($type, ['insert', 'update', 'search'])) { if (!in_array($type, ['insert', 'update', 'search'])) {
$type = 'insert'; $type = 'insert';
@ -735,10 +741,11 @@ EOF;
/** /**
* 构建表格 * 构建表格
* @param $table * @param $table
* @param $indent * @param int $indent
* @return array|string|string[] * @return array|string|string[]
* @throws BusinessException
*/ */
static public function buildTable($table, $indent = 0) static public function buildTable($table, int $indent = 0)
{ {
$schema = Util::getSchema($table); $schema = Util::getSchema($table);
$forms = $schema['forms']; $forms = $schema['forms'];

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder; use Illuminate\Database\Schema\Builder;
use plugin\admin\app\model\Option; use plugin\admin\app\model\Option;
use support\Db; use support\Db;
use Support\Exception\BusinessException; use support\exception\BusinessException;
use Throwable; use Throwable;
use function config; use function config;

View File

@ -9,8 +9,8 @@ use plugin\admin\app\common\Util;
use plugin\admin\app\model\Role; use plugin\admin\app\model\Role;
use plugin\admin\app\model\Rule; use plugin\admin\app\model\Rule;
use plugin\admin\app\model\Option; use plugin\admin\app\model\Option;
use Support\Exception\BusinessException; use support\exception\BusinessException;
use Support\Request; use support\Request;
use support\Response; use support\Response;
class TableController extends Base class TableController extends Base

View File

@ -20,9 +20,9 @@ use Webman\Http\Response;
/** /**
* Class Handler * Class Handler
* @package Support\Exception * @package support\exception
*/ */
class Handler extends \Support\Exception\Handler class Handler extends \support\exception\Handler
{ {
public function render(Request $request, Throwable $exception): Response public function render(Request $request, Throwable $exception): Response
{ {

View File

@ -160,8 +160,8 @@
name: "roles", name: "roles",
initValue: initValue, initValue: initValue,
data: e.data, data: e.data,
tree: {"show":true}, tree: {show: true, expandedKeys: initValue},
toolbar: {"show":true,"list":["ALL","CLEAR","REVERSE"]}, toolbar: {show: true, list: ["ALL","CLEAR","REVERSE"]},
}) })
} }
}); });

View File

@ -89,8 +89,8 @@
name: "rules", name: "rules",
initValue: initValue, initValue: initValue,
data: e.data, data: e.data,
tree: {"show":true}, tree: {show: true, expandedKeys: initValue},
toolbar: {"show":true,"list":["ALL","CLEAR","REVERSE"]}, toolbar: {show: true, list: ["ALL","CLEAR","REVERSE"]},
}) })
} }
}); });

View File

@ -138,7 +138,7 @@
model: {"icon":"hidden","label":{"type":"text"}}, model: {"icon":"hidden","label":{"type":"text"}},
clickClose: true, clickClose: true,
radio: true, radio: true,
tree: {show: true,"strict":false,"clickCheck":true,"clickExpand":false}, tree: {show: true,"strict":false,"clickCheck":true,"clickExpand":false,expandedKeys: initValue},
}) })
} }
}); });