You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.0 KiB
75 lines
2.0 KiB
<?php
|
|
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid\Filter;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Form\Field;
|
|
|
|
/**
|
|
* Dcat-admin - admin builder based on Laravel.
|
|
* @author jqh <https://github.com/jqhph>
|
|
*
|
|
* Bootstraper for Admin.
|
|
*
|
|
* Here you can remove builtin form field:
|
|
*
|
|
* extend custom field:
|
|
* Dcat\Admin\Form::extend('php', PHPEditor::class);
|
|
* Dcat\Admin\Grid\Column::extend('php', PHPEditor::class);
|
|
* Dcat\Admin\Grid\Filter::extend('php', PHPEditor::class);
|
|
*
|
|
* Or require js and css assets:
|
|
* Admin::css('/packages/prettydocs/css/styles.css');
|
|
* Admin::js('/packages/prettydocs/js/main.js');
|
|
*
|
|
*/
|
|
|
|
// 地图
|
|
Form\Field\Map::collectAssets();
|
|
|
|
// 官方例子,验证字符长度
|
|
Field\Text::macro('len', function (int $length, ?string $error = null) {
|
|
// 前端验证逻辑扩展
|
|
Admin::script(
|
|
<<<'JS'
|
|
Dcat.validator.extend('len', function ($el) {
|
|
console.log($el.val().length , $el.attr('data-len'));
|
|
return $el.val().length != $el.attr('data-len');
|
|
});
|
|
JS
|
|
);
|
|
|
|
// 同时添加后端验证逻辑,这个可以看需要
|
|
$this->rules('size:'.$length);
|
|
|
|
return $this->attribute([
|
|
'data-len' => $length,
|
|
'data-len-error' => str_replace(
|
|
[':attribute', ':len'],
|
|
[$this->label, $length],
|
|
$error ?: "只能输入:len个字符"
|
|
),
|
|
]);
|
|
});
|
|
|
|
/* 验证最多包含两位小数的浮点数,可不带小数 */
|
|
Field\Text::macro('floatTwo', function (int $bit = 2, ?string $error = null) {
|
|
// 前端验证逻辑扩展
|
|
Admin::script(
|
|
<<<'JS'
|
|
Dcat.validator.extend('floatTwo', function ($el) {
|
|
return !(/^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$/.test($el.val()));
|
|
});
|
|
JS
|
|
);
|
|
|
|
// 同时添加后端验证逻辑,这个可以看需要
|
|
// $this->rules('size:'.$length);
|
|
|
|
return $this->attribute([
|
|
'data-floatTwo' => '^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$',
|
|
'data-floatTwo-error' => "只能输入数字(最多包含两位小数)"
|
|
]);
|
|
});
|