Skip to content

Commit 72f8388

Browse files
committedDec 22, 2022
更新:完成修改帖子页面视图
·
v2.7.7v2.1.7
1 parent 0ee8608 commit 72f8388

File tree

10 files changed

+320
-171
lines changed

10 files changed

+320
-171
lines changed
 

‎app/Plugins/Core/src/Models/Post.php

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?php
22

3-
declare (strict_types=1);
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
411
namespace App\Plugins\Core\src\Models;
512

613
use App\Model\Model;
@@ -10,11 +17,11 @@
1017
use Carbon\Carbon;
1118

1219
/**
13-
* @property int $id
14-
* @property string $content
15-
* @property string $markdown
16-
* @property string $user_agent
17-
* @property string $user_ip
20+
* @property int $id
21+
* @property string $content
22+
* @property string $markdown
23+
* @property string $user_agent
24+
* @property string $user_ip
1825
* @property Carbon $created_at
1926
* @property Carbon $updated_at
2027
*/
@@ -26,43 +33,50 @@ class Post extends Model
2633
* @var string
2734
*/
2835
protected $table = 'posts';
36+
2937
/**
3038
* The attributes that are mass assignable.
3139
*
3240
* @var array
3341
*/
34-
protected $fillable = ['id','user_id','comment_id','topic_id','content','markdown','user_agent','user_ip','created_at', 'updated_at'];
42+
protected $fillable = ['id', 'user_id', 'comment_id', 'topic_id', 'content', 'markdown', 'user_agent', 'user_ip', 'created_at', 'updated_at'];
43+
3544
/**
3645
* The attributes that should be cast to native types.
3746
*
3847
* @var array
3948
*/
4049
protected $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
41-
42-
/**
43-
* 获取作者信息
44-
* @return \Hyperf\Database\Model\Relations\BelongsTo
45-
*/
46-
public function user(): \Hyperf\Database\Model\Relations\BelongsTo
47-
{
48-
return $this->belongsTo(User::class,"user_id","id");
49-
}
50-
51-
/**
52-
* 获取所属帖子信息
53-
* @return \Hyperf\Database\Model\Relations\BelongsTo
54-
*/
55-
public function topic(): \Hyperf\Database\Model\Relations\BelongsTo
56-
{
57-
return $this->belongsTo(Topic::class,"topic_id","id");
58-
}
59-
60-
/**
61-
* 获取所属评论信息
62-
* @return \Hyperf\Database\Model\Relations\BelongsTo
63-
*/
64-
public function comments(): \Hyperf\Database\Model\Relations\BelongsTo
65-
{
66-
return $this->belongsTo(TopicComment::class,"comment_id","id");
67-
}
68-
}
50+
51+
/**
52+
* 获取作者信息.
53+
*/
54+
public function user(): \Hyperf\Database\Model\Relations\BelongsTo
55+
{
56+
return $this->belongsTo(User::class, 'user_id', 'id');
57+
}
58+
59+
/**
60+
* 获取所属帖子信息.
61+
*/
62+
public function topic(): \Hyperf\Database\Model\Relations\BelongsTo
63+
{
64+
return $this->belongsTo(Topic::class, 'topic_id', 'id');
65+
}
66+
67+
/**
68+
* 获取所属评论信息.
69+
*/
70+
public function comments(): \Hyperf\Database\Model\Relations\BelongsTo
71+
{
72+
return $this->belongsTo(TopicComment::class, 'comment_id', 'id');
73+
}
74+
75+
/*
76+
* 获取options信息
77+
*/
78+
public function options(): \Hyperf\Database\Model\Relations\HasOne
79+
{
80+
return $this->hasOne(PostsOption::class, 'post_id');
81+
}
82+
}

‎app/Plugins/Topic/bootstrap.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,23 @@
246246
Itf()->add('topic-create-editor-external_plugins', 0, [
247247
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
248248
]);
249+
250+
251+
Itf()->add('topic-edit-data', 0, [
252+
'enable' => (function () {
253+
return true;
254+
}),
255+
'view' => 'Topic::edit.basis',
256+
'scripts' => [
257+
file_hash('plugins/Topic/js/topic.js'),
258+
file_hash('tabler/libs/tom-select/dist/js/tom-select.base.min.js'),
259+
file_hash('tabler/libs/tinymce/tinymce.min.js'),
260+
],
261+
]);
262+
263+
Itf()->add('topic-edit-options', 0, [
264+
'enable' => (function () {
265+
return true;
266+
}),
267+
'view' => 'Topic::edit.options.disable_comment',
268+
]);

‎app/Plugins/Topic/resources/views/edit.blade.php

Lines changed: 54 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@extends("App::app")
22

3-
@section('title', __("topic.edit topic").':'.$data['title'])
3+
@section('title', __("topic.edit topic").':'.$data['title']."")
44

55
@section('header')
66
<div class="page-wrapper">
@@ -26,91 +26,70 @@
2626
@endsection
2727
@section('content')
2828

