mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
优化图片加载已修复fixed表现;优化导出功能,使导出效果与页面表格一致;
This commit is contained in:
@@ -9,7 +9,11 @@ use app\admin\traits\Curd;
|
||||
use app\common\controller\AdminController;
|
||||
use EasyAdmin\annotation\ControllerAnnotation;
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use think\App;
|
||||
use think\helper\Arr;
|
||||
|
||||
/**
|
||||
* Class Goods
|
||||
@@ -83,5 +87,5 @@ class Goods extends AdminController
|
||||
$this->assign('row', $row);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
namespace app\admin\traits;
|
||||
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use EasyAdmin\tool\CommonTool;
|
||||
use jianyan\excel\Excel;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 后台CURD复用
|
||||
@@ -67,7 +65,7 @@ trait Curd
|
||||
try {
|
||||
$save = $this->model->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败:'.$e->getMessage());
|
||||
$this->error('保存失败:' . $e->getMessage());
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
@@ -118,26 +116,48 @@ trait Curd
|
||||
public function export()
|
||||
{
|
||||
list($page, $limit, $where) = $this->buildTableParames();
|
||||
$tableName = $this->model->getName();
|
||||
$tableName = CommonTool::humpToLine(lcfirst($tableName));
|
||||
$prefix = config('database.connections.mysql.prefix');
|
||||
$dbList = Db::query("show full columns from {$prefix}{$tableName}");
|
||||
$header = [];
|
||||
foreach ($dbList as $vo) {
|
||||
$comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
|
||||
if (!in_array($vo['Field'], $this->noExportFields)) {
|
||||
$header[] = [$comment, $vo['Field']];
|
||||
}
|
||||
}
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->limit(100000)
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
$fileName = time();
|
||||
|
||||
return Excel::exportData($list, $header, $fileName, 'xlsx',);
|
||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$fields = $this->request->param('fields', '{}', null);
|
||||
|
||||
$fields = json_decode($fields, true);
|
||||
|
||||
$write_col = 1;
|
||||
$write_line = 1;
|
||||
foreach ($fields as $field_key => $field_name) {
|
||||
$col_key = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($write_col);
|
||||
$sheet->setCellValue($col_key . $write_line, $field_name);
|
||||
|
||||
$write_col++;
|
||||
}
|
||||
|
||||
$this->model
|
||||
->where($where)->chunk(100, function ($list) use ($sheet, &$write_line, $fields) {
|
||||
foreach ($list as $list_index => $item) {
|
||||
$write_line++;
|
||||
$write_col = 1;
|
||||
|
||||
foreach ($fields as $field_key => $field_name) {
|
||||
$col_key = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($write_col);
|
||||
|
||||
$value = \think\helper\Arr::get($item, $field_key);
|
||||
|
||||
$sheet->setCellValue($col_key . $write_line, $value);
|
||||
$write_col++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||
|
||||
ob_start();
|
||||
$writer->save('php://output');
|
||||
$content = ob_get_contents();
|
||||
ob_clean();
|
||||
|
||||
return download($content, $this->model->getName() . time() . '.xlsx', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,5 +189,4 @@ trait Curd
|
||||
}
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
"qcloud/cos-sdk-v5": "^2.0",
|
||||
"qiniu/php-sdk": "^7.2",
|
||||
"alibabacloud/client": "^1.5",
|
||||
"jianyan74/php-excel": "^1.0",
|
||||
"zhongshaofa/easy-admin": "^1.0.2",
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/guzzle": "^7.4"
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"phpoffice/phpspreadsheet": "^1.22"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
||||
70
composer.lock
generated
70
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b165f907f620d029664c50085142cb1a",
|
||||
"content-hash": "c3e52378111fa626fade09fbbe489d34",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adbario/php-dot-notation",
|
||||
@@ -1160,60 +1160,6 @@
|
||||
],
|
||||
"time": "2021-10-07T12:57:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jianyan74/php-excel",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jianyan74/php-excel.git",
|
||||
"reference": "347e80c98a39d9743c9d7582497f891b90d5e5cf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jianyan74/php-excel/zipball/347e80c98a39d9743c9d7582497f891b90d5e5cf",
|
||||
"reference": "347e80c98a39d9743c9d7582497f891b90d5e5cf",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"phpoffice/phpspreadsheet": "^1.3"
|
||||
},
|
||||
"type": "extension",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"jianyan\\excel\\": "./src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "jianyan74"
|
||||
}
|
||||
],
|
||||
"description": "php excel 导入导出",
|
||||
"keywords": [
|
||||
"csv",
|
||||
"excel",
|
||||
"html",
|
||||
"jianyan74",
|
||||
"xls",
|
||||
"xlsx"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/jianyan74/php-excel/issues",
|
||||
"source": "https://github.com/jianyan74/php-excel/tree/1.0.2"
|
||||
},
|
||||
"time": "2020-09-04T06:16:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/flysystem",
|
||||
"version": "1.1.9",
|
||||
@@ -1764,16 +1710,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpspreadsheet",
|
||||
"version": "1.21.0",
|
||||
"version": "1.22.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
|
||||
"reference": "1a359d2ccbb89c05f5dffb32711a95f4afc67964"
|
||||
"reference": "3a9e29b4f386a08a151a33578e80ef1747037a48"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/1a359d2ccbb89c05f5dffb32711a95f4afc67964",
|
||||
"reference": "1a359d2ccbb89c05f5dffb32711a95f4afc67964",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/3a9e29b4f386a08a151a33578e80ef1747037a48",
|
||||
"reference": "3a9e29b4f386a08a151a33578e80ef1747037a48",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@@ -1810,7 +1756,7 @@
|
||||
"dompdf/dompdf": "^1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.2",
|
||||
"jpgraph/jpgraph": "^4.0",
|
||||
"mpdf/mpdf": "^8.0",
|
||||
"mpdf/mpdf": "8.0.17",
|
||||
"phpcompatibility/php-compatibility": "^9.3",
|
||||
"phpstan/phpstan": "^1.1",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
@@ -1868,9 +1814,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
|
||||
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.21.0"
|
||||
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.22.0"
|
||||
},
|
||||
"time": "2022-01-06T11:10:08+00:00"
|
||||
"time": "2022-02-18T12:57:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/cache",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@import url("../../plugs/layui-v2.5.6/css/layui.css");
|
||||
@import url("../../plugs/layui-v2.6.8/css/layui.css");
|
||||
@import url("../../plugs/font-awesome-4.7.0/css/font-awesome.min.css");
|
||||
@import url("../css/iconfont.css");
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ require.config({
|
||||
"echarts": ["plugs/echarts/echarts.min"],
|
||||
"echarts-theme": ["plugs/echarts/echarts-theme"],
|
||||
"easy-admin": ["plugs/easy-admin/easy-admin"],
|
||||
"layuiall": ["plugs/layui-v2.6.8/layui.all"],
|
||||
"layui": ["plugs/layui-v2.6.8/layui"],
|
||||
"miniAdmin": ["plugs/lay-module/layuimini/miniAdmin"],
|
||||
"miniMenu": ["plugs/lay-module/layuimini/miniMenu"],
|
||||
|
||||
@@ -300,6 +300,10 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
// 监听表格开关切换
|
||||
admin.table.listenEdit(options.init, options.layFilter, options.id, options.modifyReload);
|
||||
|
||||
admin.table.listenExport(options);
|
||||
|
||||
|
||||
|
||||
return newTable;
|
||||
},
|
||||
renderToolbar: function (data, elem, tableId, init) {
|
||||
@@ -432,7 +436,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
|
||||
$(elem).before('<fieldset id="searchFieldset_' + tableId + '" class="table-search-fieldset layui-hide">\n' +
|
||||
'<legend>条件搜索</legend>\n' +
|
||||
'<form class="layui-form layui-form-pane form-search" lay-filter="' + tableId + '">\n' +
|
||||
'<form class="layui-form layui-form-pane form-search" lay-filter="' + tableId + '_filter_form">\n' +
|
||||
formHtml +
|
||||
'<div class="layui-form-item layui-inline" style="margin-left: 115px">\n' +
|
||||
'<button type="submit" class="layui-btn layui-btn-normal" data-type="tableSearch" data-table="' + tableId + '" lay-submit lay-filter="' + tableId + '_filter"> 搜 索</button>\n' +
|
||||
@@ -756,12 +760,12 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
var value = undefined;
|
||||
}
|
||||
if (value === undefined || value === null) {
|
||||
return '<img style="max-width: ' + option.imageWidth + 'px; max-height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">';
|
||||
return '<img style="max-width: ' + option.imageWidth + 'px; height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">';
|
||||
} else {
|
||||
var values = value.split(option.imageSplit),
|
||||
valuesHtml = [];
|
||||
values.forEach((value, index) => {
|
||||
valuesHtml.push('<img style="max-width: ' + option.imageWidth + 'px; max-height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">');
|
||||
valuesHtml.push('<img style="max-width: ' + option.imageWidth + 'px; height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">');
|
||||
});
|
||||
return valuesHtml.join(option.imageJoin);
|
||||
}
|
||||
@@ -963,6 +967,59 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
});
|
||||
}
|
||||
},
|
||||
listenExport: function (options) {
|
||||
|
||||
var exportFields = {};
|
||||
|
||||
options.cols[0].forEach(col => {
|
||||
if (col.field) {
|
||||
exportFields[col.field] = col.title;
|
||||
}
|
||||
});
|
||||
|
||||
// excel导出
|
||||
$('body').on('click', '[data-table-export]', function () {
|
||||
var tableId = $(this).attr('data-table-export'),
|
||||
url = $(this).attr('data-url');
|
||||
|
||||
|
||||
var searchVals = form.val(tableId + '_filter_form');
|
||||
|
||||
var dataField = searchVals;
|
||||
|
||||
var formatFilter = {},
|
||||
formatOp = {};
|
||||
$.each(dataField, function (key, val) {
|
||||
if (val !== '') {
|
||||
formatFilter[key] = val;
|
||||
var op = $('#c-' + key).attr('data-search-op');
|
||||
op = op || '%*%';
|
||||
formatOp[key] = op;
|
||||
}
|
||||
});
|
||||
|
||||
var searchQuery = {
|
||||
filter: JSON.stringify(formatFilter),
|
||||
op: JSON.stringify(formatOp),
|
||||
fields: JSON.stringify(exportFields)
|
||||
}
|
||||
|
||||
var query = $.param(searchQuery);
|
||||
|
||||
var index = admin.msg.confirm('根据查询进行导出,确定导出?', function () {
|
||||
|
||||
toUrl = admin.url(url);
|
||||
if (toUrl.indexOf('?') < 0) {
|
||||
toUrl += '?';
|
||||
}
|
||||
toUrl += query;
|
||||
|
||||
window.open(toUrl)
|
||||
|
||||
layer.close(index);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
checkMobile: function () {
|
||||
var userAgentInfo = navigator.userAgent;
|
||||
@@ -1248,25 +1305,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
|
||||
return false;
|
||||
});
|
||||
|
||||
// excel导出
|
||||
$('body').on('click', '[data-table-export]', function () {
|
||||
var tableId = $(this).attr('data-table-export') || init.table_render_id,
|
||||
url = admin.url($(this).attr('data-url')),
|
||||
formatFilter = {},
|
||||
formatOp = {};
|
||||
$.each(form.val(tableId), function (key, val) {
|
||||
if (val !== '') {
|
||||
formatFilter[key] = val;
|
||||
var op = $('[id=\'c-' + key + '\']').attr('data-search-op');
|
||||
op = op || '%*%';
|
||||
formatOp[key] = op;
|
||||
}
|
||||
});
|
||||
var index = admin.msg.confirm('根据查询进行导出,确定导出?', function () {
|
||||
window.location = url + (url.indexOf('?') !== -1 ? '&' : '?') + 'filter=' + JSON.stringify(formatFilter) + '&op=' + JSON.stringify(formatOp);
|
||||
layer.close(index);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// 数据表格多删除
|
||||
$('body').on('click', '[data-table-delete]', function () {
|
||||
|
||||
Reference in New Issue
Block a user