新增文本编辑器选择

This commit is contained in:
wolfcode
2023-10-10 00:26:47 +08:00
parent 67a3980714
commit 5f5fb6d322
224 changed files with 58458 additions and 15 deletions

View File

@@ -6,7 +6,6 @@ use app\admin\model\SystemUploadfile;
use app\admin\service\UploadService;
use app\common\controller\AdminController;
use app\common\service\MenuService;
use app\admin\service\upload\Uploadfile;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@@ -128,4 +127,68 @@ class Ajax extends AdminController
return json($data);
}
/**
* @desc 百度编辑器上传
* @return Json
*/
public function uploadUEditor(): Json
{
$this->isDemo && $this->error('演示环境下不允许修改');
$uploadConfig = sysconfig('upload');
$upload_allow_size = $uploadConfig['upload_allow_size'];
$_upload_allow_ext = explode(',', $uploadConfig['upload_allow_ext']);
$upload_allow_ext = [];
array_map(function ($value) use (&$upload_allow_ext) {
$upload_allow_ext[] = '.' . $value;
}, $_upload_allow_ext);
$config = [
// 上传图片配置项
"imageActionName" => "image",
"imageFieldName" => "file",
"imageMaxSize" => $upload_allow_size,
"imageAllowFiles" => $upload_allow_ext,
"imageCompressEnable" => true,
"imageCompressBorder" => 5000,
"imageInsertAlign" => "none",
"imageUrlPrefix" => "",
// 列出图片
"imageManagerActionName" => "listImage",
"imageManagerListSize" => 20,
"imageManagerUrlPrefix" => "",
"imageManagerInsertAlign" => "none",
"imageManagerAllowFiles" => $upload_allow_ext,
];
$action = $this->request->param('action/s', '');
$file = $this->request->file('file');
$upload_type = $uploadConfig['upload_type'];
switch ($action) {
case 'image':
try {
$upload = UploadService::instance()->setConfig($uploadConfig)->$upload_type($file);
$code = $upload['code'] ?? 0;
if ($code == 0) {
return json(['state' => $upload['data'] ?? '上传错误信息']);
} else {
return json(['state' => 'SUCCESS', 'url' => $upload['data']['url'] ?? '']);
}
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
case 'listImage':
$res = (new SystemUploadfile())->order($this->sort)->limit(100)->column('url');
$list = [];
array_map(function ($value) use (&$list) {
$list[] = ['url' => $value,];
}, $res);
$result = [
"state" => "SUCCESS",
"list" => $list,
"total" => 0,
"start" => 0,
];
return json($result);
default:
return json($config);
}
}
}

View File

@@ -22,6 +22,7 @@ class Config extends AdminController
parent::__construct($app);
$this->model = new SystemConfig();
$this->assign('upload_types', config('admin.upload_types'));
$this->assign('editor_types', config('admin.editor_types'));
}
/**