29-
<div id="edit-topic-vue">
30-
<form action="" method="post" @@submit.prevent="submit">
31-
<div class="row row-cards">
32-
<div class="col-md-12">
33-
<div class="mb-3 border-0 card card-body">
34-
<h3 class="card-title">{{__("app.title")}}</h3>
35-
<input type="text" v-model="title" class="form-control form-control-lg form-control-flush"
36-
placeholder="{{__("topic.Please enter a title")}}" required>
37-
<h3 class="card-title">{{__("app.tag")}}</h3>
38-
<div class="mb-3">
39-
<select id="select-tags" v-model="tag_selected"
40-
class="form-select form-select-lg form-control-flush">
41-
<option v-for="option in tags" :data-custom-properties="option.icons" :value="option.value">
42-
@{{ option . text }}
43-
</option>
44-
</select>
45-
</div>
46-
<div class="mb-3">
47-
<div class="row">
48-
@if(get_options("topic_emoji_close",'false')!=="true" && count((new \App\Plugins\Core\src\Lib\Emoji())->get()))
49-
<div class="col-lg-3">
50-
<div class="card">
51-
<ul class="nav nav-tabs" data-bs-toggle="tabs" style="flex-wrap: inherit;
52-
width: 100%;
53-
height: 3.333333rem;
54-
padding: 0.373333rem 0.32rem 0;
55-
box-sizing: border-box;
56-
/* 下面是实现横向滚动的关键代码 */
57-
display: inline;
58-
float: left;
59-
white-space: nowrap;
60-
overflow-x: scroll;
61-
-webkit-overflow-scrolling: touch; /*解决在ios滑动不顺畅问题*/
62-
overflow-y: hidden;">
63-
@foreach((new \App\Plugins\Core\src\Lib\Emoji())->get() as $key => $value)
64-
<li class="nav-item">
65-
<a href="#emoji-list-{{$key}}" class="nav-link @if ($loop->first) active @endif" data-bs-toggle="tab">{{$key}}</a>
66-
</li>
67-
@endforeach
68-
</ul>
69-
<div class="card-body">
70-
<div class="tab-content">
71-
@foreach((new \App\Plugins\Core\src\Lib\Emoji())->get() as $key => $value)
72-
<div class="tab-pane @if ($loop->first) active @endif show" id="emoji-list-{{$key}}" style="max-height: 320px;overflow-x: hidden;">
73-
<div class="row">
74-
@if($value['type'] === 'image')
75-
@foreach($value['container'] as $emojis)
76-
<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>
77-
@endforeach
78-
@endif
79-
</div>
80-
</div>
81-
@endforeach
82-
</div>
83-
</div>
84-
</div>
85-
</div>
86-
<div class="col-lg-9">
87-
<div id="content-vditor"></div>
88-
</div>
89-
@else
90-
<div class="col-md-12">
91-
<div id="content-vditor"></div>
92-
</div>
93-
@endif
29+
<div class="row row-cards">
30+
31+
<div class="col-12" id="topic-create">
32+
<form action="/topic/update" method="POST">
33+
<div class="row row-cards">
34+
<div class="col-lg-9">
9435

36+
<div class="card">
37+
<div class="card-header">
38+
<h3 class="card-title">帖子信息</h3>
39+
</div>
40+
<div class="card-body">
41+
@foreach(Itf()->get('topic-edit-data') as $k=>$v)
42+
@if(call_user_func($v['enable'])===true && isset($v['view']))
43+
@include($v['view'])
44+
@endif
45+
@endforeach
9546
</div>
9647
</div>
97-
<div class="mb-3">
98-
<button class="btn btn-primary">{{__("app.submit")}}</button>
48+
49+
</div>
50+
51+
<div class="col-lg-3">
52+
<div class="card">
53+
<div class="card-header">
54+
<h3 class="card-title">附加信息</h3>
55+
</div>
56+
<div class="card-body">
57+
<div class="row">
58+
@foreach(Itf()->get('topic-edit-options') as $k=>$v)
59+
@if(call_user_func($v['enable'])===true)
60+
@include($v['view'])
61+
@endif
62+
@endforeach
63+
</div>
64+
</div>
9965
</div>
10066
</div>
67+
<div class="col-12">
68+
@csrf()
69+
<button class="btn btn-primary" type="submit">提交</button>
70+
</div>
10171
</div>
102-
</div>
103-
</form>
72+
</form>
73+
</div>
10474
</div>
10575

10676
@endsection
10777

