Skip to content

Commit 72c8f16

Browse files
authored
Merge pull request #7 from liaodeity/8.x
8.2.1新增富文本编辑器,支持wangEditor和umeditor
2 parents 2be71ce + 47dadfa commit 72c8f16

File tree

32 files changed

+1085
-10232
lines changed

32 files changed

+1085
-10232
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.0...8.x)
3+
## [Unreleased](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.1...8.x)
4+
5+
## [v8.2.1(2021-06-09)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.2.0...8.2.1)
6+
7+
### Added
8+
- 添加单页面管理,添加富文本编辑器,修改图片上传
9+
- 更新wangEditor到最新4.7.2、修改富文本图片上传
10+
- 添加开发进度,修改说明
411

512
## [v8.2.0(2021-06-03)](https://github.com/liaodeity/laravel-admin-cms/compare/v8.1.14...8.2.0)
613

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
/*
3+
|-----------------------------------------------------------------------------------------------------------
4+
| laravel-admin-cms [ 简单高效的开发插件系统 ]
5+
|-----------------------------------------------------------------------------------------------------------
6+
| Licensed ( MIT )
7+
| ----------------------------------------------------------------------------------------------------------
8+
| Copyright (c) 2020-2021 https://gitee.com/liaodeiy/laravel-admin-cms All rights reserved.
9+
| ----------------------------------------------------------------------------------------------------------
10+
| Author: 廖春贵 < liaodeity@gmail.com >
11+
|-----------------------------------------------------------------------------------------------------------
12+
*/
13+
14+
namespace App\Http\Controllers\Admin;
15+
16+
use App\Enums\SexEnum;
17+
use App\Enums\StatusEnum;
18+
use App\Exceptions\BusinessException;
19+
use App\Http\Controllers\Controller;
20+
use App\Libs\QueryWhere;
21+
use App\Models\Log;
22+
use App\Models\Page;
23+
use App\Repositories\PageRepository;
24+
use Illuminate\Http\Request;
25+
use Illuminate\Support\Facades\View;
26+
27+
class PageController extends Controller
28+
{
29+
protected $module_name = 'page';
30+
/**
31+
* @var PageRepository
32+
*/
33+
private $repository;
34+
35+
public function __construct (PageRepository $repository)
36+
{
37+
SexEnum::attrs ();
38+
View::share ('MODULE_NAME', $this->module_name);//模块名称
39+
$this->repository = $repository;
40+
}
41+
42+
/**
43+
* Display a listing of the resource.
44+
*
45+
* @return \Illuminate\Http\Response
46+
*/
47+
public function index (Request $request)
48+
{
49+
50+
$category_id = $request->input ('category_id', 0);
51+
if (request ()->wantsJson ()) {
52+
$limit = $request->input ('limit', 15);
53+
QueryWhere::defaultOrderBy ('pages.id', 'DESC')->setRequest ($request->all ());
54+
$M = $this->repository->makeModel ()->select ('pages.*');
55+
QueryWhere::eq ($M, 'pages.category_id', $category_id);
56+
QueryWhere::eq ($M, 'pages.status');
57+
QueryWhere::eq ($M, 'pages.istop');
58+
QueryWhere::like ($M, 'pages.title');
59+
QueryWhere::like ($M, 'pages.link_label');
60+
QueryWhere::orderBy ($M);
61+
62+
$M = $M->paginate ($limit);
63+
$count = $M->total ();
64+
$data = $M->items ();
65+
foreach ($data as $key => $item) {
66+
$data[ $key ]['_url'] = url ('page/detail/' . $item->id);
67+
$data[ $key ]['status'] = StatusEnum::toLabel ($item->status);
68+
}
69+
$result = [
70+
'count' => $count,
71+
'data' => $data
72+
];
73+
74+
return ajax_success_result ('成功', $result);
75+
76+
} else {
77+
$page = $this->repository->makeModel ();
78+
79+
return view ('admin.' . $this->module_name . '.index', compact ('page', 'category_id'));
80+
}
81+
}
82+
83+
/**
84+
* Show the form for creating a new resource.
85+
*
86+
* @return \Illuminate\Http\Response
87+
*/
88+
public function create (Request $request)
89+
{
90+
$page = $this->repository->makeModel ();
91+
$_method = 'POST';
92+
$page->status = StatusEnum::NORMAL;
93+
94+
return view ('admin.' . $this->module_name . '.add', compact ('page', '_method'));
95+
}
96+
97+
/**
98+
* Store a newly created resource in storage.
99+
*
100+
* @param \Illuminate\Http\Request $request
101+
* @return \Illuminate\Http\Response
102+
*/
103+
public function store (Request $request)
104+
{
105+
$request->validate ([
106+
'Page.title' => 'required',
107+
'Page.name' => 'unique:pages,name',
108+
'Page.content' => 'required',
109+
'Page.status' => 'required',
110+
], [], [
111+
'Page.title' => '标题',
112+
'Page.name' => '英文标识',
113+
'Page.content' => '内容',
114+
'Page.status' => '状态',
115+
]);
116+
if (!check_admin_auth ($this->module_name . '_edit')) {
117+
return auth_error_return ();
118+
}
119+
$input = $request->input ('Page');
120+
$input = $this->formatRequestInput (__FUNCTION__, $input);
121+
try {
122+
$input['user_id'] = get_login_user_id ();
123+
$page = $this->repository->create ($input);
124+
if ($page) {
125+
$log_title = '添加单页面记录';
126+
Log::createLog (Log::ADD_TYPE, $log_title, '', $page->id, Page::class);
127+
128+
return ajax_success_result ('添加成功');
129+
} else {
130+
return ajax_success_result ('添加失败');
131+
}
132+
133+
} catch (BusinessException $e) {
134+
return ajax_error_result ($e->getMessage ());
135+
}
136+
}
137+
138+
private function formatRequestInput (string $__FUNCTION__, $input)
139+
{
140+
return $input;
141+
}
142+
143+
/**
144+
* Display the specified resource.
145+
*
146+
* @param \App\Models\Page $page
147+
* @return \Illuminate\Http\Response
148+
*/
149+
public function show (Page $page)
150+
{
151+
//
152+
}
153+
154+
/**
155+
* Show the form for editing the specified resource.
156+
*
157+
* @param \App\Models\Page $page
158+
* @return \Illuminate\Http\Response
159+
*/
160+
public function edit (Page $page)
161+
{
162+
$_method = 'PUT';
163+
164+
return view ('admin.' . $this->module_name . '.add', compact ('page', '_method'));
165+
}
166+
167+
/**
168+
* Update the specified resource in storage.
169+
*
170+
* @param \Illuminate\Http\Request $request
171+
* @param \App\Models\Page $page
172+
* @return \Illuminate\Http\Response
173+
*/
174+
public function update (Request $request, Page $page)
175+
{
176+
$request->validate ([
177+
'Page.title' => 'required',
178+
'Page.name' => 'unique:pages,name,' . $page->id,
179+
'Page.content' => 'required',
180+
'Page.status' => 'required',
181+
], [], [
182+
'Page.title' => '标题',
183+
'Page.name' => '英文标识',
184+
'Page.content' => '内容',
185+
'Page.status' => '状态',
186+
]);
187+
$input = $request->input ('Page');
188+
$input = $this->formatRequestInput (__FUNCTION__, $input);
189+
try {
190+
$input['user_id'] = get_login_user_id ();
191+
$page = $this->repository->update ($input, $page->id);
192+
if ($page) {
193+
$content = $page->toArray () ?? '';
194+
$log_title = '修改单页面记录';
195+
Log::createLog (Log::EDIT_TYPE, $log_title, $content, $page->id, Page::class);
196+
197+
return ajax_success_result ('修改成功');
198+
} else {
199+
return ajax_success_result ('修改失败');
200+
}
201+
202+
} catch (BusinessException $e) {
203+
return ajax_error_result ($e->getMessage ());
204+
}
205+
}
206+
207+
/**
208+
* Remove the specified resource from storage.
209+
*
210+
* @return \Illuminate\Http\Response
211+
* @throws BusinessException
212+
*/
213+
public function destroy ($id, Request $request)
214+
{
215+
$ids = $request->input ('ids', []);
216+
if (empty($ids)) {
217+
$ids[] = $id;
218+
}
219+
$ids = (array)$ids;
220+
$M = $this->repository->makeModel ();
221+
$lists = $M->whereIn ('id', $ids)->get ();
222+
$num = 0;
223+
foreach ($lists as $item) {
224+
try {
225+
$this->repository->checkAuth ($item);
226+
} catch (BusinessException $e) {
227+
return ajax_error_result ($e->getMessage ());
228+
}
229+
$log_title = '删除单页面[' . ($item->category->title ?? '') . '->' . $item->title . ']记录';
230+
$check = $this->repository->allowDelete ($item->id);
231+
if ($check) {
232+
$ret = $this->repository->delete ($item->id);
233+
if ($ret) {
234+
Log::createLog (Log::DELETE_TYPE, $log_title, $item, $item->id, Page::class);
235+
$num++;
236+
}
237+
}
238+
}
239+
240+
return ajax_success_result ('成功删除' . $num . '条记录');
241+
}
242+
}

