diff --git a/app/Controller/Admin/ComponentController.php b/app/Controller/Admin/Hook/ComponentController.php similarity index 60% rename from app/Controller/Admin/ComponentController.php rename to app/Controller/Admin/Hook/ComponentController.php index 9d793bcfb..a3c8a3ee7 100644 --- a/app/Controller/Admin/ComponentController.php +++ b/app/Controller/Admin/Hook/ComponentController.php @@ -8,7 +8,8 @@ * @contact laravel@88.com * @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE */ -namespace App\Controller\Admin; + +namespace App\Controller\Admin\Hook; use App\Middleware\AdminMiddleware; use Hyperf\HttpServer\Annotation\Controller; @@ -17,21 +18,22 @@ use Hyperf\Paginator\LengthAwarePaginator; use Hyperf\Utils\Collection; use Hyperf\Utils\Str; +use Hyperf\ViewEngine\Contract\FactoryInterface; use Swoole\Coroutine\System; use Symfony\Component\Finder\Finder; -#[Controller(prefix: '/admin/setting/components')] +#[Controller(prefix: '/admin/hook/components')] #[Middleware(AdminMiddleware::class)] class ComponentController { #[GetMapping(path: '')] public function index() { - if (! is_dir(BASE_PATH . '/resources/views/customize/component')) { + if (!is_dir(BASE_PATH . '/resources/views/customize/component')) { System::exec('cd ' . BASE_PATH . '/resources/views' . '&& mkdir ' . 'customize && cd customize && mkdir component'); } $page = $this->page(); - return view('admin.setting.components', ['page' => $page]); + return view('admin.setting.hook.components', ['page' => $page]); } private function getAllComponents(): array @@ -39,8 +41,9 @@ private function getAllComponents(): array $path = BASE_PATH . '/resources/views/customize/component/'; $files = []; $result = Finder::create()->in($path)->files()->name('*.blade.php'); + $id = 1; foreach ($result as $item) { - $Filename = $item->getFilename(); + $Filename = $item->getRelativePath(); $viewName = Str::before($item->getFilename(), '.'); $RelativePath = $item->getRelativePath(); if ($RelativePath) { @@ -48,11 +51,12 @@ private function getAllComponents(): array $viewName = implode('.', $RelativePath) . '.' . $viewName; } $files[] = [ - 'id' => Str::random(10), + 'id' => $id++, 'file_name' => $Filename, 'view' => 'customize.component.' . $viewName, 'import' => $viewName, 'path' => $item->getRealPath(), + 'remark' => $this->get_remark($item->getRealPath()) ?: "暂无", ]; } return array_values($files); @@ -60,8 +64,8 @@ private function getAllComponents(): array private function page(): LengthAwarePaginator { - $currentPage = (int) request()->input('page', 1); - $perPage = (int) request()->input('per_page', 15); + $currentPage = (int)request()->input('page', 1); + $perPage = (int)request()->input('per_page', 15); // 这里根据 $currentPage 和 $perPage 进行数据查询,以下使用 Collection 代替 $collection = new Collection($this->getAllComponents()); @@ -69,4 +73,30 @@ private function page(): LengthAwarePaginator $data = array_values($collection->forPage($currentPage, $perPage)->toArray()); return new LengthAwarePaginator($data, count($this->getAllComponents()), $perPage, $currentPage); } + + /** + * get remark + * @param $file + * @return string|null + */ + private function get_remark($file): string|null + { + $content = fopen($file, 'rb'); + $content = fgets($content); + $result = []; + preg_match_all('/(?:\\{{--)(.*)(?:\\--}})/i', $content, $result); + return @$result[1][0] ?: null; + } + + #[GetMapping(path:"preview")] + public function preview(){ + $component = request()->input('component'); + $component = 'customize.component.'.$component; + $container = \Hyperf\Utils\ApplicationContext::getContainer(); + $factory = $container->get(FactoryInterface::class); + if(!$factory->exists($component)){ + return admin_abort('小部件不存在',403); + } + return view('admin.setting.hook.preview', ['view' => $component]); + } } diff --git a/app/Plugins/User/resources/views/notice/userfollow.blade.php b/app/Plugins/User/resources/views/notice/userfollow.blade.php index 32b551106..5e4bb2dfd 100644 --- a/app/Plugins/User/resources/views/notice/userfollow.blade.php +++ b/app/Plugins/User/resources/views/notice/userfollow.blade.php @@ -1,13 +1,13 @@
- + diff --git a/app/Plugins/User/resources/views/notice/userfollow_d.blade.php b/app/Plugins/User/resources/views/notice/userfollow_d.blade.php index 9326b7f0f..a53719d17 100644 --- a/app/Plugins/User/resources/views/notice/userfollow_d.blade.php +++ b/app/Plugins/User/resources/views/notice/userfollow_d.blade.php @@ -1,13 +1,13 @@
- + diff --git a/app/Plugins/User/src/Controller/ApiController.php b/app/Plugins/User/src/Controller/ApiController.php index f91cd8410..38571c549 100644 --- a/app/Plugins/User/src/Controller/ApiController.php +++ b/app/Plugins/User/src/Controller/ApiController.php @@ -202,7 +202,7 @@ public function user_follow() user_notice()->send( $user_id, auth()->data()->username . ' 取关了你!', - view('User::notice.userfollow_d', ['user' => auth()->data()]) + view('User::notice.userfollow_d') ); return Json_Api(201, true, ['msg' => '已取关!']); } @@ -212,7 +212,7 @@ public function user_follow() user_notice()->send( $user_id, auth()->data()->username . ' 关注了你!', - view('User::notice.userfollow', ['user' => auth()->data()]) + view('User::notice.userfollow') ); return Json_Api(200, true, ['msg' => '已关注']); diff --git a/resources/views/admin/setting/components.blade.php b/resources/views/admin/setting/components.blade.php deleted file mode 100644 index 55484563a..000000000 --- a/resources/views/admin/setting/components.blade.php +++ /dev/null @@ -1,61 +0,0 @@ -@extends('app') - -@section('title','部件管理') - -@section('content') -
- @if($page->count()) - @foreach($page as $item) -
-
- - -
- -
-
- @include($item['view']) -
-
- -
-
-
引用代码
-

