chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/*
|
||||
* @Author: YwxApp <ywx@ywxapp.cn>
|
||||
* @Date: 2026-04-29 02:32:33
|
||||
* @LastEditors: YwxApp <ywx@ywxapp.cn>
|
||||
* @LastEditTime: 2026-07-21 22:27:10
|
||||
* @Description:
|
||||
* @FilePath: \ywxapp_dev\app\backend\controller\Ajax.php
|
||||
* @CustomString: Copyright (c) 2026 YwxApp
|
||||
*/
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\backend\controller;
|
||||
|
||||
use think\facade\Request;
|
||||
use think\facade\Filesystem;
|
||||
|
||||
use think\captcha\facade\Captcha;
|
||||
/**
|
||||
* Ajax 类
|
||||
*
|
||||
* @author ywxapp <admin@ywxapp.cn>
|
||||
*/
|
||||
class Ajax
|
||||
{
|
||||
/**
|
||||
* Summary of needLogin
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedLogin = ['verify', 'captcha'];
|
||||
|
||||
/**
|
||||
* Summary of needRight
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedVerify = ['*'];
|
||||
|
||||
/**
|
||||
* 控制器初始化 initialize
|
||||
* @return void
|
||||
*/
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
public function verify()
|
||||
{
|
||||
ob_clean();
|
||||
return Captcha::create();
|
||||
}
|
||||
|
||||
|
||||
public function captcha()
|
||||
{
|
||||
ob_clean();
|
||||
return Captcha::create();
|
||||
}
|
||||
|
||||
// 专供 UEditor 上传使用
|
||||
|
||||
public function ueditor()
|
||||
{
|
||||
$action = Request::param('action');
|
||||
|
||||
if ($action == 'config') {
|
||||
// 返回配置文件(JSON)
|
||||
$configStr = file_get_contents(public_path() . 'assets/plugin/ueditor/config.json');
|
||||
$config = json_decode($configStr, true);
|
||||
|
||||
// // 修改上传路径为 ThinkPHP 存储目录
|
||||
// $config['imagePathFormat'] = '/storage/ueditor/images/{yyyy}{mm}{dd}/{filename}_{time}';
|
||||
// $config['scrawlPathFormat'] = '/storage/ueditor/images/{yyyy}{mm}{dd}/{filename}_{time}';
|
||||
// $config['snapscreenPathFormat'] = '/storage/ueditor/images/{yyyy}{mm}{dd}/{filename}_{time}';
|
||||
// $config['catcherPathFormat'] = '/storage/ueditor/images/{yyyy}{mm}{dd}/{filename}_{time}';
|
||||
// $config['videoPathFormat'] = '/storage/ueditor/video/{yyyy}{mm}{dd}/{filename}_{time}';
|
||||
// $config['filePathFormat'] = '/storage/ueditor/files/{yyyy}{mm}{dd}/{filename}_{time}';
|
||||
|
||||
return json($config);
|
||||
}
|
||||
|
||||
// 图片上传处理
|
||||
if ($action == 'image' ||$action == 'uploadimage' || $action == 'uploadscrawl' || $action == 'uploadvideo' || $action == 'uploadfile') {
|
||||
return $this->handleUpload($action);
|
||||
}
|
||||
|
||||
return json(['state' => '请求类型错误']);
|
||||
}
|
||||
|
||||
|
||||
protected function handleUpload($action)
|
||||
{
|
||||
$file = request()->file('file') ?: null;
|
||||
|
||||
if (!$file) {
|
||||
return json(['state' => '没有文件上传']);
|
||||
}
|
||||
|
||||
try {
|
||||
$savename = Filesystem::disk('local')->putFile('ueditor', $file);
|
||||
$url = '/storage/' . str_replace('\\', '/', $savename); // Windows兼容
|
||||
|
||||
return json([
|
||||
'state' => 'SUCCESS',
|
||||
'url' => $url,
|
||||
'title' => basename($url),
|
||||
'original' => $file->getOriginalName(),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json(['state' => '上传失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user