/
basis.blade.php
135 lines (127 loc) · 5.55 KB
/
basis.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<div x-data="basis">
<div class="mb-3">
<label class="form-label">标题</label>
<input type="text" x-model="title" id="topic-create-title" class="form-control" value="{{request()->input('basis.title')}}" name="basis[title]" placeholder="title" required>
</div>
<div class="mb-3">
<label class="form-label">选择标签</label>
<select type="text" x-model="tag" name="basis[tag]" class="form-select" id="select-topic-tags" required>
<option value="null"
data-custom-properties="">
请选择
</option>
@foreach(\App\Plugins\Topic\src\Models\TopicTag::query()->where('status','=',null)->get() as $topic_tags)
<option value="{{$topic_tags->id}}"
data-custom-properties="<span class="badge" style="background-color: {{$topic_tags->color}} " >{{$topic_tags->icon}}</span>" @if(request()->input('basis.tag') && request()->input('basis.tag')==$topic_tags->id){{"selected"}}@endif>
{{$topic_tags->name}}
</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label class="form-label">内容正文</label>
<textarea name="basis[content]" id="basis-content" cols="30" rows="10"></textarea>
</div>
</div>
<script src="{{file_hash("js/axios.min.js")}}"></script>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('basis', () => ({
init() {
this.$watch('title', () => {
localStorage.setItem('create_topic_title',this.title)
})
this.$watch('tag', () => {
localStorage.setItem('create_topic_tag',this.tag)
})
},
title: (()=>{
if(localStorage.getItem('create_topic_title')){
return localStorage.getItem('create_topic_title')
}
return null;
}),
tag:(()=>{
if(localStorage.getItem('create_topic_tag')){
return localStorage.getItem('create_topic_tag')
}
return null;
})
}))
})
</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);
formData.append('_session', _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: '#basis-content',
height: 450,
menu:{!! \App\Plugins\Topic\src\Lib\Create\Editor::menu() !!},
menubar:"{!! \App\Plugins\Topic\src\Lib\Create\Editor::menubar() !!}",
statusbar: true,
elementpath: true,
promotion: false,
plugins: {!! \App\Plugins\Topic\src\Lib\Create\Editor::plugins() !!},
language: "zh-Hans",
toolbar: "{!! \App\Plugins\Topic\src\Lib\Create\Editor::toolbar() !!}",
link_default_target: '_blank',
toolbar_mode: 'sliding',
image_advtab: true,
automatic_uploads: true,
convert_urls:false,
setup : function(ed) {
//console.log(ed)
},
external_plugins:{!! \App\Plugins\Topic\src\Lib\Create\Editor::externalPlugins() !!},
images_upload_handler: image_upload_handler,
init_instance_callback: (editor) => {
if(localStorage.getItem('topic_create_content')){
editor.setContent(localStorage.getItem('topic_create_content'))
}
editor.on('input', function(e) {
localStorage.setItem('topic_create_content',editor.getContent())
});
},
mobile:{
menu:{!! \App\Plugins\Topic\src\Lib\Create\Editor::menu() !!},
menubar:"{!! \App\Plugins\Topic\src\Lib\Create\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>