- {{"<<"}}{{$item['import']}}{{">>"}} -

-
-
- -
-
-
文件路径
-

- {{$item['path']}} -

-
-
-
-
-
- @endforeach -
- {!! make_page($page) !!} -
- @else -
-
-
403
-

暂无可用部件

-

- 如果你是开发者,可以在 {{BASE_PATH."/resources/views/customize/component/"}} 目录下创建 -

-
-
- @endif -
-@endsection \ No newline at end of file diff --git a/resources/views/admin/setting/hook/components.blade.php b/resources/views/admin/setting/hook/components.blade.php new file mode 100644 index 000000000..33642b9a8 --- /dev/null +++ b/resources/views/admin/setting/hook/components.blade.php @@ -0,0 +1,72 @@ +@extends('app') + +@section('title','部件管理') + +@section('content') +
+
+
+
+

部件列表

+
+
+ + + + + + + + + + + + @if(!$page->count()) + + + + + + + @else + @foreach($page as $component) + + + + + + + + @endforeach + @endif + +
#调用代码备注
暂无更多结果暂无更多结果暂无更多结果暂无更多结果
+ {{$component['id']}} + + {{$component['import']}} + + {{$component['remark']}} + + 预览 + + 编辑 +
+
+
+ {!! make_page($page) !!} +
+
+
+ @if(!$page->count()) +
+
+
403
+

暂无可用部件

+

+ 如果你是开发者,可以在 {{BASE_PATH."/resources/views/customize/component/"}} 目录下创建 +

+
+
+ @endif +
+@endsection \ No newline at end of file diff --git a/resources/views/admin/setting/hook/preview.blade.php b/resources/views/admin/setting/hook/preview.blade.php new file mode 100644 index 000000000..0d83ce473 --- /dev/null +++ b/resources/views/admin/setting/hook/preview.blade.php @@ -0,0 +1,14 @@ +@extends('App::app') +@section('title','小部件预览') +@section('content') +
+
+
+

小部件预览

+
+
+ @include($view) +
+
+
+@endsection \ No newline at end of file