refactor: 进一步区分banner的pc与mobile

This commit is contained in:
2025-05-27 14:02:14 +08:00
parent 9c215476f9
commit 9787c9b3e3
5 changed files with 47 additions and 9 deletions

View File

@@ -2,9 +2,9 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 模板设置 // | 模板设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
$view_deivce_name = 'pc'; $view_device_name = 'pc';
if (request()->isMobile()) { if (request()->isMobile()) {
$view_deivce_name = 'mobile'; $view_device_name = 'mobile';
} }
return [ return [
@@ -13,7 +13,7 @@ return [
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法 // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1, 'auto_rule' => 1,
// 模板目录名 // 模板目录名
'view_dir_name' => "view/{$view_deivce_name}", 'view_dir_name' => "view/{$view_device_name}",
// 模板后缀 // 模板后缀
'view_suffix' => 'html', 'view_suffix' => 'html',
// 模板文件名分隔符 // 模板文件名分隔符
@@ -28,8 +28,8 @@ return [
'taglib_end' => '}', 'taglib_end' => '}',
// 模板输出替换 // 模板输出替换
'tpl_replace_string' => [ 'tpl_replace_string' => [
'__CSS__' => "/static/index/{$view_deivce_name}/css", '__CSS__' => "/static/index/{$view_device_name}/css",
'__JS__' => "/static/index/{$view_deivce_name}/js", '__JS__' => "/static/index/{$view_device_name}/js",
'__IMAGES__' => "/static/index/{$view_deivce_name}/images", '__IMAGES__' => "/static/index/{$view_device_name}/images",
] ]
]; ];

View File

@@ -54,11 +54,12 @@ class Index extends Common
$banners = SysBannerModel::with(['items' => function($query) { $banners = SysBannerModel::with(['items' => function($query) {
$query->where('type', 'IN', ['image', 'video'])->where('status', '=', 1)->order(['sort' => 'asc', 'id' => 'desc']); $query->where('type', 'IN', ['image', 'video'])->where('status', '=', 1)->order(['sort' => 'asc', 'id' => 'desc']);
}]) }])
->atPlatform(request()->from)
->uniqueLabel([ ->uniqueLabel([
'BANNER_67f61cd70e8e1', 'BANNER_67f61cd70e8e1',
'BANNER_67f633023a5b3', 'BANNER_67f633023a5b3',
'BANNER_67f63f8ab5029', 'BANNER_67f63f8ab5029',
'BANNER_67f724ed81b1e', 'BANNER_67f724ed81b1e',
'BANNER_67f7392b4d83a', 'BANNER_67f7392b4d83a',
'BANNER_67f7410e244fb', 'BANNER_67f7410e244fb',
'BANNER_67f76a96545f9', 'BANNER_67f76a96545f9',

View File

@@ -3,4 +3,6 @@
return [ return [
// 启用多语言支持 // 启用多语言支持
think\middleware\LoadLangPack::class, think\middleware\LoadLangPack::class,
// 确认请求来源
app\index\middleware\ConfirmRequestFrom::class,
]; ];

View File

@@ -0,0 +1,25 @@
<?php
declare (strict_types = 1);
namespace app\index\middleware;
class ConfirmRequestFrom
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
// 确认请求来源
$request->from = 'pc';
if ($request->isMobile()) {
$request->from = 'mobile';
}
return $next($request);
}
}

View File

@@ -23,6 +23,16 @@ class SysBannerModel extends SysBannerBaseModel
return $this->hasMany(SysBannerItemModel::class, 'banner_id', 'id'); return $this->hasMany(SysBannerItemModel::class, 'banner_id', 'id');
} }
// 所属平台范围查询
public function scopeAtPlatform($query, string|array $platform)
{
if (is_array($platform)) {
$query->whereIn('at_platform', $platform);
return;
}
$query->where('at_platform', '=', $platform);
}
// 唯一标识范围查询 // 唯一标识范围查询
public function scopeUniqueLabel($query, string|array $unique_label) public function scopeUniqueLabel($query, string|array $unique_label)
{ {