FieldValidate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\validate\sys_manage;
  3. use support\Validate;
  4. class FieldValidate extends Validate
  5. {
  6. protected $rule = [
  7. 'field_status|状态' => 'require|in:ACTIVED,DISABLED',
  8. 'field_category|分类' => 'in:NORMAL,PAGE,OTHER',
  9. 'field_name|名称' => 'require',
  10. 'field_table|所属表' => 'require|alphaDash',
  11. 'field_column_key|字段列名' => 'alphaDash',
  12. 'field_column_datatype|数据类型' => 'in:string,decimal,text,dateTime',
  13. 'field_column_default|列默认值' => 'checkDefault',
  14. // 'field_form_key' => 'in:id,name',
  15. 'field_form_type|DOM表单类型' => 'alphaDash',
  16. // 'field_form_default' => 'chsDash',
  17. // 'field_refer_json' => 'isJson',
  18. // 'field_remark' => 'chsDash',
  19. 'field_extend_json' => 'isJson'
  20. ];
  21. protected $message = [];
  22. protected $scene = [
  23. 'add' => ['field_status', 'field_category', 'field_name', 'field_table', 'field_column_key', 'field_column_datatype', 'field_form_key', 'field_form_type', 'field_column_default', 'field_refer_json', 'field_extend_json'],
  24. 'update' => ['field_category', 'field_name', 'field_table', 'field_column_key', 'field_column_datatype', 'field_form_key', 'field_form_type', 'field_column_default', 'field_refer_json', 'field_extend_json'],
  25. 'update_status' => ['field_status']
  26. ];
  27. /**
  28. * @Desc 验证json
  29. * @Author Gorden
  30. * @Date 2024/2/22 14:09
  31. *
  32. * @param $value
  33. * @return string|true
  34. */
  35. protected function isJson($value)
  36. {
  37. if (is_json($value)) {
  38. return true;
  39. }
  40. return '数据格式错误~';
  41. }
  42. protected function checkDefault($value, $rule, $data)
  43. {
  44. if ($data['field_column_datatype'] == 'dateTime') {
  45. if (strlen($value) >= 14 && false !== strtotime($value)) {
  46. return true;
  47. }
  48. return "数据格式错误~ 例如:2024-01-01 12:00:00";
  49. }
  50. return true;
  51. }
  52. }