diff --git a/beike/Admin/Http/Controllers/PluginController.php b/beike/Admin/Http/Controllers/PluginController.php index c43e27ba..0b9c4d45 100644 --- a/beike/Admin/Http/Controllers/PluginController.php +++ b/beike/Admin/Http/Controllers/PluginController.php @@ -90,6 +90,7 @@ class PluginController extends Controller * @param Request $request * @param $code * @return mixed + * @throws Exception */ public function update(Request $request, $code) { diff --git a/beike/Admin/Http/Resources/PluginResource.php b/beike/Admin/Http/Resources/PluginResource.php index 428ca06e..21f6083f 100644 --- a/beike/Admin/Http/Resources/PluginResource.php +++ b/beike/Admin/Http/Resources/PluginResource.php @@ -18,12 +18,13 @@ class PluginResource extends JsonResource $data = [ 'name' => $this->name, 'version' => $this->version, + 'dir_name' => $this->dirName, 'path' => $this->path, 'code' => $this->code, 'description' => $this->description, 'type' => $this->type, 'type_format' => trans('admin/plugin.' . $this->type), - 'icon' => $this->icon, + 'icon' => plugin_resize($this->code, $this->icon), 'author' => $this->author, 'status' => $this->getStatus(), 'installed' => $this->getInstalled(), diff --git a/beike/Helpers.php b/beike/Helpers.php index c3bd78a3..49f8fcd3 100644 --- a/beike/Helpers.php +++ b/beike/Helpers.php @@ -342,6 +342,39 @@ function time_format($datetime = null) return date($format); } + +/** + * 获取插件根目录 + * + * @param string $path + * @return string + */ +function plugin_path(string $path = ''): string +{ + return base_path('plugins') . ($path ? DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR) : $path); +} + + +/** + * 插件图片缩放 + * + * @param $pluginCode + * @param $image + * @param int $width + * @param int $height + * @return mixed|void + * @throws Exception + */ +function plugin_resize($pluginCode, $image, int $width = 100, int $height = 100) +{ + $plugin = app('plugin')->getPlugin($pluginCode); + if (Str::startsWith($image, 'http')) { + return $image; + } + $pluginDirName = $plugin->getDirname(); + return (new \Beike\Services\ImageService($image))->setPluginDirName($pluginDirName)->resize($width, $height); +} + /** * 图片缩放 * diff --git a/beike/Plugin/Manager.php b/beike/Plugin/Manager.php index d99b4387..14511247 100644 --- a/beike/Plugin/Manager.php +++ b/beike/Plugin/Manager.php @@ -54,7 +54,7 @@ class Manager $plugin->setColumns(); if ($plugins->has($plugin->code)) { - throw new \Exception("有重名插件:" . $plugin->code); + continue; } $plugins->put($plugin->code, $plugin); @@ -123,10 +123,10 @@ class Manager public function getPluginOrFail($code): ?Plugin { $plugin = $this->getPlugin($code); - $plugin->handleLabel(); if (empty($plugin)) { throw new \Exception('无效的插件'); } + $plugin->handleLabel(); return $plugin; } diff --git a/beike/Plugin/Plugin.php b/beike/Plugin/Plugin.php index a727f6db..f6eaa141 100644 --- a/beike/Plugin/Plugin.php +++ b/beike/Plugin/Plugin.php @@ -201,9 +201,9 @@ class Plugin implements Arrayable, \ArrayAccess */ public function getColumnView(): string { - $viewFile = $this->getPath() . '/Views/columns.blade.php'; + $viewFile = $this->getPath() . '/Views/admin/config.blade.php'; if (file_exists($viewFile)) { - return "{$this->dirName}::columns"; + return "{$this->dirName}::admin.config"; } return ''; } diff --git a/beike/Services/ImageService.php b/beike/Services/ImageService.php index 15392de1..4e9ba5f1 100644 --- a/beike/Services/ImageService.php +++ b/beike/Services/ImageService.php @@ -28,14 +28,33 @@ class ImageService public function __construct($image) { $this->image = $image ?: self::PLACEHOLDER_IMAGE; - if (!is_file($image)) { - $this->image = self::PLACEHOLDER_IMAGE; - } - $imagePath = public_path($this->image); - $this->imagePath = $imagePath; + $this->imagePath = public_path($this->image); } + /** + * 设置插件目录名称 + * @param $dirName + * @return $this + */ + public function setPluginDirName($dirName): static + { + $originImage = $this->image; + if ($this->image == self::PLACEHOLDER_IMAGE) { + return $this; + } + + $this->imagePath = plugin_path("{$dirName}/Static") . $originImage; + if (file_exists($this->imagePath)) { + $this->image = strtolower('plugin/' . $dirName . $originImage); + } else { + $this->image = self::PLACEHOLDER_IMAGE; + $this->imagePath = public_path($this->image); + } + + return $this; + } + /** * 生成并获取缩略图 * @param int $width diff --git a/beike/Shop/Providers/PluginServiceProvider.php b/beike/Shop/Providers/PluginServiceProvider.php index 52542716..45a79b08 100644 --- a/beike/Shop/Providers/PluginServiceProvider.php +++ b/beike/Shop/Providers/PluginServiceProvider.php @@ -15,7 +15,6 @@ use Beike\Plugin\Manager; use Beike\Models\AdminUser; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; -use Illuminate\Support\Str; class PluginServiceProvider extends ServiceProvider { @@ -51,6 +50,11 @@ class PluginServiceProvider extends ServiceProvider $this->bootPlugin($plugin); $this->loadRoutes($pluginCode); $this->loadTranslations($pluginCode); + } + + $allPlugins = $manager->getPlugins(); + foreach ($allPlugins as $plugin) { + $pluginCode = $plugin->getDirname(); $this->loadViews($pluginCode); } } diff --git a/plugins/LatestProducts/config.json b/plugins/LatestProducts/config.json index 845075f2..d7291fa6 100644 --- a/plugins/LatestProducts/config.json +++ b/plugins/LatestProducts/config.json @@ -4,7 +4,7 @@ "description": "首页菜单添加最新商品列表功能", "type": "view", "version": "v1.0.0", - "icon": "https://via.placeholder.com/100x100.png/aabbcc?text=MENU", + "icon": "", "author": { "name": "成都光大网络科技有限公司", "email": "yangjin@beikeshop.com" diff --git a/plugins/Paypal/config.json b/plugins/Paypal/config.json index 79742db2..42b76e45 100644 --- a/plugins/Paypal/config.json +++ b/plugins/Paypal/config.json @@ -4,7 +4,7 @@ "description": "PayPal 支付 PayPal Developer", "type": "payment", "version": "v1.0.0", - "icon": "plugin/paypal/image/logo.png", + "icon": "/image/logo.png", "author": { "name": "成都光大网络科技有限公司", "email": "yangjin@beikeshop.com" diff --git a/plugins/Social/Views/admin/config.blade.php b/plugins/Social/Views/admin/config.blade.php new file mode 100644 index 00000000..a9958ee0 --- /dev/null +++ b/plugins/Social/Views/admin/config.blade.php @@ -0,0 +1,25 @@ +@extends('admin::layouts.master') + +@section('title', __('admin/plugin.plugins_show')) + +@section('content') +
+
+
{{ $plugin->name }}
+ + @if (session('success')) + + @endif +
+ @csrf + {{ method_field('put') }} + +这里是social配置模板 + + + + +
+
+
+@endsection diff --git a/plugins/Social/config.json b/plugins/Social/config.json new file mode 100644 index 00000000..46732713 --- /dev/null +++ b/plugins/Social/config.json @@ -0,0 +1,12 @@ +{ + "code": "social", + "name": "Social", + "description": "第三方登录(包括微信、QQ、微博、Google、Facebook)", + "type": "social", + "version": "v1.0.0", + "icon": "/image/logo.png", + "author": { + "name": "成都光大网络科技有限公司", + "email": "yangjin@beikeshop.com" + } +} diff --git a/plugins/Stripe/config.json b/plugins/Stripe/config.json index 6b759481..baff2f37 100644 --- a/plugins/Stripe/config.json +++ b/plugins/Stripe/config.json @@ -4,7 +4,7 @@ "description": "Stripe 支付 Stripe", "type": "payment", "version": "v1.0.0", - "icon": "plugin/stripe/image/logo.png", + "icon": "/image/logo.png", "author": { "name": "成都光大网络科技有限公司", "email": "yangjin@beikeshop.com" diff --git a/resources/beike/admin/views/errors/500.blade.php b/resources/beike/admin/views/errors/500.blade.php index d9e95d9b..48629962 100644 --- a/resources/beike/admin/views/errors/500.blade.php +++ b/resources/beike/admin/views/errors/500.blade.php @@ -1,5 +1,13 @@ -@extends('errors::minimal') +@extends('admin::layouts.master') @section('title', __('Server Error')) @section('code', '500') @section('message', __('Server Error')) + + + +{{--@extends('admin::layouts.master')--}} +{{----}} +{{--@section('title', __('admin/common.forbidden'))--}} +{{--@section('code', '403')--}} +{{--@section('content', __('admin/common.has_no_permission'))--}} diff --git a/resources/lang/en/admin/plugin.php b/resources/lang/en/admin/plugin.php index 31b47ea0..1c3d7fb2 100644 --- a/resources/lang/en/admin/plugin.php +++ b/resources/lang/en/admin/plugin.php @@ -26,6 +26,7 @@ return [ 'shipping' => 'Shipping', 'payment' => 'Payment', + 'social' => 'Social', 'total' => 'Total', 'view' => 'View', 'social' => 'Social', diff --git a/resources/lang/zh_cn/admin/plugin.php b/resources/lang/zh_cn/admin/plugin.php index b1943101..2dc45fbe 100644 --- a/resources/lang/zh_cn/admin/plugin.php +++ b/resources/lang/zh_cn/admin/plugin.php @@ -26,6 +26,7 @@ return [ 'shipping' => '配送方式', 'payment' => '支付方式', + 'social' => '社交网络', 'total' => '订单计算', 'view' => '页面修改', 'social' => '第三方登录',