<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/19
* Time: 10:34
*/
namespace App\Admin\Extensions\Form\Tabs;
use Encore\Admin\Form;
use Encore\Admin\Form\Field;
class Tabs extends Field
{
protected $view = 'admin.form.tabs';
protected $_tabs = [];
protected $_clickEventFunc = '';
protected $fieldName = '';
protected $_max_height = '100%';
protected $_max_width = '100%';
protected $_min_height = '100%';
protected $_min_width = '100%';
protected $width = [
'label' => 5,
'field' => 7
];
public function __construct(string $column = '', array $arguments = [])
{
$this->checkViewFile();
parent::__construct($column, $arguments);
}
public function setWidth($field = 8, $label = 4): Field
{
$label = 4;
return parent::setWidth($field, $label); // TODO: Change the autogenerated stub
}
public function getViewElementClasses(): array
{
if ($this->horizontal) {
return [
'label' => "col-sm-{$this->width['label']} {$this->getLabelClass()}",
'field' => "col-sm-{$this->width['field']}",
'form-group' => $this->getGroupClass(true),
];
}
return ['label' => $this->getLabelClass(), 'field' => '', 'form-group' => ''];
}
protected function checkViewFile()
{
$dirPath = resource_path('views/admin/form');
$filePath = $dirPath . '/tabs.blade.php';
$originPath = __DIR__ . '/tabs.blade.php';
if (!is_file($filePath) || filemtime($originPath) > filemtime($filePath)) {
if (!is_dir($dirPath)) {
mkdir($dirPath, 0777, true);
}
file_put_contents($filePath, file_get_contents($originPath));
}
return $this;
}
/**
* @param array $arguments
* @return string
*/
public function formatLabel($arguments = []): string
{
if (isset($arguments[0]) && is_callable($arguments[0])) {
$column = is_array($this->column) ? current($this->column) : $this->column;
$this->_tabs[] = [
'tabName' => $column,
'closure' => $arguments[0],
];
return ucfirst($column);
} else {
return parent::formatLabel($arguments); // TODO: Change the autogenerated stub
}
}
/**
* @param $fieldName
* @return $this
*/
public function setFieldName($fieldName)
{
$this->fieldName = $fieldName;
return $this;
}
/**
* @param $eventFun
* @return $this
*/
public function clickEvent($eventFun)
{
$this->_clickEventFunc = $eventFun;
return $this;
}
/**
* @param $title
* @param \Closure $closure
* @return $this
*/
public function addTab($title, \Closure $closure)
{
$this->_tabs[] = [
'tabName' => $title,
'closure' => $closure,
];
return $this;
}
/**
* 设置最大宽高
* @param $width
* @param $height
* @return $this
*/
public function max($width, $height)
{
$this->_max_height = $height;
$this->_max_width = $width;
return $this;
}
/**
* 设置最新宽高
* @param $width
* @param $height
* @return $this
*/
public function min($width, $height)
{
$this->_min_height = $height;
$this->_min_width = $width;
return $this;
}
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
*/
public function render()
{
$tabs = [];
$activeTab = '';
$activeClass = '';
foreach ($this->_tabs as $k => $tab) {
$form = new Form($this->form->model());
$closure = $tab['closure'];
call_user_func($closure, $form);
$content = $form->render();
$reg = '/<form[^>]*>([\s\S]*)<div\s*class="box-footer"\s*>/';
preg_match($reg, $content, $result);
$tabs[] = [
'tabName' => $tab['tabName'],
'content' => $result[1] ?? '',
'class' => md5($tab['tabName']),
];
if ($k == 0) {
$activeTab = $tab['tabName'];
$activeClass = md5($tab['tabName']);
}
}
// dd($this->variables());
$this->addVariables([
'tabs' => $tabs,
'activeTab' => $activeTab,
'activeClass' => $activeClass,
'eventFunc' => $this->_clickEventFunc,
'fieldName' => $this->fieldName,
'maxHeight' => $this->_max_height,
'maxWidth' => $this->_max_width,
'minHeight' => $this->_min_height,
'minWidth' => $this->_min_width,
]);
return parent::render(); // TODO: Change the autogenerated stub
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
laravel-admin:form表单tab标签切换组件.rar
共2个文件
php:2个
需积分: 50 9 下载量 178 浏览量
2021-03-01
15:51:39
上传
评论
收藏 2KB RAR 举报
温馨提示
该组件仿造laravel-admin form表单自带的tab组件。 区别在于laravel-admin自带的tab标签切换组件只能出现form表单的顶部所有的输入只能在tab标签内; 而该组件允许tab标签切换在form表单的任何位置,与代码顺序相关。
资源详情
资源评论
资源推荐
收起资源包目录
Tabs.rar (2个子文件)
Tabs
Tabs.php 5KB
tabs.blade.php 3KB
共 2 条
- 1
wenruns
- 粉丝: 23
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0