去除大多数文件的外部功能依赖;

This commit is contained in:
2022-07-12 11:00:47 +08:00
parent ef6fd7bfbc
commit 4ab8630617
8 changed files with 43 additions and 62 deletions

View File

@@ -4,15 +4,11 @@
namespace app\common\command;
use app\admin\model\SystemNode;
use app\admin\service\curd\BuildCurdService;
use EasyAdmin\console\CliEcho;
use app\common\tools\BuildCurdTools;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use EasyAdmin\auth\Node as NodeService;
use think\Exception;
class Curd extends Command
@@ -39,10 +35,8 @@ class Curd extends Command
$force = $input->getOption('force');
$delete = $input->getOption('delete');
if (empty($table)) {
CliEcho::error('请设置主表');
$output->error('请设置主表');
return false;
}
@@ -63,7 +57,7 @@ class Curd extends Command
$define = $column['define'];
if (!isset($define['table'])) {
CliEcho::error("关联字段{$field}没有设置关联表名称");
$output->error("关联字段{$field}没有设置关联表名称");
return false;
}
@@ -92,40 +86,40 @@ class Curd extends Command
if (!$delete) {
if ($force) {
$output->info(">>>>>>>>>>>>>>>");
$output->writeln(">>>>>>>>>>>>>>>");
foreach ($fileList as $key => $val) {
$output->info($key);
$output->writeln($key);
}
$output->info(">>>>>>>>>>>>>>>");
$output->info("确定强制生成上方所有文件? 如果文件存在会直接覆盖。 请输入 'yes' 按回车键继续操作: ");
$output->writeln(">>>>>>>>>>>>>>>");
$output->writeln("确定强制生成上方所有文件? 如果文件存在会直接覆盖。 请输入 'yes' 按回车键继续操作: ");
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r'));
if (trim($line) != 'yes') {
throw new Exception("取消文件CURD生成操作");
}
}
$result = $build->create();
CliEcho::success('自动生成CURD成功');
$output->info('自动生成CURD成功');
} else {
$output->info(">>>>>>>>>>>>>>>");
$output->writeln(">>>>>>>>>>>>>>>");
foreach ($fileList as $key => $val) {
$output->info($key);
$output->writeln($key);
}
$output->info(">>>>>>>>>>>>>>>");
$output->info("确定删除上方所有文件? 请输入 'yes' 按回车键继续操作: ");
$output->writeln(">>>>>>>>>>>>>>>");
$output->writeln("确定删除上方所有文件? 请输入 'yes' 按回车键继续操作: ");
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r'));
if (trim($line) != 'yes') {
throw new Exception("取消删除文件操作");
}
$result = $build->delete();
CliEcho::success('>>>>>>>>>>>>>>>');
CliEcho::success('删除自动生成CURD文件成功');
$output->info('>>>>>>>>>>>>>>>');
$output->info('删除自动生成CURD文件成功');
}
CliEcho::success('>>>>>>>>>>>>>>>');
$output->info('>>>>>>>>>>>>>>>');
foreach ($result as $vo) {
CliEcho::success($vo);
$output->info($vo);
}
} catch (\Exception $e) {
CliEcho::error($e->getMessage());
$output->error($e->getMessage());
return false;
}
}

View File

@@ -9,7 +9,6 @@ use app\admin\service\ConfigService;
use app\BaseController;
use app\common\constants\AdminConstant;
use app\common\service\AuthService;
use EasyAdmin\tool\CommonTool;
use think\facade\Env;
use think\facade\View;
use think\Model;
@@ -208,7 +207,7 @@ class AdminController extends BaseController
$excludes = [];
// 判断是否关联查询
$tableName = CommonTool::humpToLine(lcfirst($this->model->getName()));
$tableName = \think\helper\Str::snake(lcfirst($this->model->getName()));
foreach ($filters as $key => $val) {
if (in_array($key, $excludeFields)) {

View File

@@ -4,7 +4,6 @@
namespace app\common\service;
use app\common\constants\AdminConstant;
use EasyAdmin\tool\CommonTool;
use think\facade\Config;
use think\facade\Db;
@@ -200,7 +199,7 @@ class AuthService
if ($key == 0) {
$val = explode('.', $val);
foreach ($val as &$vo) {
$vo = CommonTool::humpToLine(lcfirst($vo));
$vo = \think\helper\Str::snake(lcfirst($vo));
}
$val = implode('.', $val);
$array[$key] = $val;

View File

@@ -56,7 +56,7 @@ class UploadService
return $url;
}
public function save(File $file)
public function save(File $file, string $save_name = null)
{
$model_file = new SystemUploadfile();
@@ -74,8 +74,10 @@ class UploadService
$model_file->mime_type = $file->getMime();
}
$save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () {
$save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () use ($save_name) {
if (!is_null($save_name)) {
return $save_name;
}
return date('Ymd') . '/' . uniqid();
});