Skip to content

Commit

Permalink
更新:完成修改评论内容
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Dec 25, 2022
1 parent 1fc866a commit 12b2e6a
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 95 deletions.
3 changes: 2 additions & 1 deletion app/Plugins/Comment/bootstrap.php
@@ -1,6 +1,7 @@
<?php

Itf()->add('create-topic-comment-handle-middleware-end', 0, \App\Plugins\Comment\src\Handler\Middleware\Create\Topic\EndMiddleware::class);
Itf()->add('edit-topic-comment-handle-middleware-end', 0, \App\Plugins\Comment\src\Handler\Middleware\Edit\Topic\EndMiddleware::class);

Itf()->add('comment-topic-create-editor-external_plugins', 0, [
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
Expand All @@ -9,7 +10,7 @@
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
]);
Itf()->add('comment-topic-create-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
Itf()->add('comment-topic-edit-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
Itf()->add('comment-topic-edit-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);

Itf()->add('comment-topic-create-editor-toolbar', 0, ['undo', 'redo', '|', 'blocks', '|', 'bold', 'italic', 'underline', 'strikethrough', '|', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'outdent', 'indent', 'numlist', 'bullist', '|', 'forecolor', 'backcolor', 'removeformat', 'insertfile', 'image', 'media', 'link', 'sfPreview', 'restoredraft', 'codesample', '|', 'ltr', 'rtl']);
Itf()->add('comment-topic-edit-editor-toolbar', 0, ['undo', 'redo', '|', 'blocks', '|', 'bold', 'italic', 'underline', 'strikethrough', '|', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'outdent', 'indent', 'numlist', 'bullist', '|', 'forecolor', 'backcolor', 'removeformat', 'insertfile', 'image', 'media', 'link', 'sfPreview', 'restoredraft', 'codesample', '|', 'ltr', 'rtl']);
Expand Down
14 changes: 7 additions & 7 deletions app/Plugins/Comment/resources/views/topic/create.blade.php
Expand Up @@ -82,29 +82,29 @@
let options = {
selector: '#content',
height: 450,
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
menu:{!! \App\Plugins\Comment\src\Lib\Create\Editor::menu() !!},
menubar:"{!! \App\Plugins\Comment\src\Lib\Create\Editor::menubar() !!}",
statusbar: true,
elementpath: true,
promotion: false,
plugins: {!! \App\Plugins\Comment\src\Lib\Edit\Editor::plugins() !!},
plugins: {!! \App\Plugins\Comment\src\Lib\Create\Editor::plugins() !!},
language: "zh-Hans",
toolbar: "{!! \App\Plugins\Comment\src\Lib\Edit\Editor::toolbar() !!}",
toolbar: "{!! \App\Plugins\Comment\src\Lib\Create\Editor::toolbar() !!}",
link_default_target: '_blank',
toolbar_mode: 'sliding',
image_advtab: true,
automatic_uploads: true,
convert_urls:false,
external_plugins:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::externalPlugins() !!},
external_plugins:{!! \App\Plugins\Comment\src\Lib\Create\Editor::externalPlugins() !!},
images_upload_handler: image_upload_handler,
init_instance_callback: (editor) => {
@if(request()->has('restoredraft'))
editor.plugins.autosave.restoreDraft()
@endif
},
mobile:{
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
menu:{!! \App\Plugins\Comment\src\Lib\Create\Editor::menu() !!},
menubar:"{!! \App\Plugins\Comment\src\Lib\Create\Editor::menubar() !!}",
toolbar_mode: 'scrolling'
},
autosave_ask_before_unload: true,
Expand Down
178 changes: 103 additions & 75 deletions app/Plugins/Comment/resources/views/topic/edit.blade.php
@@ -1,80 +1,45 @@
@extends("App::app")

@section('title',"修改id为:".$data->id."的评论")
@section('title',"修改评论")


@section('content')

<div class="row justify-content-center">
<div class="col-md-12">
<div class="border-0 card">
<div class="row row-cards justify-content-center">
<div class="col-lg-12">
<ol class="breadcrumb breadcrumb-arrows" aria-label="breadcrumbs">
<li class="breadcrumb-item"><a href="/">首页</a></li>
<li class="breadcrumb-item"><a href="/tags/{{$comment->topic->tag->id}}.html">
{!! $comment->topic->tag->icon !!}
{{$comment->topic->tag->name}}
</a>
</li>
<li class="breadcrumb-item"><a href="/{{$comment->topic->id}}.html">
{{\Hyperf\Utils\Str::limit($comment->topic->title,25)}}
</a>
</li>
<li class="breadcrumb-item"><a href="{{'/' . $comment->topic_id . '.html/' . $comment->id . '?page=' . get_topic_comment_page($comment->id)}}">
ID【{{$comment->id}}】的评论
</a>
</li>
<li class="breadcrumb-item active" aria-current="page"><a href="#">修改评论</a></li>
</ol>
</div>
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<h3 class="card-title"><a class="text-red"
href="/{{$data->topic->id}}.html">{{$data->topic->title}}</a>
下id为{{$data->id}}的评论</h3>
<h3 class="card-title">回帖</h3>
</div>
<div class="card-body" id="vue-comment-topic-edit-form">
<form action="" method="post" @@submit.prevent="submit">
<div class="row">
<div class="mb-3">
<div class="row">
@if(get_options("comment_emoji_close",'false')!=="true" && count((new \App\Plugins\Core\src\Lib\Emoji())->get()))
<div class="col-lg-3">
<div class="card">
<ul class="nav nav-tabs" data-bs-toggle="tabs" style="flex-wrap: inherit;
width: 100%;
height: 3.333333rem;
padding: 0.373333rem 0.32rem 0;
box-sizing: border-box;
/* 下面是实现横向滚动的关键代码 */
display: inline;
float: left;
white-space: nowrap;
overflow-x: scroll;
-webkit-overflow-scrolling: touch; /*解决在ios滑动不顺畅问题*/
overflow-y: hidden;">
@foreach((new \App\Plugins\Core\src\Lib\Emoji())->get() as $key => $value)
<li class="nav-item">
<a href="#emoji-list-{{$key}}"
class="nav-link @if ($loop->first) active @endif"
data-bs-toggle="tab">{{$key}}</a>
</li>
@endforeach
</ul>
<div class="card-body">
<div class="tab-content">
@foreach((new \App\Plugins\Core\src\Lib\Emoji())->get() as $key => $value)
<div class="tab-pane @if ($loop->first) active @endif show"
id="emoji-list-{{$key}}"
style="max-height: 220px;overflow-x: hidden;">
<div class="row">
@if($value['type'] === 'image')
@foreach($value['container'] as $emojis)
<div @@click="selectEmoji('{{$emojis['text']}}')"
class="col-3 col-sm-2 col-md-4 col-lg-3 hvr-glow emoji-picker"
emoji-data="{{$emojis['text']}}">{!! $emojis['icon'] !!}</div>
@endforeach
@endif
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="col-lg-9">
<div id="vditor"></div>
</div>
@else
<div class="col-md-12">
<div id="vditor"></div>
</div>
@endif
<div class="col-12 mt-3">
<button class="btn btn-primary" style="margin-top: 5px">提交</button>
</div>
</div>
</div>
<div class="card-body">
<form action="/comment/topic/{{$comment->id}}/edit" method="post">
<x-csrf/>
<input type="hidden" name="comment_id" value="{{$comment->id}}">
<div class="mb-3">
<label for="" class="form-label"></label>
<textarea name="content" id="content" rows="3">{!! $comment->post->content !!}</textarea>
</div>
<div class="mb-3 d-flex flex-row-reverse">
<button class="btn btn-primary" type="submit">修改评论</button>
</div>
</form>
</div>
Expand All @@ -84,11 +49,74 @@ class="col-3 col-sm-2 col-md-4 col-lg-3 hvr-glow emoji-picker"

@endsection

@section('headers')
<link rel="stylesheet" href="{{ mix('plugins/Topic/css/app.css') }}">
@endsection
@section('scripts')
<script>var comment_id = {{$data->id}}</script>
<script>var topic_id = {{$data->topic_id}}</script>
<script src="{{mix("plugins/Comment/js/edit.js")}}"></script>
<script src="{{file_hash("js/axios.min.js")}}"></script>
<script src="{{file_hash('tabler/libs/tinymce/tinymce.min.js')}}"></script>
<script defer>
const target = document.getElementsByTagName("html")[0]
const body_className = document.getElementsByTagName("html")[0].getAttribute("data-theme");
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (body_className !== document.getElementsByTagName("html")[0].getAttribute("data-theme")) {
location.reload()
}
});
});

