generated from liutk/owl-admin-base
136 lines
6.9 KiB
PHP
136 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Controllers\AdminController;
|
|
use App\Admin\Services\AppVersionService;
|
|
use App\Enums\AppOs;
|
|
use App\Enums\AppUpdateStrategy;
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Operation;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
|
|
/**
|
|
* @property AppVersionService $service
|
|
*/
|
|
class AppVersionController extends AdminController
|
|
{
|
|
protected string $serviceName = AppVersionService::class;
|
|
|
|
public function list(): Page
|
|
{
|
|
$crud = $this->baseCRUD()->tableLayout('fixed')
|
|
->headerToolbar([
|
|
$this->createTypeButton('drawer', 'lg')->visible(Admin::user()->can('admin.app_versions.create')),
|
|
amis('reload')->align('right'),
|
|
])
|
|
->bulkActions([])
|
|
->columns([
|
|
amis()->TableColumn('name', __('app_version.name')),
|
|
amis()->TableColumn('version', __('app_version.version')),
|
|
amis()->TableColumn('title', __('app_version.title')),
|
|
amis()->TableColumn('update_strategy', __('app_version.update_strategy'))->type('mapping')->map(AppUpdateStrategy::labelMap()),
|
|
amis()->TableColumn('is_force', __('app_version.is_force'))->type('static-mapping')->map([
|
|
'0' => '<span class="label label-success">否</span>',
|
|
'1' => '<span class="label label-danger">是</span>',
|
|
]),
|
|
amis()->TableColumn('os', __('app_version.os'))->type('mapping')->map(AppOs::labelMap()),
|
|
amis()->TableColumn('is_release', __('app_version.is_release'))->type('static-mapping')->map([
|
|
'0' => '<span class="label label-default">否</span>',
|
|
'1' => '<span class="label label-success">是</span>',
|
|
]),
|
|
amis()->TableColumn('release_at', __('app_version.release_at')),
|
|
amis()->TableColumn('created_at', __('admin.created_at'))->type('datetime'),
|
|
Operation::make()->label(__('admin.actions'))->buttons([
|
|
$this->rowEditTypeButton('drawer', 'lg')->visible(Admin::user()->can('admin.app_versions.update')),
|
|
$this->rowDeleteButton()->visible(Admin::user()->can('admin.app_versions.delete')),
|
|
$this->rowShowButton()->visible(Admin::user()->can('admin.app_versions.view')),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form($isEdit = false): Form
|
|
{
|
|
return $this->baseForm()->body([
|
|
amis()->TextControl('name', __('app_version.name'))
|
|
->placeholder(__('app_version.name'))
|
|
->required(),
|
|
amis()->NumberControl('version', __('app_version.version'))
|
|
->placeholder(__('app_version.version'))
|
|
->precision(0)
|
|
->required(),
|
|
amis()->TextControl('title', __('app_version.title'))
|
|
->placeholder(__('app_version.title'))
|
|
->required(),
|
|
amis()->TextareaControl('description', __('app_version.description'))
|
|
->placeholder(__('app_version.description'))
|
|
->minRows(10)
|
|
->required(),
|
|
amis()->RadiosControl('update_strategy', __('app_version.update_strategy'))
|
|
->options(AppUpdateStrategy::options())
|
|
->value(AppUpdateStrategy::Wgt->value)
|
|
->required(),
|
|
amis()->RadiosControl('is_force', __('app_version.is_force'))
|
|
->options([
|
|
['label' => '是', 'value' => true],
|
|
['label' => '否', 'value' => false],
|
|
])
|
|
->value(false)
|
|
->required(),
|
|
amis()->RadiosControl('os', __('app_version.os'))->options(AppOs::options())->value(AppOs::Android->value)->required(),
|
|
|
|
amis()->FileControl('android[wgt_url]', __('app_version.wgt_url'))
|
|
->accept('.wgt')
|
|
->useChunk(false)
|
|
->receiver($this->uploadFilePath().'?full-url=1')
|
|
->visibleOn('${AND(os == "'.AppOs::Android->value.'", update_strategy == "wgt")}'),
|
|
amis()->FileControl('android[apk_url]', __('app_version.apk_url'))
|
|
->accept('.apk')
|
|
->useChunk(false)
|
|
->receiver($this->uploadFilePath().'?full-url=1')
|
|
->visibleOn('${os == "'.AppOs::Android->value.'"}'),
|
|
|
|
amis()->FileControl('ios[wgt_url]', __('app_version.wgt_url'))
|
|
->accept('.wgt')
|
|
->useChunk(false)
|
|
->receiver($this->uploadFilePath().'?full-url=1')
|
|
->visibleOn('${AND(os == "'.AppOs::Ios->value.'", update_strategy == "wgt")}'),
|
|
amis()->TextControl('ios[apk_url]', '苹果应用地址')
|
|
->placeholder('苹果应用地址')
|
|
->visibleOn('${os == "'.AppOs::Ios->value.'"}'),
|
|
|
|
amis()->DateTimeControl('release_at', __('app_version.release_at'))
|
|
->valueFormat('YYYY-MM-DD HH:mm:ss')
|
|
->description('必须设置发布时间,才可更新'),
|
|
]);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
return $this->baseDetail()->body([
|
|
amis()->Property()->items([
|
|
['label' => __('app_version.name'), 'content' => '${name}'],
|
|
['label' => __('app_version.version'), 'content' => '${version}'],
|
|
['label' => __('app_version.os'), 'content' => amis()->Mapping()->name('os')->map(AppOs::labelMap())],
|
|
['label' => __('app_version.title'), 'content' => '${title}', 'span' => 3],
|
|
['label' => __('app_version.description'), 'content' => amis()->TextareaControl()->name('description')->static()->labelClassName('hidden'), 'span' => 3],
|
|
['label' => __('app_version.update_strategy'), 'content' => amis()->Mapping()->name('update_strategy')->map(AppUpdateStrategy::labelMap())],
|
|
[
|
|
'label' => __('app_version.is_force'),
|
|
'content' => amis()->Mapping()->name('${is_force}')->static()->map([
|
|
'0' => '<span class="label label-success">否</span>',
|
|
'1' => '<span class="label label-danger">是</span>',
|
|
]),
|
|
],
|
|
['label' => __('app_version.apk_url'), 'content' => amis()->Link()->href('${apk_url}')->body('下载')->blank()->visibleOn('${apk_url != null && apk_url != ""}')],
|
|
['label' => __('app_version.wgt_url'), 'content' => amis()->Link()->href('${wgt_url}')->body('下载')->blank()->visibleOn('${wgt_url != null && wgt_url != ""}')],
|
|
['label' => __('app_version.release_at'), 'content' => '${release_at}'],
|
|
['label' => __('app_version.created_at'), 'content' => '${created_at}'],
|
|
]),
|
|
]);
|
|
}
|
|
}
|