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

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

@@ -7,10 +7,9 @@ use app\admin\model\SystemUploadfile;
use app\common\controller\AdminController;
use app\common\service\MenuService;
use app\common\service\UploadService;
use EasyAdmin\upload\Uploadfile;
use think\db\Query;
use think\facade\Cache;
use think\facade\Filesystem;
class Ajax extends AdminController
{
@@ -61,7 +60,7 @@ class Ajax extends AdminController
'upload_type' => $this->request->post('upload_type'),
'file' => $this->request->file('file'),
];
try {
$upload_service = new UploadService($data['upload_type']);
@@ -69,7 +68,6 @@ class Ajax extends AdminController
$upload_service->validateException($data['file']);
$result = $upload_service->save($data['file']);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
@@ -88,35 +86,26 @@ class Ajax extends AdminController
'upload_type' => $this->request->post('upload_type'),
'file' => $this->request->file('upload'),
];
$uploadConfig = sysconfig('upload');
empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type'];
$rule = [
'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}",
'file|文件' => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}",
];
$this->validate($data, $rule);
try {
$upload = Uploadfile::instance()
->setUploadType($data['upload_type'])
->setUploadConfig($uploadConfig)
->setFile($data['file'])
->save();
$upload_service = new UploadService($data['upload_type']);
$upload_service->validateException($data['file']);
$result = $upload_service->save($data['file']);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
if ($upload['save'] == true) {
return json([
'error' => [
'message' => '上传成功',
'number' => 201,
],
'fileName' => '',
'uploaded' => 1,
'url' => $upload['url'],
]);
} else {
$this->error($upload['msg']);
}
return json([
'error' => [
'message' => '上传成功',
'number' => 201,
],
'fileName' => '',
'uploaded' => 1,
'url' => $result['url'],
]);
}
/**

View File

@@ -4,8 +4,8 @@
namespace app\admin\middleware;
use app\Request;
use EasyAdmin\tool\CommonTool;
use think\facade\Log;
use think\facade\Request as FacadeRequest;
/**
* 系统操作日志中间件
@@ -40,7 +40,7 @@ class SystemLog
if ($request->isAjax()) {
if (in_array($method, ['post', 'put', 'delete'])) {
$ip = CommonTool::getRealIp();
$ip = FacadeRequest::ip();
$data = [
'admin_id' => session('admin.id'),
'url' => $url,

View File

@@ -11,7 +11,6 @@ use think\helper\Str;
/**
* 快速构建系统CURD
* Class BuildCurd
* @package EasyAdmin\curd
*/
class BuildCurdService
{

View File

@@ -22,7 +22,6 @@ use think\helper\Str;
/**
* 节点处理类
* Class Node
* @package EasyAdmin\auth
*/
class Node
{

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();
});