|
@@ -46,12 +46,17 @@ class MakeAdmin extends Command
|
|
|
/**
|
|
|
* Int类型识别为日期时间的结尾字符,默认会识别为日期文本框
|
|
|
*/
|
|
|
- protected $intDateSuffix = ['_time'];
|
|
|
+ protected $intDateSuffix = ['time'];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Int类型识别为日期时间的结尾字符,默认会识别为日期文本框
|
|
|
+ */
|
|
|
+ protected $intListSuffix = ['images', 'ids', 'list'];
|
|
|
|
|
|
/**
|
|
|
* 开关后缀
|
|
|
*/
|
|
|
- protected $switchSuffix = ['_switch'];
|
|
|
+ protected $switchSuffix = ['switch'];
|
|
|
|
|
|
protected function configure()
|
|
|
{
|
|
@@ -106,7 +111,7 @@ class MakeAdmin extends Command
|
|
|
//模型
|
|
|
list($modelNamespace, $modelName, $modelFile, $modelArr) = $this->getModelData($path, $table);
|
|
|
list($serviceNamespace, $serviceName, $serviceFile, $serviceArr) = $this->getServicesData($path, $table);
|
|
|
- list($controllerNamespace, $controllerName, $controllerFile, $controllerArr) = $this->getControllerData($path, $table);
|
|
|
+ list($controllerNamespace, $controllerName, $controllerFile, $controllerArr, $controllerPath, $resourceName) = $this->getControllerData($path, $table);
|
|
|
list($validateNamespace, $validateName, $validateFile, $validateArr) = $this->getValidateData($path, $table);
|
|
|
|
|
|
if ($delete) {
|
|
@@ -196,6 +201,8 @@ class MakeAdmin extends Command
|
|
|
$appendAttrList = [];
|
|
|
$exportAttr = [];
|
|
|
$validateRules = [];
|
|
|
+ $searchAttr = [];
|
|
|
+ $searchFieldAttr = [];
|
|
|
$validateMessage = [];
|
|
|
$createParams = [];
|
|
|
|
|
@@ -260,12 +267,12 @@ class MakeAdmin extends Command
|
|
|
$this->setCreate($createParams, $v);
|
|
|
$this->appendAttr($appendAttrList, $field);
|
|
|
$exportAttr[$field . '_chs'] = $langList[$field] ?? parseName($field, 1);
|
|
|
- break;
|
|
|
} else {
|
|
|
$this->setCreate($createParams, $v);
|
|
|
$exportAttr[$field] = $langList[$field] ?? parseName($field, 1);
|
|
|
}
|
|
|
- $this->checkValidate($validateRules, $validateMessage, $v, $field, $langList[$field] ?? parseName($field, 1));
|
|
|
+ $this->checkValidate($validateRules, $validateMessage, $v, $field, $langList[$field] ?? parseName($field, 1), $itemArr);
|
|
|
+ $this->searchAttrHandel($searchAttr, $searchFieldAttr, $field, $langList[$field] ?? parseName($field, 1), $inputType);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -278,6 +285,8 @@ class MakeAdmin extends Command
|
|
|
'table' => $table,
|
|
|
'tableComment' => $tableComment,
|
|
|
'tableName' => $modelTableName,
|
|
|
+ 'resourceName' => $resourceName,
|
|
|
+ 'path' => $controllerPath,
|
|
|
'pk' => $priKey,
|
|
|
'controllerNamespace' => $controllerNamespace,
|
|
|
'controllerName' => $controllerName,
|
|
@@ -301,6 +310,8 @@ class MakeAdmin extends Command
|
|
|
'validateMessage' => implode(",\n", $this->handelArrayDate($validateMessage)),
|
|
|
'exportAttrList' => implode(",\n", $this->handelArrayDate($exportAttr)),
|
|
|
'createParams' => implode(",\n\t", $createParams),
|
|
|
+ 'searchFieldAttr' => implode(",\n\t", $searchFieldAttr),
|
|
|
+ 'searchAttrList' => implode("\n\n", $searchAttr),
|
|
|
];
|
|
|
|
|
|
// 生成控制器文件
|
|
@@ -351,11 +362,11 @@ class MakeAdmin extends Command
|
|
|
{
|
|
|
$field = $item['COLUMN_NAME'];
|
|
|
$type = $item['DATA_TYPE'];
|
|
|
- if ($type == 'set' || $this->isMatchSuffix($field, ['_images', '_ids'])) {
|
|
|
+ if ($type == 'set' || $this->isMatchSuffix($field, $this->intListSuffix)) {
|
|
|
$createParams[] = <<<EOD
|
|
|
['{$field}', []]
|
|
|
EOD;
|
|
|
- } else if (in_array($type, ['bigint', 'int', 'mediumint', 'smallint', 'tinyint', 'decimal', 'double', 'float'])) {
|
|
|
+ } else if (in_array($type, ['bigint', 'int', 'mediumint', 'smallint', 'tinyint', 'decimal', 'double', 'float']) && !$this->isMatchSuffix($field, $this->intDateSuffix)) {
|
|
|
$default = !($item['COLUMN_DEFAULT'] == '' || $item['COLUMN_DEFAULT'] == 'null') ? $item['COLUMN_DEFAULT'] : 0;
|
|
|
$createParams[] = <<<EOD
|
|
|
['{$field}', {$default}]
|
|
@@ -370,7 +381,7 @@ EOD;
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected function checkValidate(&$validateArr, &$validateMessage, $item, $field, $fieldName)
|
|
|
+ protected function checkValidate(&$validateArr, &$validateMessage, $item, $field, $fieldName, $itemArr = [])
|
|
|
{
|
|
|
if (empty($validateArr[$field]))
|
|
|
$validateArr[$field] = [];
|
|
@@ -379,11 +390,19 @@ EOD;
|
|
|
$validateArr[$field][] = 'require';
|
|
|
$validateMessage[$field . '.require'] = $fieldName . '是必需的';
|
|
|
}
|
|
|
- if ($item['DATA_TYPE'] == 'set' || $this->isMatchSuffix($field, ['_images', '_ids'])) {
|
|
|
+ if ($itemArr) {
|
|
|
+ $list = [];
|
|
|
+ foreach ($itemArr as $k => $v) {
|
|
|
+ $list[] = $k;
|
|
|
+ }
|
|
|
+ $validateArr[$field][] = 'in:' . implode(',', $list);
|
|
|
+ $validateMessage[$field . '.in'] = '请选择正确的' . $fieldName;
|
|
|
+ }
|
|
|
+ if ($item['DATA_TYPE'] == 'set' || $this->isMatchSuffix($field, $this->intListSuffix)) {
|
|
|
$validateArr[$field][] = 'array';
|
|
|
- $validateMessage[$field . '.array'] = $fieldName . '需要是数组';
|
|
|
+ $validateMessage[$field . '.array'] = $fieldName . '必须是数组';
|
|
|
}
|
|
|
- if (in_array($item['DATA_TYPE'], ['bigint', 'int', 'mediumint', 'smallint', 'tinyint'])) {
|
|
|
+ if (in_array($item['DATA_TYPE'], ['bigint', 'int', 'mediumint', 'smallint', 'tinyint']) && !$this->isMatchSuffix($field, $this->intDateSuffix)) {
|
|
|
$validateArr[$field][] = 'number';
|
|
|
$validateMessage[$field . '.number'] = $fieldName . '必须是整数';
|
|
|
}
|
|
@@ -393,15 +412,19 @@ EOD;
|
|
|
}
|
|
|
if (stripos($item['COLUMN_TYPE'], 'unsigned') !== false) {
|
|
|
$validateArr[$field][] = 'egt:0';
|
|
|
- $validateMessage[$field . '.egt'] = $fieldName . '是必需大于等于0';
|
|
|
+ $validateMessage[$field . '.egt'] = $fieldName . '大于等于0';
|
|
|
}
|
|
|
if ($this->isMatchSuffix($field, ['phone', 'mobile'])) {
|
|
|
$validateArr[$field][] = 'mobile';
|
|
|
- $validateMessage[$field . '.mobile'] = $fieldName . '格式不正确';
|
|
|
+ $validateMessage[$field . '.mobile'] = $fieldName . '不是有效的手机号码';
|
|
|
}
|
|
|
- if ($this->isMatchSuffix($field, 'email')) {
|
|
|
+ if ($this->isMatchSuffix($field, ['email'])) {
|
|
|
$validateArr[$field][] = 'email';
|
|
|
- $validateMessage[$field . '.email'] = $fieldName . '格式不正确';
|
|
|
+ $validateMessage[$field . '.email'] = $fieldName . '不是有效的邮箱地址';
|
|
|
+ }
|
|
|
+ if ($this->isMatchSuffix($field, ['url', 'link'])) {
|
|
|
+ $validateArr[$field][] = 'url';
|
|
|
+ $validateMessage[$field . '.url'] = $fieldName . '不是有效的url';
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -543,6 +566,13 @@ EOD;
|
|
|
EOD;
|
|
|
}
|
|
|
|
|
|
+ protected function searchAttr(&$searchFieldAttr, $field)
|
|
|
+ {
|
|
|
+ $searchFieldAttr[] = <<<EOD
|
|
|
+ ['{$field}', '']
|
|
|
+EOD;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
protected function getFieldListName($field)
|
|
|
{
|
|
@@ -558,7 +588,7 @@ EOD;
|
|
|
|
|
|
protected function getAttr(&$getAttr, $field, $inputType = '')
|
|
|
{
|
|
|
- if (!in_array($inputType, ['datetime', 'select', 'multiple', 'add_time', 'add_time_datetime'])) {
|
|
|
+ if (!in_array($inputType, ['datetime', 'select', 'multiple', 'add_time', 'add_time_datetime', 'list'])) {
|
|
|
return;
|
|
|
}
|
|
|
$attrField = ucfirst($this->getCamelizeName($field));
|
|
@@ -566,6 +596,29 @@ EOD;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ protected function searchAttrHandel(&$searchAttr, &$searchFieldAttr, $field, $fieldName, $inputType = '')
|
|
|
+ {
|
|
|
+ $type = 'default';
|
|
|
+ if ($this->isMatchSuffix($field, ['id'])) {
|
|
|
+ $type = 'id';
|
|
|
+ } else if ($this->isMatchSuffix($field, ['name', 'title', 'info'])) {
|
|
|
+ $type = 'like';
|
|
|
+ } else if (in_array($inputType, ['datetime'])) {
|
|
|
+ $type = 'time';
|
|
|
+ } else if (in_array($inputType, ['multiple', 'list'])) {
|
|
|
+ $type = 'find_in_set';
|
|
|
+ } else if (in_array($inputType, ['select'])) {
|
|
|
+ $type = 'default';
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $attrField = ucfirst($this->getCamelizeName($field));
|
|
|
+ $searchAttr[] = $this->getReplacedStub("search" . DS . $type, ['field' => $field, 'fieldName' => $fieldName, 'methodName' => "search{$attrField}Attr"]);
|
|
|
+ $this->searchAttr($searchFieldAttr, $field);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取替换后的数据
|
|
|
* @param string $name
|
|
@@ -632,7 +685,7 @@ EOD;
|
|
|
$inputType = "select";
|
|
|
}
|
|
|
// 指定后缀结尾且类型为enum,说明是个单选框
|
|
|
- if ($this->isMatchSuffix($fieldsName, ['_ids', '_images'])) {
|
|
|
+ if ($this->isMatchSuffix($fieldsName, $this->intListSuffix)) {
|
|
|
$inputType = "list";
|
|
|
}
|
|
|
// 指定后缀结尾且类型为char或tinyint且长度为1,说明是个Switch复选框
|
|
@@ -724,13 +777,19 @@ EOD;
|
|
|
$path = str_replace(['.', '/', '\\'], '/', $path);
|
|
|
$arr = explode('/', $path);
|
|
|
}
|
|
|
+ $resourceName = $table;
|
|
|
+ foreach ($arr as $v) {
|
|
|
+ if (strpos($resourceName, $v . '_') === 0) {
|
|
|
+ $resourceName = substr($resourceName, strlen($v . '_'));
|
|
|
+ }
|
|
|
+ }
|
|
|
$parseArr = $arr;
|
|
|
array_push($parseArr, $parseName);
|
|
|
$appNamespace = Config::get('app.app_namespace');
|
|
|
$parseNamespace = "{$appNamespace}\\{$type}" . (in_array($type, ['controller', 'validate']) ? '\\admin' : '') . ($arr ? "\\" . implode("\\", $arr) : "");
|
|
|
$moduleDir = $this->app->getRootPath() . 'app' . DS . $type . DS . ((in_array($type, ['controller', 'validate']) ? 'admin' : '') . DS);
|
|
|
$parseFile = $moduleDir . ($arr ? implode(DS, $arr) . DS : '') . $parseName . '.php';
|
|
|
- return [$parseNamespace, $parseName, $parseFile, $parseArr];
|
|
|
+ return [$parseNamespace, $parseName, $parseFile, $parseArr, ($arr ? implode('.', $arr) . '.' : ''), $resourceName];
|
|
|
}
|
|
|
|
|
|
|