123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Displayers\WxName;
- use App\Admin\Repositories\WxExtension;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Http\Actions\Extensions\InstallFromLocal;
- use Dcat\Admin\Http\Controllers\HasResourceActions;
- use Dcat\Admin\Http\Displayers\Extensions;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Support\Helper;
- use Dcat\Admin\Support\StringOutput;
- use Illuminate\Routing\Controller;
- use Illuminate\Support\Facades\Artisan;
- class WxExtensionController extends Controller
- {
- use HasResourceActions;
- public function index(Content $content)
- {
- return $content
- ->title('MINI扩展')
- ->description('官方推荐的扩展,不开放第三方(安装或卸载时,若出现红色的错误,重新刷新一下浏览器就行)')
- ->body($this->grid());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return new Grid(new WxExtension(), function (Grid $grid) {
- $grid->number();
- $grid->column('name')->displayUsing(WxName::class);
- $grid->column('description')->displayUsing(Extensions\Description::class)->width('50%');
- $grid->column('authors')->display(function ($v) {
- if (! $v) {
- return;
- }
- foreach ($v as &$item) {
- $item = "<span class='text-80'>{$item['name']}</span> <<code>{$item['email']}</code>>";
- }
- return implode('<div style="margin-top: 5px"></div>', $v);
- });
- $grid->disablePagination();
- $grid->disableCreateButton();
- $grid->disableDeleteButton();
- $grid->disableBatchDelete();
- $grid->disableFilterButton();
- $grid->disableFilter();
- $grid->disableQuickEditButton();
- $grid->disableEditButton();
- $grid->disableDeleteButton();
- $grid->disableViewButton();
- $grid->disableActions();
- $grid->tools([
- '<a style="cursor: pointer;" class="btn btn-primary btn-outline" href="https://minisns.cn/social/appstore/minisns" target="_blank"><i class="feather icon-shopping-cart"></i> 应用市场</a>',
- new InstallFromLocal(),
- ]);
- if(env('APP_ENV') == 'local'){
- $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
- $create->text('name')
- ->attribute('style', 'width:240px')
- ->placeholder('Input Name. Eg: dcat-admin/demo')
- ->required();
- $create->text('namespace')
- ->attribute('style', 'width:240px')
- ->placeholder('Input Namespace. Eg: DcatAdmin\\Demo');
- $create->select('type')
- ->options([1 => trans('admin.application'), 2 => trans('admin.theme')])
- ->attribute('style', 'width:140px!important')
- ->default(1)
- ->required();
- });
- }
- });
- }
- public function form()
- {
- $form = new Form(new WxExtension());
- $form->hidden('name')->rules(function () {
- return [
- 'required',
- function ($attribute, $value, $fail) {
- if (! Helper::validateExtensionName($value)) {
- return $fail(
- "[$value] is not a valid package name, please type a name like \"vendor/name\""
- );
- }
- },
- ];
- });
- $form->hidden('namespace');
- $form->hidden('type');
- $self = $this;
- $form->saving(function (Form $form) use ($self) {
- $package = $form->name;
- $namespace = $form->namespace;
- $type = $form->type;
- if ($package) {
- $results = $self->createExtension($package, $namespace, $type);
- return $form
- ->response()
- ->refresh()
- ->timeout(10)
- ->success($results);
- }
- });
- return $form;
- }
- public function createExtension($package, $namespace, $type)
- {
- $namespace = trim($namespace, '\\');
- $output = new StringOutput();
- Artisan::call('admin:ext-make', [
- 'name' => $package,
- '--namespace' => $namespace ?: 'default',
- '--theme' => $type == 2,
- ], $output);
- return sprintf('<pre class="bg-transparent text-white">%s</pre>', (string) $output->getContent());
- }
- }
|