完成表注释方式关联表;

This commit is contained in:
augushong
2021-11-29 21:14:41 +08:00
parent 10046031e6
commit 9d4828bf6f
2 changed files with 243 additions and 54 deletions

View File

@@ -3,12 +3,11 @@
namespace app\common\tools; namespace app\common\tools;
use EasyAdmin\curd\BuildCurd as CurdBuildCurd; use EasyAdmin\curd\BuildCurd as CurdBuildCurd;
use EasyAdmin\tool\CommonTool;
class BuildCurd extends CurdBuildCurd class BuildCurd extends CurdBuildCurd
{ {
/** /**
* 表单类型 * 表单类型
* @var array * @var array
@@ -69,4 +68,193 @@ class BuildCurd extends CurdBuildCurd
return $colum; return $colum;
} }
/**
* 初始化视图
* @return $this
*/
protected function renderView()
{
// 列表页面
$viewIndexFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}index.html";
$viewIndexValue = CommonTool::replaceTemplate(
$this->getTemplate("view{$this->DS}index"),
[
'controllerUrl' => $this->controllerUrl,
]
);
$this->fileList[$viewIndexFile] = $viewIndexValue;
// 添加页面
$viewAddFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}add.html";
$addFormList = '';
foreach ($this->tableColumns as $field => $val) {
if (in_array($field, ['id', 'create_time'])) {
continue;
}
$templateFile = "view{$this->DS}module{$this->DS}input";
$define = '';
// 根据formType去获取具体模板
if ($val['formType'] == 'image') {
$templateFile = "view{$this->DS}module{$this->DS}image";
} elseif ($val['formType'] == 'images') {
$templateFile = "view{$this->DS}module{$this->DS}images";
$define = isset($val['define']) ? $val['define'] : '|';
} elseif ($val['formType'] == 'file') {
$templateFile = "view{$this->DS}module{$this->DS}file";
} elseif ($val['formType'] == 'files') {
$templateFile = "view{$this->DS}module{$this->DS}files";
$define = isset($val['define']) ? $val['define'] : '|';
} elseif ($val['formType'] == 'editor') {
$templateFile = "view{$this->DS}module{$this->DS}editor";
} elseif ($val['formType'] == 'date') {
$templateFile = "view{$this->DS}module{$this->DS}date";
if (isset($val['define']) && !empty($val['define'])) {
$define = $val['define'];
} else {
$define = 'datetime';
}
if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) {
$define = 'datetime';
}
} elseif ($val['formType'] == 'radio') {
$templateFile = "view{$this->DS}module{$this->DS}radio";
if (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildRadioView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}');
}
} elseif ($val['formType'] == 'checkbox') {
$templateFile = "view{$this->DS}module{$this->DS}checkbox";
if (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildCheckboxView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}');
}
} elseif ($val['formType'] == 'select') {
$templateFile = "view{$this->DS}module{$this->DS}select";
if (isset($val['bindRelation'])) {
$define = $this->buildOptionView($val['bindRelation']);
} elseif (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildOptionView($field);
}
} elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') {
$templateFile = "view{$this->DS}module{$this->DS}textarea";
} elseif ($val['formType'] == 'relation') {
// 使用select生成
$templateFile = "view{$this->DS}module{$this->DS}select";
if (isset($val['bindRelation'])) {
$define = $this->buildOptionView($val['bindRelation']);
} elseif (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildOptionView($field);
}
}
$addFormList .= CommonTool::replaceTemplate(
$this->getTemplate($templateFile),
[
'comment' => $val['comment'],
'field' => $field,
'required' => $this->buildRequiredHtml($val['required']),
'value' => $val['default'],
'define' => $define,
]
);
}
$viewAddValue = CommonTool::replaceTemplate(
$this->getTemplate("view{$this->DS}form"),
[
'formList' => $addFormList,
]
);
$this->fileList[$viewAddFile] = $viewAddValue;
// 编辑页面
$viewEditFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}edit.html";
$editFormList = '';
foreach ($this->tableColumns as $field => $val) {
if (in_array($field, ['id', 'create_time'])) {
continue;
}
$templateFile = "view{$this->DS}module{$this->DS}input";
$define = '';
$value = '{$row.' . $field . '|default=\'\'}';
// 根据formType去获取具体模板
if ($val['formType'] == 'image') {
$templateFile = "view{$this->DS}module{$this->DS}image";
} elseif ($val['formType'] == 'images') {
$templateFile = "view{$this->DS}module{$this->DS}images";
} elseif ($val['formType'] == 'file') {
$templateFile = "view{$this->DS}module{$this->DS}file";
} elseif ($val['formType'] == 'files') {
$templateFile = "view{$this->DS}module{$this->DS}files";
} elseif ($val['formType'] == 'editor') {
$templateFile = "view{$this->DS}module{$this->DS}editor";
$value = '{$row.' . $field . '|raw|default=\'\'}';
} elseif ($val['formType'] == 'date') {
$templateFile = "view{$this->DS}module{$this->DS}date";
if (isset($val['define']) && !empty($val['define'])) {
$define = $val['define'];
} else {
$define = 'datetime';
}
if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) {
$define = 'datetime';
}
} elseif ($val['formType'] == 'radio') {
$templateFile = "view{$this->DS}module{$this->DS}radio";
if (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildRadioView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}');
}
} elseif ($val['formType'] == 'checkbox') {
$templateFile = "view{$this->DS}module{$this->DS}checkbox";
if (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildCheckboxView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}');
}
} elseif ($val['formType'] == 'select') {
$templateFile = "view{$this->DS}module{$this->DS}select";
if (isset($val['bindRelation'])) {
$define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
} elseif (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
}
} elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') {
$templateFile = "view{$this->DS}module{$this->DS}textarea";
$value = '{$row.' . $field . '|raw|default=\'\'}';
} elseif ($val['formType'] == 'relation') {
// 使用select生成
$templateFile = "view{$this->DS}module{$this->DS}select";
if (isset($val['bindRelation'])) {
$define = $this->buildOptionView($val['bindRelation']);
} elseif (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildOptionView($field);
}
}
$editFormList .= CommonTool::replaceTemplate(
$this->getTemplate($templateFile),
[
'comment' => $val['comment'],
'field' => $field,
'required' => $this->buildRequiredHtml($val['required']),
'value' => $value,
'define' => $define,
]
);
}
$viewEditValue = CommonTool::replaceTemplate(
$this->getTemplate("view{$this->DS}form"),
[
'formList' => $editFormList,
]
);
$this->fileList[$viewEditFile] = $viewEditValue;
return $this;
}
} }

