增加数据验证生成

This commit is contained in:
liaofei 2023-04-23 15:36:06 +08:00
parent b3b3c6985b
commit 913d845339
4 changed files with 44 additions and 3 deletions

View File

@ -538,7 +538,9 @@ class SystemCrudServices extends BaseServices
]);
//生成验证器
$validate = app()->make(Validate::class);
$validate->setFilePathName($filePath['validate'] ?? '')->setbasePath($basePath)->handle($tableName);
$validate->setFilePathName($filePath['validate'] ?? '')->setbasePath($basePath)->handle($tableName, [
'field' => $options['fromField'],
]);
//生成控制器
$controller = app()->make(Controller::class);
$controller->setFilePathName($filePath['controller'] ?? '')->setbasePath($basePath)->handle($tableName, [

View File

@ -148,6 +148,7 @@ class Service extends Make
*/
protected function getframeImageOnePhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-add', string $width = '950px', string $height = '505px')
{
$name = addslashes($name);
$requiredText = $required ? '->required()' : '';
$content = <<<CONTENT
\$rule[] = FormBuilder::frameImage('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field']), \$info['$field'] ?? '')->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
@ -170,6 +171,7 @@ CONTENT;
*/
protected function getframeImagesPhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-images', int $maxLength = 10, string $width = '950px', string $height = '505px')
{
$name = addslashes($name);
$requiredText = $required ? '->required()' : '';
$content = <<<CONTENT
\$rule[] = FormBuilder::frameImages('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field', 'type' => 'many', 'maxLength' => $maxLength]), \$info['$field'] ?? [])->maxLength($maxLength)->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText

View File

@ -38,6 +38,43 @@ class Validate extends Make
return 'app' . DS . 'adminapi' . DS . 'validate' . DS . 'crud';
}
/**
* @param string $name
* @param array $options
* @return Validate
* @author 等风来
* @email 136327134@qq.com
* @date 2023/4/23
*/
public function handle(string $name, array $options = [])
{
[$rule, $message] = $this->getRuleContent($options['field']);
$this->value['rule-php'] = $rule;
$this->value['message-php'] = $message;
return parent::handle($name, $options); // TODO: Change the autogenerated stub
}
/**
* @param array $field
* @return array
* @author 等风来
* @email 136327134@qq.com
* @date 2023/4/23
*/
protected function getRuleContent(array $field)
{
$content = [];
$message = [];
foreach ($field as $item) {
$item['name'] = addslashes($item['name']);
if ($item['required']) {
$content[] = $this->tab(2) . '\'' . $item['field'] . '\'=>\'require\'';
$message[] = $this->tab(2) . '\'' . $item['field'] . '.require\'=>\'' . $item['name'] . '必须填写\'';
}
}
return [implode("\n", $content), implode("\n", $message)];
}
/**
* 模板文件配置
* @param string $type

View File

@ -33,14 +33,14 @@ class {%nameCamel%}Validate extends Validate
* @var array
*/
protected $rule = [
{%rule-php%}
];
/**
* @var array
*/
protected $message = [
{%message-php%}
];
/**