|
@@ -6,6 +6,7 @@ use App\Distributor\Repositories\SitePages;
|
|
|
use App\Models\SitePages as Model;
|
|
|
use App\Distributor\Repositories\SitePagesTag;
|
|
|
use App\Libraries\CommonHelper;
|
|
|
+use DateTime;
|
|
|
use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Grid;
|
|
|
use Dcat\Admin\Models\Permission;
|
|
@@ -13,18 +14,24 @@ use Dcat\Admin\Show;
|
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
use Dcat\Admin\Layout\Content;
|
|
|
use Dcat\Admin\Admin;
|
|
|
+use Dcat\Admin\Widgets\Form as widgetsForm;
|
|
|
|
|
|
class SitePagesController extends AdminDistController
|
|
|
{
|
|
|
+ public function title()
|
|
|
+ {
|
|
|
+ return admin_trans( 'admin.pages');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* page index
|
|
|
*/
|
|
|
public function index(Content $content)
|
|
|
{
|
|
|
return $content
|
|
|
- ->header('列表')
|
|
|
- ->description('全部')
|
|
|
- ->breadcrumb(['text'=>'列表','url'=>''])
|
|
|
+ ->header(admin_trans( 'admin.pages'))
|
|
|
+ ->description('')
|
|
|
+ ->breadcrumb(['text'=>'','url'=>''])
|
|
|
->body($this->grid());
|
|
|
}
|
|
|
|
|
@@ -35,13 +42,6 @@ class SitePagesController extends AdminDistController
|
|
|
*/
|
|
|
protected function grid()
|
|
|
{
|
|
|
- // 检查是否支持 pcntl 扩展
|
|
|
- if (!function_exists('pcntl_fork')) {
|
|
|
- die('pcntl_fork() is not available on this system.');
|
|
|
- } else {
|
|
|
- die('pcntl_fork() supported on this system.');
|
|
|
- }
|
|
|
- exit;
|
|
|
return Grid::make(SitePages::with(['pagesTag']), function (Grid $grid) {
|
|
|
$grid->column('id')->sortable();
|
|
|
$grid->column('title');
|
|
@@ -51,7 +51,13 @@ class SitePagesController extends AdminDistController
|
|
|
$dataImages = [$image];
|
|
|
return CommonHelper::displayImage($dataImages,100);
|
|
|
});
|
|
|
- $grid->column('post_date');
|
|
|
+ //发布日期
|
|
|
+ $grid->column('post_date')->display(function ($date) {
|
|
|
+ $dateTime = new DateTime($date);
|
|
|
+ $date = $dateTime->format('Y-m-d');
|
|
|
+ return $date;
|
|
|
+ });
|
|
|
+ //状态
|
|
|
$grid->column('status')->using(config('dictionary.pages_status'));
|
|
|
$grid->column('updated_at')->sortable();
|
|
|
$grid->column('created_at');
|
|
@@ -82,7 +88,11 @@ class SitePagesController extends AdminDistController
|
|
|
return array_column($pagesTag,'name');
|
|
|
})->label();
|
|
|
$show->field('author');
|
|
|
- $show->field('post_date');
|
|
|
+ $show->field('post_date')->as(function ($date) {
|
|
|
+ $dateTime = new DateTime($date);
|
|
|
+ $date = $dateTime->format('Y-m-d');
|
|
|
+ return $date;
|
|
|
+ });
|
|
|
$show->field('cover_image')->as(function ($image) {
|
|
|
// 开始生成 HTML
|
|
|
$dataImages = [$image];
|
|
@@ -122,14 +132,34 @@ class SitePagesController extends AdminDistController
|
|
|
->dir('images/pages/'.date("Ymd"));
|
|
|
$form->editor('content')->required();
|
|
|
$form->switch('status',admin_trans_label('publish'))->default(1);
|
|
|
- $form->hidden('slug');
|
|
|
- $form->hidden('dist_id');
|
|
|
- //保存前,强制写死dist_id
|
|
|
+ //SEO
|
|
|
+ $form->radio('visibility')->when(1,function (Form $form) {
|
|
|
+ $form->text('seo_title');
|
|
|
+ $form->text('seo_keywords');
|
|
|
+ $form->textarea('seo_description');
|
|
|
+ $form->text('slug',admin_trans_label('url_and_handle'))->width(4, 2)->prepend(getSiteDomain().config('dictionary.site_url.pages'));
|
|
|
+ })->options(config('dictionary.visibility'))->default(1)->value(1);
|
|
|
+ //隐藏字段
|
|
|
+ $form->hidden('dist_id',);
|
|
|
+ $form->ignore(['visibility']);
|
|
|
+ //新建时插入JS
|
|
|
+ $form->creating(function (Form $form) {
|
|
|
+ CommonHelper::seoReplace();
|
|
|
+ });
|
|
|
+ //保存前
|
|
|
$form->saving(function (Form $form) {
|
|
|
- //$form->pagesTag = [1,2];
|
|
|
+ //强制写死dist_id
|
|
|
$form->dist_id = getDistributorId();
|
|
|
- //生成slug
|
|
|
- if ($form->isCreating()) {
|
|
|
+ //slug配置是否重复
|
|
|
+ $id = $form->getKey();
|
|
|
+ if ($form->slug != '') {
|
|
|
+ if (SitePages::isRepeatedSlug($id, $form->slug)) {
|
|
|
+ //slug重复
|
|
|
+ return $form->response()->error(admin_trans_label('url_repeated'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当slug为空时生成slug
|
|
|
+ if ($form->slug == '') {
|
|
|
$form->slug = SitePages::generateSlug($form->title);
|
|
|
}
|
|
|
});
|