form->number($field, $label) ->required() ->min(1) ->help('用户ID,必须是有效的用户'); } /** * 添加管理员ID输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Number */ public function numberAdminId(string $field = 'admin_id', string $label = '管理员ID'): Field\Number { return $this->form->number($field, $label) ->min(1) ->help('管理员ID,必须是有效的管理员'); } /** * 添加惩罚类型选择 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Select */ public function selectPunishType(string $field = 'type', string $label = '惩罚类型'): Field\Select { return $this->form->select($field, $label) ->options(function () { $options = []; foreach (PUNISH_TYPE::cases() as $case) { $options[$case->name] = $case->name; } return $options; }) ->required(); } /** * 添加惩罚等级输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Number */ public function numberPunishLevel(string $field = 'level', string $label = '惩罚等级'): Field\Number { return $this->form->number($field, $label) ->min(1) ->max(10) ->default(1) ->required() ->help('惩罚等级,1-10级'); } /** * 添加描述输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Textarea */ public function textareaDesc(string $field = 'desc', string $label = '描述'): Field\Textarea { return $this->form->textarea($field, $label) ->rows(3) ->required(); } /** * 添加消息标题输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Text */ public function textMessageTitle(string $field = 'title', string $label = '消息标题'): Field\Text { return $this->form->text($field, $label) ->required() ->rules('required|max:100'); } /** * 添加消息内容输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Textarea */ public function textareaMessageContent(string $field = 'content', string $label = '消息内容'): Field\Textarea { return $this->form->textarea($field, $label) ->rows(5) ->required() ->rules('required'); } /** * 添加消息类型选择 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Select */ public function selectMessageType(string $field = 'type', string $label = '消息类型'): Field\Select { return $this->form->select($field, $label) ->options([ APP_MESSAGE_TYPE::SYSTEM->value => '系统消息', APP_MESSAGE_TYPE::USER->value => '用户消息', APP_MESSAGE_TYPE::BUSINESS->value => '业务消息', APP_MESSAGE_TYPE::SECURITY->value => '安全消息', ]) ->default(APP_MESSAGE_TYPE::SYSTEM->value) ->required(); } /** * 添加消息状态选择 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Select */ public function selectMessageStatus(string $field = 'status', string $label = '消息状态'): Field\Select { return $this->form->select($field, $label) ->options([ APP_MESSAGE_STATUS::DRAFT->value => '草稿', APP_MESSAGE_STATUS::PUBLISHED->value => '已发布', APP_MESSAGE_STATUS::ARCHIVED->value => '已归档', ]) ->default(APP_MESSAGE_STATUS::DRAFT->value) ->required(); } /** * 添加发送者类型选择 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Select */ public function selectSenderType(string $field = 'sender_type', string $label = '发送者类型'): Field\Select { return $this->form->select($field, $label) ->options([ APP_SENDER_TYPE::SYSTEM->value => '系统', APP_SENDER_TYPE::USER->value => '用户', APP_SENDER_TYPE::ADMIN->value => '管理员', ]) ->default(APP_SENDER_TYPE::SYSTEM->value) ->required(); } /** * 添加发送者ID输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Number */ public function numberSenderId(string $field = 'sender_id', string $label = '发送者ID'): Field\Number { return $this->form->number($field, $label) ->min(0) ->default(0) ->help('发送者ID,系统消息可为0'); } /** * 添加接收者ID输入 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Number */ public function numberReceiverId(string $field = 'receiver_id', string $label = '接收者ID'): Field\Number { return $this->form->number($field, $label) ->min(0) ->default(0) ->help('接收者ID,0表示全部用户'); } /** * 添加是否允许回复选择 * * @param string $field 字段名 * @param string $label 标签名 * @return Field\Switch */ public function switchAllowReply(string $field = 'allow_reply', string $label = '允许回复'): Field\Switch { return $this->form->switch($field, $label) ->default(false); } }