初始化仓库
This commit is contained in:
117
admin/controllers/system/GeneratorController.php
Normal file
117
admin/controllers/system/GeneratorController.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace admin\controllers\system;
|
||||
|
||||
use admin\components\BaseAdminController;
|
||||
use admin\exceptions\ApiException;
|
||||
use admin\generators\model\Generator;
|
||||
use admin\models\Menu;
|
||||
use common\enums\StatusEnum;
|
||||
use common\helpers\ArrayHelper;
|
||||
use common\models\Role;
|
||||
use common\modelsgii\Menu2;
|
||||
use common\modelsgii\RoleMenu;
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: chatfeed
|
||||
* Date: 2022/5/14
|
||||
* Time: 7:43 PM
|
||||
*/
|
||||
class GeneratorController extends BaseAdminController {
|
||||
|
||||
public $enableCsrfValidation=false;
|
||||
public function actionTables(){
|
||||
$db = \Yii::$app->db;
|
||||
if ($db === null) {
|
||||
return [];
|
||||
}
|
||||
$tableNames = [];
|
||||
//if (strpos($this->tableName, '*') !== false) {
|
||||
// if (($pos = strrpos($this->tableName, '.')) !== false) {
|
||||
// $schema = substr($this->tableName, 0, $pos);
|
||||
// $pattern = '/^' . str_replace('*', '\w+', substr($this->tableName, $pos + 1)) . '$/';
|
||||
// } else {
|
||||
// $schema = '';
|
||||
// $pattern = '/^' . str_replace('*', '\w+', $this->tableName) . '$/';
|
||||
// }
|
||||
$schema = '';
|
||||
|
||||
foreach ($db->schema->getTableNames($schema) as $table) {
|
||||
$tableNames[] = $schema === '' ? $table : ($schema . '.' . $table);
|
||||
}
|
||||
//} elseif (($table = $db->getTableSchema($this->tableName, true)) !== null) {
|
||||
// $tableNames[] = $this->tableName;
|
||||
// $this->classNames[$this->tableName] = $this->modelClass;
|
||||
//}
|
||||
|
||||
return $tableNames;
|
||||
}
|
||||
public function actionFields(){
|
||||
$tableName = $this->post('table_name');
|
||||
$db = \Yii::$app->db;
|
||||
if ($db === null) {
|
||||
return [];
|
||||
}
|
||||
$tableSchema = $db->getTableSchema($tableName);
|
||||
return $tableSchema->columns;
|
||||
}
|
||||
|
||||
public function actionConfig(){
|
||||
return [
|
||||
'controllerClass'=>'backend\controllers\\',
|
||||
'baseControllerClass'=>'backend\components\BaseBackendController',
|
||||
'actionIds'=>'list,save,info,del',
|
||||
'vuePath'=>'/Users/chatfeed/arco-work/',
|
||||
'controllerNamespace'=>'backend\controllers\\',
|
||||
];
|
||||
}
|
||||
public function actionGenerate(){
|
||||
//model generate
|
||||
$modelGen = new Generator();
|
||||
$modelGen->setAttributes(
|
||||
[
|
||||
'db'=>'db',
|
||||
'useTablePrefix'=>$this->post('useTablePrefix'),
|
||||
'ns'=>'common\modelsgii',
|
||||
'tableName'=>$this->post('table_name'),
|
||||
'baseClass'=>'common\core\BaseActiveRecord',
|
||||
'queryNs'=>'common\models',
|
||||
],
|
||||
);
|
||||
$modelClass = $modelGen->generateClassName($this->post('table_name'));
|
||||
$files = $modelGen->generate();
|
||||
//controller 生成
|
||||
$conGEn = new \backend\generators\controller\Generator();
|
||||
$conGEn->setAttributes([
|
||||
'controllerClass'=>$this->post('controllerClass'),
|
||||
'baseClass'=>$this->post('baseControllerClass'),
|
||||
'actions'=>$this->post('actionIds'),
|
||||
'controllerNamespace'=>$this->post('controllerNamespace')
|
||||
]);
|
||||
$files = $conGEn->generate();
|
||||
foreach ($files as $f){
|
||||
$f->save();
|
||||
}
|
||||
//vue生成
|
||||
$vueGen = new \backend\generators\vue\Generator();
|
||||
$vueGen->setAttributes([
|
||||
'className'=>$modelClass,
|
||||
'vuePath'=>$this->post('vuePath'),
|
||||
'columns'=>$this->post('columns'),
|
||||
'pagePath'=>$this->post('pagePath'),
|
||||
'apiPath'=>$conGEn->getControllerSubPath().$conGEn->getControllerID(),
|
||||
'actions'=>$this->post('actionIds'),
|
||||
]);
|
||||
$files = $vueGen->generate();
|
||||
|
||||
foreach ($files as $f){
|
||||
$f->save();
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function generatePHP(){
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user