fixed pages
This commit is contained in:
parent
77197021cd
commit
7aa0a2047e
|
|
@ -51,7 +51,7 @@ class AdminRoleController extends Controller
|
|||
|
||||
|
||||
/**
|
||||
* 保存
|
||||
* 保存后台用户角色
|
||||
*
|
||||
* @param AdminRoleRequest $request
|
||||
* @return array
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Beike\Admin\Http\Controllers;
|
|||
|
||||
use Beike\Models\Page;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Beike\Shop\Http\Resources\PageDetail;
|
||||
use Illuminate\Http\Request;
|
||||
use Beike\Admin\Repositories\PageRepo;
|
||||
|
||||
|
|
@ -20,8 +21,10 @@ class PagesController
|
|||
{
|
||||
public function index()
|
||||
{
|
||||
$pageList = PageRepo::getList();
|
||||
$data = [
|
||||
'pages' => PageRepo::getList()
|
||||
'pages' => $pageList,
|
||||
'pages_format' => PageDetail::collection($pageList)->jsonSerialize()
|
||||
];
|
||||
return view('admin::pages.pages.index', $data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,19 +13,23 @@ namespace Beike\Admin\Repositories;
|
|||
|
||||
use Beike\Models\Page;
|
||||
use Beike\Models\Product;
|
||||
use Beike\Shop\Http\Resources\PageDetail;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class PageRepo
|
||||
{
|
||||
/**
|
||||
* 获取列表页数据
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public static function getList(): LengthAwarePaginator
|
||||
{
|
||||
return Page::query()->with([
|
||||
$builder = Page::query()->with([
|
||||
'description'
|
||||
])->paginate();
|
||||
])->orderByDesc('created_at');
|
||||
|
||||
return $builder->paginate();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -374,12 +374,11 @@ function quantity_format($quantity)
|
|||
*/
|
||||
function json_success($message, $data = []): array
|
||||
{
|
||||
$result = [
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -387,12 +386,30 @@ function json_success($message, $data = []): array
|
|||
*/
|
||||
function json_fail($message, $data = []): array
|
||||
{
|
||||
$result = [
|
||||
return [
|
||||
'status' => 'fail',
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!function_exists('sub_string')) {
|
||||
/**
|
||||
* @param $string
|
||||
* @param int $length
|
||||
* @param string $dot
|
||||
* @return string
|
||||
*/
|
||||
function sub_string($string, int $length = 16, string $dot = '...'): string
|
||||
{
|
||||
$strLength = strlen($string);
|
||||
if ($length <= 0) {
|
||||
return $string;
|
||||
} elseif ($strLength <= $length) {
|
||||
return $string;
|
||||
}
|
||||
return mb_substr($string, 0, $length) . $dot;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ class PageDetail extends JsonResource
|
|||
$description = $this->description;
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'active' => $this->active,
|
||||
'title' => $description->title,
|
||||
'title_format' => sub_string($description->title),
|
||||
'content' => $description->content,
|
||||
'meta_title' => $description->meta_title,
|
||||
'meta_description' => $description->meta_description,
|
||||
|
|
|
|||
|
|
@ -20,16 +20,16 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($pages as $page)
|
||||
@foreach ($pages_format as $page)
|
||||
<tr>
|
||||
<td>{{ $page->id }}</td>
|
||||
<td>{{ $page->description->title ?? '' }}</td>
|
||||
<td>{{ $page->active }}</td>
|
||||
<td>{{ $page->created_at }}</td>
|
||||
<td>{{ $page->updated_at }}</td>
|
||||
<td>{{ $page['id'] }}</td>
|
||||
<td>{{ $page['title_format'] ?? '' }}</td>
|
||||
<td>{{ $page['active'] }}</td>
|
||||
<td>{{ $page['created_at'] }}</td>
|
||||
<td>{{ $page['updated_at'] }}</td>
|
||||
<td class="text-end">
|
||||
<a href="{{ admin_route('pages.edit', [$page->id]) }}" class="btn btn-outline-secondary btn-sm">编辑</a>
|
||||
<form action="{{ admin_route('pages.destroy', [$page->id]) }}" method="post" class="d-inline-block">
|
||||
<a href="{{ admin_route('pages.edit', [$page['id']]) }}" class="btn btn-outline-secondary btn-sm">编辑</a>
|
||||
<form action="{{ admin_route('pages.destroy', [$page['id']]) }}" method="post" class="d-inline-block">
|
||||
{{ method_field('delete') }}
|
||||
{{ csrf_field() }}
|
||||
<button class="btn btn-outline-danger btn-sm">删除</button>
|
||||
|
|
@ -41,6 +41,7 @@
|
|||
</table>
|
||||
|
||||
{{ $pages->links('admin::vendor/pagination/bootstrap-4') }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Reference in New Issue