observer.observe(target, {attributes: true});

const image_upload_handler = (blobInfo, progress) => new Promise((resolve, reject) => {
const formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('_token', csrf_token);
axios.post("/user/upload/image",formData,{
'Content-type' : 'multipart/form-data'
}).then(function(r){
console.log(r)
const data = r.data;
if(data.success){
resolve(data.result.url);
return ;
}
reject({message:'HTTP Error: ' + data.result.msg + ', Error Code: '+data.code,remove: true});
}).catch(function(e){
console.log(e)
})

});

document.addEventListener("DOMContentLoaded", function () {
let options = {
selector: '#content',
height: 450,
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
statusbar: true,
elementpath: true,
promotion: false,
plugins: {!! \App\Plugins\Comment\src\Lib\Edit\Editor::plugins() !!},
language: "zh-Hans",
toolbar: "{!! \App\Plugins\Comment\src\Lib\Edit\Editor::toolbar() !!}",
link_default_target: '_blank',
toolbar_mode: 'sliding',
image_advtab: true,
automatic_uploads: true,
convert_urls:false,
external_plugins:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::externalPlugins() !!},
images_upload_handler: image_upload_handler,
mobile:{
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
toolbar_mode: 'scrolling'
},
branding:false,
content_style: 'body { font-family: -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }'
}
if (document.body.className === 'theme-dark') {
options.skin = 'oxide-dark';
options.content_css = 'dark';
}
tinyMCE.init(options);
});
</script>
@endsection
Expand Up @@ -10,20 +10,22 @@
*/
namespace App\Plugins\Comment\src\Controller;

