add:新增excel的导入导出组件

This commit is contained in:
JaguarJack 2021-04-24 20:30:28 +08:00
parent f67a4f33d5
commit 48c41f7948
4 changed files with 170 additions and 2 deletions

View File

@ -30,9 +30,9 @@ trait ComponentsTrait
* @param null $updateFields
* @return HeaderItem
*/
public function withSwitchComponent($updateFields = null): HeaderItem
public function withSwitchComponent(array $options = [], $updateFields = null): HeaderItem
{
return $this->component('switch_', $updateFields ? : $this->attributes['prop']);
return $this->component('switch_', $updateFields ? : $this->attributes['prop'], $options);
}
/**

View File

@ -0,0 +1,109 @@
<?php
namespace catcher\library\table;
/**
*
* @time 2021年04月21日
*/
class Excel
{
protected static $label;
protected $sheets = [];
/**
* name
*
* @time 2021年04月21日
* @param string $name
* @return $this
*/
public function prop(string $name): Excel
{
$this->sheets['prop'] = $name;
return $this;
}
/**
* label
*
* @time 2021年04月21日
* @param string $label
* @return $this
*/
protected function label(string $label): Excel
{
$this->sheets['label'] = $label;
return $this;
}
/**
* options
*
* @time 2021年04月21日
* @param array $options
* @return $this
*/
public function options(array $options): Excel
{
$this->sheets['options'] = $options;
return $this;
}
/**
* 导入
*
* @time 2021年04月22日
* @param bool $import
* @return $this
*/
public function import(bool $import = true): Excel
{
$this->sheets['import'] = $import;
return $this;
}
/**
* 导出
*
* @time 2021年04月22日
* @param bool $export
* @return $this
*/
public function export(bool $export = true): Excel
{
$this->sheets['export'] = $export;
return $this;
}
/**
* 渲染
*
* @time 2021年04月21日
* @return array
*/
public function render(): array
{
return $this->sheets;
}
/**
* 静态访问
*
* @time 2021年04月21日
* @param $method
* @param $params
* @return false|mixed
*/
public static function __callStatic($method, $params)
{
return call_user_func_array([new self(), $method], $params);
}
}

View File

@ -73,6 +73,31 @@ class HeaderItem
return $this->width(50)->type('selection');
}
/**
* dont export
*
* @time 2021年04月22日
* @return $this
*/
public function dontExport(): HeaderItem
{
$this->attributes['export'] = false;
return $this;
}
/**
* dont import
*
* @time 2021年04月22日
* @return $this
*/
public function dontImport(): HeaderItem
{
$this->attributes['import'] = false;
return $this;
}
/**
* 动态访问

View File

@ -98,6 +98,21 @@ class Table
*/
protected $forceUpdate = false;
/**
* @var array
*/
protected $excel = [];
/**
* 导出 excel 所使用 model
*
* @var string
*/
protected $usedModel;
/**
* Table constructor.
* @param string $ref
@ -167,6 +182,25 @@ class Table
return $this;
}
/**
* excel 信息
*
* @time 2021年04月21日
* @param array $excel
* @param string $usedModel
* @return $this
*/
public function withUsedModelAndExcel(string $usedModel, array $excel): Table
{
foreach ($excel as $e) {
$this->excel[] = $e->render();
}
$this->usedModel = $usedModel;
return $this;
}
/**
* set
*