소스 검색

RPC调用相册系统

moshaorui 1 개월 전
부모
커밋
865a780b59
4개의 변경된 파일110개의 추가작업 그리고 76개의 파일을 삭제
  1. 1 0
      app/Admin/Repositories/RpcAlbum.php
  2. 107 74
      app/Distributor/Controllers/SiteAlbumController.php
  3. 1 0
      lang/en/global.php
  4. 1 2
      lang/zh_CN/global.php

+ 1 - 0
app/Admin/Repositories/RpcAlbum.php

@@ -63,6 +63,7 @@ class RpcAlbum extends EloquentRepository
         ]);
 
 
+
         $data = $result['data'] ?? [];
 
         return $model->makePaginator(

+ 107 - 74
app/Distributor/Controllers/SiteAlbumController.php

@@ -63,6 +63,7 @@ class SiteAlbumController extends AdminController
         //相册分类
         $rpcAlbumFolder = RpcAlbumFolder::selectOptions();
         return Grid::make(new RpcAlbum(), function (Grid $grid) use ($rpcAlbumFolder) {
+            $lang = config('app.locale');//当前语言
             $grid->view('admin.grid.table');
             $grid->column('id')->display(function () {
                 return $this->_index+1;
@@ -73,7 +74,11 @@ class SiteAlbumController extends AdminController
                 $dataImages = array_slice($images, 0, 1);
                 return CommonHelper::displayImage($dataImages,100);
             });
-            $grid->column('title');
+            if ($lang == 'en') {
+                $grid->column('title_en');
+            } else {
+                $grid->column('title');
+            }
             $grid->column('model');
             $grid->column('updated_at')->sortable();
             // 筛选
@@ -106,81 +111,109 @@ class SiteAlbumController extends AdminController
     protected function detail($id)
     {
         return Show::make($id, new RpcAlbum(), function (Show $show) {
-            $show->field('title');
-            $show->field('model');
-            $show->field('parameters',admin_trans_label('attribute'))->as(function ($items) {
-                $items = json_decode($items);
-                if (is_array($items)) {
-                    // 创建表格的表头
-                    $table = '<table class="table table-bordered table-condensed">';
-                    // 遍历数组并将数据填充到表格中
-                    foreach ($items as $item) {
-                        $item = (array)$item;
-                        $table .= '<tr>';
-                        $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>';    // 商品名称
-                        $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
-                        $table .= '</tr>';
+            $lang = config('app.locale');//当前语言
+            //名称
+            if ($lang == 'en') {
+                $show->field('title');
+            } else {
+                $show->field('title_en');
+            }
+            //型号
+            if ($show->model()->model) {
+                $show->field('model');
+            }
+
+            //属性
+            if ($show->model()->parameters) {
+                $show->field('parameters', admin_trans_label('attribute'))->as(function ($items) {
+                    $items = json_decode($items);
+                    if (is_array($items)) {
+                        // 创建表格的表头
+                        $table = '<table class="table table-bordered table-condensed">';
+                        // 遍历数组并将数据填充到表格中
+                        foreach ($items as $item) {
+                            $item = (array)$item;
+                            $table .= '<tr>';
+                            $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>';    // 商品名称
+                            $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
+                            $table .= '</tr>';
+                        }
+                        $table .= '</table>';
+                        return $table;
                     }
-                    $table .= '</table>';
-                    return $table;
-                }
-                return ''; // 当没有数组数据时
-            })->unescape();
-
-            $show->field('cover')->as(function ($images) {
-                $images = json_decode($images);
-                return CommonHelper::displayImage($images,150);
-            })->unescape();
-
-            $show->field('en_detail')->as(function ($images) {
-                $images = json_decode($images);
-                $html = '<div style="text-align: center">';
-                foreach ($images as $key => $image) {
-                    $url = CommonHelper::ossUrl($image);
-                    $html .= '<img src="' . $url . '" style="max-width:90%;margin-bottom:10px">';
-                }
-                $html .= '</div>';
-                return $html;
-            })->unescape();
-
-            $show->field('video')->as(function ($items) {
-                $items = json_decode($items);
-                return CommonHelper::displayVideo($items,'cover','video_src','150');
-            })->unescape();
-
-            $show->field('poster')->as(function ($images) {
-                $images = json_decode($images);
-                return CommonHelper::displayImage($images,150);
-            })->unescape();
-
-            $show->field('cert')->as(function ($images) {
-                $images = json_decode($images);
-                return CommonHelper::displayImage($images,150);
-            })->unescape();
-
-            $show->field('cert')->as(function ($images) {
-                $images = json_decode($images);
-                return CommonHelper::displayImage($images,150);
-            })->unescape();
-
-            $show->field('pdf')->as(function ($items) {
-                $items = json_decode($items);
-                if (is_array($items)) {
-                    // 创建表格的表头
-                    $table = '<table class="table table-bordered table-condensed">';
-                    // 遍历数组并将数据填充到表格中
-                    foreach ($items as $item) {
-                        $table .= '<tr>';
-                        $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item->pdf_title . '</td>';    // 商品名称
-                        $table .= '<td style="vertical-align: middle !important;"><a target="_blank" href="' . CommonHelper::ossUrl($item->pdf_src). '">查看</a></td>'; // 数量
-                        $table .= '</tr>';
+                    return ''; // 当没有数组数据时
+                })->unescape();
+            }
+
+            //封面
+            if (empty($show->model()->cover) == false && $show->model()->cover!= '[]') {
+                $show->field('cover')->as(function ($images) {
+                    $images = json_decode($images);
+                    return CommonHelper::displayImage($images,150);
+                })->unescape();
+            }
+            //详情
+            if (empty($show->model()->en_detail) == false && $show->model()->en_detail!= '[]') {
+                $show->field('en_detail')->as(function ($images) {
+                    $images = json_decode($images);
+                    $html = '<div style="text-align: center">';
+                    foreach ($images as $key => $image) {
+                        $url = CommonHelper::ossUrl($image);
+                        $html .= '<img src="' . $url . '" style="max-width:90%;margin-bottom:10px">';
                     }
-                    $table .= '</table>';
-                    return $table;
-                }
-                return ''; // 当没有数组数据时
-            })->unescape();
-
+                    $html .= '</div>';
+                    return $html;
+                })->unescape();
+            }
+            //视频
+            if (empty($show->model()->video) == false && $show->model()->video!= '[]') {
+                $show->field('video')->as(function ($items) {
+                    $items = json_decode($items);
+                    //倒序
+                    $items = array_reverse($items);
+                    return CommonHelper::displayVideo($items,'cover','video_src','150');
+                })->unescape();
+            }
+            //海报
+            if (empty($show->model()->poster) == false && $show->model()->poster!= '[]') {
+                $show->field('poster')->as(function ($images) {
+                    $images = json_decode($images);
+                    return CommonHelper::displayImage($images,150);
+                })->unescape();
+            }
+            //证书
+            if (empty($show->model()->cert) == false && $show->model()->cert != '[]') {
+                $show->field('cert')->as(function ($images) {
+                    $images = json_decode($images);
+                    return CommonHelper::displayImage($images,150);
+                })->unescape();
+            }
+            //PDF
+            if (empty($show->model()->pdf) == false && $show->model()->pdf != '[]') {
+                $show->field('pdf')->as(function ($items) use ($lang) {
+                    $items = json_decode($items);
+                    if (is_array($items)) {
+                        //倒序
+                        $items = array_reverse($items);
+                        // 创建表格的表头
+                        $table = '<table class="table table-bordered table-condensed">';
+                        // 遍历数组并将数据填充到表格中
+                        foreach ($items as $item) {
+                            $pdf_title = $item->pdf_title;
+                            if ($lang == 'en') {
+                                $pdf_title = $item->pdf_title_en;
+                            }
+                            $table .= '<tr>';
+                            $table .= '<td style="vertical-align: middle !important;width: 20%">' . $pdf_title . '</td>';    // 商品名称
+                            $table .= '<td style="vertical-align: middle !important;"><a target="_blank" href="' . CommonHelper::ossUrl($item->pdf_src). '">查看</a></td>'; // 数量
+                            $table .= '</tr>';
+                        }
+                        $table .= '</table>';
+                        return $table;
+                    }
+                    return ''; // 当没有数组数据时
+                })->unescape();
+            }
             // 禁用操作
             $show->disableEditButton();
             $show->disableDeleteButton();

+ 1 - 0
lang/en/global.php

@@ -105,6 +105,7 @@ return [
         'pdf_title'             => 'PDF Title',
         'pdf_src'               => 'PDF Src',
         'video_src'             => 'Video Src',
+        'title_en'              => 'Title',
     ],
     'labels' => [
         'list'                  => 'List',

+ 1 - 2
lang/zh_CN/global.php

@@ -111,8 +111,7 @@ return [
         'pdf_title'             => 'PDF标题',
         'pdf_src'               => 'PDF文件',
         'video_src'             => '视频文件',
-
-
+        'title_en'              => '标题',
     ],
     'labels' => [
         'list'         => '列表',