mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
自动生成CURD导出生成关联查询
This commit is contained in:
@@ -224,7 +224,7 @@ class BuildCurdService
|
||||
* 表单类型
|
||||
* @var array
|
||||
*/
|
||||
protected $formTypeArray = ['text', 'image', 'images', 'file', 'files', 'select', 'switch', 'date', 'editor', 'textarea', 'checkbox', 'radio', 'relation', 'table', 'city','tag'];
|
||||
protected $formTypeArray = ['text', 'image', 'images', 'file', 'files', 'select', 'switch', 'date', 'editor', 'textarea', 'checkbox', 'radio', 'relation', 'table', 'city', 'tag'];
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
@@ -1060,6 +1060,7 @@ class BuildCurdService
|
||||
$controllerFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}controller{$this->DS}{$this->controllerFilename}.php";
|
||||
if (empty($this->relationArray)) {
|
||||
$controllerIndexMethod = '';
|
||||
$controllerExportMethod = '';
|
||||
} else {
|
||||
$relationCode = '';
|
||||
foreach ($this->relationArray as $key => $val) {
|
||||
@@ -1072,6 +1073,12 @@ class BuildCurdService
|
||||
'relationIndexMethod' => $relationCode,
|
||||
]
|
||||
);
|
||||
$controllerExportMethod = $this->replaceTemplate(
|
||||
$this->getTemplate("controller{$this->DS}exportMethod"),
|
||||
[
|
||||
'relationIndexMethod' => trim($relationCode),
|
||||
]
|
||||
);
|
||||
}
|
||||
$selectList = '';
|
||||
|
||||
@@ -1091,6 +1098,7 @@ class BuildCurdService
|
||||
'controllerAnnotation' => $this->tableComment,
|
||||
'modelFilename' => "\app\admin\model\\{$modelFilenameExtend}",
|
||||
'indexMethod' => $controllerIndexMethod,
|
||||
'exportMethod' => $controllerExportMethod,
|
||||
'selectList' => $selectList,
|
||||
]
|
||||
);
|
||||
@@ -1276,7 +1284,7 @@ class BuildCurdService
|
||||
} elseif ($val['formType'] == 'city') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}city";
|
||||
$define = $this->buildCityView($field, $val, $val['default']);
|
||||
}elseif ($val['formType'] == 'tag') {
|
||||
} elseif ($val['formType'] == 'tag') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
||||
}
|
||||
|
||||
@@ -1375,7 +1383,7 @@ class BuildCurdService
|
||||
} elseif ($val['formType'] == 'city') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}city";
|
||||
$define = $this->buildCityView($field, $val, $value);
|
||||
}elseif ($val['formType'] == 'tag') {
|
||||
} elseif ($val['formType'] == 'tag') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
||||
}
|
||||
|
||||
|
||||
@@ -24,4 +24,7 @@ class {{controllerName}} extends AdminController
|
||||
}
|
||||
|
||||
{{indexMethod}}
|
||||
|
||||
|
||||
{{exportMethod}}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="导出")
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
list($page, $limit, $where) = $this->buildTableParames();
|
||||
|
||||
|
||||
$this->model = $this->model{{relationIndexMethod}};
|
||||
|
||||
$fields = $this->request->param('fields', '{}', null);
|
||||
$image_fields = $this->request->param('image_fields', '{}', null);
|
||||
$select_fields = $this->request->param('select_fields', '{}', null);
|
||||
$date_fields = $this->request->param('date_fields', '{}', null);
|
||||
|
||||
$fields = json_decode($fields, true);
|
||||
$image_fields = json_decode($image_fields, true);
|
||||
$select_fields = json_decode($select_fields, true);
|
||||
$date_fields = json_decode($date_fields, true);
|
||||
|
||||
$content = \app\common\tools\ExcelTools::exportModel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
|
||||
|
||||
return download($content, $this->model->getName() . date('YmdHis') . '.xlsx', true);
|
||||
}
|
||||
@@ -12,10 +12,10 @@ use think\console\Output;
|
||||
class Version extends Command
|
||||
{
|
||||
|
||||
const VERSION = 'v2.0.3';
|
||||
const VERSION = 'v2.0.4';
|
||||
|
||||
const COMMENT = [
|
||||
'优化导出功能,兼容自定义参数、兼容关联查询用法',
|
||||
'自动生成CURD导出生成关联查询',
|
||||
];
|
||||
|
||||
protected function configure()
|
||||
|
||||
@@ -72,8 +72,8 @@ class ExcelTools
|
||||
}
|
||||
} else if (array_key_exists($field_key, $select_fields)) {
|
||||
// 需要设置选项
|
||||
|
||||
$cel = $select_fields[$field_key][$value];
|
||||
|
||||
$cel = $select_fields[$field_key][$value] ?? '';
|
||||
} else if (in_array($field_key, $date_fields)) {
|
||||
if (empty($value)) {
|
||||
$cel = '';
|
||||
|
||||
Reference in New Issue
Block a user