完善插件静态图片

解决插件自定义设置模板

fixed plugin
This commit is contained in:
Edward Yang 2022-09-16 17:43:19 +08:00 committed by Edward Yang
parent 526827ff64
commit 370364002b
15 changed files with 120 additions and 15 deletions

View File

@ -90,6 +90,7 @@ class PluginController extends Controller
* @param Request $request
* @param $code
* @return mixed
* @throws Exception
*/
public function update(Request $request, $code)
{

View File

@ -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(),

View File

@ -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);
}
/**
* 图片缩放
*

View File

@ -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;
}

View File

@ -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 '';
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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"

View File

@ -4,7 +4,7 @@
"description": "PayPal 支付 <a href='https://developer.paypal.com/' target='_blank'>PayPal Developer</a>",
"type": "payment",
"version": "v1.0.0",
"icon": "plugin/paypal/image/logo.png",
"icon": "/image/logo.png",
"author": {
"name": "成都光大网络科技有限公司",
"email": "yangjin@beikeshop.com"

View File

@ -0,0 +1,25 @@
@extends('admin::layouts.master')
@section('title', __('admin/plugin.plugins_show'))
@section('content')
<div class="card">
<div class="card-body">
<h6 class="border-bottom pb-3 mb-4">{{ $plugin->name }}</h6>
@if (session('success'))
<x-admin-alert type="success" msg="{{ session('success') }}" class="mt-4"/>
@endif
<form class="needs-validation" novalidate action="{{ admin_route('plugins.update', [$plugin->code]) }}" method="POST">
@csrf
{{ method_field('put') }}
这里是social配置模板
<x-admin::form.row title="">
<button type="submit" class="btn btn-primary btn-lg mt-4">{{ __('common.submit') }}</button>
</x-admin::form.row>
</form>
</div>
</div>
@endsection

View File

@ -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"
}
}

View File

@ -4,7 +4,7 @@
"description": "Stripe 支付 <a href='https://stripe.com/' target='_blank'>Stripe</a>",
"type": "payment",
"version": "v1.0.0",
"icon": "plugin/stripe/image/logo.png",
"icon": "/image/logo.png",
"author": {
"name": "成都光大网络科技有限公司",
"email": "yangjin@beikeshop.com"

View File

@ -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'))--}}

View File

@ -26,6 +26,7 @@ return [
'shipping' => 'Shipping',
'payment' => 'Payment',
'social' => 'Social',
'total' => 'Total',
'view' => 'View',
'social' => 'Social',

View File

@ -26,6 +26,7 @@ return [
'shipping' => '配送方式',
'payment' => '支付方式',
'social' => '社交网络',
'total' => '订单计算',
'view' => '页面修改',
'social' => '第三方登录',