1. <?php
    2. namespace app\model;
    3. use think\db\Query;
    4. use tpScriptVueCurd\base\model\BaseModel;
    5. use tpScriptVueCurd\field\RadioField;
    6. use tpScriptVueCurd\field\StringField;
    7. use tpScriptVueCurd\FieldCollection;
    8. use tpScriptVueCurd\ModelField;
    9. class User extends BaseModel
    10. {
    11. /**
    12. * 表字段配置
    13. * @return FieldCollection
    14. */
    15. public function fields(): FieldCollection
    16. {
    17. $nameField=StringField::init('name','姓名');
    18. $nameField->pushFieldDo()->setEditShowDo(function (BaseModel &$info,?BaseModel $base,ModelField $field,bool $isStepNext){
    19. if(empty($info->id)){//如果是添加数据,设置姓名默认为 张三
    20. $info[$field->name()]='张三';
    21. }
    22. });
    23. $sexField=RadioField::init('sex', '性别')->items(['男','女']);
    24. $sexField->pushFieldDo()->setIndexFilterBeforeDo(function (ModelField $field,Query $query,array &$filterData){
    25. if(empty($info->id)){//如果是添加数据,设置性别默认为 男
    26. $info[$field->name()]='男';
    27. }
    28. });
    29. return new FieldCollection([
    30. $nameField,
    31. $sexField,
    32. ]);
    33. }
    34. }