mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 19:42:47 +08:00
自动生成CURD导出生成关联查询
This commit is contained in:
@@ -224,7 +224,7 @@ class BuildCurdService
|
|||||||
* 表单类型
|
* 表单类型
|
||||||
* @var array
|
* @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";
|
$controllerFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}controller{$this->DS}{$this->controllerFilename}.php";
|
||||||
if (empty($this->relationArray)) {
|
if (empty($this->relationArray)) {
|
||||||
$controllerIndexMethod = '';
|
$controllerIndexMethod = '';
|
||||||
|
$controllerExportMethod = '';
|
||||||
} else {
|
} else {
|
||||||
$relationCode = '';
|
$relationCode = '';
|
||||||
foreach ($this->relationArray as $key => $val) {
|
foreach ($this->relationArray as $key => $val) {
|
||||||
@@ -1072,6 +1073,12 @@ class BuildCurdService
|
|||||||
'relationIndexMethod' => $relationCode,
|
'relationIndexMethod' => $relationCode,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$controllerExportMethod = $this->replaceTemplate(
|
||||||
|
$this->getTemplate("controller{$this->DS}exportMethod"),
|
||||||
|
[
|
||||||
|
'relationIndexMethod' => trim($relationCode),
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$selectList = '';
|
$selectList = '';
|
||||||
|
|
||||||
@@ -1091,6 +1098,7 @@ class BuildCurdService
|
|||||||
'controllerAnnotation' => $this->tableComment,
|
'controllerAnnotation' => $this->tableComment,
|
||||||
'modelFilename' => "\app\admin\model\\{$modelFilenameExtend}",
|
'modelFilename' => "\app\admin\model\\{$modelFilenameExtend}",
|
||||||
'indexMethod' => $controllerIndexMethod,
|
'indexMethod' => $controllerIndexMethod,
|
||||||
|
'exportMethod' => $controllerExportMethod,
|
||||||
'selectList' => $selectList,
|
'selectList' => $selectList,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -1276,7 +1284,7 @@ class BuildCurdService
|
|||||||
} elseif ($val['formType'] == 'city') {
|
} elseif ($val['formType'] == 'city') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}city";
|
$templateFile = "view{$this->DS}module{$this->DS}city";
|
||||||
$define = $this->buildCityView($field, $val, $val['default']);
|
$define = $this->buildCityView($field, $val, $val['default']);
|
||||||
}elseif ($val['formType'] == 'tag') {
|
} elseif ($val['formType'] == 'tag') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1375,7 +1383,7 @@ class BuildCurdService
|
|||||||
} elseif ($val['formType'] == 'city') {
|
} elseif ($val['formType'] == 'city') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}city";
|
$templateFile = "view{$this->DS}module{$this->DS}city";
|
||||||
$define = $this->buildCityView($field, $val, $value);
|
$define = $this->buildCityView($field, $val, $value);
|
||||||
}elseif ($val['formType'] == 'tag') {
|
} elseif ($val['formType'] == 'tag') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,4 +24,7 @@ class {{controllerName}} extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
{{indexMethod}}
|
{{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
|
class Version extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
const VERSION = 'v2.0.3';
|
const VERSION = 'v2.0.4';
|
||||||
|
|
||||||
const COMMENT = [
|
const COMMENT = [
|
||||||
'优化导出功能,兼容自定义参数、兼容关联查询用法',
|
'自动生成CURD导出生成关联查询',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class ExcelTools
|
|||||||
} else if (array_key_exists($field_key, $select_fields)) {
|
} 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)) {
|
} else if (in_array($field_key, $date_fields)) {
|
||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
$cel = '';
|
$cel = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user