refactor: 修改各模块导出

This commit is contained in:
2025-04-02 16:23:29 +08:00
parent 7b8d0b085f
commit 8eaa5559ef
11 changed files with 14 additions and 13 deletions

View File

@@ -115,13 +115,14 @@ if (!function_exists('xlsx_writer')) {
flush(); flush();
ob_flush(); ob_flush();
if ($filename == '') $filename = date('YmdHis'); if ($filename == '') $filename = date('YmdHis');
$filename = urlencode($filename);
// 文件写入缓冲区 // 文件写入缓冲区
\PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx')->save($output); \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx')->save($output);
// 从缓冲区获取导出文件并通过Response返回解决thinkphp框架的Response无法获取设置的header问题 // 从缓冲区获取导出文件并通过Response返回解决thinkphp框架的Response无法获取设置的header问题
$file_data = ob_get_clean(); $file_data = ob_get_clean();
$response = \think\Response::create($file_data)->header([ $response = \think\Response::create($file_data)->header([
'Access-Control-Expose-Headers' => 'Content-Disposition', 'Access-Control-Expose-Headers' => 'Content-Disposition',
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; Charset=UTF-8', 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8',
'Content-Disposition' => 'attachment;filename=' . $filename . '.xlsx', 'Content-Disposition' => 'attachment;filename=' . $filename . '.xlsx',
'Cache-Control' => 'max-age=0' 'Cache-Control' => 'max-age=0'
]); ]);

View File

@@ -93,7 +93,7 @@ class Agent
$agents = $this->getAgentExportData(); $agents = $this->getAgentExportData();
// 导出 // 导出
return xlsx_writer($agents, $schema); return xlsx_writer($agents, $schema, '代理商申请列表' . date('YmdHis'));
} }
// 获取要导出的代理商数据 // 获取要导出的代理商数据
private function getAgentExportData() private function getAgentExportData()

View File

@@ -217,7 +217,7 @@ class Article
$data = $this->getExportArticleData(); $data = $this->getExportArticleData();
// 导出 // 导出
return xlsx_writer($data, $schema); return xlsx_writer($data, $schema, '文章列表' . date('YmdHis'));
} }
// 获取文章导出数据 // 获取文章导出数据

View File

@@ -105,7 +105,7 @@ class ArticleLeaveMessage
$data = $this->getExportMessageData(); $data = $this->getExportMessageData();
// 导出 // 导出
return xlsx_writer($data, $schema); return xlsx_writer($data, $schema, '文章评论列表' . date('YmdHis'));
} }
private function getExportMessageData() private function getExportMessageData()
{ {

View File

@@ -196,7 +196,7 @@ class BannerItem
$banner_items = $this->getBannerExportData(); $banner_items = $this->getBannerExportData();
// 导出 // 导出
return xlsx_writer($banner_items, $schema); return xlsx_writer($banner_items, $schema, 'banner列表' . date('YmdHis'));
} }
// 获取导出数据 // 获取导出数据
private function getBannerExportData() private function getBannerExportData()

View File

@@ -86,7 +86,7 @@ class BulkPurchaseInquiry
$data = $this->getExportData(); $data = $this->getExportData();
// 导出 // 导出
return xlsx_writer($data, $schema); return xlsx_writer($data, $schema, '批量购买询盘列表' . date('YmdHis'));
} }
// 获取要导出的采购询盘数据 // 获取要导出的采购询盘数据
private function getExportData() private function getExportData()

View File

@@ -40,19 +40,19 @@ class LeaveMessage
public function export() public function export()
{ {
$schema = [ $schema = [
'created_at' => '提交时间',
'id' => 'ID', 'id' => 'ID',
'name' => '姓名', 'name' => '姓名',
'email' => '邮箱', 'email' => '邮箱',
'ip' => 'IP', 'ip' => 'IP',
'content' => '留言内容', 'content' => '留言内容'
'created_at' => '提交时间'
]; ];
// 获取留言导出数据 // 获取留言导出数据
$msgs = $this->getLeaveMessageExportData(); $msgs = $this->getLeaveMessageExportData();
// 导出 // 导出
return xlsx_writer($msgs, $schema); return xlsx_writer($msgs, $schema, '联系我们列表' . date('YmdHis'));
} }
// 获取留言导出数据 // 获取留言导出数据
private function getLeaveMessageExportData() private function getLeaveMessageExportData()

View File

@@ -433,7 +433,7 @@ class Menu
$data = $this->getExportMenuData(); $data = $this->getExportMenuData();
// 导出 // 导出
return xlsx_writer($data, $schema, '', 'php://output', 'file'); return xlsx_writer($data, $schema, '菜单列表' . date('YmdHis'), 'php://output', 'file');
} }
private function getExportMenuData() private function getExportMenuData()
{ {

View File

@@ -339,7 +339,7 @@ class Product
$data = $this->getExportProductData(); $data = $this->getExportProductData();
// 导出 // 导出
return xlsx_writer($data, $schema); return xlsx_writer($data, $schema, '产品列表' . date('YmdHis'));
} }
// 获取产品导出数据 // 获取产品导出数据
private function getExportProductData() private function getExportProductData()

View File

@@ -263,7 +263,7 @@ class ProductPurchaseLink
$data = $this->getExportLinkData(); $data = $this->getExportLinkData();
/// 导出 /// 导出
return xlsx_writer($data, $schema); return xlsx_writer($data, $schema, '产品购买链接' . date('YmdHis'));
} }
private function getExportLinkData() private function getExportLinkData()
{ {

View File

@@ -199,7 +199,7 @@ class Video
$data = $this->getExportVideoData(); $data = $this->getExportVideoData();
// 导出 // 导出
return xlsx_writer($data, $schema); return xlsx_writer($data, $schema, '视频列表' . date('YmdHis'));
} }
private function getExportVideoData() private function getExportVideoData()
{ {