'id', 'symbol' => '<' ]; public function __construct(array $params = []) { $this->params = $params; $this->init(); } protected function init() { } public function query() { return null; } public function array(): array { return []; } public function collection(): Collection { return new Collection([]); } /** * 导出时每行的数据 */ public function map($item): array { return []; } /** * 导出时的表头 */ public function headings(): array { return []; } public function summary(): array { return []; } public function rangeQueryItems($items) { return $items; } /** * 导出时文件后缀 */ public function getExtension() { /* $extensions = [ Excel::XLSX => '.xlsx', Excel::CSV => '.csv', // Excel::TSV => '.tsv', Excel::ODS => '.ods', Excel::XLS => '.xls', Excel::HTML => '.html', Excel::MPDF => '.pdf', Excel::DOMPDF => '.pdf', Excel::TCPDF => '.pdf', ]; return $extensions[$this->writerType] ?? '.xlsx'; */ return '.xlsx'; } public function generateFileName() { $uniqueCode = Excel::generateUniqueCode($this->params, '', 8); if (!$this->name) { $this->fileName = date('YmdHis') . $uniqueCode; } else { $this->fileName = date('YmdHis') . $uniqueCode . '_' . $this->name; } } protected function generateFilePath() { if (!$this->fileName) { $this->generateFileName(); } $excelPath = getRoutePrefix() . '/excels/'; if (!is_dir($this->basePath . $excelPath)) { mkdir($this->basePath . $excelPath); } $this->fileUrl = $excelPath . $this->fileName. $this->getExtension(); $this->filePath = $this->basePath . $this->fileUrl; } public function getMode() { return self::MODE_QUERY; } protected function prepare() { } public function store() { $this->prepare(); $this->generateFilePath(); $exporter = new Exporter(); $exporter->store($this, $this->filePath); } /** * 返回设置单元格样式的函数 function(Export, Worksheet) */ public function getStyleSetting(): ?Closure { return null; } public function setFileName($fileName) { return $this->fileName = $fileName; } public function getFileName() { return $this->fileName; } public function getFileUrl() { return $this->fileUrl; } protected function check() { } public static function identity() { return Str::encrypt(static::class); } public static function getClassByIdentity($identity) { return Str::decrypt($identity); } }