10878
@section('scripts')
109-
<script type="text/javascript">
110-
var topic_id = {{$data->id}};
111-
</script>
112-
113-
<script src="{{ mix('plugins/Topic/js/topic.js') }}"></script>
79+
@foreach(Itf()->get('topic-edit-data') as $k=>$v)
80+
@if(call_user_func($v['enable'])===true && isset($v['scripts']))
81+
@foreach($v['scripts'] as $script)
82+
<script src="{{$script}}" defer></script>
83+
@endforeach
84+
@endif
85+
@endforeach
86+
@foreach(Itf()->get('topic-edit-options') as $k=>$v)
87+
@if(call_user_func($v['enable'])===true && isset($v['scripts']) && is_array($v['scripts']))
88+
@foreach($v['scripts'] as $script)
89+
<script src="{{$script}}" defer></script>
90+
@endforeach
91+
@endif
92+
@endforeach
11493
@endsection
11594
@section('headers')
11695
<link rel="stylesheet" href="{{ mix('plugins/Topic/css/app.css') }}">
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<div class="mb-3">
2+
<label class="form-label">标题</label>
3+
<input type="text" class="form-control" value="{{$data->title}}" name="basis[title]" placeholder="title" required>
4+
</div>
5+
6+
<div class="mb-3">
7+
<label class="form-label">选择标签</label>
8+
<select type="text" name="basis[tag]" class="form-select" id="select-topic-tags" required>
9+
@foreach(\App\Plugins\Topic\src\Models\TopicTag::query()->where('status','=',null)->get() as $topic_tags)
10+
<option value="{{$topic_tags->id}}"
11+
data-custom-properties="&lt;span class=&quot;badge&quot; style=&quot;background-color: {{$topic_tags->color}} &quot; &gt;{{$topic_tags->icon}}&lt;/span&gt;" @if($data->tag->id===$topic_tags->id){{"selected"}}@endif>
12+
{{$topic_tags->name}}
13+
</option>
14+
@endforeach
15+
</select>
16+
</div>
17+
18+
19+
<div class="mb-3">
20+
<label class="form-label">内容正文</label>
21+
<textarea name="basis[content]" id="basis-content" cols="30" rows="10">{!! $data->post->content !!}</textarea>
22+
</div>
23+
24+
<script src="{{file_hash("js/axios.min.js")}}"></script>
25+
<script defer>
26+
const target = document.getElementsByTagName("html")[0]
27+
const body_className = document.getElementsByTagName("html")[0].getAttribute("data-theme");
28+
const observer = new MutationObserver(function (mutations) {
29+
mutations.forEach(function (mutation) {
30+
if (body_className !== document.getElementsByTagName("html")[0].getAttribute("data-theme")) {
31+
location.reload()
32+
}
33+
});
34+
});
35+
36+
observer.observe(target, {attributes: true});
37+
38+
const image_upload_handler = (blobInfo, progress) => new Promise((resolve, reject) => {
39+
const formData = new FormData();
40+
formData.append('file', blobInfo.blob(), blobInfo.filename());
41+
formData.append('_token', csrf_token);
42+
axios.post("/user/upload/image",formData,{
43+
'Content-type' : 'multipart/form-data'
44+
}).then(function(r){
45+
console.log(r)
46+
const data = r.data;
47+
if(data.success){
48+
resolve(data.result.url);
49+
return ;
50+
}
51+
reject({message:'HTTP Error: ' + data.result.msg + ', Error Code: '+data.code,remove: true});
52+
}).catch(function(e){
53+
console.log(e)
54+
})
55+
56+
});
57+
58+
document.addEventListener("DOMContentLoaded", function () {
59+
let options = {
60+
selector: '#basis-content',
61+
height: 450,
62+
menu:{!! \App\Plugins\Topic\src\Lib\Editor::menu() !!},
63+
menubar:"{!! \App\Plugins\Topic\src\Lib\Editor::menubar() !!}",
64+
statusbar: true,
65+
elementpath: true,
66+
promotion: false,
67+
plugins: {!! \App\Plugins\Topic\src\Lib\Editor::plugins() !!},
68+
language: "zh-Hans",
69+
toolbar: "{!! \App\Plugins\Topic\src\Lib\Editor::toolbar() !!}",
70+
link_default_target: '_blank',
71+
toolbar_mode: 'sliding',
72+
image_advtab: true,
73+
automatic_uploads: true,
74+
convert_urls:false,
75+
setup : function(ed) {
76+
//console.log(ed)
77+
},
78+
external_plugins:{!! \App\Plugins\Topic\src\Lib\Editor::externalPlugins() !!},
79+
images_upload_handler: image_upload_handler,
80+
init_instance_callback: (editor) => {
81+
@if(request()->has('restoredraft'))
82+
editor.plugins.autosave.restoreDraft()
83+
@endif
84+
},
85+
mobile:{
86+
menu:{!! \App\Plugins\Topic\src\Lib\Editor::menu() !!},
87+
menubar:"{!! \App\Plugins\Topic\src\Lib\Editor::menubar() !!}",
88+
toolbar_mode: 'scrolling'
89+
},
90+
autosave_ask_before_unload: true,
91+
autosave_interval: '1s',
92+
autosave_prefix: '{{config('codefec.app.name')}}-{path}{query}-{id}-',
93+
autosave_restore_when_empty: false,
94+
autosave_retention: '1400m',
95+
branding:false,
96+
content_style: 'body { font-family: -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }'
97+
}
98+
if (document.body.className === 'theme-dark') {
99+
options.skin = 'oxide-dark';
100+
options.content_css = 'dark';
101+
}
102+
tinyMCE.init(options);
103+
});
104+
</script>

0 commit comments

Comments
 (0)
Please sign in to comment.