From 48c41f79488c614ce09bc067dc46412dcd52b451 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 24 Apr 2021 20:30:28 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9Eexcel=E7=9A=84=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catcher/library/table/ComponentsTrait.php | 4 +- extend/catcher/library/table/Excel.php | 109 ++++++++++++++++++ extend/catcher/library/table/HeaderItem.php | 25 ++++ extend/catcher/library/table/Table.php | 34 ++++++ 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 extend/catcher/library/table/Excel.php diff --git a/extend/catcher/library/table/ComponentsTrait.php b/extend/catcher/library/table/ComponentsTrait.php index b708b48..4a0bc1c 100644 --- a/extend/catcher/library/table/ComponentsTrait.php +++ b/extend/catcher/library/table/ComponentsTrait.php @@ -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); } /** diff --git a/extend/catcher/library/table/Excel.php b/extend/catcher/library/table/Excel.php new file mode 100644 index 0000000..092d780 --- /dev/null +++ b/extend/catcher/library/table/Excel.php @@ -0,0 +1,109 @@ +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); + } +} \ No newline at end of file diff --git a/extend/catcher/library/table/HeaderItem.php b/extend/catcher/library/table/HeaderItem.php index be65120..b0d84b8 100644 --- a/extend/catcher/library/table/HeaderItem.php +++ b/extend/catcher/library/table/HeaderItem.php @@ -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; + } /** * 动态访问 diff --git a/extend/catcher/library/table/Table.php b/extend/catcher/library/table/Table.php index 4a4c107..c63ffeb 100644 --- a/extend/catcher/library/table/Table.php +++ b/extend/catcher/library/table/Table.php @@ -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 *