diff --git a/beike/Admin/Http/Controllers/PluginController.php b/beike/Admin/Http/Controllers/PluginController.php index 9880febc..a2c2e6d2 100644 --- a/beike/Admin/Http/Controllers/PluginController.php +++ b/beike/Admin/Http/Controllers/PluginController.php @@ -12,6 +12,7 @@ namespace Beike\Admin\Http\Controllers; use Beike\Plugin\Manager; +use Illuminate\Http\Request; class PluginController extends Controller { @@ -23,4 +24,16 @@ class PluginController extends Controller $data['plugins'] = (new Manager)->getPlugins(); return view('admin::pages.plugins.index', $data); } + + + /** + * @param Request $request + * @param $code + * @throws \Exception + */ + public function edit(Request $request, $code) + { + $plugin = (new Manager)->getPlugin($code); + dd($plugin); + } } diff --git a/beike/Admin/Routes/admin.php b/beike/Admin/Routes/admin.php index d392a40a..8438d07b 100644 --- a/beike/Admin/Routes/admin.php +++ b/beike/Admin/Routes/admin.php @@ -9,7 +9,7 @@ Route::prefix('admin') Route::get('login', [\Beike\Admin\Http\Controllers\LoginController::class, 'show'])->name('login.show'); Route::post('login', [\Beike\Admin\Http\Controllers\LoginController::class, 'store'])->name('login.store'); - Route::middleware('admin_auth:'.\Beike\Models\AdminUser::AUTH_GUARD) + Route::middleware('admin_auth:' . \Beike\Models\AdminUser::AUTH_GUARD) ->group(function () { Route::get('/', [\Beike\Admin\Http\Controllers\HomeController::class, 'index'])->name('home.index'); @@ -23,8 +23,10 @@ Route::prefix('admin') Route::put('products/restore', [\Beike\Admin\Http\Controllers\ProductController::class, 'restore']); Route::resource('products', \Beike\Admin\Http\Controllers\ProductController::class); - Route::get('settings', [\Beike\Admin\Http\Controllers\SettingController::class,'index'])->name('settings.index'); - Route::get('plugins', [\Beike\Admin\Http\Controllers\PluginController::class,'index'])->name('plugins.index'); + Route::get('settings', [\Beike\Admin\Http\Controllers\SettingController::class, 'index'])->name('settings.index'); + + Route::get('plugins', [\Beike\Admin\Http\Controllers\PluginController::class, 'index'])->name('plugins.index'); + Route::get('plugins/{code}/edit', [\Beike\Admin\Http\Controllers\PluginController::class, 'edit'])->name('plugins.edit'); Route::get('logout', [\Beike\Admin\Http\Controllers\LogoutController::class, 'index'])->name('logout.index'); diff --git a/beike/Plugin/Manager.php b/beike/Plugin/Manager.php index 0d8cbcbc..3d0130af 100644 --- a/beike/Plugin/Manager.php +++ b/beike/Plugin/Manager.php @@ -11,6 +11,7 @@ namespace Beike\Plugin; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Filesystem\Filesystem; @@ -47,6 +48,7 @@ class Manager $plugin->setInstalled(true); $plugin->setEnabled(false); $plugin->setVersion(Arr::get($package, 'version')); + $plugin->setColumns(); if ($plugins->has($plugin->code)) { throw new \Exception("有重名插件:" . $plugin->code); @@ -56,12 +58,29 @@ class Manager } $this->plugins = $plugins->sortBy(function ($plugin) { - return $plugin->name; + return $plugin->code; }); return $this->plugins; } + /** + * 获取单个插件 + * + * @throws \Exception + */ + public function getPlugin($code) + { + $plugins = $this->getPlugins(); + return $plugins[$code] ?? null; + } + + /** + * 获取插件目录以及配置 + * + * @return array + * @throws FileNotFoundException + */ protected function getPluginsConfig(): array { $installed = []; diff --git a/beike/Plugin/Plugin.php b/beike/Plugin/Plugin.php index 5a1060ba..4277d2a9 100644 --- a/beike/Plugin/Plugin.php +++ b/beike/Plugin/Plugin.php @@ -24,6 +24,7 @@ class Plugin implements Arrayable, \ArrayAccess protected $installed; protected $enabled; protected $version; + protected $columns; public function __construct(string $path, array $packageInfo) @@ -78,12 +79,27 @@ class Plugin implements Arrayable, \ArrayAccess return $this; } + public function setColumns(): Plugin + { + $columnsPath = $this->path . DIRECTORY_SEPARATOR . 'columns.php'; + if (!file_exists($columnsPath)) { + return $this; + } + $this->columns = require_once $columnsPath; + return $this; + } + public function getVersion(): string { return $this->version; } + public function getEditUrl(): string + { + return admin_route('plugins.edit', ['code' => $this->code]); + } + public function toArray(): array { return (array)array_merge([ diff --git a/plugins/BKStripe/columns.php b/plugins/BKStripe/columns.php new file mode 100644 index 00000000..f282034f --- /dev/null +++ b/plugins/BKStripe/columns.php @@ -0,0 +1,22 @@ + + * @created 2022-06-29 21:16:23 + * @modified 2022-06-29 21:16:23 + */ + +return [ + [ + 'name' => 'api_key', + 'type' => 'string', + ], + [ + 'name' => 'gender', + 'type' => 'select', + 'option' => ['male', 'female'] + ] +]; diff --git a/resources/beike/admin/views/pages/plugins/index.blade.php b/resources/beike/admin/views/pages/plugins/index.blade.php index 81903b81..950fc707 100644 --- a/resources/beike/admin/views/pages/plugins/index.blade.php +++ b/resources/beike/admin/views/pages/plugins/index.blade.php @@ -38,7 +38,7 @@ - 编辑 + 编辑 @endforeach