mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-01 16:22:49 +08:00
feat: 添加Vditor编辑器支持并扩展文件上传功能
- 新增Vditor编辑器静态资源文件,包括图片、字体和样式文件 - 在文件上传控制器中添加vditorSave方法,支持Vditor编辑器文件上传 - 在文章创建页面添加编辑器类型选择(富文本/Markdown) - 更新.gitignore文件,排除Playwright和QA截图目录 - 扩展UploadFiles类以支持Vditor编辑器的文件上传格式
This commit is contained in:
@@ -148,6 +148,38 @@ class UploadFiles
|
||||
]);
|
||||
}
|
||||
|
||||
public static function vditorSave(Request $request)
|
||||
{
|
||||
$type = $request->param('type', 'editor');
|
||||
if (empty($type)) {
|
||||
return json_message('缺少类型参数');
|
||||
}
|
||||
$dir_name = $request->param('dir', $type);
|
||||
|
||||
$files = $request->file();
|
||||
$succMap = [];
|
||||
$errFiles = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
try {
|
||||
self::fileScan($file);
|
||||
$model_file = self::saveFile($file, $type, $dir_name);
|
||||
$succMap[$file->getOriginalName()] = $model_file->src;
|
||||
} catch (\Throwable $th) {
|
||||
$errFiles[] = $file->getOriginalName();
|
||||
}
|
||||
}
|
||||
|
||||
return json([
|
||||
'msg' => '',
|
||||
'code' => 0,
|
||||
'data' => [
|
||||
'errFiles' => $errFiles,
|
||||
'succMap' => $succMap,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function saveFile($file, $type, $dir_name = null)
|
||||
{
|
||||
if (is_null($dir_name)) {
|
||||
|
||||
@@ -70,6 +70,11 @@ class File extends Common
|
||||
return AppUploadFiles::editormdSave($request);
|
||||
}
|
||||
|
||||
public function vditorSave(Request $request)
|
||||
{
|
||||
return AppUploadFiles::vditorSave($request);
|
||||
}
|
||||
|
||||
public function wangEditorSave(Request $request)
|
||||
{
|
||||
return AppUploadFiles::wangEditorSave($request);
|
||||
|
||||
@@ -8,6 +8,10 @@ use app\model\Nav;
|
||||
use app\model\Post as ModelPost;
|
||||
use app\model\PostCategory;
|
||||
use app\model\PostTag;
|
||||
use League\CommonMark\Environment\Environment;
|
||||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
||||
use League\CommonMark\Extension\Table\TableExtension;
|
||||
use League\CommonMark\MarkdownConverter;
|
||||
use League\HTMLToMarkdown\HtmlConverter;
|
||||
use think\facade\Cache;
|
||||
use think\facade\View;
|
||||
@@ -188,6 +192,10 @@ class Post extends Common
|
||||
|
||||
View::assign('post', $model_post);
|
||||
|
||||
if ($model_post->content_type === 'markdown') {
|
||||
return View::fetch('edit_content_markdown');
|
||||
}
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
@@ -223,6 +231,9 @@ class Post extends Common
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
// 禁止修改 content_type
|
||||
unset($post_data['content_type']);
|
||||
|
||||
$model_post = ModelPost::find($id);
|
||||
|
||||
$categorys = [];
|
||||
@@ -274,6 +285,14 @@ class Post extends Common
|
||||
}
|
||||
}
|
||||
|
||||
// Markdown->HTML 自动转换
|
||||
if ($model_post->getData('content_type') === 'markdown' && isset($post_data['content'])) {
|
||||
$environment = Environment::createCommonMarkEnvironment();
|
||||
$environment->addExtension(new TableExtension());
|
||||
$converter = new MarkdownConverter($environment);
|
||||
$post_data['content_html'] = $converter->convert($post_data['content'])->getContent();
|
||||
}
|
||||
|
||||
$model_post->save($post_data);
|
||||
|
||||
Cache::delete('sitemap_last_etag');
|
||||
|
||||
Reference in New Issue
Block a user