mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 10:02:49 +08:00
优化导出,开始图片导出;
This commit is contained in:
@@ -121,8 +121,11 @@ trait Curd
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$fields = $this->request->param('fields', '{}', null);
|
||||
$image_fields = $this->request->param('image_fields', '{}', null);
|
||||
|
||||
$fields = json_decode($fields, true);
|
||||
$image_fields = json_decode($image_fields, true);
|
||||
|
||||
|
||||
$write_col = 1;
|
||||
$write_line = 1;
|
||||
@@ -134,7 +137,7 @@ trait Curd
|
||||
}
|
||||
|
||||
$this->model
|
||||
->where($where)->chunk(100, function ($list) use ($sheet, &$write_line, $fields) {
|
||||
->where($where)->chunk(100, function ($list) use ($sheet, &$write_line, $fields, $image_fields) {
|
||||
foreach ($list as $list_index => $item) {
|
||||
$write_line++;
|
||||
$write_col = 1;
|
||||
@@ -142,9 +145,36 @@ trait Curd
|
||||
foreach ($fields as $field_key => $field_name) {
|
||||
$col_key = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($write_col);
|
||||
|
||||
$value = \think\helper\Arr::get($item, $field_key);
|
||||
$cel = '';
|
||||
|
||||
$sheet->setCellValue($col_key . $write_line, $value);
|
||||
$value = \think\helper\Arr::get($item, $field_key);
|
||||
|
||||
if (in_array($field_key, $image_fields)) {
|
||||
// 是图片
|
||||
$cel = $value;
|
||||
|
||||
try {
|
||||
|
||||
// $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
|
||||
// $drawing->setName($field_name);
|
||||
// $drawing->setDescription($field_key);
|
||||
// $drawing->setPath($value);
|
||||
// $drawing->setHeight(36);
|
||||
|
||||
// $drawing->setCoordinates($col_key . $write_line);
|
||||
// $drawing->setWorksheet($sheet);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$message = $th->getMessage();
|
||||
|
||||
$cel .= "\n" . $message;
|
||||
|
||||
}
|
||||
} else {
|
||||
$cel = $value;
|
||||
}
|
||||
|
||||
$sheet->setCellValue($col_key . $write_line, $cel);
|
||||
$write_col++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
||||
{ field: 'sort', width: 80, title: '排序', edit: 'text' },
|
||||
{ field: 'cate.title', minWidth: 80, title: '商品分类', },
|
||||
{ field: 'cate.id', minWidth: 80, title: '商品分类', hide: true, defaultSearchValue: ea.getQueryVariable('cate_id', '') },
|
||||
{ field: 'cate.image', minWidth: 80, title: '分类图片', search: false, templet: ea.table.image },
|
||||
{ field: 'title', minWidth: 80, title: '商品名称', },
|
||||
{ field: 'logo', minWidth: 80, title: '分类图片', search: false, templet: ea.table.image },
|
||||
{ field: 'logo', minWidth: 80, title: '商品图片', search: false, templet: ea.table.image },
|
||||
{ field: 'market_price', width: 100, title: '市场价', templet: ea.table.price },
|
||||
{ field: 'discount_price', width: 100, title: '折扣价', templet: ea.table.price },
|
||||
{ field: 'total_stock', width: 100, title: '库存统计' },
|
||||
|
||||
@@ -968,12 +968,20 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
}
|
||||
},
|
||||
listenExport: function (options) {
|
||||
|
||||
|
||||
var exportFields = {};
|
||||
|
||||
var imageFields = [];
|
||||
|
||||
options.cols[0].forEach(col => {
|
||||
if (col.field) {
|
||||
|
||||
exportFields[col.field] = col.title;
|
||||
|
||||
if(col.templet == admin.table.image){
|
||||
imageFields.push(col.field)
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -982,7 +990,6 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
var tableId = $(this).attr('data-table-export'),
|
||||
url = $(this).attr('data-url');
|
||||
|
||||
|
||||
var searchVals = form.val(tableId + '_filter_form');
|
||||
|
||||
var dataField = searchVals;
|
||||
@@ -1001,7 +1008,8 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
var searchQuery = {
|
||||
filter: JSON.stringify(formatFilter),
|
||||
op: JSON.stringify(formatOp),
|
||||
fields: JSON.stringify(exportFields)
|
||||
fields: JSON.stringify(exportFields),
|
||||
image_fields: JSON.stringify(imageFields),
|
||||
}
|
||||
|
||||
var query = $.param(searchQuery);
|
||||
|
||||
Reference in New Issue
Block a user