mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
去除大多数文件的外部功能依赖;
This commit is contained in:
@@ -7,10 +7,9 @@ use app\admin\model\SystemUploadfile;
|
|||||||
use app\common\controller\AdminController;
|
use app\common\controller\AdminController;
|
||||||
use app\common\service\MenuService;
|
use app\common\service\MenuService;
|
||||||
use app\common\service\UploadService;
|
use app\common\service\UploadService;
|
||||||
use EasyAdmin\upload\Uploadfile;
|
|
||||||
use think\db\Query;
|
use think\db\Query;
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
use think\facade\Filesystem;
|
|
||||||
|
|
||||||
class Ajax extends AdminController
|
class Ajax extends AdminController
|
||||||
{
|
{
|
||||||
@@ -61,7 +60,7 @@ class Ajax extends AdminController
|
|||||||
'upload_type' => $this->request->post('upload_type'),
|
'upload_type' => $this->request->post('upload_type'),
|
||||||
'file' => $this->request->file('file'),
|
'file' => $this->request->file('file'),
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$upload_service = new UploadService($data['upload_type']);
|
$upload_service = new UploadService($data['upload_type']);
|
||||||
@@ -69,7 +68,6 @@ class Ajax extends AdminController
|
|||||||
$upload_service->validateException($data['file']);
|
$upload_service->validateException($data['file']);
|
||||||
|
|
||||||
$result = $upload_service->save($data['file']);
|
$result = $upload_service->save($data['file']);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -88,35 +86,26 @@ class Ajax extends AdminController
|
|||||||
'upload_type' => $this->request->post('upload_type'),
|
'upload_type' => $this->request->post('upload_type'),
|
||||||
'file' => $this->request->file('upload'),
|
'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 {
|
try {
|
||||||
$upload = Uploadfile::instance()
|
$upload_service = new UploadService($data['upload_type']);
|
||||||
->setUploadType($data['upload_type'])
|
|
||||||
->setUploadConfig($uploadConfig)
|
$upload_service->validateException($data['file']);
|
||||||
->setFile($data['file'])
|
|
||||||
->save();
|
$result = $upload_service->save($data['file']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
if ($upload['save'] == true) {
|
|
||||||
return json([
|
return json([
|
||||||
'error' => [
|
'error' => [
|
||||||
'message' => '上传成功',
|
'message' => '上传成功',
|
||||||
'number' => 201,
|
'number' => 201,
|
||||||
],
|
],
|
||||||
'fileName' => '',
|
'fileName' => '',
|
||||||
'uploaded' => 1,
|
'uploaded' => 1,
|
||||||
'url' => $upload['url'],
|
'url' => $result['url'],
|
||||||
]);
|
]);
|
||||||
} else {
|
|
||||||
$this->error($upload['msg']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
namespace app\admin\middleware;
|
namespace app\admin\middleware;
|
||||||
|
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use EasyAdmin\tool\CommonTool;
|
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
|
use think\facade\Request as FacadeRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统操作日志中间件
|
* 系统操作日志中间件
|
||||||
@@ -40,7 +40,7 @@ class SystemLog
|
|||||||
|
|
||||||
if ($request->isAjax()) {
|
if ($request->isAjax()) {
|
||||||
if (in_array($method, ['post', 'put', 'delete'])) {
|
if (in_array($method, ['post', 'put', 'delete'])) {
|
||||||
$ip = CommonTool::getRealIp();
|
$ip = FacadeRequest::ip();
|
||||||
$data = [
|
$data = [
|
||||||
'admin_id' => session('admin.id'),
|
'admin_id' => session('admin.id'),
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use think\helper\Str;
|
|||||||
/**
|
/**
|
||||||
* 快速构建系统CURD
|
* 快速构建系统CURD
|
||||||
* Class BuildCurd
|
* Class BuildCurd
|
||||||
* @package EasyAdmin\curd
|
|
||||||
*/
|
*/
|
||||||
class BuildCurdService
|
class BuildCurdService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ use think\helper\Str;
|
|||||||
/**
|
/**
|
||||||
* 节点处理类
|
* 节点处理类
|
||||||
* Class Node
|
* Class Node
|
||||||
* @package EasyAdmin\auth
|
|
||||||
*/
|
*/
|
||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,15 +4,11 @@
|
|||||||
namespace app\common\command;
|
namespace app\common\command;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\SystemNode;
|
|
||||||
use app\admin\service\curd\BuildCurdService;
|
use app\admin\service\curd\BuildCurdService;
|
||||||
use EasyAdmin\console\CliEcho;
|
|
||||||
use app\common\tools\BuildCurdTools;
|
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
use think\console\input\Option;
|
use think\console\input\Option;
|
||||||
use think\console\Output;
|
use think\console\Output;
|
||||||
use EasyAdmin\auth\Node as NodeService;
|
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
class Curd extends Command
|
class Curd extends Command
|
||||||
@@ -39,10 +35,8 @@ class Curd extends Command
|
|||||||
$force = $input->getOption('force');
|
$force = $input->getOption('force');
|
||||||
$delete = $input->getOption('delete');
|
$delete = $input->getOption('delete');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (empty($table)) {
|
if (empty($table)) {
|
||||||
CliEcho::error('请设置主表');
|
$output->error('请设置主表');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +57,7 @@ class Curd extends Command
|
|||||||
$define = $column['define'];
|
$define = $column['define'];
|
||||||
|
|
||||||
if (!isset($define['table'])) {
|
if (!isset($define['table'])) {
|
||||||
CliEcho::error("关联字段{$field}没有设置关联表名称");
|
$output->error("关联字段{$field}没有设置关联表名称");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,40 +86,40 @@ class Curd extends Command
|
|||||||
|
|
||||||
if (!$delete) {
|
if (!$delete) {
|
||||||
if ($force) {
|
if ($force) {
|
||||||
$output->info(">>>>>>>>>>>>>>>");
|
$output->writeln(">>>>>>>>>>>>>>>");
|
||||||
foreach ($fileList as $key => $val) {
|
foreach ($fileList as $key => $val) {
|
||||||
$output->info($key);
|
$output->writeln($key);
|
||||||
}
|
}
|
||||||
$output->info(">>>>>>>>>>>>>>>");
|
$output->writeln(">>>>>>>>>>>>>>>");
|
||||||
$output->info("确定强制生成上方所有文件? 如果文件存在会直接覆盖。 请输入 'yes' 按回车键继续操作: ");
|
$output->writeln("确定强制生成上方所有文件? 如果文件存在会直接覆盖。 请输入 'yes' 按回车键继续操作: ");
|
||||||
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r'));
|
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r'));
|
||||||
if (trim($line) != 'yes') {
|
if (trim($line) != 'yes') {
|
||||||
throw new Exception("取消文件CURD生成操作");
|
throw new Exception("取消文件CURD生成操作");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = $build->create();
|
$result = $build->create();
|
||||||
CliEcho::success('自动生成CURD成功');
|
$output->info('自动生成CURD成功');
|
||||||
} else {
|
} else {
|
||||||
$output->info(">>>>>>>>>>>>>>>");
|
$output->writeln(">>>>>>>>>>>>>>>");
|
||||||
foreach ($fileList as $key => $val) {
|
foreach ($fileList as $key => $val) {
|
||||||
$output->info($key);
|
$output->writeln($key);
|
||||||
}
|
}
|
||||||
$output->info(">>>>>>>>>>>>>>>");
|
$output->writeln(">>>>>>>>>>>>>>>");
|
||||||
$output->info("确定删除上方所有文件? 请输入 'yes' 按回车键继续操作: ");
|
$output->writeln("确定删除上方所有文件? 请输入 'yes' 按回车键继续操作: ");
|
||||||
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r'));
|
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r'));
|
||||||
if (trim($line) != 'yes') {
|
if (trim($line) != 'yes') {
|
||||||
throw new Exception("取消删除文件操作");
|
throw new Exception("取消删除文件操作");
|
||||||
}
|
}
|
||||||
$result = $build->delete();
|
$result = $build->delete();
|
||||||
CliEcho::success('>>>>>>>>>>>>>>>');
|
$output->info('>>>>>>>>>>>>>>>');
|
||||||
CliEcho::success('删除自动生成CURD文件成功');
|
$output->info('删除自动生成CURD文件成功');
|
||||||
}
|
}
|
||||||
CliEcho::success('>>>>>>>>>>>>>>>');
|
$output->info('>>>>>>>>>>>>>>>');
|
||||||
foreach ($result as $vo) {
|
foreach ($result as $vo) {
|
||||||
CliEcho::success($vo);
|
$output->info($vo);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
CliEcho::error($e->getMessage());
|
$output->error($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use app\admin\service\ConfigService;
|
|||||||
use app\BaseController;
|
use app\BaseController;
|
||||||
use app\common\constants\AdminConstant;
|
use app\common\constants\AdminConstant;
|
||||||
use app\common\service\AuthService;
|
use app\common\service\AuthService;
|
||||||
use EasyAdmin\tool\CommonTool;
|
|
||||||
use think\facade\Env;
|
use think\facade\Env;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
@@ -208,7 +207,7 @@ class AdminController extends BaseController
|
|||||||
$excludes = [];
|
$excludes = [];
|
||||||
|
|
||||||
// 判断是否关联查询
|
// 判断是否关联查询
|
||||||
$tableName = CommonTool::humpToLine(lcfirst($this->model->getName()));
|
$tableName = \think\helper\Str::snake(lcfirst($this->model->getName()));
|
||||||
|
|
||||||
foreach ($filters as $key => $val) {
|
foreach ($filters as $key => $val) {
|
||||||
if (in_array($key, $excludeFields)) {
|
if (in_array($key, $excludeFields)) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
namespace app\common\service;
|
namespace app\common\service;
|
||||||
|
|
||||||
use app\common\constants\AdminConstant;
|
use app\common\constants\AdminConstant;
|
||||||
use EasyAdmin\tool\CommonTool;
|
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@@ -200,7 +199,7 @@ class AuthService
|
|||||||
if ($key == 0) {
|
if ($key == 0) {
|
||||||
$val = explode('.', $val);
|
$val = explode('.', $val);
|
||||||
foreach ($val as &$vo) {
|
foreach ($val as &$vo) {
|
||||||
$vo = CommonTool::humpToLine(lcfirst($vo));
|
$vo = \think\helper\Str::snake(lcfirst($vo));
|
||||||
}
|
}
|
||||||
$val = implode('.', $val);
|
$val = implode('.', $val);
|
||||||
$array[$key] = $val;
|
$array[$key] = $val;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class UploadService
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save(File $file)
|
public function save(File $file, string $save_name = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$model_file = new SystemUploadfile();
|
$model_file = new SystemUploadfile();
|
||||||
@@ -74,8 +74,10 @@ class UploadService
|
|||||||
$model_file->mime_type = $file->getMime();
|
$model_file->mime_type = $file->getMime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () use ($save_name) {
|
||||||
$save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () {
|
if (!is_null($save_name)) {
|
||||||
|
return $save_name;
|
||||||
|
}
|
||||||
return date('Ymd') . '/' . uniqid();
|
return date('Ymd') . '/' . uniqid();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user