columns
This commit is contained in:
parent
5d30cbbad9
commit
6bd52e1a8a
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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([
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
/**
|
||||
* columns.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @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']
|
||||
]
|
||||
];
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="">编辑</a>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="{{ $plugin->getEditUrl() }}">编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
|
|
|||
Loading…
Reference in New Issue