app/Http/Controllers/Admin/UploadController.php

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
| Author: 廖春贵 < liaodeity@gmail.com >
1111
|-----------------------------------------------------------------------------------------------------------
1212
*/
13+
1314
namespace App\Http\Controllers\Admin;
1415

1516

1617
use App\Http\Controllers\Controller;
1718
use App\Models\Attachment;
1819
use App\Models\Log;
19-
use App\Models\User;
2020
use Illuminate\Http\Request;
2121
use Illuminate\Support\Facades\Storage;
22-
use Illuminate\Support\Str;
2322

2423
class UploadController extends Controller
2524
{
@@ -31,9 +30,14 @@ class UploadController extends Controller
3130
public function image (Request $request)
3231
{
3332
set_time_limit (0);
33+
$sourceType = $request->input ('type');
34+
$sourceId = $request->input ('id', '');
35+
if ($sourceType) {
36+
$sourceType = urldecode ($sourceType);
37+
}
3438
$name = $request->input ('name', 'upfile');
3539
$images = $request->file ($name);
36-
$filedir = "Uploads/" . date ('Ym') . '/';
40+
$filedir = "uploads/" . date ('Ym') . '/';
3741
$imagesName = $images->getClientOriginalName ();
3842
$extension = $images->getClientOriginalExtension ();
3943
$size = $images->getSize ();
@@ -45,56 +49,53 @@ public function image (Request $request)
4549
$newImagesName = get_uuid () . "." . $extension;
4650

4751

48-
$path = $filedir . $newImagesName;
52+
$path = $filedir . $newImagesName;
4953
$content = file_get_contents ($images->getRealPath ());
50-
Storage::disk ('web_public')->put ($path, $content);
51-
$insArr = [
52-
'name' => $imagesName,
53-
'path' => $path,
54-
'file_md5' => md5_file ($path),
55-
'file_sha1' => sha1_file ($path),
56-
'status' => 1
54+
Storage::disk ('public')->put ($path, $content);
55+
$public_path = 'storage/' . $path;
56+
$insArr = [
57+
'name' => $imagesName,
58+
'path' => $public_path,
59+
'file_md5' => md5_file ($public_path),
60+
'file_sha1' => sha1_file ($public_path),
61+
'source_type' => $sourceType,
62+
'source_id' => $sourceId,
63+
'status' => 1
5764
];
58-
$Attachment = Attachment::addFile ($insArr);
65+
$Attachment = Attachment::addFile ($insArr);
5966
if (!$Attachment) {
6067
return ajax_error_result ('上传失败');
6168
}
62-
//$result = [
63-
// 'data' => [
64-
// 'id' => $Attachment->id,
65-
// 'name' => $Attachment->name,
66-
// 'title' => str_replace ('.' . $extension, '', $picture->name),
67-
// 'src' => asset ($picture->path)
68-
// ]
69-
//];
70-
$data['id'] = $Attachment->id;
71-
$data['size'] = $size;
72-
$data['state'] = 'SUCCESS';
73-
$data['name'] = $newImagesName;
74-
$data['url'] = '/' . $Attachment->path;
75-
$data['type'] = '.' . $extension;
76-
$data['originalName'] = $Attachment->name;
7769

78-
// 图片水印
79-
$watermark = get_config_value ('watermark_text', '');
80-
if ($watermark) {
81-
$img = \Intervention\Image\Facades\Image::make ($path);
82-
$img->text ($watermark, $img->width () - 10, $img->height () - 10, function ($font) {
83-
$font_dir = public_path ('fonts/gdht.ttf');
84-
$font->file ($font_dir);
85-
$font->size (18);
86-
$font->color ('#FFFFFF');
87-
$font->align ('right');
88-
$font->valign ('bottom');
89-
});
90-
$img->save ($path);
91-
}
92-
93-
$data['src'] = $data['url'];
94-
$data['code'] = 0;
9570
Log::createLog (Log::INFO_TYPE, '上传图片记录', '', $Attachment->id, Attachment::class);
71+
$type = config ('gui.rich_editor');
72+
$data = [];
73+
switch ($type) {
74+
case 'umeditor':
75+
$data['code'] = 0;
76+
$data['id'] = $Attachment->id;
77+
$data['size'] = $size;
78+
$data['state'] = 'SUCCESS';
79+
$data['name'] = $newImagesName;
80+
$data['url'] = '/' . $Attachment->path;
81+
$data['type'] = '.' . $extension;
82+
$data['originalName'] = $Attachment->name;
83+
$data['src'] = $data['url'];
84+
//
85+
return @json_encode ($data);
86+
break;
87+
case 'wangEditor':
88+
$data['errno'] = 0;
89+
$row = [
90+
'url' => '/' . $Attachment->path,
91+
'alt' => $Attachment->name,
92+
'href' => '/' . $Attachment->path
93+
];
94+
$data['data'][] = $row;
95+
break;
96+
}
9697

97-
return json_encode ($data);
98+
return $data;
9899
}
99100

100101
/**

0 commit comments

Comments
 (0)