mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-31 15:00:52 +00:00
调整crud模板
This commit is contained in:
parent
01783a2af0
commit
1ee97a89f4
@ -17,6 +17,7 @@ namespace app\adminapi\controller\v1\setting;
|
||||
use app\adminapi\controller\AuthController;
|
||||
use app\services\system\SystemCrudServices;
|
||||
use app\services\system\SystemMenusServices;
|
||||
use crmeb\services\crud\Make;
|
||||
use think\facade\App;
|
||||
use think\helper\Str;
|
||||
|
||||
@ -82,14 +83,15 @@ class SystemCrud extends AuthController
|
||||
if ($item['from_type']) {
|
||||
$fromField[] = [
|
||||
'field' => $item['field'],
|
||||
'type' => $item['from_type'],
|
||||
'name' => $item['table_name'],
|
||||
'required' => $item['required'],
|
||||
'option' => $item['option'] ?? [],
|
||||
];
|
||||
}
|
||||
}
|
||||
$data['fromField '] = $fromField;
|
||||
$data['columnField '] = $columnField;
|
||||
$data['fromField'] = $fromField;
|
||||
$data['columnField'] = $columnField;
|
||||
if (!$data['tableName']) {
|
||||
return app('json')->fail('缺少表名');
|
||||
}
|
||||
@ -186,28 +188,12 @@ class SystemCrud extends AuthController
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fromField = $columnField = [];
|
||||
foreach ($info->tableField as $item) {
|
||||
if ($item['is_table']) {
|
||||
$columnField[] = [
|
||||
'field' => $item['field'],
|
||||
'name' => $item['table_name'],
|
||||
];
|
||||
}
|
||||
if ($item['from_type']) {
|
||||
$fromField[] = [
|
||||
'field' => $item['field'],
|
||||
'name' => $item['table_name'],
|
||||
'required' => $item['required'],
|
||||
'option' => $item['option'] ?? [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$make = $this->services->makeFile($info->table_name, $routeName, false, [
|
||||
'menuName' => $info->name,
|
||||
'key' => $key,
|
||||
'fromField' => $fromField,
|
||||
'columnField' => $columnField,
|
||||
'fromField' => $info->field['fromField'] ?? [],
|
||||
'columnField' => $info->field['columnField'] ?? [],
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
@ -251,13 +237,40 @@ class SystemCrud extends AuthController
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/11
|
||||
*/
|
||||
public function delete($id)
|
||||
public function delete(SystemMenusServices $services, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
|
||||
$this->services->delete($id);
|
||||
$info = $this->services->get($id);
|
||||
if (!$info) {
|
||||
return app('json')->fail('删除的数据不存在');
|
||||
}
|
||||
|
||||
$services->transaction(function () use ($services, $info) {
|
||||
if ($info->menu_ids) {
|
||||
$services->deleteMenus($info->menu_ids);
|
||||
}
|
||||
|
||||
$info->delete();
|
||||
});
|
||||
|
||||
if ($info->make_path) {
|
||||
try {
|
||||
foreach ($info->make_path as $key => $item) {
|
||||
if (in_array($key, ['pages', 'router', 'api'])) {
|
||||
$item = Make::adminTemplatePath() . $item;
|
||||
} else {
|
||||
$item = app()->getRootPath() . $item;
|
||||
}
|
||||
unlink($item);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return app('json')->success('删除生成的菜单和信息成功,删除文件出错,详细错误:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return app('json')->success('删除成功');
|
||||
}
|
||||
|
||||
@ -49,6 +49,22 @@ class SystemMenus extends AuthController
|
||||
return app('json')->success($this->services->getList($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/14
|
||||
* @return \think\Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function unique()
|
||||
{
|
||||
$adminInfo = $this->request->adminInfo();
|
||||
[$menus, $uniqueAuth] = app()->make(SystemMenusServices::class)->getMenusList($adminInfo['roles'], (int)$adminInfo['level']);
|
||||
return app('json')->success(compact('menus', 'uniqueAuth'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
|
||||
@ -15,10 +15,11 @@ use think\facade\Route;
|
||||
*/
|
||||
Route::group('cms', function () {
|
||||
//文章资源路由
|
||||
Route::resource('cms', 'v1.cms.Article')->except(['read'])->option([
|
||||
Route::resource('cms', 'v1.cms.Article')->option([
|
||||
'real_name' => [
|
||||
'index' => '获取文章列表',
|
||||
'create' => '获取文章表单',
|
||||
'read' => '获取文章详细信息',
|
||||
'save' => '保存文章',
|
||||
'edit' => '获取修改文章表单',
|
||||
'update' => '修改文章',
|
||||
|
||||
@ -36,6 +36,8 @@ Route::group('setting', function () {
|
||||
Route::put('update_admin', 'v1.setting.SystemAdmin/update_admin')->name('SystemAdminUpdateAdmin')->option(['real_name' => '修改当前管理员信息']);
|
||||
//设置文件管理密码
|
||||
Route::put('set_file_password', 'v1.setting.SystemAdmin/set_file_password')->name('SystemAdminSetFilePassword')->option(['real_name' => '设置当前文件管理密码']);
|
||||
//获取菜单权限和权限标识
|
||||
Route::get('menus/unique', 'v1.setting.SystemMenus/unique')->name('SystemMenusUnique')->option(['real_name' => '获取菜单权限和权限标识']);
|
||||
//批量保存权限
|
||||
Route::post('menus/batch', 'v1.setting.SystemMenus/batchSave')->name('SystemMenusBatchSave')->option(['real_name' => '批量保存权限']);
|
||||
//权限菜单资源路由
|
||||
|
||||
@ -70,6 +70,25 @@ abstract class BaseDao
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function selectList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = '', array $with = [], bool $search = false)
|
||||
{
|
||||
return $this->selectModel($where, $field, $page, $limit, $order, $with, $search)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param string $order
|
||||
* @param array $with
|
||||
* @param bool $search
|
||||
* @return BaseModel
|
||||
* @throws \ReflectionException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/14
|
||||
*/
|
||||
public function selectModel(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = '', array $with = [], bool $search = false)
|
||||
{
|
||||
if ($search) {
|
||||
$model = $this->search($where);
|
||||
@ -82,7 +101,7 @@ abstract class BaseDao
|
||||
$query->order($order);
|
||||
})->when($with, function ($query) use ($with) {
|
||||
$query->with($with);
|
||||
})->select();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,6 +237,7 @@ abstract class BaseDao
|
||||
return $this->getModel()->where($where)->column($field, $key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param int|string|array $id
|
||||
@ -331,7 +351,11 @@ abstract class BaseDao
|
||||
$with[] = $key;
|
||||
} else {
|
||||
if (!in_array($key, ['timeKey', 'store_stock', 'integral_time'])) {
|
||||
$otherWhere[] = is_array($value) ? $value : [$key, '=', $value];
|
||||
if (!is_array($value)) {
|
||||
$otherWhere[] = [$key, '=', $value];
|
||||
} else if (count($value) === 3) {
|
||||
$otherWhere[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,18 @@ class SystemMenusDao extends BaseDao
|
||||
return SystemMenus::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $menusIds
|
||||
* @return bool
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/13
|
||||
*/
|
||||
public function deleteMenus(array $menusIds)
|
||||
{
|
||||
return $this->getModel()->whereIn('id', $menusIds)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限菜单列表
|
||||
* @param array $where
|
||||
|
||||
@ -40,4 +40,20 @@ class SystemCrud extends BaseModel
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
public function getFieldAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function getMenuIdsAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function getMakePathAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,11 +26,13 @@ use crmeb\services\crud\Validate;
|
||||
use crmeb\services\crud\ViewApi;
|
||||
use crmeb\services\crud\ViewPages;
|
||||
use crmeb\services\crud\ViewRouter;
|
||||
use Phinx\Db\Adapter\AdapterFactory;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\helper\Str;
|
||||
use think\migration\Migrator;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
use think\migration\db\Table;
|
||||
|
||||
/**
|
||||
* Class SystemCrudServices
|
||||
@ -72,7 +74,7 @@ class SystemCrudServices extends BaseServices
|
||||
public function getList()
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->selectList([], 'add_time,id,name,table_name', $page, $limit, 'id desc');
|
||||
$list = $this->dao->selectList([], 'add_time,id,name,table_name,table_comment,table_comment', $page, $limit, 'id desc');
|
||||
$count = $this->dao->count();
|
||||
|
||||
return compact('list', 'count');
|
||||
@ -88,9 +90,10 @@ class SystemCrudServices extends BaseServices
|
||||
public function getTabelRule()
|
||||
{
|
||||
$rule = [
|
||||
'varchat' => 'string',
|
||||
'varchar' => 'string',
|
||||
'int' => 'integer',
|
||||
'biginteger' => 'bigint',
|
||||
'tinyint' => 'boolean',
|
||||
];
|
||||
return [
|
||||
'types' => [
|
||||
@ -136,13 +139,29 @@ class SystemCrudServices extends BaseServices
|
||||
public function changeTabelRule(string $type)
|
||||
{
|
||||
|
||||
if (!in_array($type, $this->getTabelRule()['type'])) {
|
||||
if (!in_array($type, $this->getTabelRule()['types'])) {
|
||||
throw new ValidateException('类型不在支持范围');
|
||||
}
|
||||
|
||||
return $this->getTabelRule()['rule'][$type] ?? $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* @return mixed
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/14
|
||||
*/
|
||||
public function getTableInfo(string $tableName)
|
||||
{
|
||||
$sql = 'SELECT * FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?';
|
||||
|
||||
$tableInfo = Db::query($sql, [config('database.connections.mysql.database'), $this->getTableName($tableName)]);
|
||||
|
||||
return $tableInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段
|
||||
* @param string $tableName
|
||||
@ -210,7 +229,7 @@ class SystemCrudServices extends BaseServices
|
||||
public function createCrud(array $data)
|
||||
{
|
||||
$tableName = $data['tableName'];
|
||||
$tableComment = $data['tableComment'];
|
||||
$tableComment = $data['tableComment'] ?? $data['menuName'];
|
||||
$tableField = $this->valueReplace($data['tableField']);
|
||||
$filePath = $this->valueReplace($data['filePath']);
|
||||
|
||||
@ -229,6 +248,9 @@ class SystemCrudServices extends BaseServices
|
||||
if (!$column) {
|
||||
throw new ValidateException('请先创建' . $tableName . '表');
|
||||
}
|
||||
|
||||
$tableInfo = $this->getTableInfo($tableName);
|
||||
|
||||
//获取主键
|
||||
foreach ($column as $value) {
|
||||
if ($value['primaryKey']) {
|
||||
@ -255,7 +277,7 @@ class SystemCrudServices extends BaseServices
|
||||
$dataMenu = [
|
||||
'pid' => $data['pid'],
|
||||
'menu_name' => $data['menuName'],
|
||||
'menu_path' => '',
|
||||
'menu_path' => '/' . $routeName . '/list',
|
||||
'auth_type' => 1,
|
||||
'is_show' => 1,
|
||||
'is_del' => 0,
|
||||
@ -263,7 +285,7 @@ class SystemCrudServices extends BaseServices
|
||||
'is_header' => $data['pid'] ? 0 : 1,
|
||||
];
|
||||
|
||||
$res = $this->transaction(function () use ($filePath, $tableName, $routeName, $data, $dataMenu) {
|
||||
$res = $this->transaction(function () use ($tableInfo, $filePath, $tableName, $routeName, $data, $dataMenu) {
|
||||
$menuInfo = app()->make(SystemMenusServices::class)->save($dataMenu);
|
||||
//写入路由权限
|
||||
$cateId = app()->make(SystemRouteServices::class)->topCateId('adminapi');
|
||||
@ -329,7 +351,9 @@ class SystemCrudServices extends BaseServices
|
||||
'is_del' => 0,
|
||||
];
|
||||
}
|
||||
app()->make(SystemMenusServices::class)->saveAll($menuData);
|
||||
$menus = app()->make(SystemMenusServices::class)->saveAll($menuData);
|
||||
$menuIds = array_column($menus->toArray(), 'id');
|
||||
array_push($menuIds, $menuInfo->id);
|
||||
//生成文件
|
||||
$make = $this->makeFile($tableName, $routeName, true, $data, $filePath);
|
||||
$makePath = [];
|
||||
@ -341,7 +365,10 @@ class SystemCrudServices extends BaseServices
|
||||
'pid' => $data['pid'],
|
||||
'name' => $data['menuName'],
|
||||
'table_name' => $tableName,
|
||||
'field' => json_encode($data),
|
||||
'table_comment' => $tableInfo['TABLE_COMMENT'] ?? '',
|
||||
'table_collation' => $tableInfo['TABLE_COLLATION'] ?? '',
|
||||
'field' => json_encode($data),//提交的数据
|
||||
'menu_ids' => json_encode($menuIds),//生成的菜单id
|
||||
'make_path' => json_encode($makePath),
|
||||
'add_time' => time()
|
||||
]);
|
||||
@ -352,6 +379,60 @@ class SystemCrudServices extends BaseServices
|
||||
return $res->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库配置
|
||||
* @return array
|
||||
*/
|
||||
protected function getDbConfig(): array
|
||||
{
|
||||
$default = app()->config->get('database.default');
|
||||
|
||||
$config = app()->config->get("database.connections.{$default}");
|
||||
|
||||
if (0 == $config['deploy']) {
|
||||
$dbConfig = [
|
||||
'adapter' => $config['type'],
|
||||
'host' => $config['hostname'],
|
||||
'name' => $config['database'],
|
||||
'user' => $config['username'],
|
||||
'pass' => $config['password'],
|
||||
'port' => $config['hostport'],
|
||||
'charset' => $config['charset'],
|
||||
'table_prefix' => $config['prefix'],
|
||||
];
|
||||
} else {
|
||||
$dbConfig = [
|
||||
'adapter' => explode(',', $config['type'])[0],
|
||||
'host' => explode(',', $config['hostname'])[0],
|
||||
'name' => explode(',', $config['database'])[0],
|
||||
'user' => explode(',', $config['username'])[0],
|
||||
'pass' => explode(',', $config['password'])[0],
|
||||
'port' => explode(',', $config['hostport'])[0],
|
||||
'charset' => explode(',', $config['charset'])[0],
|
||||
'table_prefix' => explode(',', $config['prefix'])[0],
|
||||
];
|
||||
}
|
||||
|
||||
$table = app()->config->get('database.migration_table', 'migrations');
|
||||
|
||||
$dbConfig['default_migration_table'] = $dbConfig['table_prefix'] . $table;
|
||||
|
||||
return $dbConfig;
|
||||
}
|
||||
|
||||
public function getAdapter()
|
||||
{
|
||||
$options = $this->getDbConfig();
|
||||
|
||||
$adapter = AdapterFactory::instance()->getAdapter($options['adapter'], $options);
|
||||
|
||||
if ($adapter->hasOption('table_prefix') || $adapter->hasOption('table_suffix')) {
|
||||
$adapter = AdapterFactory::instance()->getWrapper('prefix', $adapter);
|
||||
}
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据库
|
||||
* @param string $tableName
|
||||
@ -363,27 +444,26 @@ class SystemCrudServices extends BaseServices
|
||||
*/
|
||||
public function makeDatebase(string $tableName, string $tableComment, array $tableField = [])
|
||||
{
|
||||
$migrator = app()->make(Migrator::class, [date('YmdHis')]);
|
||||
//创建表
|
||||
$table = $migrator->table($tableName, $tableComment);
|
||||
$table = new Table($tableName, ['comment' => $tableComment], $this->getAdapter());
|
||||
//创建字段
|
||||
foreach ($tableField as $item) {
|
||||
$option = [];
|
||||
if (!isset($item['limit'])) {
|
||||
if (isset($item['limit'])) {
|
||||
$option['limit'] = (int)$item['limit'];
|
||||
}
|
||||
if (!isset($item['default'])) {
|
||||
if (isset($item['default'])) {
|
||||
$option['default'] = $item['default'];
|
||||
}
|
||||
//创建伪删除
|
||||
if ($item['type'] === 'addSoftDelete') {
|
||||
if ($item['file_type'] === 'addSoftDelete') {
|
||||
$table->addSoftDelete();
|
||||
} else if ($item['type'] === 'addTimestamps') {
|
||||
} else if ($item['file_type'] === 'addTimestamps') {
|
||||
//创建修改和增加时间
|
||||
$table->addTimestamps();
|
||||
} else {
|
||||
$option['comment'] = $item['comment'];
|
||||
$table->addColumn($item['field'], $this->changeTabelRule($item['type']), $option);
|
||||
$table->addColumn($item['field'], $this->changeTabelRule($item['file_type']), $option);
|
||||
}
|
||||
}
|
||||
//创建索引
|
||||
@ -432,7 +512,8 @@ class SystemCrudServices extends BaseServices
|
||||
//生成控制器
|
||||
$controller = app()->make(Controller::class);
|
||||
[$controllerContent, $controllerPath] = $controller->setFilePathName($filePath['controller'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'usePath' => $usePath
|
||||
'usePath' => $usePath,
|
||||
'field' => array_column($options['fromField'], 'field'),
|
||||
]);
|
||||
//生成路由
|
||||
$route = app()->make(Route::class);
|
||||
@ -455,6 +536,7 @@ class SystemCrudServices extends BaseServices
|
||||
$viewPages = app()->make(ViewPages::class);
|
||||
[$pagesContent, $pagesPath] = $viewPages->setFilePathName($filePath['pages'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'field' => $options['columnField'],
|
||||
'route' => $routeName,
|
||||
'pathApiJs' => '@/' . str_replace('\\', '/', str_replace([Make::adminTemplatePath(), '.js'], '', $apiPath)),
|
||||
]);
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ class Controller extends Make
|
||||
if ($field) {
|
||||
$fieldStr = '';
|
||||
foreach ($field as $k) {
|
||||
$fieldStr .= "['$k',''],\n";
|
||||
$fieldStr .= $this->tab(3) . "['$k', ''],\n";
|
||||
}
|
||||
$fieldPhp[] = $fieldStr;
|
||||
}
|
||||
@ -94,7 +94,7 @@ class Controller extends Make
|
||||
$this->value['name'] = $className;
|
||||
$this->value['path'] = $this->getfolderPath($path);
|
||||
$this->value['content-php'] = $contentPhp;
|
||||
$this->value['use-php'] = "use " . $options['usePath'] . ";\n";
|
||||
$this->value['use-php'] = "use " . $options['usePath'] . "Services;\n";
|
||||
|
||||
$contentStr = str_replace($this->var, $this->value, $contentController);
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ namespace crmeb\services\crud;
|
||||
|
||||
|
||||
use crmeb\exceptions\CrudException;
|
||||
use think\helper\Str;
|
||||
|
||||
class Route extends Make
|
||||
{
|
||||
@ -44,7 +45,8 @@ class Route extends Make
|
||||
$path = $options['path'] ?? '';
|
||||
$action = $options['action'] ?? [];
|
||||
$route = $options['route'] ?? '';
|
||||
$controller = $options['controller'] ?? '';
|
||||
$controller = $options['controller'] ?? $name;
|
||||
$routePath = $options['routePath'] ?? '';
|
||||
$menus = $options['menus'] ?? '';
|
||||
if (!$route) {
|
||||
throw new CrudException('缺少路由名称');
|
||||
@ -56,12 +58,14 @@ class Route extends Make
|
||||
$var = [
|
||||
'{%route%}',
|
||||
'{%controller%}',
|
||||
'{%routePath%}',
|
||||
'{%menus%}',
|
||||
];
|
||||
|
||||
$value = [
|
||||
$route,
|
||||
$controller ? '.' . $controller : '',
|
||||
$routePath,
|
||||
$controller ? ($routePath ? '.' : '') . Str::studly($controller) : '',
|
||||
$menus
|
||||
];
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace crmeb\services\crud;
|
||||
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\facade\Route as Url;
|
||||
use think\helper\Str;
|
||||
|
||||
/**
|
||||
@ -67,7 +69,18 @@ class Service extends Make
|
||||
$value = [$this->value['date'], Str::snake($options['route'] ?? $name)];
|
||||
$from = [];
|
||||
foreach ($field as $item) {
|
||||
$from[] = $this->tab(2) . '$rule[] = FormBuilder::' . $item['type'] . '("' . $item['field'] . '","' . $item['name'] . '",$info["' . $item['field'] . '"] ?? "")' . $this->getOptionContent($item['option'] ?? []) . (!empty($item['required']) ? '->required()' : '') . ';';
|
||||
switch ($item['type']) {
|
||||
case 'frameImageOne':
|
||||
$from[] = $this->tab(2) . $this->getframeImageOnePhpContent($item['field'], $item['name'], $item['required'] ?? false) . ';';
|
||||
break;
|
||||
case 'frameImages':
|
||||
$from[] = $this->tab(2) . $this->getframeImagesPhpContent($item['field'], $item['name'], $item['required'] ?? false) . ';';
|
||||
break;
|
||||
default:
|
||||
$from[] = $this->tab(2) . '$rule[] = FormBuilder::' . $item['type'] . '("' . $item['field'] . '","' . $item['name'] . '",$info["' . $item['field'] . '"] ?? "")' . $this->getOptionContent($item['option'] ?? []) . (!empty($item['required']) ? '->required()' : '') . ';';
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if ($from) {
|
||||
$this->value['use-php'] .= "\n" . 'use crmeb\services\FormBuilder;';
|
||||
@ -121,6 +134,49 @@ class Service extends Make
|
||||
return $php;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单图获取formphp内容
|
||||
* @param string $field
|
||||
* @param string $name
|
||||
* @param string $icon
|
||||
* @param string $width
|
||||
* @param string $height
|
||||
* @return string
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/14
|
||||
*/
|
||||
protected function getframeImageOnePhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-add', string $width = '950px', string $height = '505px')
|
||||
{
|
||||
$requiredText = $required ? '->required()' : '';
|
||||
$content = <<<CONTENT
|
||||
\$rule[] = FormBuilder::frameImage('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field']), \$info[\'$field\'] ?? '')->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
|
||||
CONTENT;
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多图获取formphp内容
|
||||
* @param string $field
|
||||
* @param string $name
|
||||
* @param string $icon
|
||||
* @param int $maxLength
|
||||
* @param string $width
|
||||
* @param string $height
|
||||
* @return string
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/14
|
||||
*/
|
||||
protected function getframeImagesPhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-images', int $maxLength = 10, string $width = '950px', string $height = '505px')
|
||||
{
|
||||
$requiredText = $required ? '->required()' : '';
|
||||
$content = <<<CONTENT
|
||||
\$rule[] = FormBuilder::frameImages('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field', 'type' => 'many', 'maxLength' => $maxLength]), \$info[\'$field\'] ?? [])->maxLength($maxLength)->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
|
||||
CONTENT;
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
@ -133,7 +189,7 @@ class Service extends Make
|
||||
{
|
||||
$path = str_replace(['app\\services', 'app/services'], '', $path);
|
||||
$path = ltrim(str_replace('\\', '/', $path), '/');
|
||||
return 'use app\dao\\' . ($path ? $path . '\\' : '') . Str::studly($name) . 'Dao;';
|
||||
return 'use app\dao\crud\\' . ($path ? $path . '\\' : '') . Str::studly($name) . 'Dao;';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ class ViewApi extends Make
|
||||
$path = $options['path'] ?? '';
|
||||
$action = $options['action'] ?? [];
|
||||
if (!$action) {
|
||||
$action = ['index', 'create', 'save', 'edit', 'update'];
|
||||
$action = ['index', 'create', 'save', 'edit', 'update', 'delete'];
|
||||
}
|
||||
$route = $options['route'] ?? '';
|
||||
if (!$route) {
|
||||
@ -87,8 +87,8 @@ class ViewApi extends Make
|
||||
$nameCamel = Str::studly($name);
|
||||
|
||||
if ($contentJs) {
|
||||
$var = ['{%name%}', '{%route%}', '{%nameCamel%}'];
|
||||
$value = [$name, $route, $nameCamel];
|
||||
$var = ['{%name%}', '{%route%}', '{%nameCamel%}', '{%nameStudly%}'];
|
||||
$value = [$name, $route, $nameCamel, Str::studly($name)];
|
||||
$contentJs = str_replace($var, $value, $contentJs);
|
||||
}
|
||||
|
||||
@ -131,9 +131,10 @@ class ViewApi extends Make
|
||||
|
||||
$stubs = [
|
||||
'index' => $servicePath . 'getCrudListApi.stub',
|
||||
'create' => $servicePath . 'crudUpdateApi.stub',
|
||||
'create' => $servicePath . 'getCrudCreateApi.stub',
|
||||
'save' => $servicePath . 'crudSaveApi.stub',
|
||||
'edit' => $servicePath . 'getCrudEditApi.stub',
|
||||
'delete' => $servicePath . 'crudDeleteApi.stub',
|
||||
'update' => $servicePath . 'crudUpdateApi.stub',
|
||||
'api' => $servicePath . 'crud.stub',
|
||||
];
|
||||
|
||||
@ -69,15 +69,18 @@ class ViewPages extends Make
|
||||
public function handle(string $name, array $options = [])
|
||||
{
|
||||
$field = $options['field'] ?? [];
|
||||
$route = $options['route'] ?? '';
|
||||
|
||||
$columnStr = [];
|
||||
foreach ($field as $item) {
|
||||
$columnStr[] = $this->tab() . "{\ntitle:\"{$item['name']}\",\nkey:\"{$item['field']}\"\n}";
|
||||
foreach ($field as $key => $item) {
|
||||
$columnStr[] = ($key == 0 ? $this->tab(2) : '') . "{\n" . $this->tab(3) . "title:\"{$item['name']}\"," . $this->tab(2) . "\n" . $this->tab(3) . "key:\"{$item['field']}\"\n" . $this->tab(2) . "}\n";
|
||||
}
|
||||
$this->value['route'] = $route;
|
||||
$this->value['auth'] = Str::snake($name);
|
||||
$this->value['content-vue'] = "\n" . implode(',', $columnStr);
|
||||
$this->value['content-vue'] = $columnStr ? "\n" . implode($this->tab(2) . ',', $columnStr) . $this->tab(2) . ',' : '';
|
||||
$this->value['pathApiJs'] = $options['pathApiJs'] ?? '';
|
||||
$this->value['nameCamel'] = Str::snake($name, '-');
|
||||
$this->value['nameStudly'] = Str::studly($name);
|
||||
$this->value['nameCamel'] = Str::camel($name);
|
||||
|
||||
return parent::handle($name, $options);
|
||||
}
|
||||
@ -93,7 +96,7 @@ class ViewPages extends Make
|
||||
protected function getFilePathName(string $path, string $name): string
|
||||
{
|
||||
$path = ltrim(str_replace('\\', '/', $path), '/');
|
||||
return $this->getBasePath($path) . $name . '.' . $this->fileMime;
|
||||
return $this->getBasePath($path) . $name . DS . 'index.' . $this->fileMime;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -30,22 +30,22 @@ class {%nameCamel%} extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var {%nameCamel%}Service
|
||||
* @var {%nameCamel%}Services
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* {%nameCamel%}Controller constructor.
|
||||
* @param App $app
|
||||
* @param {%nameCamel%}Service $service
|
||||
* @param {%nameCamel%}Services $service
|
||||
*/
|
||||
public function __construct(App $app, {%nameCamel%}Service $service)
|
||||
public function __construct(App $app, {%nameCamel%}Services $service)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
|
||||
{%content-php%}
|
||||
{%content-php%}
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
public function save()
|
||||
{
|
||||
$data = $this->request->postMore([
|
||||
{%field-php%}
|
||||
{%field-php%}
|
||||
]);
|
||||
|
||||
$this->service->crudSave($data);
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
}
|
||||
|
||||
$data = $this->request->postMore([
|
||||
{%field-php%}
|
||||
{%field-php%}
|
||||
]);
|
||||
|
||||
$this->service->crudUpdate((int)$id, $data);
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* @date {%time%}
|
||||
*/
|
||||
|
||||
namespace app\dao\crub{%path%};
|
||||
namespace app\dao\crud{%path%};
|
||||
|
||||
|
||||
use app\dao\BaseDao;
|
||||
@ -24,7 +24,7 @@ use app\dao\BaseDao;
|
||||
/**
|
||||
* Class {%nameCamel%}Dao
|
||||
* @date {%date%}
|
||||
* @package app\dao\crub{%path%}
|
||||
* @package app\dao\crud{%path%}
|
||||
*/
|
||||
class {%nameCamel%}Dao extends BaseDao
|
||||
{
|
||||
|
||||
@ -1 +1 @@
|
||||
Route::get('{%route%}/create', 'v1.{%route%}{%controller%}/create')->name('{%menus%}获取创建表单接口');
|
||||
Route::get('{%route%}/create', 'crud.{%routePath%}{%controller%}/create')->name('{%menus%}获取创建表单接口');
|
||||
|
||||
@ -1 +1 @@
|
||||
Route::delete('{%route%}/:id', 'v1.{%route%}{%controller%}/delete')->name('{%menus%}删除数据接口');
|
||||
Route::delete('{%route%}/:id', 'crud.{%routePath%}{%controller%}/delete')->name('{%menus%}删除数据接口');
|
||||
|
||||
@ -1 +1 @@
|
||||
Route::get('{%route%}/:id/edit', 'v1.{%route%}{%controller%}/edit')->name('{%menus%}获取修改表单接口');
|
||||
Route::get('{%route%}/:id/edit', 'crud.{%routePath%}{%controller%}/edit')->name('{%menus%}获取修改表单接口');
|
||||
|
||||
@ -1 +1 @@
|
||||
Route::get('{%route%}', 'v1.{%route%}{%controller%}/index')->name('{%menus%}列表接口');
|
||||
Route::get('{%route%}', 'crud.{%routePath%}{%controller%}/index')->name('{%menus%}列表接口');
|
||||
|
||||
@ -1 +1 @@
|
||||
Route::post('{%route%}', 'v1.{%route%}{%controller%}/save')->name('{%menus%}保存数据接口');
|
||||
Route::post('{%route%}', 'crud.{%routePath%}{%controller%}/save')->name('{%menus%}保存数据接口');
|
||||
|
||||
@ -1 +1 @@
|
||||
Route::put('{%route%}/:id', 'v1.{%route%}{%controller%}/update')->name('{%menus%}修改数据接口');
|
||||
Route::put('{%route%}/:id', 'crud.{%routePath%}{%controller%}/update')->name('{%menus%}修改数据接口');
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* @date {%time%}
|
||||
*/
|
||||
|
||||
namespace app\services\crub{%path%};
|
||||
namespace app\services\crud{%path%};
|
||||
|
||||
use app\services\BaseServices;
|
||||
use think\exception\ValidateException;
|
||||
@ -25,13 +25,13 @@ use think\exception\ValidateException;
|
||||
/**
|
||||
* Class CrudService
|
||||
* @date {%date%}
|
||||
* @package app\services\crub{%path%}
|
||||
* @package app\services\crud{%path%}
|
||||
*/
|
||||
class {%nameCamel%}Service extends BaseServices
|
||||
class {%nameCamel%}Services extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* {%nameCamel%}Service constructor.
|
||||
* {%nameCamel%}Services constructor.
|
||||
* @param {%nameCamel%}Dao $dao
|
||||
*/
|
||||
public function __construct({%nameCamel%}Dao $dao)
|
||||
@ -39,6 +39,6 @@ class {%nameCamel%}Service extends BaseServices
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
{%content-php%}
|
||||
{%content-php%}
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
*/
|
||||
public function getCrudForm(int $id = 0)
|
||||
{
|
||||
$url = '/{%route%}';
|
||||
$url = '/crud/{%route%}';
|
||||
$info = [];
|
||||
if ($id) {
|
||||
$info = $this->dao->get($id);
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* @date {%time%}
|
||||
*/
|
||||
|
||||
namespace app\adminapi\validate\crub{%path%};
|
||||
namespace app\adminapi\validate\crud{%path%};
|
||||
|
||||
|
||||
use think\Validate;
|
||||
@ -24,7 +24,7 @@ use think\Validate;
|
||||
/**
|
||||
* Class CrudValidate
|
||||
* @date {%date%}
|
||||
* @package app\adminapi\validate\crub{%path%}
|
||||
* @package app\adminapi\validate\crud{%path%}
|
||||
*/
|
||||
class {%nameCamel%}Validate extends Validate
|
||||
{
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* @param id
|
||||
* @return {*}
|
||||
*/
|
||||
export function {%name%}DeleteApi(id) {
|
||||
export function {%nameCamel%}DeleteApi(id) {
|
||||
return request({
|
||||
url: `{%route%}/${id}`,
|
||||
method: 'delete'
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* @param data
|
||||
* @return {*}
|
||||
*/
|
||||
export function {%name%}SaveApi(data) {
|
||||
export function {%nameCamel%}SaveApi(data) {
|
||||
return request({
|
||||
url: '{%route%}',
|
||||
method: 'post',
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* @param id
|
||||
* @return {*}
|
||||
*/
|
||||
export function {%name%}UpdateApi(id, data) {
|
||||
export function {%nameCamel%}UpdateApi(id, data) {
|
||||
return request({
|
||||
url: `{%route%}/${id}`,
|
||||
method: 'put',
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* 获取添加表单数据
|
||||
* @return {*}
|
||||
*/
|
||||
export function get{%nameCamel%}CreateApi() {
|
||||
export function get{%nameStudly%}CreateApi() {
|
||||
return request({
|
||||
url: '{%route%}/create',
|
||||
method: 'get',
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* @param id
|
||||
* @return {*}
|
||||
*/
|
||||
export function get{%nameCamel%}EditApi(id) {
|
||||
export function get{%nameStudly%}EditApi(id) {
|
||||
return request({
|
||||
url: `{%route%}/${id}`,
|
||||
url: `{%route%}/${id}/edit`,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* @param params
|
||||
* @return {*}
|
||||
*/
|
||||
export function get{%nameCamel%}ListApi(params) {
|
||||
export function get{%nameStudly%}ListApi(params) {
|
||||
return request({
|
||||
url: '{%route%}',
|
||||
method: 'get',
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex';
|
||||
import { {%name%}SaveApi, {%name%}DeleteApi, {%name%}UpdateApi, get{%nameCamel%}CreateApi, get{%nameCamel%}EditApi, get{%nameCamel%}ListApi} from '{%pathApiJs%}';
|
||||
import { {%nameCamel%}SaveApi, {%nameCamel%}DeleteApi, {%nameCamel%}UpdateApi, get{%nameStudly%}CreateApi, get{%nameStudly%}EditApi, get{%nameStudly%}ListApi} from '{%pathApiJs%}';
|
||||
export default {
|
||||
name: 'user_group',
|
||||
data() {
|
||||
@ -85,12 +85,12 @@ export default {
|
||||
methods: {
|
||||
// 添加
|
||||
add() {
|
||||
this.$modalForm(get{%nameCamel%}CreateApi()).then(() => this.getList());
|
||||
this.$modalForm(get{%nameStudly%}CreateApi()).then(() => this.getList());
|
||||
},
|
||||
//列表
|
||||
getList() {
|
||||
this.loading = true;
|
||||
get{%nameCamel%}ListApi(this.from)
|
||||
get{%nameStudly%}ListApi(this.from)
|
||||
.then(async (res) => {
|
||||
let data = res.data;
|
||||
this.dataList = data.list;
|
||||
@ -109,7 +109,7 @@ export default {
|
||||
},
|
||||
// 修改
|
||||
edit(id) {
|
||||
this.$modalForm(get{%nameCamel%}EditApi(id)).then(() => this.getList());
|
||||
this.$modalForm(get{%nameStudly%}EditApi(id)).then(() => this.getList());
|
||||
},
|
||||
// 删除
|
||||
del(row, tit, num) {
|
||||
@ -123,7 +123,6 @@ export default {
|
||||
this.$modalSure(delfromData)
|
||||
.then((res) => {
|
||||
this.$Message.success(res.msg);
|
||||
this.groupLists.splice(num, 1);
|
||||
this.getList();
|
||||
})
|
||||
.catch((res) => {
|
||||
|
||||
@ -21,7 +21,7 @@ const pre = '{%name%}_'
|
||||
|
||||
export default {
|
||||
path: `${routePre}/{%route%}`,
|
||||
name: '{%name%}',
|
||||
name: 'crud_{%name%}',
|
||||
header: '{%nameHeader%}',
|
||||
meta,
|
||||
component: BasicLayout,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user