105
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c6d2a0afafddc47a177c5e3a901d9ed0", "content-hash": "6f1ec526803f2ecbe4f1486314294fdd",
"packages": [ "packages": [
{ {
"name": "adbario/php-dot-notation", "name": "adbario/php-dot-notation",
@@ -1223,16 +1223,16 @@
}, },
{ {
"name": "league/flysystem", "name": "league/flysystem",
"version": "1.1.5", "version": "1.1.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/flysystem.git", "url": "https://github.com/thephpleague/flysystem.git",
"reference": "18634df356bfd4119fe3d6156bdb990c414c14ea" "reference": "c995bb0c23c58c9813d081f9523c9b7bb496698e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/18634df356bfd4119fe3d6156bdb990c414c14ea", "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/c995bb0c23c58c9813d081f9523c9b7bb496698e",
"reference": "18634df356bfd4119fe3d6156bdb990c414c14ea", "reference": "c995bb0c23c58c9813d081f9523c9b7bb496698e",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@@ -1311,7 +1311,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/thephpleague/flysystem/issues", "issues": "https://github.com/thephpleague/flysystem/issues",
"source": "https://github.com/thephpleague/flysystem/tree/1.1.5" "source": "https://github.com/thephpleague/flysystem/tree/1.1.8"
}, },
"funding": [ "funding": [
{ {
@@ -1319,7 +1319,7 @@
"type": "other" "type": "other"
} }
], ],
"time": "2021-08-17T13:49:42+00:00" "time": "2021-11-28T21:50:23+00:00"
}, },
{ {
"name": "league/flysystem-cached-adapter", "name": "league/flysystem-cached-adapter",
@@ -1380,16 +1380,16 @@
}, },
{ {
"name": "league/mime-type-detection", "name": "league/mime-type-detection",
"version": "1.8.0", "version": "1.9.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/mime-type-detection.git", "url": "https://github.com/thephpleague/mime-type-detection.git",
"reference": "b38b25d7b372e9fddb00335400467b223349fd7e" "reference": "aa70e813a6ad3d1558fc927863d47309b4c23e69"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/b38b25d7b372e9fddb00335400467b223349fd7e", "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/aa70e813a6ad3d1558fc927863d47309b4c23e69",
"reference": "b38b25d7b372e9fddb00335400467b223349fd7e", "reference": "aa70e813a6ad3d1558fc927863d47309b4c23e69",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@@ -1403,7 +1403,7 @@
"php": "^7.2 || ^8.0" "php": "^7.2 || ^8.0"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.18", "friendsofphp/php-cs-fixer": "^3.2",
"phpstan/phpstan": "^0.12.68", "phpstan/phpstan": "^0.12.68",
"phpunit/phpunit": "^8.5.8 || ^9.3" "phpunit/phpunit": "^8.5.8 || ^9.3"
}, },
@@ -1426,7 +1426,7 @@
"description": "Mime-type detection for Flysystem", "description": "Mime-type detection for Flysystem",
"support": { "support": {
"issues": "https://github.com/thephpleague/mime-type-detection/issues", "issues": "https://github.com/thephpleague/mime-type-detection/issues",
"source": "https://github.com/thephpleague/mime-type-detection/tree/1.8.0" "source": "https://github.com/thephpleague/mime-type-detection/tree/1.9.0"
}, },
"funding": [ "funding": [
{ {
@@ -1438,7 +1438,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-09-25T08:23:19+00:00" "time": "2021-11-21T11:48:40+00:00"
}, },
{ {
"name": "maennchen/zipstream-php", "name": "maennchen/zipstream-php",
@@ -1771,16 +1771,16 @@
}, },
{ {
"name": "phpoffice/phpspreadsheet", "name": "phpoffice/phpspreadsheet",
"version": "1.19.0", "version": "1.20.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git", "url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "a9ab55bfae02eecffb3df669a2e19ba0e2f04bbf" "reference": "44436f270bb134b4a94670f3d020a85dfa0a3c02"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/a9ab55bfae02eecffb3df669a2e19ba0e2f04bbf", "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/44436f270bb134b4a94670f3d020a85dfa0a3c02",
"reference": "a9ab55bfae02eecffb3df669a2e19ba0e2f04bbf", "reference": "44436f270bb134b4a94670f3d020a85dfa0a3c02",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@@ -1807,7 +1807,7 @@
"maennchen/zipstream-php": "^2.1", "maennchen/zipstream-php": "^2.1",
"markbaker/complex": "^3.0", "markbaker/complex": "^3.0",
"markbaker/matrix": "^3.0", "markbaker/matrix": "^3.0",
"php": "^7.2 || ^8.0", "php": "^7.3 || ^8.0",
"psr/http-client": "^1.0", "psr/http-client": "^1.0",
"psr/http-factory": "^1.0", "psr/http-factory": "^1.0",
"psr/simple-cache": "^1.0" "psr/simple-cache": "^1.0"
@@ -1815,15 +1815,15 @@
"require-dev": { "require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "dev-master", "dealerdirect/phpcodesniffer-composer-installer": "dev-master",
"dompdf/dompdf": "^1.0", "dompdf/dompdf": "^1.0",
"friendsofphp/php-cs-fixer": "^2.18", "friendsofphp/php-cs-fixer": "^3.2",
"jpgraph/jpgraph": "^4.0", "jpgraph/jpgraph": "^4.0",
"mpdf/mpdf": "^8.0", "mpdf/mpdf": "^8.0",
"phpcompatibility/php-compatibility": "^9.3", "phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^0.12.82", "phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^0.12.18", "phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^8.5", "phpunit/phpunit": "^8.5 || ^9.0",
"squizlabs/php_codesniffer": "^3.5", "squizlabs/php_codesniffer": "^3.6",
"tecnickcom/tcpdf": "^6.3" "tecnickcom/tcpdf": "^6.4"
}, },
"suggest": { "suggest": {
"dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)", "dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
@@ -1875,9 +1875,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues", "issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.19.0" "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.20.0"
}, },
"time": "2021-10-31T15:09:20+00:00" "time": "2021-11-23T15:23:42+00:00"
}, },
{ {
"name": "psr/cache", "name": "psr/cache",
@@ -2281,16 +2281,16 @@
}, },
{ {
"name": "qcloud/cos-sdk-v5", "name": "qcloud/cos-sdk-v5",
"version": "v2.4.0", "version": "v2.4.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/tencentyun/cos-php-sdk-v5.git", "url": "https://github.com/tencentyun/cos-php-sdk-v5.git",
"reference": "57e8e354ff94cfadabf13b1aacca1c6a20252595" "reference": "899cf8987fae0402c5db1863c302805715444107"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/57e8e354ff94cfadabf13b1aacca1c6a20252595", "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/899cf8987fae0402c5db1863c302805715444107",
"reference": "57e8e354ff94cfadabf13b1aacca1c6a20252595", "reference": "899cf8987fae0402c5db1863c302805715444107",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@@ -2302,18 +2302,19 @@
"require": { "require": {
"ext-curl": "*", "ext-curl": "*",
"ext-json": "*", "ext-json": "*",
"guzzlehttp/guzzle": ">=6.2.1", "ext-simplexml": "*",
"guzzlehttp/guzzle-services": ">=1.1", "guzzlehttp/guzzle": "^6.2.1 || ^7.0",
"guzzlehttp/psr7": "<=2.1", "guzzlehttp/guzzle-services": "^1.1",
"guzzlehttp/psr7": "^1.3.1 || ^2.0",
"php": ">=5.6" "php": ">=5.6"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Qcloud\\Cos\\": "src/Qcloud/Cos/" "Qcloud\\Cos\\": "src/"
}, },
"files": [ "files": [
"src/Qcloud/Cos/Common.php" "src/Common.php"
] ]
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@@ -2342,9 +2343,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/tencentyun/cos-php-sdk-v5/issues", "issues": "https://github.com/tencentyun/cos-php-sdk-v5/issues",
"source": "https://github.com/tencentyun/cos-php-sdk-v5/tree/v2.4.0" "source": "https://github.com/tencentyun/cos-php-sdk-v5/tree/v2.4.2"
}, },
"time": "2021-10-28T14:01:51+00:00" "time": "2021-11-22T09:22:47+00:00"
}, },
{ {
"name": "qiniu/php-sdk", "name": "qiniu/php-sdk",
@@ -2460,16 +2461,16 @@
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
"version": "v2.4.0", "version": "v2.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git", "url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@@ -2484,7 +2485,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-main": "2.4-dev" "dev-main": "2.5-dev"
}, },
"thanks": { "thanks": {
"name": "symfony/contracts", "name": "symfony/contracts",
@@ -2513,7 +2514,7 @@
"description": "A generic function and convention to trigger deprecation notices", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0" "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.0"
}, },
"funding": [ "funding": [
{ {
@@ -2529,7 +2530,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-03-23T23:28:01+00:00" "time": "2021-07-12T14:48:14+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@@ -3485,16 +3486,16 @@
}, },
{ {
"name": "symfony/var-dumper", "name": "symfony/var-dumper",
"version": "v4.4.33", "version": "v4.4.34",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/var-dumper.git", "url": "https://github.com/symfony/var-dumper.git",
"reference": "50286e2b7189bfb4f419c0731e86632cddf7c5ee" "reference": "2d0c056b2faaa3d785bdbd5adecc593a5be9c16e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/50286e2b7189bfb4f419c0731e86632cddf7c5ee", "url": "https://api.github.com/repos/symfony/var-dumper/zipball/2d0c056b2faaa3d785bdbd5adecc593a5be9c16e",
"reference": "50286e2b7189bfb4f419c0731e86632cddf7c5ee", "reference": "2d0c056b2faaa3d785bdbd5adecc593a5be9c16e",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@@ -3560,7 +3561,7 @@
"dump" "dump"
], ],
"support": { "support": {
"source": "https://github.com/symfony/var-dumper/tree/v4.4.33" "source": "https://github.com/symfony/var-dumper/tree/v4.4.34"
}, },
"funding": [ "funding": [
{ {
@@ -3576,7 +3577,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-10-25T20:24:58+00:00" "time": "2021-11-12T10:50:54+00:00"
} }
], ],
"aliases": [], "aliases": [],
@@ -3591,5 +3592,5 @@
"ext-json": "*" "ext-json": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.1.0" "plugin-api-version": "2.0.0"
} }