- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace crmeb\form\components;
|
|
|
|
|
|
use crmeb\form\BuildInterface;
|
|
|
|
/**
|
|
* Tabs 组件
|
|
* Class Tabs
|
|
* @package crmeb\form\components
|
|
*/
|
|
class Tabs implements BuildInterface
|
|
{
|
|
|
|
//组件名
|
|
const NAME = 'tabs';
|
|
|
|
/**
|
|
* 规则
|
|
* @var array[]
|
|
*/
|
|
protected $rule = [
|
|
'options' => []
|
|
];
|
|
|
|
/**
|
|
* Tabs constructor.
|
|
* @param array $options
|
|
*/
|
|
public function __construct(array $options = [])
|
|
{
|
|
$this->rule['options'] = $options;
|
|
}
|
|
|
|
/**
|
|
* 添加单个选项卡组件群
|
|
* @param string $label
|
|
* @param array $components
|
|
* @return $this
|
|
*/
|
|
public function option(string $label, array $components = [])
|
|
{
|
|
$this->rule['options'][] = ['label' => $label, 'componentsModel' => $components];
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return array|array[]
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
$this->rule['name'] = self::NAME;
|
|
$options = [];
|
|
foreach ($this->rule['options'] as $option) {
|
|
$data = ['label' => $option['label'], 'componentsModel' => []];
|
|
foreach ($option['componentsModel'] as $item) {
|
|
if ($item instanceof BuildInterface) {
|
|
$data['componentsModel'][] = $item->toArray();
|
|
}
|
|
}
|
|
$options[] = $data;
|
|
}
|
|
$this->rule['options'] = $options;
|
|
return $this->rule;
|
|
}
|
|
}
|