use App\Plugins\Comment\src\Handler\EditTopicComment;
use App\Plugins\Comment\src\Model\TopicComment;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: '/comment')]
class IndexController
class EditTopicCommentController
{
#[GetMapping(path: 'topic/{id}/edit')]
public function edit_topic_comment($id)
public function index($id)
{
if (! TopicComment::query()->where('id', $id)->exists()) {
return admin_abort('id为:' . $id . '的评论不存在', 404);
}
$data = TopicComment::query()->where('id', $id)->first();
$data = TopicComment::query()->find($id);
$quanxian = false;
if (Authority()->check('admin_topic_edit') && curd()->GetUserClass(auth()->data()->class_id)['permission-value'] > curd()->GetUserClass($data->user->class_id)['permission-value']) {
$quanxian = true;
Expand All @@ -34,6 +36,13 @@ public function edit_topic_comment($id)
if ($quanxian === false) {
return admin_abort('无权操作!', 419);
}
return view('Comment::topic.edit', ['data' => $data]);
return view('Comment::topic.edit', ['comment' => $data]);
}

#[PostMapping(path: 'topic/{id}/edit')]
public function update($id)
{

return (new EditTopicComment())->handler($id);
}
}
2 changes: 1 addition & 1 deletion app/Plugins/Comment/src/Handler/CreateTopicComment.php
Expand Up @@ -20,7 +20,7 @@ class CreateTopicComment
public function handler($topic_id)
{
$request = request()->all();
$request[$topic_id] = $topic_id;
$request['topic_id'] = $topic_id;
$handler = function ($request) {
return $request;
};
Expand Down
73 changes: 73 additions & 0 deletions app/Plugins/Comment/src/Handler/EditTopicComment.php
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\Comment\src\Handler;

use App\Plugins\Comment\src\Annotation\Topic\UpdateFirstMiddleware;
use App\Plugins\Comment\src\Annotation\Topic\UpdateLastMiddleware;
use App\Plugins\Comment\src\Annotation\Topic\UpdateMiddleware;
use Hyperf\Di\Annotation\AnnotationCollector;

class EditTopicComment
{
public function handler($comment_id)
{
$request = request()->all();
$request['comment_id'] = $comment_id;
$handler = function ($request) {
return $request;
};

// 通过中间件
$run = $this->throughMiddleware($handler, $this->middlewares());
return $run($request);
}

/**
* 通过中间件 through the middleware.
* @param $handler
* @param $stack
* @return \Closure|mixed
*/
protected function throughMiddleware($handler, $stack)
{
// 闭包实现中间件功能 closures implement middleware functions
foreach ($stack as $middleware) {
$handler = function ($request) use ($handler, $middleware) {
if ($middleware instanceof \Closure) {
return call_user_func($middleware, $request, $handler);
}

return call_user_func([new $middleware(), 'handler'], $request, $handler);
};
}
return $handler;
}

private function middlewares(): array
{
$middlewares = [];
foreach (AnnotationCollector::getClassesByAnnotation(UpdateFirstMiddleware::class) as $key => $value) {
$middlewares[] = $key;
}
foreach (AnnotationCollector::getClassesByAnnotation(UpdateMiddleware::class) as $key => $value) {
$middlewares[] = $key;
}
foreach (AnnotationCollector::getClassesByAnnotation(UpdateLastMiddleware::class) as $key => $value) {
$middlewares[] = $key;
}
$endMiddlewares = Itf()->get('edit-topic-comment-handle-middleware-end');
krsort($endMiddlewares);
foreach ($endMiddlewares as $value) {
$middlewares[] = $value;
}
return array_reverse($middlewares);
}
}

0 comments on commit 12b2e6a

Please sign in to comment.