| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Module\Article\AdminControllers\Helper;
- use App\Module\Article\Enums\STATUS;
- use App\Module\Article\Models\ArticleCate;
- use Dcat\Admin\Show;
- /**
- * 详情页辅助特性
- *
- * 提供文章模块后台控制器的详情页构建功能的具体实现
- */
- trait ShowHelperTrait
- {
- /**
- * 显示文章标题
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldTitle(string $field = 'title', string $label = '标题'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- /**
- * 显示文章描述
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldDescription(string $field = 'description', string $label = '简述'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- /**
- * 显示文章分类
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldCategory(string $field = 'category_id', string $label = '分类'): Show\Field
- {
- return $this->show->field($field, $label)->as(function ($value) {
- return ArticleCate::getCate()[$value] ?? '未知分类';
- });
- }
- /**
- * 显示文章状态
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldStatus(string $field = 'status', string $label = '状态'): Show\Field
- {
- return $this->show->field($field, $label)->as(function ($value) {
- return STATUS::getValueDescription()[$value] ?? '未知状态';
- });
- }
- /**
- * 显示文章内容
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldContent(string $field = 'content', string $label = '内容'): Show\Field
- {
- return $this->show->field($field, $label)->unescape();
- }
- /**
- * 显示文章排序
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldSortOrder(string $field = 'sort_order', string $label = '排序'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- /**
- * 显示文章是否置顶
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldIsTop(string $field = 'is_top', string $label = '是否置顶'): Show\Field
- {
- return $this->show->field($field, $label)->as(function ($value) {
- return $value ? '是' : '否';
- });
- }
- /**
- * 显示文章是否推荐
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldIsRecommend(string $field = 'is_recommend', string $label = '是否推荐'): Show\Field
- {
- return $this->show->field($field, $label)->as(function ($value) {
- return $value ? '是' : '否';
- });
- }
- /**
- * 显示文章浏览量
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldViewsCount(string $field = 'views_count', string $label = '浏览量'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- /**
- * 显示文章创建者
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldCreatedBy(string $field = 'created_by', string $label = '创建者'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- }
|