first
This commit is contained in:
10
app/Admin/Controllers/AuthController.php
Normal file
10
app/Admin/Controllers/AuthController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Controllers\AuthController as BaseAuthController;
|
||||
|
||||
class AuthController extends BaseAuthController
|
||||
{
|
||||
|
||||
}
|
||||
183
app/Admin/Controllers/Dashboard.php
Normal file
183
app/Admin/Controllers/Dashboard.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Admin;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\View;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class Dashboard
|
||||
{
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public static function title()
|
||||
{
|
||||
return view('admin.dashboard.title');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public static function environment()
|
||||
{
|
||||
$envs = [
|
||||
['name' => 'PHP version', 'value' => 'PHP/'.PHP_VERSION],
|
||||
['name' => 'Laravel version', 'value' => app()->version()],
|
||||
['name' => 'CGI', 'value' => php_sapi_name()],
|
||||
['name' => 'Uname', 'value' => php_uname()],
|
||||
['name' => 'Server', 'value' => Arr::get($_SERVER, 'SERVER_SOFTWARE')],
|
||||
|
||||
['name' => 'Cache driver', 'value' => config('cache.default')],
|
||||
['name' => 'Session driver', 'value' => config('session.driver')],
|
||||
['name' => 'Queue driver', 'value' => config('queue.default')],
|
||||
|
||||
['name' => 'Timezone', 'value' => config('app.timezone')],
|
||||
['name' => 'Locale', 'value' => config('app.locale')],
|
||||
['name' => 'Env', 'value' => config('app.env')],
|
||||
['name' => 'URL', 'value' => config('app.url')],
|
||||
];
|
||||
|
||||
return view('admin.dashboard.environment', compact('envs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public static function extensions()
|
||||
{
|
||||
$extensions = [
|
||||
'user' => [
|
||||
'name' => '用户模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-user-module',
|
||||
'icon' => 'users',
|
||||
],
|
||||
'chain' => [
|
||||
'name' => '区块链管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-chain-module',
|
||||
'icon' => 'chain',
|
||||
],
|
||||
'lottery' => [
|
||||
'name' => '抽奖模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-lottery-module',
|
||||
'icon' => 'gavel',
|
||||
],
|
||||
'task' => [
|
||||
'name' => '任务模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-task-module',
|
||||
'icon' => 'hourglass-end',
|
||||
],
|
||||
'cms' => [
|
||||
'name' => '内容管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-cms-module',
|
||||
'icon' => 'book',
|
||||
],
|
||||
'appversion' => [
|
||||
'name' => 'App版本',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-appversion-module',
|
||||
'icon' => 'apple',
|
||||
],
|
||||
'mall' => [
|
||||
'name' => '多用户商城',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-mall-module',
|
||||
'icon' => 'shopping-cart',
|
||||
],
|
||||
'payment' => [
|
||||
'name' => '支付模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-payment-module',
|
||||
'icon' => 'paypal',
|
||||
],
|
||||
'company' => [
|
||||
'name' => '企业管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-company-module',
|
||||
'icon' => 'black-tie',
|
||||
],
|
||||
'coupon' => [
|
||||
'name' => '优惠券模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-coupon-module',
|
||||
'icon' => 'qrcode',
|
||||
],
|
||||
'settlement' => [
|
||||
'name' => '结算模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-settlement-module',
|
||||
'icon' => 'sliders',
|
||||
],
|
||||
'configuration' => [
|
||||
'name' => '参数配置',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-configuration-module',
|
||||
'icon' => 'cogs',
|
||||
],
|
||||
'withdraw' => [
|
||||
'name' => '提现管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-withdraw-module',
|
||||
'icon' => 'clock-o',
|
||||
],
|
||||
'notification' => [
|
||||
'name' => '消息中心',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-notification-module',
|
||||
'icon' => 'envelope',
|
||||
],
|
||||
'linker' => [
|
||||
'name' => '链接管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-linker-module',
|
||||
'icon' => 'link',
|
||||
],
|
||||
'storage' => [
|
||||
'name' => '文件存储',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-storage-module',
|
||||
'icon' => 'file',
|
||||
],
|
||||
'omniform' => [
|
||||
'name' => '万能表单',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-omni-form-module',
|
||||
'icon' => 'wpforms',
|
||||
],
|
||||
'tao' => [
|
||||
'name' => '淘宝客',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-tao-module',
|
||||
'icon' => 'simplybuilt',
|
||||
],
|
||||
'market' => [
|
||||
'name' => '交易市场',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-market-module',
|
||||
'icon' => 'asl-interpreting',
|
||||
],
|
||||
'tokenmall' => [
|
||||
'name' => '区块链商城',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-token-mall-module',
|
||||
'icon' => 'flask',
|
||||
],
|
||||
'acme' => [
|
||||
'name' => 'SSL免费证书',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-acme-module',
|
||||
'icon' => 'html5',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($extensions as $key => &$extension) {
|
||||
$module = Module::find($key);
|
||||
|
||||
if ($module) {
|
||||
$extension['installed'] = (int) $module->isEnabled();
|
||||
} else {
|
||||
$extension['installed'] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return view('admin.dashboard.extensions', compact('extensions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function dependencies(): string
|
||||
{
|
||||
$json = file_get_contents(base_path('composer.json'));
|
||||
|
||||
$dependencies = json_decode($json, true)['require'];
|
||||
|
||||
return Admin::component('admin.dashboard.dependencies', compact('dependencies'));
|
||||
}
|
||||
}
|
||||
46
app/Admin/Controllers/HomeController.php
Normal file
46
app/Admin/Controllers/HomeController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Encore\Admin\Layout\Column;
|
||||
use Encore\Admin\Layout\Content;
|
||||
use Encore\Admin\Layout\Row;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Notes : 数据看板
|
||||
*
|
||||
* @Date : 2021/3/10 5:12 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function index(Content $content): Content
|
||||
{
|
||||
if (config('app.debug')) {
|
||||
return $content
|
||||
->title(__('admin.menu_titles.dashboard'))
|
||||
->description('Description...')
|
||||
->row(Dashboard::title())
|
||||
->row(function (Row $row) {
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::environment());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::dependencies());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::extensions());
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return $content
|
||||
->title(__('admin.menu_titles.dashboard'))
|
||||
->description('Description...');
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/Admin/Controllers/ModuleController.php
Normal file
105
app/Admin/Controllers/ModuleController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Models\Module;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Grid;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Nwidart\Modules\Facades\Module as ModuleManager;
|
||||
|
||||
class ModuleController extends AdminController
|
||||
{
|
||||
protected $title = '模块管理';
|
||||
|
||||
/**
|
||||
* Notes : 模块列表
|
||||
*
|
||||
* @Date : 2021/10/28 9:18 上午
|
||||
* @Author : <Jason.C>
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Module());
|
||||
|
||||
$grid->disableBatchActions();
|
||||
$grid->disableFilter();
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->column('name', '模块名称');
|
||||
$grid->column('alias', '别名');
|
||||
$grid->column('version', '版本');
|
||||
$grid->column('author', '作者');
|
||||
$grid->column('description', '模块简介');
|
||||
$grid->column('enabled', '状态')->bool();
|
||||
$grid->column('id', '操作')->display(function () {
|
||||
if ($this->enabled) {
|
||||
return sprintf('<a href="%s">%s</a>', route('admin.module.disable', $this->name), '禁用');
|
||||
} else {
|
||||
return sprintf('<a href="%s">%s</a>', route('admin.module.enable', $this->name), '启用');
|
||||
}
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 禁用模块
|
||||
*
|
||||
* @Date : 2021/3/11 1:13 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string $name
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function disable(string $name): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$module = ModuleManager::find($name);
|
||||
|
||||
$module->disable();
|
||||
|
||||
$class = sprintf('\\%s\\%s\\%s', config('modules.namespace'), $module->getName(), $module->getName());
|
||||
|
||||
if (class_exists($class)) {
|
||||
call_user_func([$class, 'uninstall']);
|
||||
}
|
||||
|
||||
admin_success('Success', $name . '模块禁用成功');
|
||||
} catch (\Exception $exception) {
|
||||
admin_error('Error', $exception->getMessage());
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 启用模块
|
||||
*
|
||||
* @Date : 2021/3/11 1:13 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string $name
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function enable(string $name): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$module = ModuleManager::find($name);
|
||||
|
||||
$module->enable();
|
||||
|
||||
$class = sprintf('\\%s\\%s\\%s', config('modules.namespace'), $module->getName(), $module->getName());
|
||||
|
||||
if (class_exists($class)) {
|
||||
call_user_func([$class, 'install']);
|
||||
}
|
||||
|
||||
admin_success('Success', $name . '模块启用成功');
|
||||
} catch (\Exception $exception) {
|
||||
admin_error('Error', $exception->getMessage());
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
35
app/Admin/Extensions/CleanCache.php
Normal file
35
app/Admin/Extensions/CleanCache.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Extensions;
|
||||
|
||||
use Encore\Admin\Actions\Action;
|
||||
use Encore\Admin\Actions\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class CleanCache extends Action
|
||||
{
|
||||
protected $selector = '.clear-cache';
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
Artisan::call('modelCache:clear');
|
||||
return $this->response()->success('清理完成')->refresh();
|
||||
}
|
||||
|
||||
public function dialog()
|
||||
{
|
||||
$this->confirm('确认清除缓存');
|
||||
}
|
||||
|
||||
public function html(): string
|
||||
{
|
||||
return <<<HTML
|
||||
<li>
|
||||
<a class="clear-cache" href="#">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</li>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
21
app/Admin/Extensions/FormQrCode.php
Normal file
21
app/Admin/Extensions/FormQrCode.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Extensions;
|
||||
|
||||
use Encore\Admin\Form\Field;
|
||||
|
||||
class FormQrCode extends Field
|
||||
{
|
||||
protected $view = 'admin.form.qr_code';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$google2fa = app('pragmarx.google2fa');
|
||||
$this->value = $google2fa->getQRCodeUrl(
|
||||
$this->data['username'],
|
||||
$this->data['name'],
|
||||
$this->data['g2fa_secret']
|
||||
);
|
||||
return parent::render();
|
||||
}
|
||||
}
|
||||
12
app/Admin/Routes/modules.php
Normal file
12
app/Admin/Routes/modules.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group([
|
||||
'prefix' => 'modules',
|
||||
], function (Router $router) {
|
||||
$router->get('', 'ModuleController@index');
|
||||
$router->get('{name}/disable', 'ModuleController@disable')->name('module.disable');
|
||||
$router->get('{name}/enable', 'ModuleController@enable')->name('module.enable');
|
||||
});
|
||||
94
app/Admin/Traits/WithUploads.php
Normal file
94
app/Admin/Traits/WithUploads.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Traits;
|
||||
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Form\Field\Image;
|
||||
use Encore\Admin\Form\Field\MultipleFile;
|
||||
use Encore\Admin\Form\Field\MultipleImage;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
|
||||
trait WithUploads
|
||||
{
|
||||
/**
|
||||
* Notes : 单张封面图上传
|
||||
*
|
||||
* @Date : 2021/4/25 2:06 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Form $form
|
||||
* @param string $filed
|
||||
* @param string $label
|
||||
* @return Image
|
||||
*/
|
||||
public function cover(Renderable $form, string $filed = 'cover', string $label = '封面图片'): Image
|
||||
{
|
||||
$cover = $form->image($filed, $label)
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->uniqueName()
|
||||
->removable()
|
||||
->retainable();
|
||||
|
||||
$waterConfig = config('admin.image_water');
|
||||
|
||||
if (! empty($waterConfig)) {
|
||||
$cover->insert(...$waterConfig);
|
||||
}
|
||||
|
||||
$coverThumb = config('admin.cover_thumb');
|
||||
|
||||
if (! empty($coverThumb)) {
|
||||
$cover->thumbnail($coverThumb);
|
||||
}
|
||||
return $cover;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 统一的多图上传
|
||||
*
|
||||
* @Date : 2021/4/25 2:06 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Form $form
|
||||
* @param string $filed
|
||||
* @param string $label
|
||||
* @return MultipleImage
|
||||
*/
|
||||
public function pictures(Renderable $form, string $filed = 'pictures', string $label = '多图轮播'): MultipleImage
|
||||
{
|
||||
$pictures = $form->multipleImage($filed, $label)
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->uniqueName()
|
||||
->removable()
|
||||
->retainable();
|
||||
|
||||
// 多图如果开启排序的话,会报错,暂时没由解决办法 ->sortable()
|
||||
$waterConfig = config('admin.image_water');
|
||||
|
||||
if (! empty($waterConfig)) {
|
||||
$pictures->insert(...$waterConfig);
|
||||
}
|
||||
return $pictures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 统一的附件上传
|
||||
*
|
||||
* @Date : 2021/4/25 3:03 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Renderable $form
|
||||
* @param string $filed
|
||||
* @param string $label
|
||||
* @return MultipleFile
|
||||
*/
|
||||
public function attachments(
|
||||
Renderable $form,
|
||||
string $filed = 'attachments',
|
||||
string $label = '内容附件'
|
||||
): MultipleFile {
|
||||
return $form->multipleFile($filed, $label)
|
||||
->move('attachments/'.date('Y/m/d'))
|
||||
->uniqueName()
|
||||
->removable()
|
||||
->retainable()
|
||||
->sortable();
|
||||
}
|
||||
}
|
||||
51
app/Admin/bootstrap.php
Normal file
51
app/Admin/bootstrap.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use App\Admin\Extensions\CleanCache;
|
||||
use App\Admin\Extensions\FormQrCode;
|
||||
use Encore\Admin\Facades\Admin;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Show;
|
||||
use Encore\Admin\Widgets\Navbar;
|
||||
|
||||
Form::forget(['map', 'editor']);
|
||||
|
||||
Admin::navbar(function (Navbar $navbar) {
|
||||
$navbar->right(new CleanCache());
|
||||
$navbar->right(new Navbar\Fullscreen());
|
||||
});
|
||||
|
||||
Form::init(function (Form $form) {
|
||||
$form->disableEditingCheck();
|
||||
$form->disableCreatingCheck();
|
||||
$form->disableViewCheck();
|
||||
|
||||
$form->tools(function (Form\Tools $tools) {
|
||||
$tools->disableView();
|
||||
// $tools->disableDelete();
|
||||
// $tools->disableList();
|
||||
});
|
||||
});
|
||||
|
||||
Show::init(function (Show $show) {
|
||||
$show->panel()
|
||||
->tools(function ($tools) {
|
||||
// $tools->disableEdit();
|
||||
// $tools->disableList();
|
||||
$tools->disableDelete();
|
||||
});;
|
||||
});
|
||||
|
||||
Grid::init(function (Grid $grid) {
|
||||
$grid->disableExport();
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableView();
|
||||
});
|
||||
$grid->disableBatchActions();
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
// $grid->expandFilter();
|
||||
});
|
||||
|
||||
Form::extend('qrCode', FormQrCode::class);
|
||||
20
app/Admin/routes.php
Normal file
20
app/Admin/routes.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use Encore\Admin\Facades\Admin;
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Admin::routes();
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace'),
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
'as' => config('admin.route.as'),
|
||||
], function (Router $router) {
|
||||
$router->get('/', 'HomeController@index')->name('home');
|
||||
|
||||
foreach (glob(admin_path('Routes') . '/*.php') as $routeFile) {
|
||||
require $routeFile;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user