hyperf-view/builder/View/Grid/Concerns/HasColumnAttributes.php

552 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace Builder\View\Grid\Concerns;
use Builder\View\Grid\Column\Attributes;
trait HasColumnAttributes
{
/**
*
* @var Attributes
*/
protected $attributes;
/**
* 显示的标题
* @param string $label
* @return $this
*/
public function title(string $title)
{
$this->attributes->title = $title;
return $this;
}
/**
* 设置字段
* @param string $label
* @return $this
*/
public function dataIndex(string $dataIndex)
{
$this->attributes->dataIndex = $dataIndex;
return $this;
}
/**
* 对应列表单类型
* @param $type
* @return $this
*/
public function formType($type)
{
$this->attributes->formType = $type;
return $this;
}
/***
* 表格列对齐方式:'center', 'left', 'right'
* @param $align
* @return $this
*/
public function align($align)
{
$this->attributes->align = $align;
return $this;
}
/**
* 设置表格字段排序:
* { sortDirections: ['ascend', 'descend'], sorter: true }
* 其中 sorter 是否设置为服务器排序
* @param string $sortable
* @return $this
*/
public function sortable($sortable = 'custom')
{
$this->attributes->sortable = $sortable == 'custom';
return $this;
}
/***
* 是否搜索字段
* @param array $search
* @return $this
*/
public function search($search = false)
{
$this->attributes->search = $search;
return $this;
}
/**
* 对应列的宽度
* @param string|int $width
* @return $this
*/
public function width($width = 'auto')
{
$this->attributes->width = $width;
return $this;
}
/***
* 表格列是否设置隐藏
* @param bool $hide
* @return $this
*/
public function hide($hide = false)
{
$this->attributes->hide = $hide;
return $this;
}
/***
* 是否显示省略号
* @param bool $ellipsis
* @return $this
*/
public function ellipsis($ellipsis = true)
{
$this->attributes->ellipsis = $ellipsis;
return $this;
}
/**
* 当内容过长被隐藏时显示 tooltip
* @param bool $showOverflowTooltip
* @return $this
*/
public function tooltip($Tooltip = true)
{
$this->attributes->tooltip = $Tooltip;
return $this;
}
/***
* 设置表格列筛选功能
* JS Function
* @param filterable $ellipsis
* @return $this
*/
public function filterable($js)
{
$this->attributes->filterable = $js;
return $this;
}
/**
* 自定义单元格类名 cellClass
* @param string $className
* @return $this
*/
public function cellClass($cellClass)
{
$this->attributes->cellClass = $cellClass;
return $this;
}
/**
* 自定义表头单元格类名
* @param $headerCellClass
* @return $this
*/
public function headerCellClass($headerCellClass)
{
$this->attributes->headerCellClass = $headerCellClass;
return $this;
}
/**
* 自定义内容单元格类名
* @param $bodyCellClass
* @return $this
*/
public function bodyCellClass($bodyCellClass)
{
$this->attributes->bodyCellClass = $bodyCellClass;
return $this;
}
/***
* 自定义总结栏单元格类名
* @param $summaryCellClass
* @return $this
*/
public function summaryCellClass($summaryCellClass)
{
$this->attributes->summaryCellClass = $summaryCellClass;
return $this;
}
/**
* 自定义单元格样式
* @param $cellStyle
* @return $this
*/
public function cellStyle($cellStyle)
{
$this->attributes->cellStyle = $cellStyle;
return $this;
}
/**
* 自定义表头单元格样式
* @param $headerCellStyle
* @return $this
*/
public function headerCellStyle($headerCellStyle)
{
$this->attributes->headerCellStyle = $headerCellStyle;
return $this;
}
/***
* 自定义内容单元格样式
* @param $bodyCellStyle
* @return $this
*/
public function bodyCellStyle($bodyCellStyle)
{
$this->attributes->headerCellStyle = $bodyCellStyle;
return $this;
}
/***
* 自定义总结栏单元格样式
* @param $summaryCellStyle
* @return $this
*/
public function summaryCellStyle($summaryCellStyle)
{
$this->attributes->summaryCellStyle = $summaryCellStyle;
return $this;
}
/***
* 设置新增和编辑时的表单字段描述
* @param $placeholder
* @return $this
*/
public function placeholder($placeholder)
{
$this->attributes->summaryCellStyle = $placeholder;
return $this;
}
/**
* 新增/编辑 通用表单验证规则,可参考 Arco
* https://arco.design/vue/component/form#Type
* @param $commonRules
* @return $this
*/
public function commonRules($commonRules)
{
$this->attributes->commonRules = $commonRules;
return $this;
}
/***
* 新增时表单的验证规则,可参考 Arco 官方的
* @param $addRules
* @return $this
*/
public function addRules($addRules)
{
$this->attributes->addRules = $addRules;
return $this;
}
/***
* 编辑时表单的验证规则
* @param $editRules
* @return $this
*/
public function editRules($editRules)
{
$this->attributes->editRules = $editRules;
return $this;
}
/***
* 新增/编辑 是否显示字段表单
* @param $display
* @return $this
*/
public function display(Boolean $display)
{
$this->attributes->display = $display;
return $this;
}
/**
* 新增是否显示字段表单
* @param $addDisplay
* @return $this
*/
public function addDisplay(Boolean $addDisplay)
{
$this->attributes->addDisplay = $addDisplay;
return $this;
}
/***
* 编辑是否显示字段表单
* @param $editDisplay
* @return $this
*/
public function editDisplay(Boolean $editDisplay)
{
$this->attributes->editDisplay = $editDisplay;
return $this;
}
/**
* 新增/编辑 是否禁用字段表单
* @param Boolean $disabled
* @return $this
*/
public function disabled(Boolean $disabled)
{
$this->attributes->disabled = $disabled;
return $this;
}
/**
* 新增是否禁用字段表单
* @param Boolean $addDisabled
* @return $this
*/
public function addDisabled(Boolean $addDisabled)
{
$this->attributes->addDisabled = $addDisabled;
return $this;
}
/**
* 编辑是否禁用字段表单
* @param Boolean $editDisabled
* @return $this
*/
public function editDisabled(Boolean $editDisabled)
{
$this->attributes->editDisabled = $editDisabled;
return $this;
}
/**
* 新增/编辑 是否只读字段表单
* @param Boolean $readonly
* @return $this
*/
public function readonly(Boolean $readonly)
{
$this->attributes->readonly = $readonly;
return $this;
}
/***
* 新增是否只读字段表单
* @param Boolean $addReadonly
* @return $this
*/
public function addReadonly(Boolean $addReadonly)
{
$this->attributes->addReadonly = $addReadonly;
return $this;
}
/***
* 编辑是否只读字段表单
* @param Boolean $editReadonly
* @return $this
*/
public function editReadonly(Boolean $editReadonly)
{
$this->attributes->editReadonly = $editReadonly;
return $this;
}
/***
* 字段新增时默认值
* @param Boolean $addDefaultValue
* @return $this
*/
public function addDefaultValue($addDefaultValue)
{
$this->attributes->addDefaultValue = $addDefaultValue;
return $this;
}
/***
* 字段编辑时默认值
* @param $editDefaultValue
* @return $this
*/
public function editDefaultValue($editDefaultValue)
{
$this->attributes->editDefaultValue = $editDefaultValue;
return $this;
}
/***
* 使用字典数据
* @param array $arr
* @return $this
*/
public function dict(array $dict)
{
$this->attributes->dict = $dict;
return $this;
}
/***
* 设置字段搜索的默认值
* @param $searchDefaultValue
* @return $this
*/
public function searchDefaultValue($searchDefaultValue)
{
$this->attributes->searchDefaultValue = $searchDefaultValue;
return $this;
}
/**
* 设置搜索字段的表单描述
* @param $searchPlaceholder
* @return $this
*/
public function searchPlaceholder(string $searchPlaceholder)
{
$this->attributes->searchPlaceholder = $searchPlaceholder;
return $this;
}
/**
* 扩展字典
* @param $extra
* @return $this
*/
public function extra($extra)
{
$this->attributes->extra = $extra;
return $this;
}
/***
* 字段交互控制
* @param $js
* @return $this
*/
public function control($js)
{
$this->attributes->control = $js;
return $this;
}
/***
* 设置表头
* @param array $children
* @return $this
*/
public function children(array $children)
{
$this->attributes->children = $children;
return $this;
}
/***
* 子表单formType为 children-form 时生效
* @param array $FormList
* @return $this
*/
public function FormList(array $formList)
{
$this->attributes->FormList = $formList;
return $this;
}
/***
* 默认空行formType为 children-form 时生效
* @param int $emptyRow
* @return $this
*/
public function emptyRow(int $emptyRow = 0)
{
$this->attributes->emptyRow = $emptyRow;
return $this;
}
/***
* @param $jsx 模板语法自定义
* @return $this
*/
public function customRender($jsx)
{
$this->attributes->customRender = $jsx;
return $this;
}
/**
* 设置数据联动
* @param array $cascaderItem
* @return $this
*/
public function cascaderItem(array $cascaderItem)
{
$this->attributes->cascaderItem = $cascaderItem;
return $this;
}
/**
* column 的 key
* @param string $columnKey
* @return $this
*/
public function columnKey($columnKey)
{
$this->attributes->columnKey = $columnKey;
return $this;
}
/**
* 表头提示内容
* @param string $help
* @return $this
*/
public function help($help)
{
$this->attributes->help = $help;
return $this;
}
/**
* 前缀
* @param string $itemPrefix
* @return $this
*/
public function itemPrefix(string $itemPrefix)
{
$this->attributes->itemPrefix = $itemPrefix;
return $this;
}
/**
* 后缀
* @param string $itemSuffix
* @return $this
*/
public function itemSuffix(string $itemSuffix)
{
$this->attributes->itemSuffix = $itemSuffix;
return $this;
}
/**
* @param $displayComponentAttrs
* @return $this
*/
private function displayComponentAttrs($displayComponentAttrs)
{
$this->attributes->displayComponentAttrs = $displayComponentAttrs;
return $this;
}
}